Class TradeExchange
- Namespace
- FishMMO.Server.Implementation.World.SceneServer
- Assembly
- FishMMO.Server.dll
Applies an agreed exchange of items to two in-memory inventories, all or nothing.
public static class TradeExchange
- Inheritance
-
TradeExchange
- Inherited Members
Remarks
Pure container arithmetic: no network, no persistence, no character lookups. The
trade system resolves the two inventories and re-validates the offers, then hands
them here; what comes back is the set of rows each character's write must carry.
That split is what lets the conservation rules — nothing duplicated, nothing lost, on
success or on refusal — be pinned by tests against real InventoryControllers.
Why this is not "remove from A, then grant to B". The grant path is all-or-nothing per item, but a trade is several items in both directions, and the receiver's room depends on which of its own items are leaving. So the exchange runs in two phases on the main thread with nothing between them: TAKE every offered item out of both bags, then GIVE each to the other bag. If any give refuses, every give already made is undone and every take is put back, and both bags are exactly as they were. Nothing else runs between the phases, so no third party can see or touch the intermediate state.
Identity survives the move. An item that crosses whole keeps its ID and is listed as CHANGED by the receiver: the row moves by being re-owned. Only an item that merged entirely into a stack the receiver already held is listed as REMOVED by the giver, because its row genuinely ceased to exist. A split-off quantity is a new Item with no identity; it is listed as changed by the receiver and as unidentified, so the write can lock its slot until the database names it.
Methods
TryApply(Side, Side, out Failure)
Moves every offer on first into second's inventory
and vice versa, or changes nothing.
public static bool TryApply(TradeExchange.Side first, TradeExchange.Side second, out TradeExchange.Failure failure)
Parameters
firstTradeExchange.SidesecondTradeExchange.SidefailureTradeExchange.Failure
Returns
- bool
True when the exchange applied. False leaves both inventories untouched.
TryApply(Side, Side, out Failure, out Applied)
As TryApply(Side, Side, out Failure), and hands back the handle that can take the applied exchange back.
public static bool TryApply(TradeExchange.Side first, TradeExchange.Side second, out TradeExchange.Failure failure, out TradeExchange.Applied applied)
Parameters
firstTradeExchange.SidesecondTradeExchange.SidefailureTradeExchange.FailureappliedTradeExchange.Applied