PostboxSender
A class in Root.Township, the global namespace.
The machine for mailing items to a friend. The player pays coins into costDock, docks items in sendingDocks, picks a friend and pulls the handle; the server packs the items into a gift and pushes it into the friend's postbox.
- Listed in Global namespace: P
- Inherits or implements
NetworkEntityBehaviour - Nested types
EffectType - Documented in Trading
Constructors
| Member | What it is |
|---|---|
PostboxSender() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
21 private and internal fields
| Member | What it is |
|---|---|
private TransformHandler coinInsertEffect | Effect played at the coin dock when coins go in. |
private PickupDock costDock | The dock that holds the coins paid for sending. |
private int currentPlayerIdentifier | Identifier of the player using the machine, or 0 when free. |
private FriendSelector friendSelector | Picks the friend the items go to. |
private Distribution giftPrefabDistribution | Random choice of gift prefab that wraps the sent items. |
private PlayerUnityEvent gotPlayer | Event fired when a player takes ownership of the machine. |
private Interactable handle | The handle the player pulls to send. |
private bool isOpen | True while enough coins are paid for at least one dock. |
private bool isSending | True while a send is in progress, so only one runs at a time. |
private AltaEvent lostPlayer | Event fired when the owner releases the machine. |
private TransformHandler rejectEffect | Effect played where rejected items are thrown out. |
private Transform rejectPosition | Where rejected coins and items are undocked to. |
private Interactable[] restrictions | Interactables only the current owner may use. |
private TransformHandler sendEffect | Effect played when a gift is sent. |
private Transform sendEffectPosition | Where the send effect plays. |
private int sendingCostPerDock | Coins needed for each filled sending dock. |
private PickupDock[] sendingDocks | The docks for items to send. Dock N needs N times sendingCostPerDock coins paid. |
private MethodSyncStruct<int> syncEffect | Message that tells clients which effect to play. |
private MethodSync syncPlayer | Message that syncs the current owner. |
private MethodSyncStruct<int> syncSend | Message a client sends to ask the server to send to a friend. |
private BoolUnityEvent updatedOpenState | Event fired with the new open state when it changes. |
Methods
| Member | What it is |
|---|---|
void CheckSend() | Sends to the friend picked in friendSelector, if the local player owns the machine. Runs directly on the server, otherwise asks the server. |
void CloseForPlayer(IPlayer player) | Releases the machine if this player owns it: clears the docks and syncs the change. |
override void Initialize() | Creates the send, owner and effect sync messages. |
override void InitializeAsServer(SpawnData spawnData) | Server: clears the docks on the next frame and hooks coin dock changes to ownership and state updates. |
13 private and internal methods
| Member | What it is |
|---|---|
private void Awake() | Hooks the interaction filters on the restricted interactables, the handle, the sending docks and the coin dock. |
private void Clear() | Server: throws everything in the coin dock and sending docks out at rejectPosition. |
private void FilterCoins(Interactor interactor, Pickup pickup, ref bool result) | Dock filter: only accepts coins from a known player, and only from the current owner once there is one. |
private void FilterHandleInteraction(Interactor interactor, Interactable interactable, ref bool result) | Interaction filter: blocks the handle until at least one dock's worth of coins is paid. |
private void FilterInteractions(Interactor interactor, Interactable interactable, ref bool result) | Interaction filter for restrictions: only the current owner may use them. |
private void PlayEffect(PostboxSender.EffectType effectType) | Plays the coin, reject or send effect locally (not on headless) and, on the server, tells nearby clients to play it too. |
private async void Send(int from, int to) | Server: packs the docked items (limited by what the sender may still send to that friend) into a random gift prefab, takes the coins and pushes the gift into the receiver's postbox. |
private void SetupForPlayer(IPlayer player) | Server: makes this player the owner, fires gotPlayer and syncs the owner. |
private void SyncEffect(IPlayer player, Stream stream, int effectIndex) | Serializes an effect index; remote clients play that effect. |
private void SyncPlayer(IPlayer player, Stream stream) | Serializes the current owner's player identifier. |
private void SyncSend(IPlayer player, Stream stream, int toIdentifier) | Serializes a send request; the server runs Send if the requester is the owner. |
private void UpdateOwnership(Interactor interactor, Pickup pickup, PickupDock dock) | Server: when a coin is docked with no owner yet, makes the coin's player the owner, then plays the coin effect. |
private void UpdateState() | Server: opens or closes the machine as the coin count crosses one dock's cost, and rejects items from docks that aren't paid for. |