Item Commands
Inventory, equipment, and item usage commands for players.Members
- _type
- addItem
- addStates
- atk
- buyItem
- consumable
- createItemInstance
- description
- elements
- equip
- getItem
- hasItem
- hitRate
- hpValue
- id
- mpValue
- name
- onAdd
- onEquip
- onRemove
- onUse
- onUseFailed
- paramsModifier
- pdef
- price
- removeItem
- removeStates
- resolveEquipmentsSnapshot
- resolveItemsSnapshot
- sdef
- sellItem
- useItem
- WithItemManager
_type
Item type (for equipment validation)- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemData
Signature
addItem
Add an item in the player’s inventory You can add items using:- Item class (automatically registered in database if needed)
- Item object (automatically registered in database if needed)
- String ID (must be pre-registered in database)
onAdd() method is called on the ItemClass or ItemObject when the item is added.
- Source:
packages/server/src/Player/ItemManager.ts - Kind:
method - Defined in:
IItemManager
Signature
Parameters
item:ItemClass | ItemObject | stringnb?:number
Returns
The item instance added to inventoryExamples
addStates
States to add when used- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemData
Signature
atk
Get the player’s attack (sum of items equipped) Returns the total attack value from all equipped items on the player.- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
IItemManager
Signature
Returns
Total attack value from equipped itemsExamples
buyItem
Purchases an item and reduces the amount of gold The player’s gold is reduced bynb * item.price. The item is then added to the inventory.
The onAdd() method is called on the ItemClass when the item is added.
- Source:
packages/server/src/Player/ItemManager.ts - Kind:
method - Defined in:
IItemManager
Signature
Parameters
item:ItemClass | ItemObject | stringnb?:number
Returns
Item instance added to inventoryExamples
consumable
Whether the item is consumable- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemData
Signature
createItemInstance
Create an item instance without inventory changes or hook execution.- Source:
packages/server/src/Player/ItemManager.ts - Kind:
method
Signature
Parameters
item:ItemClass | ItemObject | stringnb?:number
description
Item description- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemData
Signature
elements
Elemental properties- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemData
Signature
equip
Equips a weapon or armor on a player Think first to add the item in the inventory with theaddItem() method before equipping the item,
or pass "auto" to add the item if it is missing and equip it.
The onEquip() method is called on the ItemClass when the item is equipped or unequipped.
- Source:
packages/server/src/Player/ItemManager.ts - Kind:
method - Defined in:
IItemManager
Signature
Parameters
itemId:stringequip?:boolean | 'auto'
Examples
getItem
Retrieves the information of an object: the number and the instance The returned Item instance contains the quantity information accessible viaquantity() method.
- Source:
packages/server/src/Player/ItemManager.ts - Kind:
method - Defined in:
IItemManager
Signature
Parameters
itemClass:ItemClass | string
Returns
Item instance containing quantity and item dataExamples
hasItem
Check if the player has the item in his inventory- Source:
packages/server/src/Player/ItemManager.ts - Kind:
method - Defined in:
IItemManager
Signature
Parameters
itemClass:ItemClass | string
Returns
true if player has the item, false otherwise
Examples
hitRate
Chance to successfully use the item (0-1)- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemData
Signature
hpValue
HP value restored when used- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemData
Signature
id
Item identifier (required if not using class or string)- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property
Signature
mpValue
MP/SP value restored when used- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemData
Signature
name
Item name- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemData
Signature
onAdd
Called when the item is added to the player’s inventory- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemHooks
Signature
Parameters
- “ - The player receiving the item
onEquip
Called when the item is equipped or unequipped- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemHooks
Signature
Parameters
- “ - true if equipping, false if unequipping
onRemove
Called when the item is removed from the inventory- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemHooks
Signature
Parameters
- “ - The player losing the item
onUse
Called when the item is successfully used- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemHooks
Signature
Parameters
- “ - The player using the item
onUseFailed
Called when the item usage fails (e.g., chance roll failed)- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemHooks
Signature
Parameters
- “ - The player attempting to use the item
paramsModifier
Parameter modifiers- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemData
Signature
pdef
Get the player’s physical defense (sum of items equipped) Returns the total physical defense value from all equipped items on the player.- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
IItemManager
Signature
Returns
Total physical defense value from equipped itemsExamples
price
Item price- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemData
Signature
removeItem
Deletes an item from inventory Decreases the quantity bynb. If the quantity falls to 0 or below, the item is removed from the inventory.
The method returns undefined if the item is completely removed.
The onRemove() method is called on the ItemClass when the item is removed.
- Source:
packages/server/src/Player/ItemManager.ts - Kind:
method - Defined in:
IItemManager
Signature
Parameters
itemClass:ItemClass | stringnb?:number
Returns
Item instance orundefined if the item was completely removed
Examples
removeStates
States to remove when used- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
ItemData
Signature
resolveEquipmentsSnapshot
Resolve equipment snapshot entries into Item instances without side effects.- Source:
packages/server/src/Player/ItemManager.ts - Kind:
method
Signature
Parameters
snapshot:{ equipments?: any[]; items?: any[] }mapOverride?:any
resolveItemsSnapshot
Resolve item snapshot entries into Item instances without side effects.- Source:
packages/server/src/Player/ItemManager.ts - Kind:
method
Signature
Parameters
snapshot:{ items?: any[] }mapOverride?:any
sdef
Get the player’s skill defense (sum of items equipped) Returns the total skill defense value from all equipped items on the player.- Source:
packages/server/src/Player/ItemManager.ts - Kind:
property - Defined in:
IItemManager
Signature
Returns
Total skill defense value from equipped itemsExamples
sellItem
Sell an item and the player wins the amount of the item divided by 2 The player receives(item.price / 2) * nbToSell gold. The item is removed from the inventory.
The onRemove() method is called on the ItemClass when the item is removed.
- Source:
packages/server/src/Player/ItemManager.ts - Kind:
method - Defined in:
IItemManager
Signature
Parameters
itemClass:ItemClass | stringnbToSell?:number
Returns
Item instance that was soldExamples
useItem
Use an object. Applies effects and states. Removes the object from the inventory When an item is used:- Effects are applied to the player (HP/MP restoration, etc.)
- States are applied/removed as defined in the item
- The item is removed from inventory (consumed)
hitRate property (0-1), there’s a chance the usage might fail.
If usage fails, the item is still removed and onUseFailed() is called instead of onUse().
The onUse() method is called on the ItemClass if the use was successful.
The onUseFailed() method is called on the ItemClass if the chance roll failed.
The onRemove() method is called on the ItemClass when the item is removed.
- Source:
packages/server/src/Player/ItemManager.ts - Kind:
method - Defined in:
IItemManager
Signature
Parameters
itemClass:ItemClass | string
Returns
Item instance that was usedExamples
WithItemManager
Item Manager Mixin Provides comprehensive item management capabilities to any class. This mixin handles inventory management, item usage, equipment, buying/selling, and item effects. It manages the complete item system including restrictions, transactions, and equipment.- Source:
packages/server/src/Player/ItemManager.ts - Kind:
function
Signature
Parameters
Base:TBase