Namespace: GGG.Inventory
Pure runtime inventory state. Supports stacking, exact item identity, removal, move/merge/swap behavior, and change notifications.
public sealed class InventoryImpl : IInventory
Inheritance
Implements
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Constructors
InventoryImpl(InventoryDefinition, ItemCatalog)
Creates a new InventoryImpl instance.
public InventoryImpl(InventoryDefinition definition, ItemCatalog itemCatalog)
Parameters
definition InventoryDefinition
The item or inventory definition to inspect or use.
itemCatalog ItemCatalog
The catalog of accepted item definitions.
Properties
Capacity
Gets the total number of inventory slots.
public int Capacity { get; }
Property Value
Catalog
Gets the item catalog used by this instance.
public ItemCatalog Catalog { get; }
Property Value
Definition
Gets the definition associated with this runtime instance.
public InventoryDefinition Definition { get; }
Property Value
OccupiedSlotCount
Gets the number of slots currently containing items.
public int OccupiedSlotCount { get; }
Property Value
Slots
Gets the runtime slots in their configured order.
public IReadOnlyList<InventorySlot> Slots { get; }
Property Value
Methods
Accepts(ItemDefinition)
Determines whether the item definition belongs to this inventory catalog.
public bool Accepts(ItemDefinition definition)
Parameters
definition ItemDefinition
The item or inventory definition to inspect or use.
Returns
Whether the specified condition is satisfied.
CanAdd(ItemInstance)
Determines whether this inventory can accept the specified item instance.
public bool CanAdd(ItemInstance item)
Parameters
item ItemInstance
The runtime item instance to inspect or modify.
Returns
Whether the specified condition is satisfied.
Contains(ItemInstance)
Determines whether the collection contains the specified value.
public bool Contains(ItemInstance item)
Parameters
item ItemInstance
The runtime item instance to inspect or modify.
Returns
Whether the specified condition is satisfied.
GetAvailableSpace(ItemDefinition)
Returns the maximum number of additional items of the given type that could fit.
public int GetAvailableSpace(ItemDefinition definition)
Parameters
definition ItemDefinition
The item or inventory definition to inspect or use.
Returns
The number of additional items that can fit.
GetQuantity(ItemDefinition)
Returns the number of items matching the specified item definition.
public int GetQuantity(ItemDefinition definition)
Parameters
definition ItemDefinition
The item or inventory definition to inspect or use.
Returns
The number of matching items.
TryAdd(ItemInstance, out int)
Attempts to place an item in a compatible existing stack or empty slot.
public bool TryAdd(ItemInstance item, out int slotIndex)
Parameters
item ItemInstance
The runtime item instance to inspect or modify.
slotIndex int
Receives the resulting slot index when successful.
Returns
Whether the operation succeeded.
TryAddAtIndex(ItemInstance, int)
Attempts to add an item at a specific inventory slot index.
public bool TryAddAtIndex(ItemInstance item, int slotIndex)
Parameters
item ItemInstance
The runtime item instance to inspect or modify.
slotIndex int
The zero-based inventory slot index.
Returns
Whether the operation succeeded.
TryClear(out IReadOnlyList<ItemInstance>)
Attempts to clear all occupied slots, returning removed items.
public bool TryClear(out IReadOnlyList<ItemInstance> removedItems)
Parameters
removedItems IReadOnlyList<ItemInstance>
Receives the removed runtime item instances when successful.
Returns
Whether the operation succeeded.
TryGetSlot(int, out InventorySlot)
Attempts to find the specified runtime slot.
public bool TryGetSlot(int index, out InventorySlot slot)
Parameters
index int
The zero-based slot index.
slot InventorySlot
Receives the matching runtime slot when found.
Returns
Whether the operation succeeded.
TryMove(int, int, out int)
Attempts to move or combine contents between inventory slots.
public bool TryMove(int sourceSlotIndex, int destinationSlotIndex, out int movedQuantity)
Parameters
sourceSlotIndex int
The zero-based source slot index.
destinationSlotIndex int
The zero-based destination slot index.
movedQuantity int
Receives the number of items moved by the operation.
Returns
Whether the operation succeeded.
TryRemove(ItemInstance)
Attempts to remove the requested item or quantity from the inventory.
public bool TryRemove(ItemInstance item)
Parameters
item ItemInstance
The runtime item instance to inspect or modify.
Returns
Whether the operation succeeded.
TryRemove(ItemDefinition, int, out IReadOnlyList<ItemInstance>)
Attempts to remove the requested item or quantity from the inventory.
public bool TryRemove(ItemDefinition definition, int quantity, out IReadOnlyList<ItemInstance> removedItems)
Parameters
definition ItemDefinition
The item or inventory definition to inspect or use.
quantity int
The requested quantity of items.
removedItems IReadOnlyList<ItemInstance>
Receives the removed runtime item instances when successful.
Returns
Whether the operation succeeded.
TryRemoveAtIndex(int, out IReadOnlyList<ItemInstance>)
Attempts to remove the contents of a slot.
public bool TryRemoveAtIndex(int slotIndex, out IReadOnlyList<ItemInstance> removedItems)
Parameters
slotIndex int
The zero-based inventory slot index.
removedItems IReadOnlyList<ItemInstance>
Receives the removed runtime item instances when successful.
Returns
Whether the operation succeeded.
Changed
Raised when the underlying runtime state changes.
public event Action<InventoryChange> Changed