Inventory
What the player is carrying: item id -> count, capped by each item's definition.
Constructor
new Inventory(definitions: roAssociativeArray): InventoryParameters
definitions(roAssociativeArray) — item id -> ItemDefinition (at least a max)
Instance Methods
clear(): void
Empties the inventory.
Returns
void
count(id: string): integer
Parameters
id(string) — an item id from the story's items
Returns
integer— how many are carried
has(id: string): boolean
Parameters
id(string) — an item id from the story's items
Returns
boolean— true if at least one is carried
canAdd(id: string): boolean
Parameters
id(string) — an item id from the story's items
Returns
boolean— true if the item is defined and fewer than its max are carried
add(id: string): boolean
Adds one of an item. This doesn't run its onAcquire effects - the giveItem effect does.
Parameters
id(string) — an item id from the story's items
Returns
boolean— false if the item isn't defined or its max is already carried
remove(id: string): boolean
Removes one of an item.
Parameters
id(string) — an item id from the story's items
Returns
boolean— false if none was carried
toAA(): roAssociativeArray
A copy of what is carried, e.g. to save or list on an inventory screen.
Returns
roAssociativeArray— item id -> count (items not carried are left out)
loadAA(data: roAssociativeArray): void
Replaces the contents with saved ones (from toAA()). Unknown items and non-integer counts are dropped, and counts are capped at each item's max.
Parameters
data(roAssociativeArray) — item id -> count
Returns
void