Skip to main content

CommunalStorage

A class in Root.Township, Alta.Inventory.

A shared storage dock that players take from by holding an interactable, limited by a PlayerInteractionRestrictor allowance. Its stock survives server wipes through GlobalCommunalStorageValues. Server runs it; clients show the allowance.

Constructors​

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

Fields​

9 private and internal fields
MemberWhat it is
private PickupDock filterDockDock holding a sample item that decides what the internal dock accepts.
private LongHoldInteractable[] interactablesHold interactables players use to take items.
private PlayerInteractionRestrictor interactionRestrictorTracks how many items each player may still take.
private PickupDock internalDockThe dock that holds the stock.
private bool isNotUniqueTrue when there is no unique identifier, so pre-wipe stock is saved and loaded by item instead.
private TextRenderer localAllowanceText that shows the local player's remaining allowance.
private static Logger loggerLogger for this class.
private int refundQuantityHow much allowance the next refund gives back; set to a pouch's contents when a pouch is docked.
private CommunalStorageUniqueIdentifier uniqueIdentifierIdentifier used to save and load this storage's stock across wipes; saved with the entity.

Methods​

MemberWhat it is
void FillUp()Server: fills the internal dock to 150 items, spawning one from the filter dock's item if empty. Used by a progress console command.
override void Initialize()Client: hooks dock and allowance changes to update the allowance text.
override void InitializeAsServer(SpawnData spawnData)Server: hooks short and long holds to the grab methods, refunds on docking, starts DelayLoad and marks the chunk for pre-wipe work.
10 private and internal methods
MemberWhat it is
private void Awake()Adds the interaction filter to each hold interactable and, if there is a filter dock, a dock filter to the internal dock.
private async void DelayLoad()Server: loads the stock saved before a wipe for this storage's unique identifier and adds it to the internal dock.
private void DockFilter(Interactor interactor, Pickup pickup, ref bool result)Only lets items into the internal dock if the filter dock would accept them.
private void FilterInteraction(Interactor interactor, Interactable interactable, ref bool result)Blocks taking when the dock is empty or the player has no allowance left.
private void GrabAll(Interactor interactor)Server, on long hold: takes as many items as the allowance and pouch limit allow and puts them in the player's hand.
private void GrabSingle(Interactor interactor)Server, on short hold: uses one allowance and puts one item in the player's hand.
private void MarkChunk(Chunk chunk)Marks the entity's chunk as needing a pre-wipe operation so WipeOperation runs.
private async void Refund(Interactor interactor, Pickup pickup, PickupDock dock)When an item is docked back, gives the player's allowance back (for a pouch, its whole contents) and adds any pre-wipe stock saved for it.
private void UpdateAllowance()Shows how many items the local player can still take, or clears the text when empty.
private void IOperateOnWipe.WipeOperation()Before a wipe, saves the stored quantity globally by unique identifier, or by item if the storage has none.