Class Inventory
- Namespace
- AO
- Assembly
- CoreAssembly.dll
Instance of an inventory. Inventories store a collection of item instances. Inventories are automatically saved and synced across the network when modified from the server.
public class Inventory
- Inheritance
-
Inventory
- Inherited Members
- Extension Methods
Fields
OnInventoryEvent
public Action<string, Item_Instance> OnInventoryEvent
Field Value
Properties
Capacity
public long Capacity { get; set; }
Property Value
Id
public string Id { get; set; }
Property Value
Items
All the items in the inventory. If the inventory has a fixed size some items may be null.
public Item_Instance[] Items { get; }
Property Value
Methods
CalculateRoomInInventoryForItem(Item_Definition, Inventory)
Returns the count of how many instances of 'definition' we can possibly add to 'inventory' based on how full it already is.
public static long CalculateRoomInInventoryForItem(Item_Definition definition, Inventory inventory)
Parameters
definition
Item_Definitioninventory
Inventory
Returns
CanMoveItemToInventory(Item_Instance, Inventory)
Returns whether or not there is space in the inventory to add the given item.
public static bool CanMoveItemToInventory(Item_Instance instance, Inventory inventory)
Parameters
instance
Item_Instanceinventory
Inventory
Returns
CanSwapItems(Inventory, Inventory, long, long)
Returns whether the given item slots of the given inventories can be swapped. Currently just ensures that the slot indices are within the bounds of the given inventories.
public static bool CanSwapItems(Inventory a, Inventory b, long slotA, long slotB)
Parameters
Returns
CreateInventory(string, long)
Creates an inventory. 'uniqueId' must be different for all inventories but must match on client and server for network replication.
public static Inventory CreateInventory(string uniqueId, long capacity)
Parameters
Returns
CreateItem(Item_Definition, long)
public static Item_Instance CreateItem(Item_Definition definition, long count = 1)
Parameters
definition
Item_Definitioncount
long
Returns
DestroyAllItems()
Destroys all items in the inventory, clearing it. Will sync to the client when called on the server.
public void DestroyAllItems()
DestroyInventory(Inventory)
Destroys an inventory and all items inside it.
public static bool DestroyInventory(Inventory inventory)
Parameters
inventory
Inventory
Returns
DestroyItem(Item_Instance, long)
Decrements Item_Instance.Quantity by 'count'. If this brings the quantity below 1, destroy the whole Item_Instance. If 'count' == -1, destroy the whole Item_Instance.
public static void DestroyItem(Item_Instance instance, long count = -1)
Parameters
instance
Item_Instancecount
long
Draw(Rect, string, DrawOptions)
Draw the default inventory UI.
public static extern bool Draw(Rect rect, string id, Inventory.DrawOptions options)
Parameters
rect
Rectid
stringoptions
Inventory.DrawOptions
Returns
- bool
False when the player has closed the inventory UI by pressing the built in close button. True all other times.
DrawHotbar(string, DrawOptions)
Draw the default hotbar UI.
public static extern Inventory.DrawHotbarResult DrawHotbar(string id, Inventory.DrawOptions options)
Parameters
id
stringoptions
Inventory.DrawOptions
Returns
MoveItemToInventory(Item_Instance, Inventory)
Moves the given item to the given inventory. Make sure you call CanMoveItemToInventory() before calling MoveItemToInventory() to make sure there is enough room. Fails if there is not enough space for the item. Removes the given item from its current inventory if it is in one. If the item definition has a stack size greater than 1, the given item may be destroyed if the stack gets split among multiple slots.
public static void MoveItemToInventory(Item_Instance instance, Inventory inventory)
Parameters
instance
Item_Instanceinventory
Inventory
RemoveItemFromInventory(Item_Instance, Inventory)
Removes the item from the given inventory. Fails if the item is not in that inventory already.
public static void RemoveItemFromInventory(Item_Instance instance, Inventory inventory)
Parameters
instance
Item_Instanceinventory
Inventory
ServerForceSyncInventory(Inventory)
Forces an inventory sync to all clients. Inventory synchronization is done automatically when inventories are modified but when a new player joins you might want to manually sync.
public static void ServerForceSyncInventory(Inventory inventory)
Parameters
inventory
Inventory
SetCapacity(long)
Set the capacity of the inventory. Cannot set the capacity lower than the current number of items.
public void SetCapacity(long capacity)
Parameters
capacity
long
SwapItems(Inventory, Inventory, long, long)
Swaps the given item slots of the given inventories.
public static void SwapItems(Inventory a, Inventory b, long slotA, long slotB)