Skip to main content

TradeVendor

A class in Root.Township, Alta.Trading.

A player trading deck. The first player to put coins in the tax dock claims it, stocks items and sets a price, and buyers pay coins to take stock. The server runs the trades.

Constructors​

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

Fields​

20 private and internal fields
MemberWhat it is
private PickupDock buyCoinDisplayDockBuyer side display dock that gets one coin at start, probably to show the price.
private PickupDock buyItemDisplayDockBuyer side dock showing a copy of the item for sale.
private ButtonCounter coinCounterCounter for the price in coins.
private Transform coinSpawnPointWhere ejected coins and items are dropped.
private bool isEjectingPrivate: true while the vendor is being emptied, so a tax failure does not start a second empty.
private bool isProcessingSalePrivate: true while a sale is being handled, to ignore more coins.
private ButtonCounter itemCounterCounter for how many items a lot holds.
private Transform itemSpawnPointWhere bought items are dropped.
private Lever leverLever the owner pulls to empty and free the vendor.
private Pickup leverPickupPickup of the lever, used to check the owner is the one pulling it.
private static Logger loggerPrivate: logger for trade errors.
private IPlayer ownerPlayerPrivate: the owner while they are online.
private PickupDock paymentsDock where coins from sales collect for the owner.
private PickupDock sellCoinDockSeller side display dock that gets one coin at start, probably to show the price.
private PickupDock sellItemDockSeller side dock showing a copy of the stocked item.
private PickupDock stockDockDock the owner fills with stock to sell.
private MethodSync syncPrivate: owner sync message.
private PickupDock taxDockBacking field for TaxDock.
private TaxManager taxManagerHandles the tax timer and its coin cost.
private PickupDock temporaryCoinDockDock buyers put coins into to buy.

Properties​

MemberWhat it is
bool HasStock { get; }Whether the stock dock holds at least one lot of the set item amount.
int Owner { get; private set; }The user ID of the deck's owner. 0 when unclaimed.
PickupDock TaxDock { get; }The dock the owner pays tax coins into.
TradeStatus TradeState { get; private set; }Unoccupied, out of stock, or open for sale.

Events​

MemberWhat it is
event TradeVendor.StatusChangedHandler StatusChangedRaised when TradeState changes.

Methods​

MemberWhat it is
override void Initialize()Limits the stock and payment docks to the owner and sets up owner sync.
override void InitializeAsServer(SpawnData spawnData)Server: hooks up docks, counters, tax and lever. A deck whose display doesn't match its stock posts its contents to the owner and is replaced.
void Load(TradeVendorSaveData data, ISerializeChildren childSerializer)Restores the owner's user ID.
void LoadSetup()Works out the trade status after loading.
override void OnConnected(Player player)Sends the owner to a player who has just spawned the deck.
TradeVendorSaveData Save(ISerializeChildren childSerializer)Saves the owner's user ID.
void WipeOperation()Server: on a wipe, sends the owner's stock and coins to their postbox.
32 private and internal methods
MemberWhat it is
private void CoinsEjected()Private: when the owner pulls the lever, empties the vendor out in front of it and frees it.
private async void DeactivateVendor(bool isSendingToPostBox)Private: empties stock, payments and tax to the owner's postbox or out of the vendor, cancels tax and clears the owner.
private void DisableColliders(Interactor interactor, Pickup pickup, PickupDock dock)Private: turns off colliders on items in the buyer's display dock.
private bool EmptyDock(PickupDock dock, out List<Pickup> pouches)Private: undocks everything in a dock as pouches.
private void FailInteractionToBuyItemDisplayDock(Interactor interactor, Interactable interactable, ref bool result)Private: puts a display copy back in the buyer display dock when someone tries to grab it.
private void FailInteractionToSellItemDock(Interactor interactor, Interactable interactable, ref bool result)Private: puts a display copy back in the seller item dock when someone tries to grab it.
private void FilterTaxDocking(Interactor interactor, Pickup pickup, ref bool result)Private: while owned, only the owner can dock coins into the tax dock.
private void FilterWrongOwnerDock(Interactor interactor, Pickup pickup, ref bool result)Private: only the owner can put items in the stock dock.
private void FilterWrongOwnerInteraction(Interactor interactor, Interactable interactable, ref bool result)Private: only the owner can take from the stock and payment docks.
private void FixedDockToItemDisplayDock(Interactor interactor, Pickup interactable, PickupDock dock)Private: sends a display copy back to the buyer display dock if it ends up in any other dock.
private void FixedDockToSellItemDock(Interactor interactor, Pickup interactable, PickupDock dock)Private: sends a display copy back to the seller item dock if it ends up in any other dock.
private void FixValidate()Private: on start, ejects leftovers from an unowned vendor and frees a vendor whose tax dock holds something other than coins.
private void ForceAmountOnBothDocks(int amount)Private: sets both the coin and item counters to one amount.
private void InitializeDisplayDock(PickupDock displayDock)Private: spawns one coin into a display dock.
private void MarkChunk(Chunk chunk)Private: marks the chunk as needing pre wipe work, so WipeOperation runs.
private void MoneyEnteredBuyer(Interactor interactor, Pickup pickup, PickupDock dock)Private: when a buyer pays, works out how many lots they can afford, spawns the items and moves the coins to payments.
private void MoneyEnteredSeller(Interactor interactor, Pickup pickup, PickupDock dock)Private: the first player to pay tax becomes the owner; enough tax starts the tax timer.
private void OnDestroy()Private: unhooks from the owner player.
private void OwnerLeft(NetworkEntity entity, bool isUnload)Private: clears the counters' active player when the owner leaves. The vendor stays owned.
private void PlayerJoined(IPlayer player)Private: reconnects the owner to the counters when they rejoin.
private void ResetAmmounts()Private: resets both counters to 1 and updates the status.
private void ReturnToBuyDock(Interactable interactable, Interactor interactor)Private: docks a display copy back into the buyer display dock after it is grabbed.
private void ReturnToSellDock(Interactable interactable, Interactor interactor)Private: docks a display copy back into the seller item dock after it is grabbed.
private void SendToPostBox(PickupDock dock, PlayerPostboxStorage ownerStorage)Private: empties a dock into the owner's postbox storage.
private void SetOwnerPlayer(IPlayer player)Private: sets or clears the owner, resets counters when it changes and syncs the owner to clients.
private bool StatusChangedIsNull()Private: whether nothing listens to StatusChanged.
private void StockAdded(Interactor interactor, Pickup pickup, PickupDock dock)Private: on the first stock item, spawns two display copies for the seller and buyer docks and caps the item counter.
private void StockRemoved(Interactor interactor, Pickup pickup, PickupDock dock)Private: when stock runs out, destroys the display copies and resets the counters.
private void Sync(IPlayer player, Stream stream)Private: syncs the owner id. Clients let only the owner touch the stock and payment docks.
private void TaxFailed()Private: frees the vendor and sends its contents to the postbox when tax can't be paid.
private void UndockToLocation(PickupDock dock, Transform location)Private: empties a dock and drops the pouches at a spawn point.
private void UpdateStatus(ButtonCounter counter)Private: sets the trade status to unoccupied, out of stock or open for sale and raises StatusChanged.

Used in​

Members of other types that take, return or hold a TradeVendor: