Skip to main content

TradeStateManager

A class in Root.Township, Alta.Trading.

Syncs a trade vendor's status (unoccupied, out of stock, open for sale) to clients and fires an event per status for visuals. The server reads the status from the TradeVendor.

Constructors​

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

Fields​

8 private and internal fields
MemberWhat it is
private TradeStatus indexThe current TradeStatus, or -1 before the first one.
private BoolEvent[] indexedEventsClient: the status events, indexed by TradeStatus value.
private static Logger loggerLogger for this class; unused.
private BoolEvent onOpenForSaleEvent set true while the vendor is open for sale, false otherwise.
private BoolEvent onOutOfStockEvent set true while the vendor is out of stock.
private BoolEvent onUnnocupiedEvent set true while the vendor has no owner.
private MethodSync syncThe status sync message.
private TradeVendor vendorThe vendor whose status is shown.

Methods​

MemberWhat it is
override void Initialize()Server: listens to the vendor's status changes. Client: sets all status events to false. Both: sets up the sync message.
override void InitializeAsServer(SpawnData spawnData)Server: applies the vendor's current status.
override void OnConnected(Player player)Sends the current status to a player who just connected.
2 private and internal methods
MemberWhat it is
private void StatusChanged(TradeStatus index)Switches the previous status event off and the new one on. On the server it then sends the status to nearby players.
private void Sync(IPlayer player, Stream stream)Writes the status as an integer; clients apply what they read.