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.
- Listed in Global namespace: P
- Inherits or implements
NetworkEntityBehaviour,ISavable<PlayerInteractionRestrictorData>,ISavableSave<PlayerInteractionRestrictorData>,ISavableSaveBase - Derived types
PlayerInteractionRestrictorData - Documented in Items, interaction and damage
Constructors
| Member | What it is |
|---|---|
PlayerInteractionRestrictor() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
4 private and internal fields
| Member | What it is |
|---|---|
private bool acceptsRefunds | If false, RefundInteractions does nothing. |
private int id | Tracker ID in PlayerInteractionManager, saved with the entity. -1 until the server assigns one. |
private int interactionsPerCharge | Base number of interactions per charge, before the server's storage multiplier. Saved. |
private MethodSync syncID | Method sync on SyncC for the tracker ID and charge size. |
Properties
| Member | What it is |
|---|---|
int InteractionsPerCharge { get; } | Unscaled uses per day. Clients receive the scaled number instead. |
Events
| Member | What it is |
|---|---|
event Action AllowanceUpdated | Fired when this restrictor's per-player allowance changes. |
Methods
| Member | What 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
| Member | What 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: