ATMMachine
A class in Root.Township, the global namespace.
A bank teller machine. The server loads the owning player's bank coins into its docks; while it's open the bank balance is the coins in the teller, and it saves back when the owner changes or it closes.
- Listed in Global namespace: A to B
- Inherits or implements
NetworkEntityBehaviour - Documented in Trading
Constructors
| Member | What it is |
|---|---|
ATMMachine() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
8 private and internal fields
| Member | What it is |
|---|---|
private PickupDock baseDock | The teller dock holding the owner's coins. |
private PickupDock depositDock | Slot where the owner drops coins to deposit. |
private bool inverseThrottleInteraction | If true (default), throttle movement is reversed. |
private static Logger logger | NLog logger for this class. |
private int owner | User ID of the owner; 0 for none. |
private MethodSync syncOwner | Method sync for the owner. |
private Interactable throttleInteractable | Lever that moves coins in and out of the withdraw slot. |
private PickupDock withdrawDock | Slot coins are taken out from. |
Properties
| Member | What it is |
|---|---|
int QuantityInTeller { get; } | Coins in the teller plus the withdraw slot; this is the owner's balance while open. |
Methods
| Member | What it is |
|---|---|
async void ChangePlayer(IPlayer player) | Server: saves the previous owner's balance, clears the docks, then loads the new player's coins (or no owner for null). |
void Close() | Saves and clears the machine with no owner. |
override void Initialize() | Hooks the owner and deposit filters and creates the owner sync. |
override void InitializeAsServer(SpawnData spawnData) | Server: hooks deposits. |
void MoveToFromWithdraw(int movement) | Server: moves coins between the teller and the withdraw slot by an amount, sign flipped if inverseThrottleInteraction. |
override void OnConnected(Player player) | Sends the owner to the chunk. |
void UpdateWhileActive(int value) | Called when the bank balance is set while open: adds or removes coins so the teller matches. |
13 private and internal methods
| Member | What it is |
|---|---|
private void AddQuantityToDock(int quantity, PickupDock toDock) | Adds coins to a dock, spawning a coin stack if the dock is empty. |
private void DepositTaken(Interactor interactor, Pickup pickup, PickupDock dock) | Server: moves coins docked in the deposit slot into the teller next frame. Pouches are ignored. |
private void FilterDeposit(Interactor interactor, Pickup pickup, ref bool result) | Only accepts coins last held by the owner. |
private void FilterOwner(Interactor interactor, Interactable interactable, ref bool result) | Only lets the owner use the withdraw slot and the throttle. |
private async Task LoadPlayerBankContent() | Spawns the owner's bank balance as coins in the teller and links the account to this machine. |
private void LogBalanceChangeWithConsoleEvents(UserInfo userInfo, int previousBalance, int newBalance) | Server: raises the AtmBalanceChanged console event with the change and new balance. |
private void MoveQuantityBetweenDocks(int movement, PickupDock fromDock, PickupDock toDock) | Moves up to a number of coins from one dock to another. |
private bool OwnerIsNull() | True when nobody owns the machine. |
private void RemoveQuantityFromATM(int quantity) | Removes coins from the teller, then the withdraw slot. When it needs the withdraw slot it passes a negative count, so that part doesn't work. |
private void ResetDocks() | Destroys all coins in the teller and withdraw slot. |
private void SpawnAndSetCoinsInDock(int quantity, PickupDock toDock) | Spawns a coin stack of a size in a dock. |
private void SyncOwner(IPlayer player, Stream stream) | Syncs the owner's player ID to clients. |
private async void TrySave() | Writes the teller amount back to the owner's bank account, logs the change and unlinks the machine. |
Used in
Members of other types that take, return or hold a ATMMachine: