TradingArea
TableArea subclass that manages trade exchanges between agents and players. Holds a pending TradeContext and completes the trade by transferring coin value to the player and despawning the traded item.
Definition
Namespace: Paragon.Townskeep.ShopSystem
Assembly: Townskeep.dll
public class TradingArea : TableAreaInheritance: MonoBehaviour → TableArea → TradingArea
Remarks
TradingArea extends TableArea with trade lifecycle management. It supports a single pending trade at a time:
Start — An
AgentcallsStartTradeContext()with the item it wants to sell, creating aTradeContext.Await —
IsAwaitingTradereturnstruewhile a trade is pending.Complete — A
PlayercallsCompleteTrade(), which adds the item's coin value to the player, despawns the item, and clears the context.
Only one trade can be pending at a time. Starting a new trade overwrites the previous context.
Quick Lookup
Start a trade
tradingArea.StartTradeContext(agent, item)
Check if trade is pending
tradingArea.IsAwaitingTrade
Complete the trade
tradingArea.CompleteTrade(player)
Properties
IsAwaitingTrade
Whether a trade context is currently active (an agent has placed an item for trade).
Methods
StartTradeContext
Creates a new TradeContext for the given agent and item. Stores it as the pending trade.
tradingAgent
Agent
The agent initiating the trade
tradeItem
Item
The item being offered
Returns: The created TradeContext.
Overwrites existing context — If a trade is already pending, calling StartTradeContext silently replaces it. There is no guard against overwriting.
CompleteTrade
Finalizes the trade: adds the item's coin value to the player, despawns the item, and clears the trade context.
player
Player
The player receiving the coin value
Trade completion flow:
Adds
TradeContext.TradeValuetoplayerviaplayer.AddCoin().Despawns the traded
Item.Sets
tradeContexttonull(clearsIsAwaitingTrade).
Inherited Members
From TableArea:
InnerSpot / OuterSpot
Positioning transforms
HasAnyItem / HasAvailableItem
Item availability checks
DisplayItem() / RemoveItem()
Item list management
GetBounds()
Collider bounds
Usage Example
Common Pitfalls
Item is despawned on trade completion — The traded Item is destroyed via Despawn(). Any remaining references to it become invalid after CompleteTrade.
No validation on CompleteTrade — The method does not check if tradeContext is null. Calling CompleteTrade when IsAwaitingTrade is false will throw a NullReferenceException.
See Also
TradeContext — data container for pending trades
DisplayArea — sibling
TableAreafor display-only surfacesAgent — the entity initiating trades
Last updated