Adventure Creator  1.79.1
An adventure game toolkit for Unity, by Chris Burton, ICEBOX Studios 2013-2022
AC.InvCollection Class Reference

Public Member Functions

 InvCollection ()
 
 InvCollection (List< InvItem > invItems)
 
 InvCollection (List< InvInstance > _invInstances, bool allowEmptySlots=false)
 A Constructor that populates itself based on an existing list of inventory item instances. More...
 
 InvCollection (Container container)
 
void Transfer (int invID, InvCollection fromCollection)
 Transfer all counts of a given inventory item from another collection More...
 
void Transfer (InvInstance invInstance, InvCollection fromCollection)
 Transfer all counts of a given inventory item from another collection More...
 
void Transfer (int invID, InvCollection fromCollection, int amount, bool matchPropertiesWhenMerging=true)
 Transfer a set count of a given inventory item from another collection More...
 
void Transfer (InvInstance invInstance, InvCollection fromCollection, int amount, bool matchPropertiesWhenMerging=true)
 Transfer a set count of a given inventory item from another collection More...
 
void TransferAll (InvCollection fromCollection)
 Transfers all items from another collection More...
 
InvInstance Add (InvInstance addInstance, bool matchPropertiesWhenMerging=true)
 Adds an inventory item instance to the collection. If the item exists in another collection, it will be removed from there automatically. More...
 
InvInstance AddToEnd (InvInstance addInstance)
 Adds an inventory item instance to the end of the collection - or the first-available empty slot. If the item exists in another collection, it will be removed from there automatically. More...
 
InvInstance Insert (InvInstance addInstance, int index, OccupiedSlotBehaviour occupiedSlotBehaviour=OccupiedSlotBehaviour.ShiftItems, bool matchPropertiesWhenMerging=true)
 Inserts an inventory item instance into a specific index in the collection. If the item exists in another collection, it will be removed from there automatically. More...
 
void Delete (InvInstance invInstance)
 Deletes a given inventory item instance, provided it is a part of this collection More...
 
void Delete (InvInstance invInstance, int amount)
 Deletes a given inventory item instance, provided it is a part of this collection More...
 
void Delete (int itemID, int amount)
 Deletes a set number of inventory item instances More...
 
void DeleteAtIndex (int index, int amount)
 Deletes a set number of inventory item instances at a given index More...
 
void DeleteAllOfType (int itemID)
 Deletes all inventory item instances associated with a given inventory item More...
 
void DeleteAll ()
 
void DeleteAllInCategory (int categoryID)
 Deletes all item instances in a specific category More...
 
void DeleteRecipeIngredients (Recipe recipe)
 Deletes all item instances that make up a recipe's ingredients More...
 
int IndexOf (InvInstance invInstance)
 
string GetSaveData ()
 
InvInstance GetInstanceAtIndex (int index)
 Gets the inventory item instance in the collection at a given index More...
 
int GetInstanceIndex (InvInstance invInstance)
 Gets the index that a given Inventory item instance is at in the collection More...
 
int GetCount (int invID, bool includeMultipleInSameSlot=true)
 Gets the amount of instances in the collection that represent a given inventory item More...
 
int GetCount (bool includeMultipleInSameSlot=true)
 Gets the amount of instances in the collection More...
 
int GetCountInCategory (int categoryID, bool includeMultipleInSameSlot=true)
 Gets the amount of instances in the collection that represent an inventory item in a given category More...
 
bool Contains (InvInstance invInstance)
 
bool Contains (int invID)
 
InvInstance GetFirstInstance (int invID)
 Gets the first-found inventory item instance in the collection that's associated with a specific inventory item More...
 
InvInstance GetFirstInstance (string invName)
 Gets the first-found inventory item instance in the collection that's associated with a specific inventory item More...
 
InvInstance[] GetAllInstances (int invID)
 Gets all inventory item instance in the collection that are associated with a specific inventory item More...
 
InvInstance[] GetAllInstances (string invName)
 Gets all inventory item instance in the collection that are associated with a specific inventory item More...
 
int GetTotalIntProperty (int propertyID)
 Gets the total value of all instances of an Integer inventory property (e.g. currency) within a set of inventory items. More...
 
int GetTotalIntProperty (string propertyName)
 Gets the total value of all instances of an Integer inventory property (e.g. currency) within a set of inventory items. More...
 
float GetTotalFloatProperty (int propertyID)
 Gets the total value of all instances of an Float inventory property (e.g. weight) within a set of inventory items. More...
 
float GetTotalFloatProperty (string propertyName)
 Gets the total value of all instances of an Float inventory property (e.g. weight) within a set of inventory items. More...
 
InvVar GetPropertyTotals (int propertyID)
 Gets the total amount of given integer or float inventory property, found in the current inventory More...
 
InvInstance[] GetInstancesInCategory (int categoryID)
 Gets an array of all carried inventory items in a given category More...
 
bool IsPlayerInventory ()
 
Container GetSourceContainer ()
 

Static Public Member Functions

static List< InvInstanceDataToInstances (string data)
 
static InvCollection LoadData (string data)
 

Properties

List< InvInstanceInvInstances [get]
 
List< InvItemInvItems [get]
 
int MaxSlots [get, set]
 

Detailed Description

This class stores a list of InvInstance (inventory item instances), and has functions to manage them.

Constructor & Destructor Documentation

◆ InvCollection() [1/4]

AC.InvCollection.InvCollection ( )

The default Constructor

◆ InvCollection() [2/4]

AC.InvCollection.InvCollection ( List< InvItem invItems)

A Constructor that populates itself with default inventory data

◆ InvCollection() [3/4]

AC.InvCollection.InvCollection ( List< InvInstance _invInstances,
bool  allowEmptySlots = false 
)

A Constructor that populates itself based on an existing list of inventory item instances.

Parameters
_invInstancesA List of InvInstances that represent the items to be added
allowEmptySlotsIf True, then invalid or empty entries in the _invInstances List will be included and used to add empty slots, rather than removed

◆ InvCollection() [4/4]

AC.InvCollection.InvCollection ( Container  container)

A Constructor that populates itself based on a Container's default set of items

Member Function Documentation

◆ Add()

InvInstance AC.InvCollection.Add ( InvInstance  addInstance,
bool  matchPropertiesWhenMerging = true 
)

Adds an inventory item instance to the collection. If the item exists in another collection, it will be removed from there automatically.

Parameters
addInstanceThe inventory item instance to add
Returns
The new instance of the added item

◆ AddToEnd()

InvInstance AC.InvCollection.AddToEnd ( InvInstance  addInstance)

Adds an inventory item instance to the end of the collection - or the first-available empty slot. If the item exists in another collection, it will be removed from there automatically.

Parameters
addInstanceThe inventory item instance to add
Returns
The new instance of the added item

◆ Contains() [1/2]

bool AC.InvCollection.Contains ( int  invID)

Checks if the collection contains an inventory instance associated with a given inventory item

◆ Contains() [2/2]

bool AC.InvCollection.Contains ( InvInstance  invInstance)

Checks if the collection contains a given inventory instance

◆ Delete() [1/3]

void AC.InvCollection.Delete ( int  itemID,
int  amount 
)

Deletes a set number of inventory item instances

Parameters
itemIDThe ID of the inventory item to delete
amountThe amount to delete

◆ Delete() [2/3]

void AC.InvCollection.Delete ( InvInstance  invInstance)

Deletes a given inventory item instance, provided it is a part of this collection

Parameters
invInstanceThe inventory item instance to delete

◆ Delete() [3/3]

void AC.InvCollection.Delete ( InvInstance  invInstance,
int  amount 
)

Deletes a given inventory item instance, provided it is a part of this collection

Parameters
invInstanceThe inventory item instance to delete
amountThe amount to delete

◆ DeleteAll()

void AC.InvCollection.DeleteAll ( )

Deletes all item instances in the collection

◆ DeleteAllInCategory()

void AC.InvCollection.DeleteAllInCategory ( int  categoryID)

Deletes all item instances in a specific category

Parameters
categoryIDThe ID of the category to remove items from

◆ DeleteAllOfType()

void AC.InvCollection.DeleteAllOfType ( int  itemID)

Deletes all inventory item instances associated with a given inventory item

Parameters
itemIDThe ID of the inventory item to delete

◆ DeleteAtIndex()

void AC.InvCollection.DeleteAtIndex ( int  index,
int  amount 
)

Deletes a set number of inventory item instances at a given index

Parameters
indexThe index to delete from
amountThe amount to delete

◆ DeleteRecipeIngredients()

void AC.InvCollection.DeleteRecipeIngredients ( Recipe  recipe)

Deletes all item instances that make up a recipe's ingredients

Parameters
recipeThe recipe to delete ingredients from

◆ GetAllInstances() [1/2]

InvInstance [] AC.InvCollection.GetAllInstances ( int  invID)

Gets all inventory item instance in the collection that are associated with a specific inventory item

Parameters
invIDThe ID of the inventory item
Returns
An array of inventory item instance

◆ GetAllInstances() [2/2]

InvInstance [] AC.InvCollection.GetAllInstances ( string  invName)

Gets all inventory item instance in the collection that are associated with a specific inventory item

Parameters
invNameThe nameof the inventory item
Returns
An array of inventory item instance

◆ GetCount() [1/2]

int AC.InvCollection.GetCount ( bool  includeMultipleInSameSlot = true)

Gets the amount of instances in the collection

Parameters
includeMultipleInSameSlotIf True, then the result will account for multiple amounts of an item in a single slot
Returns
The amount of instances in the collection

◆ GetCount() [2/2]

int AC.InvCollection.GetCount ( int  invID,
bool  includeMultipleInSameSlot = true 
)

Gets the amount of instances in the collection that represent a given inventory item

Parameters
invIDThe inventory item's ID number
includeMultipleInSameSlotIf True, then the result will account for multiple amounts of the item in a single slot
Returns
The amount of instances in the collection that represent the inventory item

◆ GetCountInCategory()

int AC.InvCollection.GetCountInCategory ( int  categoryID,
bool  includeMultipleInSameSlot = true 
)

Gets the amount of instances in the collection that represent an inventory item in a given category

Parameters
categoryIDThe category's ID number.
includeMultipleInSameSlotIf True, then the result will account for multiple amounts of the item in a single slot
Returns
The amount of instances in the collection that represent inventory items in the category

◆ GetFirstInstance() [1/2]

InvInstance AC.InvCollection.GetFirstInstance ( int  invID)

Gets the first-found inventory item instance in the collection that's associated with a specific inventory item

Parameters
invIDThe ID number of the inventory item
Returns
The first-found inventory item instance

◆ GetFirstInstance() [2/2]

InvInstance AC.InvCollection.GetFirstInstance ( string  invName)

Gets the first-found inventory item instance in the collection that's associated with a specific inventory item

Parameters
invNameThe name of the inventory item
Returns
The first-found inventory item instance

◆ GetInstanceAtIndex()

InvInstance AC.InvCollection.GetInstanceAtIndex ( int  index)

Gets the inventory item instance in the collection at a given index

Parameters
indexThe index to get
Returns
The inventory item instance at the index

◆ GetInstanceIndex()

int AC.InvCollection.GetInstanceIndex ( InvInstance  invInstance)

Gets the index that a given Inventory item instance is at in the collection

Parameters
invInstanceThe Inventory item instance to get
Returns
The item instance's index in the collection, or -1 if it is not present

◆ GetInstancesInCategory()

InvInstance [] AC.InvCollection.GetInstancesInCategory ( int  categoryID)

Gets an array of all carried inventory items in a given category

Parameters
categoryIDThe ID number of the category in question
Returns
An array of all carried inventory items in the category

◆ GetPropertyTotals()

InvVar AC.InvCollection.GetPropertyTotals ( int  propertyID)

Gets the total amount of given integer or float inventory property, found in the current inventory

Parameters
propertyIDThe ID of the integer or float inventory property
Returns
The total amount of the property's value

◆ GetSaveData()

string AC.InvCollection.GetSaveData ( )

Generates a single string that represents the class's saveable data

◆ GetSourceContainer()

Container AC.InvCollection.GetSourceContainer ( )

Gets the Container that this collection represents, if appropriate

◆ GetTotalFloatProperty() [1/2]

float AC.InvCollection.GetTotalFloatProperty ( int  propertyID)

Gets the total value of all instances of an Float inventory property (e.g. weight) within a set of inventory items.

Parameters
propertyIDThe ID number of the Inventory property (see InvVar) to get the total value of
Returns
The total value of all instances of the Float inventory property within the set of inventory items

◆ GetTotalFloatProperty() [2/2]

float AC.InvCollection.GetTotalFloatProperty ( string  propertyName)

Gets the total value of all instances of an Float inventory property (e.g. weight) within a set of inventory items.

Parameters
propertyNameThe name of the Inventory property (see InvVar) to get the total value of
Returns
The total value of all instances of the Float inventory property within the set of inventory items

◆ GetTotalIntProperty() [1/2]

int AC.InvCollection.GetTotalIntProperty ( int  propertyID)

Gets the total value of all instances of an Integer inventory property (e.g. currency) within a set of inventory items.

Parameters
propertyIDThe ID number of the Inventory property (see InvVar) to get the total value of
Returns
The total value of all instances of the Integer inventory property within the set of inventory items

◆ GetTotalIntProperty() [2/2]

int AC.InvCollection.GetTotalIntProperty ( string  propertyName)

Gets the total value of all instances of an Integer inventory property (e.g. currency) within a set of inventory items.

Parameters
propertyNameThe name of the Inventory property (see InvVar) to get the total value of
Returns
The total value of all instances of the Integer inventory property within the set of inventory items

◆ IndexOf()

int AC.InvCollection.IndexOf ( InvInstance  invInstance)

Gets the index of a given inventory item instance

◆ Insert()

InvInstance AC.InvCollection.Insert ( InvInstance  addInstance,
int  index,
OccupiedSlotBehaviour  occupiedSlotBehaviour = OccupiedSlotBehaviour.ShiftItems,
bool  matchPropertiesWhenMerging = true 
)

Inserts an inventory item instance into a specific index in the collection. If the item exists in another collection, it will be removed from there automatically.

Parameters
addInstanceThe inventory item instance to add
indexThe index to insert the item at
occupiedSlotBehaviourHow to react if the intended index is already occupied by another item instance.
Returns
The new instance of the added item

◆ IsPlayerInventory()

bool AC.InvCollection.IsPlayerInventory ( )

Checks if this collection represents the player's inventory

◆ LoadData()

static InvCollection AC.InvCollection.LoadData ( string  data)
static

Create a new class isntance based on a serialised data string generated by the GetSaveData function

◆ Transfer() [1/4]

void AC.InvCollection.Transfer ( int  invID,
InvCollection  fromCollection 
)

Transfer all counts of a given inventory item from another collection

Parameters
invIDThe ID of the inventory item (InvItem) to transfer
fromCollectionThe collection to transfer from

◆ Transfer() [2/4]

void AC.InvCollection.Transfer ( int  invID,
InvCollection  fromCollection,
int  amount,
bool  matchPropertiesWhenMerging = true 
)

Transfer a set count of a given inventory item from another collection

Parameters
invIDThe ID of the inventory item (InvItem) to transfer
fromCollectionThe collection to transfer from
amountThe amount of items to transfer
matchPropertiesWhenMergingIf True, then the property values of two slots that represent the same item must match for them to merge

◆ Transfer() [3/4]

void AC.InvCollection.Transfer ( InvInstance  invInstance,
InvCollection  fromCollection 
)

Transfer all counts of a given inventory item from another collection

Parameters
invInstanceThe instance of the inventory item (InvItem) to transfer
fromCollectionThe collection to transfer from

◆ Transfer() [4/4]

void AC.InvCollection.Transfer ( InvInstance  invInstance,
InvCollection  fromCollection,
int  amount,
bool  matchPropertiesWhenMerging = true 
)

Transfer a set count of a given inventory item from another collection

Parameters
invInstanceThe instance of the inventory item to transfer
fromCollectionThe collection to transfer from
amountThe amount of items to transfer
matchPropertiesWhenMergingIf True, then the property values of two slots that represent the same item must match for them to merge

◆ TransferAll()

void AC.InvCollection.TransferAll ( InvCollection  fromCollection)

Transfers all items from another collection

Parameters
fromCollectionThe collection of inventory item instances to transfer from

Property Documentation

◆ InvInstances

List<InvInstance> AC.InvCollection.InvInstances
get

All Inventory item instances in the collection

◆ InvItems

List<InvItem> AC.InvCollection.InvItems
get

A list of all Inventory Items represented in the collection.

◆ MaxSlots

int AC.InvCollection.MaxSlots
getset

If > 0, the maximum number of slots the collection has to store items