PlayerInteractionManager
A class in Root.Township, the global namespace.
Server-owned, saved per-player charge counters for limited interactions ("you can take 3 of these"), reset daily at a set time of day. Get it with the static instance.
- Listed in Global namespace: P
- Inherits or implements
NetworkEntityBehaviour,ISavable<PlayerInteractionManagerData>,ISavableSave<PlayerInteractionManagerData>,ISavableSaveBase - Derived types
PlayerInteractionManagerData - Nested types
Tracker - Documented in Items, interaction and damage
Constructors
| Member | What it is |
|---|---|
PlayerInteractionManager() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
static PlayerInteractionManager instance | The last created manager, set in Awake. |
const int maxIDs | 2048, the ID range the sync messages can carry. |
8 private and internal fields
| Member | What it is |
|---|---|
private Dictionary<int, int> chargesPerId | Starting charges for each registered id. |
private static Logger logger | NLog logger for this class. |
private int nextID | Next id GetId will hand out. Saved. |
private float oldInteractionMultiplier | Last seen community storage multiplier, to spot changes. |
private Dictionary<int, Dictionary<int, PlayerInteractionManager.Tracker>> playersTrackers | Trackers by user id, then by interaction id. Saved, and cleared once per game day. |
private MethodSyncStruct<bool> syncFull | Method sync for a full or clear update. |
private MethodSyncClass<PlayerInteractionManager.Tracker> syncMarker | Method sync for one tracker. |
private float timeOfDayToRefresh | Time of day (0 to 1) when all trackers reset. |
Events
| Member | What it is |
|---|---|
event Action UpdatedAllTrackers | Raised when all counters are cleared. |
event Action<int> UpdatedTracker | Raised with the ID when one counter changes for the local player. |
Methods
| Member | What it is |
|---|---|
int CheckAvailableInteractions(IPlayer player, int id) | Charges the player has left for an ID, or the full charge count if they have not used it yet. |
void ClearTrackers() | Resets every player's counters and tells clients. Runs daily, when the community storage multiplier setting changes, and from a progress console command. |
int GetId(int charges) | Registers a new counter ID with its charge count and returns the ID. |
override void Initialize() | Sets up the full sync and single counter sync messages. |
override void InitializeAsServer(SpawnData spawnData) | Server: schedules the daily reset and watches the server's community storage multiplier. |
int Interact(Player player, int id, int interactions = 1) | Server: uses up to interactions charges and returns how many were used. On a client it only returns the charges left. |
override void OnConnected(Player player) | Server: sends the joining player their counters. |
void Refund(Player player, int id, int refund) | Server: gives charges back to a player for an ID. |
void SetCharges(int id, int charges) | Changes the charge count of a registered ID. Players who already have a counter keep theirs. |
5 private and internal methods
| Member | What it is |
|---|---|
private void Awake() | Sets the static instance. |
private bool GetTracker(Player player, int id, out PlayerInteractionManager.Tracker tracker) | Server: gets or creates a player's tracker for an id, starting with that id's registered charges. False if the id isn't registered. |
private void SettingsChanged(Settings obj) | Server: clears all trackers when the community storage multiplier changes. |
private void SyncFull(IPlayer player, Stream stream, bool isClear) | Sends a clear to everyone, or a player's whole tracker list on connect. Client: applies it. |
private void SyncMarker(IPlayer player, Stream stream, PlayerInteractionManager.Tracker arguments) | Sends one tracker's id and charges left. Client: stores it under the logged-in user and raises UpdatedTracker. |