TradeItemAction
Agent action that places a carried item on the trading table and initiates a trade context. Cancels the CarryInteraction, moves the item to the table center, tags it as "AwaitingTrade", and waits for the trade to be accepted or resolved.
Definition
Namespace: Paragon.Townskeep.AgentSystem
Assembly: Townskeep.dll
public class TradeItemAction : AgentActionInheritance: Action → AgentAction → TradeItemAction
Remarks
TradeItemAction is the culmination of the agent trade sequence: after WanderAction finds an item, GrabItemAction picks it up, and GoToTradeAction navigates to the table, this action places the item and waits for the player to complete the trade.
Execution Flow
Trade Sequence
Tag item — Sets
interactable.tag = "AwaitingTrade"to mark the item for the UI/shop systemCancel carry — Calls
carryInteraction.Cancel()to release the item from the character's handsPosition item — Uses
item.Rigidbody.MovePosition()to place the item at the table centerStart trade — Creates a
TradeContextviatradingArea.StartTradeContext(agent, item)Wait — Blocks with
Yield.WaitWhileuntiltradingArea.IsAwaitingTradebecomesfalse(trade accepted or cancelled)
Quick Lookup
Execute a trade
Add TradeItemAction to sequence after GoToTradeAction
Set the item to trade
Ensure "Item" variable is set in the sequence
Fields
item
Item
[Variable] private
The item to trade; bound from sequence variables
table
Table
private
Cached "Trading Table" reference
tradingArea
TradingArea
private
The trading area of the table
placeItemPosition
Vector3
private
Center of the table bounds — where the item is placed
interactable
Interactable
private
The item's Interactable component
Methods
OnBegin
Resolves the item's Interactable, finds the "Trading Table", caches the TradingArea, and calculates the item placement position from the table bounds center.
OnExecute
Cancels the carry interaction, repositions the item, starts the trade context, and waits for trade resolution.
Common Pitfalls
Scene-dependent table lookup
Like GoToTradeAction, this action uses FindObjectsByType<Table>() filtered by name "Trading Table". If the table doesn't exist, it will throw NullReferenceException.
TradingArea cast assumption
table.Area is cast directly to TradingArea. If the table's area type is different, an InvalidCastException is thrown.
Trade context result is not checked
StartTradeContext() returns a TradeContext, but the return value is stored in a local variable that is never used after creation. The action only waits for IsAwaitingTrade to become false — it does not check whether the trade succeeded or failed.
Item position set via Rigidbody
The item is moved to the table using item.Rigidbody.MovePosition(), not transform.position. This respects physics interpolation but requires the item to have an active Rigidbody.
Indefinite wait if trade never resolves
Yield.WaitWhile(() => tradingArea.IsAwaitingTrade) will wait indefinitely if IsAwaitingTrade never becomes false. There is no timeout.
Carry interaction may not exist
If TryGetActiveInteractionWith returns false (no active CarryInteraction), the tagging and cancellation steps are skipped, but the trade still starts. This can result in the item not being physically placed on the table.
See Also
AgentAction — abstract base with agent context
GoToTradeAction — navigates to the trading table (precedes this action)
GrabItemAction — picks up the item (precedes GoToTradeAction)
WanderAction — finds the item to trade (starts the trade sequence)
Actions Overview — subsystem architecture
Last updated