This class represents a 2D array of items. It is used as the underlying storage and API for all cases that use a grid of items:
The items contained in this object are accessed either by a pair of XY coords, or a slot number (x + Width * y). There are functions available for converting between the two formats.
Name | Parameters | Return value | Notes |
AddItem |
ItemStack, [AllowNewStacks], [PrioritarySlot] |
number |
Adds as many items out of ItemStack as can fit. If AllowNewStacks is set to false, only existing stacks can be topped up. If AllowNewStacks is set to true (default), empty slots can be used for the rest. If PrioritarySlot is set to a non-negative value, then the corresponding slot will be used first (if empty or compatible with added items). If PrioritarySlot is set to -1 (default), regular order applies. Returns the number of items that fit. |
AddItems |
ItemStackList, [AllowNewStacks], [PrioritarySlot] |
number |
Same as AddItem, but works on an entire list of item stacks. The a_ItemStackList is modified to reflect the leftover items. If a_AllowNewStacks is set to false, only existing stacks can be topped up. If AllowNewStacks is set to true, empty slots can be used for the rest. If PrioritarySlot is set to a non-negative value, then the corresponding slot will be used first (if empty or compatible with added items). If PrioritarySlot is set to -1 (default), regular order applies. Returns the total number of items that fit. |
ChangeSlotCount |
SlotNum, AddToCount |
number |
Adds AddToCount to the count of items in the specified slot. If the slot was empty, ignores the call. Returns the new count in the slot, or -1 if invalid SlotNum |
ChangeSlotCount |
X, Y, AddToCount |
number |
Adds AddToCount to the count of items in the specified slot. If the slot was empty, ignores the call. Returns the new count in the slot, or -1 if invalid slot coords |
Clear |
|
|
Empties all slots |
CopyToItems |
cItems |
|
Copies all non-empty slots into the cItems object provided; original cItems contents are preserved as well. |
DamageItem |
SlotNum, [DamageAmount] |
bool |
Adds the specified damage (1 by default) to the specified item, returns true if the item reached its max damage and should be destroyed |
DamageItem |
X, Y, [DamageAmount] |
bool |
Adds the specified damage (1 by default) to the specified item, returns true if the item reached its max damage and should be destroyed |
EmptySlot |
SlotNum |
|
Destroys the item in the specified slot |
EmptySlot |
X, Y |
|
Destroys the item in the specified slot |
GetFirstEmptySlot |
|
number |
Returns the SlotNumber of the first empty slot, -1 if all slots are full |
GetFirstUsedSlot |
|
number |
Returns the SlotNumber of the first non-empty slot, -1 if all slots are empty |
GetHeight |
|
number |
Returns the Y dimension of the grid |
GetLastEmptySlot |
|
number |
Returns the SlotNumber of the last empty slot, -1 if all slots are full |
GetLastUsedSlot |
|
number |
Returns the SlotNumber of the last non-empty slot, -1 if all slots are empty |
GetNextEmptySlot |
StartFrom |
number |
Returns the SlotNumber of the first empty slot following StartFrom, -1 if all the following slots are full |
GetNextUsedSlot |
StartFrom |
number |
Returns the SlotNumber of the first non-empty slot following StartFrom, -1 if all the following slots are full |
GetNumSlots |
|
number |
Returns the total number of slots in the grid (Width * Height) |
GetSlot |
SlotNumber |
cItem |
Returns the item in the specified slot. Note that the item is read-only |
GetSlot |
X, Y |
cItem |
Returns the item in the specified slot. Note that the item is read-only |
GetSlotCoords |
SlotNum |
number, number |
Returns the X and Y coords for the specified SlotNumber. Returns "-1, -1" on invalid SlotNumber |
GetSlotNum |
X, Y |
number |
Returns the SlotNumber for the specified slot coords. Returns -1 on invalid coords |
GetWidth |
|
number |
Returns the X dimension of the grid |
HasItems |
cItem |
bool |
Returns true if there are at least as many items of the specified type as in the parameter |
HowManyCanFit |
cItem, [AllowNewStacks] |
number |
Returns the number of the specified items that can fit in the storage. If AllowNewStacks is true (default), includes empty slots in the returned count. |
HowManyItems |
cItem |
number |
Returns the number of the specified items that are currently stored |
IsSlotEmpty |
SlotNum |
bool |
Returns true if the specified slot is empty, or an invalid slot is specified |
IsSlotEmpty |
X, Y |
bool |
Returns true if the specified slot is empty, or an invalid slot is specified |
RemoveItem |
cItem |
number |
Removes the specified item from the grid, as many as possible, up to the item's m_ItemCount. Returns the number of items that were removed. |
RemoveOneItem |
SlotNum |
cItem |
Removes one item from the stack in the specified slot and returns it as a single cItem. Empty slots are skipped and an empty item is returned |
RemoveOneItem |
X, Y |
cItem |
Removes one item from the stack in the specified slot and returns it as a single cItem. Empty slots are skipped and an empty item is returned |
SetSlot |
SlotNum, ItemType, ItemCount, ItemDamage |
|
Sets the specified slot to the specified item |
SetSlot |
SlotNum, cItem |
|
Sets the specified slot to the specified item |
SetSlot |
X, Y, ItemType, ItemCount, ItemDamage |
|
Sets the specified slot to the specified item |
SetSlot |
X, Y, cItem |
|
Sets the specified slot to the specified item |