ShopItem
Lightweight wrapper around an Item that adds a reservation flag for trade coordination. Items on a shop Table are tracked as ShopItem instances, allowing the system to prevent multiple agents from claiming the same item simultaneously.
Definition
Namespace: Paragon.Townskeep.ShopSystem
Assembly: Townskeep.dll
public class ShopItemRemarks
ShopItem is a simple POCO (not a MonoBehaviour) that wraps an Item reference with reservation state. It is created by TableArea when an item enters the trigger zone and removed when the item exits.
The reservation flag is the key coordination mechanism: when an agent selects an item for trade via Table.GetItem(), the returned ShopItem can be marked as reserved to prevent other agents from selecting it. Table.HasAvailableItem and Table.GetItem() both filter by !IsReserved.
An implicit conversion operator allows ShopItem to be used anywhere an Item is expected, making it transparent for downstream code.
Quick Lookup
Create from an Item
new ShopItem(item)
Reserve for trade
shopItem.SetReserve(true)
Release reservation
shopItem.SetReserve(false)
Check if reserved
shopItem.IsReserved
Get underlying Item
Item item = shopItem (implicit conversion)
Properties
IsReserved
Whether this item is currently reserved by an agent for trading. Reserved items are excluded from Table.GetItem() queries.
Constructor
item
Item
The item to wrap. Stored as a readonly field.
Methods
SetReserve
Sets the reservation state. When true, the item will be skipped by Table.GetItem() and Table.HasAvailableItem.
isReserved
bool
Whether to reserve (true) or release (false)
Operators
Implicit to Item
Allows ShopItem to be used as an Item without explicit casting. Returns the wrapped item reference.
Common Pitfalls
Reservation is not enforced
SetReserve() is a flag — there is no access control preventing other code from modifying or using a reserved ShopItem. Reservation is a convention enforced by Table.GetItem() filtering.
No null guard on implicit conversion
The implicit operator accesses shopItem.item directly. If the ShopItem reference itself is null, a NullReferenceException occurs at the call site.
Item reference is readonly
The wrapped Item cannot be changed after construction. To swap items, remove the old ShopItem and create a new one.
See Also
Last updated