Loading...
Searching...
No Matches
AdventureCore.InventoryBase Class Referenceabstract

Detailed Description

base class for inventories, inventories manages items and the slots they are equipped to
in addition to the simple unlimited ListedInventory a possible use cases could be a re4 style case where item stacks have a position and are limited

https://adventure.softleitner.com/manual/item

Inheritance diagram for AdventureCore.InventoryBase:
AdventureCore.ListedInventory AdventureCore.TiledInventory

Public Member Functions

virtual void Initialize (CharacterBase character)
 initializes the inventory including retrieving persisted data
 
virtual bool HasItem (ItemBase item)
 checks whether the item exists in the inventory, regardless of quantity(may be 0 for stacked items to indicate they have been added at some point)
 
virtual bool HasItemQuantity (ItemBase item, int quantity=1)
 checks if the inventory has at least the passed quantity of an item
 
virtual InventoryItem GetItem (ItemBase item)
 retrieves the first inventory item for a specified item
 
virtual IEnumerable< InventoryItemGetItems (ItemBase item)
 retrieves all inventory items for a specified item
multiple entries may be resturned for items that dont stack-
or when the inventory has a maximum stack size
 
virtual IEnumerable< InventoryItemGetItems (ItemCategory itemCategory=null, ItemSlotCategory itemSlotCategory=null)
 retrieves all inventory items for a specific category or slot
 
virtual int GetQuantity (ItemBase item)
 calculates the total stored quantity of an item
 
virtual int GetQuantity (ItemCategory itemCategory=null, ItemSlotCategory itemSlotCategory=null)
 calculates the total stored quantity of items filtered by an item category and/or slot
 
virtual bool CanAddItems (ItemQuantity itemQuantity, bool fully=true)
 whether an item quantity can be added to the inventory
may be false when the quantity exceeds the capacity
 
virtual int AddItems (ItemQuantity itemQuantity)
 adds a quantity of an item to the inventory
 
virtual bool CanRemoveItems (ItemQuantity itemQuantity, bool fully=true)
 whether a quantity of items is present and can be removed
 
virtual int RemoveItems (ItemQuantity itemQuantity)
 removes a quantity of items
 
virtual bool CanRemoveItems (InventoryItem inventoryItem, int quantity=1, bool fully=true)
 whether a quantity of items is present and can be removed from an inventory item
 
virtual int RemoveItems (InventoryItem inventoryItem, int quantity=1)
 removes specified quantity from the inventory item
 
virtual bool CanUseItems (InventoryItem inventoryItem, int quantity=1)
 check if a quantity of an inventory item can be used
 
virtual void UseItems (InventoryItem inventoryItem, int quantity=1)
 uses a quantity of an inventory item can be used
 
virtual bool CanEquipItems (InventoryItem inventoryItem, int? index=null)
 checks if an inventory item can be equipped
 
virtual ItemSlotBase EquipItems (InventoryItem inventoryItem, int? index=null)
 equipps an inventory item to a slot
 
virtual bool CanUnequipItems (InventoryItem inventoryItem)
 checks if an inventory item can be unequipped
 
virtual ItemSlotBase UnequipItems (InventoryItem inventoryItem)
 unequips an inventory item
 
void SetItemStringValue (InventoryItem inventoryItem, string key, string value)
 
string GetItemStringValue (InventoryItem inventoryItem, string key, string defaultValue)
 
void SetItemIntValue (InventoryItem inventoryItem, string key, int value)
 
int GetItemIntValue (InventoryItem inventoryItem, string key, int defaultValue)
 
void SetItemFloatValue (InventoryItem inventoryItem, string key, float value)
 
float GetItemFloatValue (InventoryItem inventoryItem, string key, float defaultValue)
 
void SetItemBoolValue (InventoryItem inventoryItem, string key, bool value)
 
bool GetItemBoolValue (InventoryItem inventoryItem, string key, bool defaultValue)
 
virtual bool CheckItemValue (InventoryItem inventoryItem, string key)
 
virtual void SetItemValue< T > (InventoryItem inventoryItem, string key, T value)
 
virtual T GetItemValue< T > (InventoryItem inventoryItem, string key, T defaultValue)
 
virtual ItemSlotBase GetSlot (ItemSlotCategory category, int index=0)
 retrieves an item slot by its category
 
virtual ItemSlotBase GetSlot (ItemBase item, int index=0)
 retrieves an item slot for the passed item
 
virtual T GetSlot< T > (int index=0)
 retrieves an item slot by its type
 
virtual ItemSlotBase GetEmptySlot (ItemSlotCategory category, int? index=null)
 retrieves an empty item slot by its category
 
virtual ItemSlotBase GetEmptySlot (ItemBase item, int? index=null)
 retrieves an empty item slot for the passed item
 
virtual T GetEmptySlot< T > (int? index=null)
 retrieves an empty item slot by its type
 
virtual int GetCapacity (ItemBase item)
 
virtual int GetRemainingCapacity (ItemBase item)
 
bool Retrieve ()
 fills inventory with data retrieved from persister
 
void Persist ()
 saves inventory data to persister
 

Public Attributes

PersisterBase Persister
 
bool PersistManual
 
ItemSet ItemSet
 
bool EquipOnAdded
 
bool UnequipOnEmpty
 
ItemSlotBase[] Slots
 
List< ItemQuantityCapacities
 
UnityEvent< ItemQuantityChanging
 
UnityEvent< ItemQuantityChanged
 
UnityEvent< ItemSlotBaseEquipmentChanged
 

Static Public Attributes

const string PERSISTENCE_SUB_KEY = "INV"
 

Protected Member Functions

virtual void onItemsChanging (ItemQuantity itemQuantity)
 
virtual void onItemsChanged (ItemQuantity itemQuantity)
 
virtual void onItemValueChanged (InventoryItem inventoryItem, string key)
 
int add (ItemQuantity itemQuantity)
 
void remove (InventoryItem inventoryItem)
 

Protected Attributes

bool _isInitialized
 
bool _isChanging
 

Properties

CharacterBase Character [get]
 
IReadOnlyList< InventoryItemInventoryItems [get]
 

Member Function Documentation

◆ AddItems()

virtual int AdventureCore.InventoryBase.AddItems ( ItemQuantity itemQuantity)
inlinevirtual

adds a quantity of an item to the inventory

Parameters
itemQuantityhow much and what to add to the inventory
Returns
the remaining quantity that could not be added

◆ CanAddItems()

virtual bool AdventureCore.InventoryBase.CanAddItems ( ItemQuantity itemQuantity,
bool fully = true )
inlinevirtual

whether an item quantity can be added to the inventory
may be false when the quantity exceeds the capacity

Parameters
itemQuantitythe item and quantity to check
fullyif the quantity has to be stored entirely
Returns
whether the item quantity can be stored

Reimplemented in AdventureCore.TiledInventory.

◆ CanEquipItems()

virtual bool AdventureCore.InventoryBase.CanEquipItems ( InventoryItem inventoryItem,
int? index = null )
inlinevirtual

checks if an inventory item can be equipped

Parameters
inventoryItemthe inventory item to equip
indexindex of the slot to equip to if there are multiple(for example left/right arm in souls)
Returns
whether the item can be equipped

◆ CanRemoveItems() [1/2]

virtual bool AdventureCore.InventoryBase.CanRemoveItems ( InventoryItem inventoryItem,
int quantity = 1,
bool fully = true )
inlinevirtual

whether a quantity of items is present and can be removed from an inventory item

Parameters
inventoryItemthe inventory item to remove from
quantityhow much to remove
fullyif the quantity has to be stored entirely
Returns
whether the quantity can be removed

◆ CanRemoveItems() [2/2]

virtual bool AdventureCore.InventoryBase.CanRemoveItems ( ItemQuantity itemQuantity,
bool fully = true )
inlinevirtual

whether a quantity of items is present and can be removed

Parameters
itemQuantityhow much and what to remove from the inventory
fullyif the quantity has to be removed entirely
Returns

Reimplemented in AdventureCore.TiledInventory.

◆ CanUnequipItems()

virtual bool AdventureCore.InventoryBase.CanUnequipItems ( InventoryItem inventoryItem)
inlinevirtual

checks if an inventory item can be unequipped

Parameters
inventoryItemthe inventory item to unequip
Returns
whether the item can be unequipped

◆ CanUseItems()

virtual bool AdventureCore.InventoryBase.CanUseItems ( InventoryItem inventoryItem,
int quantity = 1 )
inlinevirtual

check if a quantity of an inventory item can be used

Parameters
inventoryItemthe inventory item to use
quantityhow many to use
Returns
whether the quantity can be used

◆ EquipItems()

virtual ItemSlotBase AdventureCore.InventoryBase.EquipItems ( InventoryItem inventoryItem,
int? index = null )
inlinevirtual

equipps an inventory item to a slot

Parameters
inventoryItemthe inventory item to equip
indexindex of the slot to equip to if there are multiple(for example left/right arm in souls)
Returns
the slot the item was equipped to

◆ GetEmptySlot() [1/2]

virtual ItemSlotBase AdventureCore.InventoryBase.GetEmptySlot ( ItemBase item,
int? index = null )
virtual

retrieves an empty item slot for the passed item

Parameters
itemthe item to retrieve a slot for
indexwhen there are mutliple slots in one category(sould left/right weapon slots)
Returns
the found slot

◆ GetEmptySlot() [2/2]

virtual ItemSlotBase AdventureCore.InventoryBase.GetEmptySlot ( ItemSlotCategory category,
int? index = null )
virtual

retrieves an empty item slot by its category

Parameters
categorythe category of the slot(helmet, shield, ...)
indexwhen there are mutliple slots in one category(sould left/right weapon slots)
Returns
the found slot

◆ GetEmptySlot< T >()

virtual T AdventureCore.InventoryBase.GetEmptySlot< T > ( int? index = null)
virtual

retrieves an empty item slot by its type

Template Parameters
Tthe type of the item slot
Parameters
indexwhen there are mutliple slots in one category(sould left/right weapon slots)
Returns
the found slot
Type Constraints
T :ItemSlotBase 

◆ GetItem()

virtual InventoryItem AdventureCore.InventoryBase.GetItem ( ItemBase item)
virtual

retrieves the first inventory item for a specified item

Parameters
itemthe item to check
Returns
first inventory items that stores the specified item

◆ GetItems() [1/2]

virtual IEnumerable< InventoryItem > AdventureCore.InventoryBase.GetItems ( ItemBase item)
virtual

retrieves all inventory items for a specified item
multiple entries may be resturned for items that dont stack-
or when the inventory has a maximum stack size

Parameters
itemthe item to check
Returns
all inventory items that store the specified item

◆ GetItems() [2/2]

virtual IEnumerable< InventoryItem > AdventureCore.InventoryBase.GetItems ( ItemCategory itemCategory = null,
ItemSlotCategory itemSlotCategory = null )
inlinevirtual

retrieves all inventory items for a specific category or slot

Parameters
itemCategorythe category to filter items for
itemSlotCategorythe slot to filter items for
Returns
all inventory items that match the given category and/or slot

◆ GetQuantity() [1/2]

virtual int AdventureCore.InventoryBase.GetQuantity ( ItemBase item)
inlinevirtual

calculates the total stored quantity of an item

Parameters
itemthe item to sum quantities for
Returns
sum of all inventory item quantities that have the specified item

◆ GetQuantity() [2/2]

virtual int AdventureCore.InventoryBase.GetQuantity ( ItemCategory itemCategory = null,
ItemSlotCategory itemSlotCategory = null )
inlinevirtual

calculates the total stored quantity of items filtered by an item category and/or slot

Parameters
itemCategorythe category to filter items for
itemSlotCategorythe slot to filter items for
Returns
sum of all inventory item quantities that have the given category and/or slot

◆ GetSlot() [1/2]

virtual ItemSlotBase AdventureCore.InventoryBase.GetSlot ( ItemBase item,
int index = 0 )
virtual

retrieves an item slot for the passed item

Parameters
itemthe item to retrieve a slot for
indexwhen there are mutliple slots in one category(sould left/right weapon slots)
Returns
the found slot

◆ GetSlot() [2/2]

virtual ItemSlotBase AdventureCore.InventoryBase.GetSlot ( ItemSlotCategory category,
int index = 0 )
virtual

retrieves an item slot by its category

Parameters
categorythe category of the slot(helmet, shield, ...)
indexwhen there are mutliple slots in one category(sould left/right weapon slots)
Returns
the found slot

◆ GetSlot< T >()

virtual T AdventureCore.InventoryBase.GetSlot< T > ( int index = 0)
virtual

retrieves an item slot by its type

Template Parameters
Tthe type of the item slot
Parameters
indexwhen there are mutliple slots in one category(sould left/right weapon slots)
Returns
the found slot
Type Constraints
T :ItemSlotBase 

◆ HasItem()

virtual bool AdventureCore.InventoryBase.HasItem ( ItemBase item)
virtual

checks whether the item exists in the inventory, regardless of quantity(may be 0 for stacked items to indicate they have been added at some point)

Parameters
item
Returns

◆ HasItemQuantity()

virtual bool AdventureCore.InventoryBase.HasItemQuantity ( ItemBase item,
int quantity = 1 )
virtual

checks if the inventory has at least the passed quantity of an item

Parameters
itemthe item to check
quantitythe minimum quantity needed
Returns
true if the needed quantity is present

◆ Initialize()

virtual void AdventureCore.InventoryBase.Initialize ( CharacterBase character)
inlinevirtual

initializes the inventory including retrieving persisted data

Parameters
characterthe owner of the inventory

◆ RemoveItems() [1/2]

virtual int AdventureCore.InventoryBase.RemoveItems ( InventoryItem inventoryItem,
int quantity = 1 )
inlinevirtual

removes specified quantity from the inventory item

Parameters
inventoryItemthe inventory item to remove from
quantitythe quantity to remove
Returns
the remaining quantity that could not be removed

◆ RemoveItems() [2/2]

virtual int AdventureCore.InventoryBase.RemoveItems ( ItemQuantity itemQuantity)
inlinevirtual

removes a quantity of items

Parameters
itemQuantityhow much and what to remove
Returns
the remaining quantity that could not be removed

◆ Retrieve()

bool AdventureCore.InventoryBase.Retrieve ( )
abstract

fills inventory with data retrieved from persister

Returns
false if no data to load was found

◆ UnequipItems()

virtual ItemSlotBase AdventureCore.InventoryBase.UnequipItems ( InventoryItem inventoryItem)
inlinevirtual

unequips an inventory item

Parameters
inventoryItemthe inventory item to unequip
Returns
the slot the inventory item was equipped to

◆ UseItems()

virtual void AdventureCore.InventoryBase.UseItems ( InventoryItem inventoryItem,
int quantity = 1 )
inlinevirtual

uses a quantity of an inventory item can be used

Parameters
inventoryItemthe inventory item to use
quantityhow many to use