Skip to main content

PlayerInteractionRestrictor

A class in Root.Township, the global namespace.

Limits how many times each player can use something per in-game day, such as taking from CommunalStorage. The limit is scaled by the server's CommunityStorageMultiplier; PlayerInteractionManager does the tracking.

Constructors​

MemberWhat it is
PlayerInteractionRestrictor()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

4 private and internal fields
MemberWhat it is
private bool acceptsRefundsIf false, RefundInteractions does nothing.
private int idTracker ID in PlayerInteractionManager, saved with the entity. -1 until the server assigns one.
private int interactionsPerChargeBase number of interactions per charge, before the server's storage multiplier. Saved.
private MethodSync syncIDMethod sync on SyncC for the tracker ID and charge size.

Properties​

MemberWhat it is
int InteractionsPerCharge { get; }Unscaled uses per day. Clients receive the scaled number instead.

Events​

MemberWhat it is
event Action AllowanceUpdatedFired when this restrictor's per-player allowance changes.

Methods​

MemberWhat it is
int CheckAvailableInteractions(IPlayer player)Uses the player has left today.
override void Initialize()Sets up the id sync and listens for allowance changes.
override void InitializeAsServer(SpawnData spawnData)Server: gets or refreshes its tracker id with the scaled charge count, and resyncs when server settings change.
int Interact(Player player, int interactions = 1)Server: uses up to that many charges and returns how many were used. On clients it only returns what is left.
int InteractFull(Player player)Uses a whole charge's worth of interactions.
override void OnConnected(Player player)Server: sends the id and charge count to a joining player.
void RefundInteractions(Player player, int refund)Server: gives uses back, if this restrictor accepts refunds.
6 private and internal methods
MemberWhat it is
private void CheckUpdated(int id)Fires AllowanceUpdated when the manager updates the tracker with this restrictor's ID.
private void DestroyClean(NetworkEntity entity, bool isUnload)Server: unhooks from server settings changes when the entity is destroyed.
private void OnAllowanceUpdated()Fires AllowanceUpdated.
private void OnDestroy()Unhooks from PlayerInteractionManager events.
private void SettingsChanged(Settings obj)Server: reapplies the charge size with the new CommunityStorageMultiplier and resyncs it.
private void SyncID(IPlayer player, Stream stream)Method sync sending the tracker ID and the charge size scaled by the server's CommunityStorageMultiplier. Remote clients apply them.

Used in​

Members of other types that take, return or hold a PlayerInteractionRestrictor: