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 : TableArea

Inheritance: MonoBehaviourTableAreaTradingArea

Remarks

TradingArea extends TableArea with trade lifecycle management. It supports a single pending trade at a time:

  1. Start — An Agent calls StartTradeContext() with the item it wants to sell, creating a TradeContext.

  2. AwaitIsAwaitingTrade returns true while a trade is pending.

  3. Complete — A Player calls CompleteTrade(), 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

Goal
How

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.

Parameter
Type
Description

tradingAgent

Agent

The agent initiating the trade

tradeItem

Item

The item being offered

Returns: The created TradeContext.

circle-exclamation

CompleteTrade

Finalizes the trade: adds the item's coin value to the player, despawns the item, and clears the trade context.

Parameter
Type
Description

player

Player

The player receiving the coin value

Trade completion flow:

  1. Adds TradeContext.TradeValue to player via player.AddCoin().

  2. Despawns the traded Item.

  3. Sets tradeContext to null (clears IsAwaitingTrade).

Inherited Members

From TableArea:

Member
Description

InnerSpot / OuterSpot

Positioning transforms

HasAnyItem / HasAvailableItem

Item availability checks

DisplayItem() / RemoveItem()

Item list management

GetBounds()

Collider bounds

Usage Example

Common Pitfalls

circle-exclamation
circle-exclamation

See Also

  • TradeContext — data container for pending trades

  • DisplayArea — sibling TableArea for display-only surfaces

  • Agent — the entity initiating trades

Last updated