Economy

Trade

Escrowed player-to-player exchange (atomic TryExchange over Inventory).

Server
services.AddCrossplayTrade();
Unity package
com.crossplay.trade
Depends on
inventory

Wire messages 8

The protocol this piece speaks. Ids are allocated per piece so they can never collide.

2001 TradeProposeRequest

Client → server: propose a trade to an online player by display name.

2002 TradeProposed

Server → target: someone proposed a trade.

2003 TradeAcceptRequest

Client → server: accept a proposal.

2004 TradeOfferRequest

Client → server: replace my offer with these inventory slots (empty = offer nothing).

2005 TradeConfirmRequest

Client → server: lock in the trade as offered. Both confirmations trigger the atomic swap.

2006 TradeCancelRequest

Client → server: walk away (nothing is exchanged).

2007 TradeStateChanged

Server → both parties: the trade table as it stands. Any offer change resets confirmations.

2008 TradeCompleted

Server → both parties: the trade ended (swap done, failed, or cancelled).

Unity services you inject 1

Crossplay binds these in the client context. Inject and call them from your own MonoBehaviours and presenters.

ITradeClient

The Trade piece, client side: propose/accept/offer/confirm/cancel, and observe the table state (any change resets confirmations server-side). The exchange itself is server-authoritative and atomic — completion arrives as Completed. No UI; your game renders the table.

  • event Action<TradeProposed> Proposed

    Someone proposed a trade to you.

  • event Action<TradeStateChanged> StateChanged

    The trade table changed (offers/confirmations, from your perspective).

  • event Action<TradeCompleted> Completed

    The trade ended (swap done, failed, or cancelled).

  • void Propose(string targetName)

    Proposes a trade to an online player by display name.

  • void Accept(long tradeId)

    Accepts a received proposal.

  • void Offer(int[] slots)

    Replaces your offer with these inventory slot indices (empty = nothing).

  • void Confirm()

    Locks in the table as shown; both confirmations trigger the atomic swap.

  • void Cancel()

    Walks away — nothing is exchanged.

UI views you can replace 1

Each ships a working uGUI panel you can drag into a scene. Substitute your own view to keep the logic and change the look — the presenter never knows.

ICrossplayTradeView

Narrow contract the presenter drives. UI-only: render calls in, user intents out.