Namespace: GGG.Inventory
Defines inventory queries, item movement, and change notifications.
public interface IInventory
Properties
Capacity
Gets the total number of inventory slots.
int Capacity { get; }
Property Value
Definition
Gets the definition associated with this runtime instance.
InventoryDefinition Definition { get; }
Property Value
OccupiedSlotCount
Gets the number of slots currently containing items.
int OccupiedSlotCount { get; }
Property Value
Slots
Gets the runtime slots in their configured order.
IReadOnlyList<InventorySlot> Slots { get; }
Property Value
Methods
Accepts(ItemDefinition)
Determines whether the item definition belongs to this inventory catalog.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
event Action<InventoryChange> Changed