Inventory

new Inventory()

Inventory component for item management.

Extends

Classes

Inventory
Inventory

Members

currency :number

Currency alias for gold.

Type:
  • number

equipment :Object

Equipment mapping getter mirroring the equipment system slots. Non-null slots are enumerable so Object.entries(equipment) reflects only equipped items, while direct slot property access (e.g. equipment.mainHand or equipment.weapon) returns the item or null.

Type:
  • Object

isFull

Check if inventory is full.

isFull :boolean

Check if inventory is full.

Type:
  • boolean

(readonly) properties

The entity that this component is attached to.

Inherited From

Methods

addCurrency(amount) → {number}

Add currency (gold).

Parameters:
NameTypeDescription
amountnumber
Returns:

Total currency.

Type: 
number

addItem(item, quantity) → {boolean}

Add an item to inventory.

Parameters:
NameTypeDefaultDescription
itemItem
quantitynumber1
Returns:

True if added successfully.

Type: 
boolean

addItem(itemOrId, quantityopt, optionsopt) → {boolean}

Add an item to the inventory. Stacks with existing matching slots up to maxStack, then allocates new slots. Enforces maxSlots capacity limits to prevent overflow.

Parameters:
NameTypeAttributesDefaultDescription
itemOrIdObject | string
quantitynumber<optional>
1
optionsObject<optional>
Returns:

True if added successfully, false if rejected due to capacity.

Type: 
boolean

canAddItem(itemOrId, quantityopt) → {boolean}

Check whether an item quantity can be added without exceeding capacity limits.

Parameters:
NameTypeAttributesDefaultDescription
itemOrIdObject | string
quantitynumber<optional>
1
Returns:
Type: 
boolean

consume(itemId, target) → {boolean}

Consume a consumable item, applying its effects to the target and decrementing count. Supports targets that are Combatant, Stats, or custom entities.

Parameters:
NameTypeDescription
itemIdstring
targetObject

Target Combatant or Stats.

Returns:

True if consumed successfully, false otherwise.

Type: 
boolean

consumeItem(itemId, target) → {boolean}

Alias for consume.

Parameters:
NameTypeDescription
itemIdstring
targetObject
Returns:
Type: 
boolean

createSnapshot() → {Object}

Create persistence snapshot of inventory, equipment, and currency.

Returns:
Type: 
Object

deserialize(props)

Populates the component properties from a data object. Override this method for custom property handling.

Parameters:
NameTypeDescription
propsobject

The properties object (usually from JSON).

Inherited From

equip(slotOrItemId, maybeItemIdopt) → {Object|boolean}

Equip an item from inventory into designated equipment slot.

Parameters:
NameTypeAttributesDescription
slotOrItemIdstring
maybeItemIdstring<optional>
Returns:
Type: 
Object | boolean

getItemCount(itemId) → {number}

Get total count of an item.

Parameters:
NameTypeDescription
itemIdstring
Returns:
Type: 
number

getItemCount(itemId) → {number}

Get total quantity of an item across all slots.

Parameters:
NameTypeDescription
itemIdstring
Returns:
Type: 
number

getItemMaxStack(item) → {number}

Resolve the maxStack limit for an item.

Parameters:
NameTypeDescription
itemObject
Returns:
Type: 
number

hasCurrency(amount) → {boolean}

Check if inventory has at least currency amount.

Parameters:
NameTypeDescription
amountnumber
Returns:
Type: 
boolean

hasItem(itemId, quantity) → {boolean}

Check if inventory contains an item.

Parameters:
NameTypeDefaultDescription
itemIdstring
quantitynumber1
Returns:
Type: 
boolean

hasItem(itemId, quantityopt) → {boolean}

Check if inventory contains at least quantity of an item.

Parameters:
NameTypeAttributesDefaultDescription
itemIdstring
quantitynumber<optional>
1
Returns:
Type: 
boolean

loadJSON(data)

Load state from plain JSON representation.

Parameters:
NameTypeDescription
dataObject

removeCurrency(amount) → {boolean}

Deduct currency (gold) if sufficient.

Parameters:
NameTypeDescription
amountnumber
Returns:

True if deducted, false if insufficient.

Type: 
boolean

removeItem(itemId, quantity) → {boolean}

Remove an item from inventory.

Parameters:
NameTypeDefaultDescription
itemIdstring
quantitynumber1
Returns:

True if removed successfully.

Type: 
boolean

removeItem(itemId, quantityopt) → {boolean}

Remove an item quantity from the inventory.

Parameters:
NameTypeAttributesDefaultDescription
itemIdstring
quantitynumber<optional>
1
Returns:

True if removed successfully, false if insufficient items.

Type: 
boolean

restoreSnapshot(snapshot, optionsopt) → {boolean}

Restore inventory, equipment, and currency from persistence snapshot.

Parameters:
NameTypeAttributesDescription
snapshotObject
optionsObject<optional>
Returns:
Type: 
boolean

toJSON() → {Object}

Export to plain JSON representation.

Returns:
Type: 
Object

unequip(slot) → {Object|boolean}

Unequip an item from equipment slot back into inventory. Rejects if inventory has no capacity to store the unequipped item.

Parameters:
NameTypeDescription
slotstring
Returns:

Unequipped item or false if failed.

Type: 
Object | boolean

useItem(itemId, target) → {boolean}

Alias for consume.

Parameters:
NameTypeDescription
itemIdstring
targetObject
Returns:
Type: 
boolean

Inventory Inventory

Slot-based inventory with stacking (maxStack), capacity limits (maxSlots), item add/remove/consume methods, and integrated equipment handling.

Constructor

new Inventory(maxSlotsOrConfigopt, configopt)

Parameters:
NameTypeAttributesDefaultDescription
maxSlotsOrConfignumber | Object<optional>
20

Max slots number or configuration object.

configObject<optional>

Optional configuration when first param is number.

Classes

Inventory
Inventory

Members

currency :number

Currency alias for gold.

Type:
  • number

equipment :Object

Equipment mapping getter mirroring the equipment system slots. Non-null slots are enumerable so Object.entries(equipment) reflects only equipped items, while direct slot property access (e.g. equipment.mainHand or equipment.weapon) returns the item or null.

Type:
  • Object

isFull

Check if inventory is full.

isFull :boolean

Check if inventory is full.

Type:
  • boolean

(readonly) properties

The entity that this component is attached to.

Inherited From

Methods

addCurrency(amount) → {number}

Add currency (gold).

Parameters:
NameTypeDescription
amountnumber
Returns:

Total currency.

Type: 
number

addItem(item, quantity) → {boolean}

Add an item to inventory.

Parameters:
NameTypeDefaultDescription
itemItem
quantitynumber1
Returns:

True if added successfully.

Type: 
boolean

addItem(itemOrId, quantityopt, optionsopt) → {boolean}

Add an item to the inventory. Stacks with existing matching slots up to maxStack, then allocates new slots. Enforces maxSlots capacity limits to prevent overflow.

Parameters:
NameTypeAttributesDefaultDescription
itemOrIdObject | string
quantitynumber<optional>
1
optionsObject<optional>
Returns:

True if added successfully, false if rejected due to capacity.

Type: 
boolean

canAddItem(itemOrId, quantityopt) → {boolean}

Check whether an item quantity can be added without exceeding capacity limits.

Parameters:
NameTypeAttributesDefaultDescription
itemOrIdObject | string
quantitynumber<optional>
1
Returns:
Type: 
boolean

consume(itemId, target) → {boolean}

Consume a consumable item, applying its effects to the target and decrementing count. Supports targets that are Combatant, Stats, or custom entities.

Parameters:
NameTypeDescription
itemIdstring
targetObject

Target Combatant or Stats.

Returns:

True if consumed successfully, false otherwise.

Type: 
boolean

consumeItem(itemId, target) → {boolean}

Alias for consume.

Parameters:
NameTypeDescription
itemIdstring
targetObject
Returns:
Type: 
boolean

createSnapshot() → {Object}

Create persistence snapshot of inventory, equipment, and currency.

Returns:
Type: 
Object

deserialize(props)

Populates the component properties from a data object. Override this method for custom property handling.

Parameters:
NameTypeDescription
propsobject

The properties object (usually from JSON).

Inherited From

equip(slotOrItemId, maybeItemIdopt) → {Object|boolean}

Equip an item from inventory into designated equipment slot.

Parameters:
NameTypeAttributesDescription
slotOrItemIdstring
maybeItemIdstring<optional>
Returns:
Type: 
Object | boolean

getItemCount(itemId) → {number}

Get total count of an item.

Parameters:
NameTypeDescription
itemIdstring
Returns:
Type: 
number

getItemCount(itemId) → {number}

Get total quantity of an item across all slots.

Parameters:
NameTypeDescription
itemIdstring
Returns:
Type: 
number

getItemMaxStack(item) → {number}

Resolve the maxStack limit for an item.

Parameters:
NameTypeDescription
itemObject
Returns:
Type: 
number

hasCurrency(amount) → {boolean}

Check if inventory has at least currency amount.

Parameters:
NameTypeDescription
amountnumber
Returns:
Type: 
boolean

hasItem(itemId, quantity) → {boolean}

Check if inventory contains an item.

Parameters:
NameTypeDefaultDescription
itemIdstring
quantitynumber1
Returns:
Type: 
boolean

hasItem(itemId, quantityopt) → {boolean}

Check if inventory contains at least quantity of an item.

Parameters:
NameTypeAttributesDefaultDescription
itemIdstring
quantitynumber<optional>
1
Returns:
Type: 
boolean

loadJSON(data)

Load state from plain JSON representation.

Parameters:
NameTypeDescription
dataObject

removeCurrency(amount) → {boolean}

Deduct currency (gold) if sufficient.

Parameters:
NameTypeDescription
amountnumber
Returns:

True if deducted, false if insufficient.

Type: 
boolean

removeItem(itemId, quantity) → {boolean}

Remove an item from inventory.

Parameters:
NameTypeDefaultDescription
itemIdstring
quantitynumber1
Returns:

True if removed successfully.

Type: 
boolean

removeItem(itemId, quantityopt) → {boolean}

Remove an item quantity from the inventory.

Parameters:
NameTypeAttributesDefaultDescription
itemIdstring
quantitynumber<optional>
1
Returns:

True if removed successfully, false if insufficient items.

Type: 
boolean

restoreSnapshot(snapshot, optionsopt) → {boolean}

Restore inventory, equipment, and currency from persistence snapshot.

Parameters:
NameTypeAttributesDescription
snapshotObject
optionsObject<optional>
Returns:
Type: 
boolean

toJSON() → {Object}

Export to plain JSON representation.

Returns:
Type: 
Object

unequip(slot) → {Object|boolean}

Unequip an item from equipment slot back into inventory. Rejects if inventory has no capacity to store the unequipped item.

Parameters:
NameTypeDescription
slotstring
Returns:

Unequipped item or false if failed.

Type: 
Object | boolean

useItem(itemId, target) → {boolean}

Alias for consume.

Parameters:
NameTypeDescription
itemIdstring
targetObject
Returns:
Type: 
boolean