Inventory System
Search Results for

    Show / Hide Table of Contents

    Interface IInventory

    Interface for an Inventory managing IInventorySlots and the IItems inside. Exposes methods for adding, removing, and getting items.

    Namespace: InventorySystem.Inventory
    Assembly: InventorySystem.dll
    Syntax
    public interface IInventory

    Properties

    | Edit this page View Source

    Capacity

    Maximum amount of items that can be inside the IInventory.

    Declaration
    int Capacity { get; }
    Property Value
    Type Description
    int
    | Edit this page View Source

    InventorySlots

    Get all IInventorySlots in this.

    Declaration
    IReadOnlyList<IInventorySlot> InventorySlots { get; }
    Property Value
    Type Description
    IReadOnlyList<IInventorySlot>

    IReadOnlyList<T> of all IInventorySlots in this IInventory.

    Remarks

    WARNING: Also returns empty IInventorySlots. Thus, always returns a list of size equal to Capacity.

    | Edit this page View Source

    IsEmpty

    Whether the entire IInventory is empty meaning all IInventorySlots are empty.

    Declaration
    bool IsEmpty { get; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    Items

    Get all IItems in IInventory.

    Declaration
    IReadOnlyList<IItem> Items { get; }
    Property Value
    Type Description
    IReadOnlyList<IItem>

    IReadOnlyList<T> of all IItems in this IInventory.

    Remarks

    WARNING: Also returns empty IItems as null. Thus, always returns a list of size equal to Capacity.

    Methods

    | Edit this page View Source

    Clear()

    Clear the entire IInventory by clearing all IInventorySlots.

    Declaration
    void Clear()
    | Edit this page View Source

    IsSlotAvailable(IItem, out int)

    Whether an IItem item can be added into an IInventorySlot. Does not add the IItem.

    Declaration
    bool IsSlotAvailable(IItem item, out int addIndex)
    Parameters
    Type Name Description
    IItem item

    IItem to be checked.

    int addIndex

    First found index for the IItem item to be added into. Looks for index with equivalent, non-full IInventorySlot and empty slots second. Returns -1, if it cannot be added.

    Returns
    Type Description
    bool

    Whether the IItem can be added or not.

    Remarks

    Does not guarantee that the IItem can be added with a quantity greater than one. Only guarantees that there is either an empty IInventorySlot or a non-full IInventorySlot that is already occupied by the item that is to be added. It is still possible that the quantity of the IItem being added exceeds the MaxStackAmount and thus needs to occupy additional Slots to be fully added.

    | Edit this page View Source

    RemoveItem(IItem, bool, bool)

    Remove IItem item from the IInventory. If the IItem is in the IInventory, we clear its IInventorySlot.

    Declaration
    void RemoveItem(IItem item, bool isRemovingFirstOccurenceOnly = false, bool isReversed = false)
    Parameters
    Type Name Description
    IItem item

    IItem to be removed.

    bool isRemovingFirstOccurenceOnly

    Whether only the first occurence of the IItem in the IInventory gets removed (true) or all of its occurrences (i.e., we have the same IItem in multiple IInventorySlots).

    bool isReversed

    Start to remove items from the back. Does not have side effects.

    | Edit this page View Source

    TryAddItem(IItem, int)

    Try to add an IItem into the first possible IInventorySlot.

    Declaration
    bool TryAddItem(IItem item, int quantity = 1)
    Parameters
    Type Name Description
    IItem item

    The IItem to be added.

    int quantity

    The number of IItem item to be added.

    Returns
    Type Description
    bool

    Whether the IItem item was added.

    Remarks

    Wrapper for TryAddItemAt(IItem, int, int). If the quantity exceeds the first found IInventorySlot capacity, it tries to find the next empty IInventorySlot and adds the leftover amount there. Loops recursively until all items are stored in the IInventory or until there is no more space available. If no more space is available, discards/ignores the remaining leftover. Returns true, even if any leftover is discarded.

    | Edit this page View Source

    TryAddItemAt(IItem, int, int)

    Try to add an IItem item into the IInventorySlot at index.

    Declaration
    bool TryAddItemAt(IItem item, int index, int quantity = 1)
    Parameters
    Type Name Description
    IItem item

    The IItem to be added.

    int index

    The index of the IInventorySlot that the item is trying to be added into.

    int quantity

    The number of IItem item to be added.

    Returns
    Type Description
    bool

    Whether the IItem item was added.

    Remarks

    If the quantity exceeds the Quantity of the IInventorySlot capacity, it tries to find the next non-full occupied IInventorySlot by the same IItem item or the next empty IInventorySlot and adds the leftover amount there. Loops recursively until all items are stored in the IInventory or until there is no more space available. If no more space is available, discards/ignores the remaining leftover. Returns true, even if any leftover is discarded. WARNING: If InventorySystem.Inventory.Inventory._handlesOverflow is true, it only tries to add the item to the first found IInventorySlot and returns true if any amount was added.

    | Edit this page View Source

    TryClearSlotAt(int)

    Try to clear the IInventorySlot, if it's valid.

    Declaration
    void TryClearSlotAt(int index)
    Parameters
    Type Name Description
    int index

    The index of the IInventorySlot to clear.

    | Edit this page View Source

    TryGetItemAt(int)

    Try to get IItem as index.

    Declaration
    IItem TryGetItemAt(int index)
    Parameters
    Type Name Description
    int index

    The index to look for IItem item.

    Returns
    Type Description
    IItem

    Returns IItem, if the index is inside the bounds of the Capacity. Otherwise, or if IInventorySlot IsEmpty, returns null.

    | Edit this page View Source

    TryGetSlotAt(int)

    Try to get the IInventorySlot at slotIndex.

    Declaration
    IInventorySlot TryGetSlotAt(int index)
    Parameters
    Type Name Description
    int index

    Index to look for the IInventorySlot

    Returns
    Type Description
    IInventorySlot

    IInventorySlot or null, if the index is higher than the Capacity.

    | Edit this page View Source

    TryInsertItemAtFront(IItem, int)

    Try to insert an IItem at the front of the IInventory, i.e., in IInventorySlot 0.

    Declaration
    bool TryInsertItemAtFront(IItem item, int quantity = 1)
    Parameters
    Type Name Description
    IItem item

    The IItem to be added to the IInventory at the front.

    int quantity

    The quantity of IItem to be added.

    Returns
    Type Description
    bool

    Whether the IItem was added to the front.

    Remarks

    Pushed all other IItems already in the IInventory one slot up. FIXME: If quantity exceeds MaxStackAmount, it is possible that IItems that were previously in the IInventory get removed.

    Events

    | Edit this page View Source

    ItemsAdded

    Event invoked when IItems were successfully added to an IInventorySlot in this IInventory. Returns the IInventorySlot the IItem was added to and the index of the IInventorySlot.

    Declaration
    event Action<IInventorySlot, int> ItemsAdded
    Event Type
    Type Description
    Action<IInventorySlot, int>
    Remarks

    Triggered per slot that receives items; each invocation returns the added IItem and the quantity placed into that slot. (i.e., if more IItems are added than MaxStackAmount for one slot, and items are added to a second slot, the event will fire again for the second slot.)

    | Edit this page View Source

    ItemsRemoved

    Event invoked when IItems were successfully removed from an IInventorySlot in this IInventory. Returns the IInventorySlot the IItem was removed from and the index of the IInventorySlot.

    Declaration
    event Action<IInventorySlot, int> ItemsRemoved
    Event Type
    Type Description
    Action<IInventorySlot, int>
    Remarks

    Fired per slot that loses items; each invocation returns the removed IItem and the quantity taken from that slot.

    • Edit this page
    • View Source
    In this article
    Back to top Generated by DocFX