@rpgjs/server 5.0.0-alpha.8 → 5.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/dist/Gui/DialogGui.d.ts +5 -0
  2. package/dist/Gui/GameoverGui.d.ts +23 -0
  3. package/dist/Gui/Gui.d.ts +6 -0
  4. package/dist/Gui/MenuGui.d.ts +22 -3
  5. package/dist/Gui/NotificationGui.d.ts +1 -2
  6. package/dist/Gui/SaveLoadGui.d.ts +13 -0
  7. package/dist/Gui/ShopGui.d.ts +28 -3
  8. package/dist/Gui/TitleGui.d.ts +23 -0
  9. package/dist/Gui/index.d.ts +10 -1
  10. package/dist/Player/BattleManager.d.ts +44 -32
  11. package/dist/Player/ClassManager.d.ts +24 -4
  12. package/dist/Player/ComponentManager.d.ts +100 -7
  13. package/dist/Player/Components.d.ts +345 -0
  14. package/dist/Player/EffectManager.d.ts +50 -4
  15. package/dist/Player/ElementManager.d.ts +77 -4
  16. package/dist/Player/GoldManager.d.ts +1 -1
  17. package/dist/Player/GuiManager.d.ts +233 -5
  18. package/dist/Player/ItemFixture.d.ts +1 -1
  19. package/dist/Player/ItemManager.d.ts +431 -4
  20. package/dist/Player/MoveManager.d.ts +301 -34
  21. package/dist/Player/ParameterManager.d.ts +364 -28
  22. package/dist/Player/Player.d.ts +558 -14
  23. package/dist/Player/SkillManager.d.ts +187 -13
  24. package/dist/Player/StateManager.d.ts +75 -4
  25. package/dist/Player/VariableManager.d.ts +62 -4
  26. package/dist/RpgServer.d.ts +278 -63
  27. package/dist/RpgServerEngine.d.ts +2 -1
  28. package/dist/decorators/event.d.ts +46 -0
  29. package/dist/decorators/map.d.ts +299 -0
  30. package/dist/index.d.ts +10 -0
  31. package/dist/index.js +17920 -29866
  32. package/dist/index.js.map +1 -1
  33. package/dist/logs/log.d.ts +2 -3
  34. package/dist/module-CaCW1SDh.js +11018 -0
  35. package/dist/module-CaCW1SDh.js.map +1 -0
  36. package/dist/module.d.ts +43 -1
  37. package/dist/node/connection.d.ts +51 -0
  38. package/dist/node/index.d.ts +5 -0
  39. package/dist/node/index.js +551 -0
  40. package/dist/node/index.js.map +1 -0
  41. package/dist/node/map.d.ts +16 -0
  42. package/dist/node/room.d.ts +21 -0
  43. package/dist/node/transport.d.ts +28 -0
  44. package/dist/node/types.d.ts +47 -0
  45. package/dist/presets/index.d.ts +0 -9
  46. package/dist/rooms/BaseRoom.d.ts +132 -0
  47. package/dist/rooms/lobby.d.ts +10 -2
  48. package/dist/rooms/map.d.ts +1359 -32
  49. package/dist/services/save.d.ts +43 -0
  50. package/dist/storage/index.d.ts +1 -0
  51. package/dist/storage/localStorage.d.ts +23 -0
  52. package/package.json +25 -10
  53. package/src/Gui/DialogGui.ts +19 -4
  54. package/src/Gui/GameoverGui.ts +39 -0
  55. package/src/Gui/Gui.ts +23 -1
  56. package/src/Gui/MenuGui.ts +155 -6
  57. package/src/Gui/NotificationGui.ts +1 -2
  58. package/src/Gui/SaveLoadGui.ts +60 -0
  59. package/src/Gui/ShopGui.ts +146 -16
  60. package/src/Gui/TitleGui.ts +39 -0
  61. package/src/Gui/index.ts +15 -2
  62. package/src/Player/BattleManager.ts +39 -56
  63. package/src/Player/ClassManager.ts +82 -74
  64. package/src/Player/ComponentManager.ts +401 -37
  65. package/src/Player/Components.ts +380 -0
  66. package/src/Player/EffectManager.ts +50 -96
  67. package/src/Player/ElementManager.ts +74 -152
  68. package/src/Player/GuiManager.ts +284 -149
  69. package/src/Player/ItemManager.ts +747 -341
  70. package/src/Player/MoveManager.ts +1532 -750
  71. package/src/Player/ParameterManager.ts +636 -106
  72. package/src/Player/Player.ts +1273 -79
  73. package/src/Player/SkillManager.ts +558 -197
  74. package/src/Player/StateManager.ts +131 -258
  75. package/src/Player/VariableManager.ts +85 -157
  76. package/src/RpgServer.ts +293 -62
  77. package/src/decorators/event.ts +61 -0
  78. package/src/decorators/map.ts +343 -0
  79. package/src/index.ts +11 -1
  80. package/src/logs/log.ts +10 -3
  81. package/src/module.ts +126 -3
  82. package/src/node/connection.ts +254 -0
  83. package/src/node/index.ts +22 -0
  84. package/src/node/map.ts +328 -0
  85. package/src/node/room.ts +63 -0
  86. package/src/node/transport.ts +532 -0
  87. package/src/node/types.ts +61 -0
  88. package/src/presets/index.ts +1 -10
  89. package/src/rooms/BaseRoom.ts +232 -0
  90. package/src/rooms/lobby.ts +25 -7
  91. package/src/rooms/map.ts +2682 -206
  92. package/src/services/save.ts +147 -0
  93. package/src/storage/index.ts +1 -0
  94. package/src/storage/localStorage.ts +76 -0
  95. package/tests/battle.spec.ts +375 -0
  96. package/tests/change-map.spec.ts +72 -0
  97. package/tests/class.spec.ts +274 -0
  98. package/tests/custom-websocket.spec.ts +127 -0
  99. package/tests/effect.spec.ts +219 -0
  100. package/tests/element.spec.ts +221 -0
  101. package/tests/event.spec.ts +80 -0
  102. package/tests/gold.spec.ts +99 -0
  103. package/tests/item.spec.ts +609 -0
  104. package/tests/module.spec.ts +38 -0
  105. package/tests/move.spec.ts +601 -0
  106. package/tests/node-transport.spec.ts +223 -0
  107. package/tests/player-param.spec.ts +45 -0
  108. package/tests/prediction-reconciliation.spec.ts +182 -0
  109. package/tests/random-move.spec.ts +65 -0
  110. package/tests/skill.spec.ts +658 -0
  111. package/tests/state.spec.ts +467 -0
  112. package/tests/variable.spec.ts +185 -0
  113. package/tests/world-maps.spec.ts +896 -0
  114. package/vite.config.ts +36 -3
  115. package/dist/Player/Event.d.ts +0 -0
  116. package/src/Player/Event.ts +0 -0
@@ -1,4 +1,10 @@
1
- import { PlayerCtor } from '@rpgjs/common';
1
+ import { RpgPlayer } from './Player';
2
+ import { Gui } from '../Gui';
3
+ import { DialogOptions, Choice } from '../Gui/DialogGui';
4
+ import { SaveLoadOptions, SaveSlot } from '../Gui/SaveLoadGui';
5
+ import { MenuGuiOptions } from '../Gui/MenuGui';
6
+ import { GameoverGuiOptions, GameoverGuiSelection } from '../Gui/GameoverGui';
7
+ import { PlayerCtor } from '../../../common/src';
2
8
  /**
3
9
  * GUI Manager Mixin
4
10
  *
@@ -23,9 +29,231 @@ import { PlayerCtor } from '@rpgjs/common';
23
29
  * player.callMainMenu();
24
30
  * ```
25
31
  */
26
- export declare function WithGuiManager<TBase extends PlayerCtor>(Base: TBase): TBase;
32
+ export declare function WithGuiManager<TBase extends PlayerCtor>(Base: TBase): new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> & IGuiManager;
27
33
  /**
28
- * Type helper to extract the interface from the WithGuiManager mixin
29
- * This provides the type without duplicating method signatures
34
+ * Interface for GUI management capabilities
35
+ * Defines the methods that will be available on the player
30
36
  */
31
- export type IGuiManager = InstanceType<ReturnType<typeof WithGuiManager>>;
37
+ export interface IGuiManager {
38
+ /**
39
+ * Show a text. This is a graphical interface already built. Opens the GUI named `rpg-dialog`
40
+ *
41
+ * ```ts
42
+ * player.showText('Hello World')
43
+ * ```
44
+ *
45
+ * The method returns a promise. It is resolved when the dialog box is closed.
46
+ *
47
+ * ```ts
48
+ * await player.showText('Hello World')
49
+ * // dialog box is closed, then ...
50
+ * ```
51
+ *
52
+ * **Option: position**
53
+ *
54
+ * You can define how the dialog box is displayed:
55
+ * - top
56
+ * - middle
57
+ * - bottom
58
+ *
59
+ * (bottom by default)
60
+ *
61
+ * ```ts
62
+ * player.showText('Hello World', {
63
+ * position: 'top'
64
+ * })
65
+ * ```
66
+ *
67
+ * **Option: fullWidth**
68
+ *
69
+ * `boolean` (true by default)
70
+ *
71
+ * Indicate that the dialog box will take the full width of the screen.
72
+ *
73
+ * ```ts
74
+ * player.showText('Hello World', {
75
+ * fullWidth: true
76
+ * })
77
+ * ```
78
+ *
79
+ * **Option: autoClose**
80
+ *
81
+ * `boolean` (false by default)
82
+ *
83
+ * If false, the user will have to press Enter to close the dialog box.
84
+ *
85
+ * ```ts
86
+ * player.showText('Hello World', {
87
+ * autoClose: true
88
+ * })
89
+ * ```
90
+ *
91
+ * **Option: typewriterEffect**
92
+ *
93
+ * `boolean` (true by default)
94
+ *
95
+ * Performs a typewriter effect
96
+ *
97
+ * ```ts
98
+ * player.showText('Hello World', {
99
+ * typewriterEffect: false
100
+ * })
101
+ * ```
102
+ *
103
+ * **Option: talkWith**
104
+ *
105
+ * `RpgPlayer` (nothing by default)
106
+ *
107
+ * If you specify the event or another player, the other player will stop his or her movement and look in the player's direction.
108
+ *
109
+ * ```ts
110
+ * // Code in an event
111
+ * player.showText('Hello World', {
112
+ * talkWith: this
113
+ * })
114
+ * ```
115
+ *
116
+ * @title Show Text
117
+ * @method player.showText(text,options)
118
+ * @param {string} text
119
+ * @param {object} [options] the different options, see usage below
120
+ * @returns {Promise}
121
+ * @memberof GuiManager
122
+ */
123
+ showText(msg: string, options?: DialogOptions): Promise<any>;
124
+ /**
125
+ * Shows a dialog box with a choice. Opens the GUI named `rpg-dialog`
126
+ *
127
+ * ```ts
128
+ * const choice = await player.showChoices('What color do you prefer?', [
129
+ * { text: 'Black', value: 'black' },
130
+ * { text: 'Rather the blue', value: 'blue' },
131
+ * { text: 'I don\'t have a preference!', value: 'none' }
132
+ * ])
133
+ *
134
+ * // If the player selects the first
135
+ * console.log(choice) // { text: 'Black', value: 'black' }
136
+ * ```
137
+ *
138
+ * @title Show Choices
139
+ * @method player.showChoices(text,choices)
140
+ * @param {string} text
141
+ * @param {Array<{ text: string, value: any }>} choices
142
+ * @param {object} [options] Same options as the openDialog method
143
+ * @returns {Promise<Choice | null>}
144
+ * @memberof GuiManager
145
+ */
146
+ showChoices(msg: string, choices: Choice[], options?: DialogOptions): Promise<Choice | null>;
147
+ /**
148
+ * Displays a notification . Opens the GUI named `rpg-notification`
149
+ *
150
+ * @title Displays a notification
151
+ * @method player.showNotification()
152
+ * @param {string} message - The message to display in the notification
153
+ * @param {object} options - An object containing options for the notification
154
+ * @param {number} options.time - The time to display the notification for (in ms). Default: 2000ms
155
+ * @param {string} options.icon - The icon to display in the notification. Put the identifier of the spritesheet (defined on the client side)
156
+ * @param {string} options.sound - The sound to play when the notification is shown. Set the sound ID (defined on the client side)
157
+ * @returns {void}
158
+ * @memberof GuiManager
159
+ */
160
+ showNotification(message: string, options?: {
161
+ time?: number;
162
+ icon?: string;
163
+ sound?: string;
164
+ type?: "info" | "warn" | "error";
165
+ }): Promise<any>;
166
+ /**
167
+ * Display a save/load slots screen. Opens the GUI named `rpg-save`
168
+ *
169
+ * ```ts
170
+ * const index = await player.showSaveLoad(slots, { mode: 'save' })
171
+ * ```
172
+ *
173
+ * @title Show Save/Load
174
+ * @method player.showSaveLoad(slots,options)
175
+ * @param {Array<object>} slots
176
+ * @param {object} [options]
177
+ * @returns {Promise<number | null>}
178
+ * @memberof GuiManager
179
+ */
180
+ showSaveLoad(slots?: SaveSlot[], options?: SaveLoadOptions): Promise<number | null>;
181
+ /**
182
+ * Display a save slots screen. Opens the GUI named `rpg-save`
183
+ *
184
+ * ```ts
185
+ * const index = await player.showSave(slots)
186
+ * ```
187
+ *
188
+ * @title Show Save
189
+ * @method player.showSave(slots,options)
190
+ * @param {Array<object>} slots
191
+ * @param {object} [options]
192
+ * @returns {Promise<number | null>}
193
+ * @memberof GuiManager
194
+ */
195
+ showSave(slots?: SaveSlot[], options?: SaveLoadOptions): Promise<number | null>;
196
+ /**
197
+ * Display a load slots screen. Opens the GUI named `rpg-save`
198
+ *
199
+ * ```ts
200
+ * const index = await player.showLoad(slots)
201
+ * ```
202
+ *
203
+ * @title Show Load
204
+ * @method player.showLoad(slots,options)
205
+ * @param {Array<object>} slots
206
+ * @param {object} [options]
207
+ * @returns {Promise<number | null>}
208
+ * @memberof GuiManager
209
+ */
210
+ showLoad(slots?: SaveSlot[], options?: SaveLoadOptions): Promise<number | null>;
211
+ /**
212
+ * Calls main menu. Opens the GUI named `rpg-main-menu`
213
+ *
214
+ * @title Call Main Menu
215
+ * @method player.callMainMenu(options)
216
+ * @param {object} [options]
217
+ * @returns {void}
218
+ * @memberof GuiManager
219
+ */
220
+ callMainMenu(options?: MenuGuiOptions): void;
221
+ /**
222
+ * Calls game over menu. Opens the GUI named `rpg-gameover`
223
+ *
224
+ * ```ts
225
+ * const selection = await player.callGameover()
226
+ * if (selection?.id === 'title') {
227
+ * await player.gui('rpg-title-screen').open()
228
+ * }
229
+ * if (selection?.id === 'load') {
230
+ * await player.showLoad()
231
+ * }
232
+ * ```
233
+ *
234
+ * @title Call Game Over Menu
235
+ * @method player.callGameover(options)
236
+ * @param {object} [options]
237
+ * @returns {Promise<GameoverGuiSelection | null>}
238
+ * @memberof GuiManager
239
+ */
240
+ callGameover(options?: GameoverGuiOptions): Promise<GameoverGuiSelection | null>;
241
+ callShop(items: any[] | {
242
+ items: any[];
243
+ sell?: Record<string, number> | Array<{
244
+ id: string;
245
+ multiplier: number;
246
+ }>;
247
+ sellMultiplier?: number;
248
+ message?: string;
249
+ face?: {
250
+ id: string;
251
+ expression?: string;
252
+ };
253
+ }): void;
254
+ gui(guiId: string): Gui;
255
+ getGui(guiId: string): Gui;
256
+ removeGui(guiId: string, data?: any): void;
257
+ showAttachedGui(players?: RpgPlayer[] | RpgPlayer): void;
258
+ hideAttachedGui(players?: RpgPlayer[] | RpgPlayer): void;
259
+ }
@@ -1,5 +1,5 @@
1
1
  import { ItemInstance } from '@rpgjs/database';
2
- import { PlayerCtor } from '@rpgjs/common';
2
+ import { PlayerCtor } from '../../../common/src';
3
3
  export declare function WithItemFixture<TBase extends PlayerCtor>(Base: TBase): TBase;
4
4
  export interface ItemFixture {
5
5
  equipments: ItemInstance[];
@@ -1,4 +1,145 @@
1
- import { PlayerCtor } from '@rpgjs/common';
1
+ import { Item, PlayerCtor } from '../../../common/src';
2
+ import { ItemClass } from '@rpgjs/database';
3
+ import { RpgPlayer } from './Player';
4
+ /**
5
+ * Interface defining the hooks that can be implemented on item classes or objects
6
+ *
7
+ * These hooks are called at specific moments during the item lifecycle:
8
+ * - `onAdd`: When the item is added to the player's inventory
9
+ * - `onUse`: When the item is successfully used
10
+ * - `onUseFailed`: When the item usage fails (e.g., chance roll failed)
11
+ * - `onRemove`: When the item is removed from the inventory
12
+ * - `onEquip`: When the item is equipped or unequipped
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const itemHooks: ItemHooks = {
17
+ * onAdd(player) {
18
+ * console.log('Item added to inventory');
19
+ * },
20
+ * onUse(player) {
21
+ * player.hp += 100;
22
+ * }
23
+ * };
24
+ * ```
25
+ */
26
+ export interface ItemHooks {
27
+ /**
28
+ * Called when the item is added to the player's inventory
29
+ *
30
+ * @param player - The player receiving the item
31
+ */
32
+ onAdd?: (player: RpgPlayer) => void | Promise<void>;
33
+ /**
34
+ * Called when the item is successfully used
35
+ *
36
+ * @param player - The player using the item
37
+ */
38
+ onUse?: (player: RpgPlayer) => void | Promise<void>;
39
+ /**
40
+ * Called when the item usage fails (e.g., chance roll failed)
41
+ *
42
+ * @param player - The player attempting to use the item
43
+ */
44
+ onUseFailed?: (player: RpgPlayer) => void | Promise<void>;
45
+ /**
46
+ * Called when the item is removed from the inventory
47
+ *
48
+ * @param player - The player losing the item
49
+ */
50
+ onRemove?: (player: RpgPlayer) => void | Promise<void>;
51
+ /**
52
+ * Called when the item is equipped or unequipped
53
+ *
54
+ * @param player - The player equipping/unequipping the item
55
+ * @param equip - true if equipping, false if unequipping
56
+ */
57
+ onEquip?: (player: RpgPlayer, equip: boolean) => void | Promise<void>;
58
+ }
59
+ /**
60
+ * Base properties that can be included in an item object
61
+ *
62
+ * This interface defines the common properties that items can have.
63
+ * Use this as a base and extend it with specific item types.
64
+ *
65
+ * @template T - Additional properties specific to the item type
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * interface PotionData extends ItemData {
70
+ * hpValue: number;
71
+ * mpValue: number;
72
+ * }
73
+ *
74
+ * const potion: ItemObject<PotionData> = {
75
+ * name: 'Health Potion',
76
+ * description: 'Restores 100 HP',
77
+ * price: 200,
78
+ * hpValue: 100,
79
+ * mpValue: 0,
80
+ * onUse(player) {
81
+ * player.hp += this.hpValue;
82
+ * }
83
+ * };
84
+ * ```
85
+ */
86
+ export interface ItemData {
87
+ /** Item name */
88
+ name?: string;
89
+ /** Item description */
90
+ description?: string;
91
+ /** Item price */
92
+ price?: number;
93
+ /** HP value restored when used */
94
+ hpValue?: number;
95
+ /** MP/SP value restored when used */
96
+ mpValue?: number;
97
+ /** Chance to successfully use the item (0-1) */
98
+ hitRate?: number;
99
+ /** Whether the item is consumable */
100
+ consumable?: boolean;
101
+ /** States to add when used */
102
+ addStates?: any[];
103
+ /** States to remove when used */
104
+ removeStates?: any[];
105
+ /** Elemental properties */
106
+ elements?: any[];
107
+ /** Parameter modifiers */
108
+ paramsModifier?: Record<string, any>;
109
+ /** Item type (for equipment validation) */
110
+ _type?: 'item' | 'weapon' | 'armor';
111
+ }
112
+ /**
113
+ * Item object type that combines data properties with hooks
114
+ *
115
+ * This type allows you to create item objects directly without needing a class.
116
+ * The object can contain both item data properties and lifecycle hooks.
117
+ *
118
+ * @template T - Additional properties specific to the item type (extends ItemData)
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * const potion: ItemObject = {
123
+ * name: 'Health Potion',
124
+ * description: 'Restores 100 HP',
125
+ * price: 200,
126
+ * hpValue: 100,
127
+ * consumable: true,
128
+ * onAdd(player) {
129
+ * console.log('Potion added!');
130
+ * },
131
+ * onUse(player) {
132
+ * player.hp += 100;
133
+ * }
134
+ * };
135
+ *
136
+ * player.addItem(potion);
137
+ * ```
138
+ */
139
+ export type ItemObject<T extends ItemData = ItemData> = T & ItemHooks & {
140
+ /** Item identifier (required if not using class or string) */
141
+ id?: string;
142
+ };
2
143
  /**
3
144
  * Item Manager Mixin
4
145
  *
@@ -25,7 +166,293 @@ import { PlayerCtor } from '@rpgjs/common';
25
166
  */
26
167
  export declare function WithItemManager<TBase extends PlayerCtor>(Base: TBase): TBase;
27
168
  /**
28
- * Type helper to extract the interface from the WithItemManager mixin
29
- * This provides the type without duplicating method signatures
169
+ * Interface for Item Manager functionality
170
+ *
171
+ * Provides comprehensive item management capabilities including inventory management,
172
+ * item usage, equipment, buying/selling, and item effects. This interface defines
173
+ * the public API of the ItemManager mixin.
30
174
  */
31
- export type IItemManager = InstanceType<ReturnType<typeof WithItemManager>>;
175
+ export interface IItemManager {
176
+ /**
177
+ * Retrieves the information of an object: the number and the instance
178
+ *
179
+ * The returned Item instance contains the quantity information accessible via `quantity()` method.
180
+ *
181
+ * @param itemClass - Item class or string identifier. If string, it's the item ID
182
+ * @returns Item instance containing quantity and item data
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * import Potion from 'your-database/potion'
187
+ *
188
+ * player.addItem(Potion, 5)
189
+ * const inventory = player.getItem(Potion)
190
+ * console.log(inventory.quantity()) // 5
191
+ * console.log(inventory) // <instance of Item>
192
+ * ```
193
+ */
194
+ getItem(itemClass: ItemClass | string): Item;
195
+ /**
196
+ * Check if the player has the item in his inventory
197
+ *
198
+ * @param itemClass - Item class or string identifier. If string, it's the item ID
199
+ * @returns `true` if player has the item, `false` otherwise
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * import Potion from 'your-database/potion'
204
+ *
205
+ * player.hasItem(Potion) // false
206
+ * player.addItem(Potion, 1)
207
+ * player.hasItem(Potion) // true
208
+ * ```
209
+ */
210
+ hasItem(itemClass: ItemClass | string): boolean;
211
+ /**
212
+ * Add an item in the player's inventory
213
+ *
214
+ * You can add items using:
215
+ * - Item class (automatically registered in database if needed)
216
+ * - Item object (automatically registered in database if needed)
217
+ * - String ID (must be pre-registered in database)
218
+ *
219
+ * The `onAdd()` method is called on the ItemClass or ItemObject when the item is added.
220
+ *
221
+ * @param item - Item class, object, or string identifier
222
+ * @param nb - Number of items to add (default: 1)
223
+ * @returns The item instance added to inventory
224
+ *
225
+ * @example
226
+ * ```ts
227
+ * import Potion from 'your-database/potion'
228
+ *
229
+ * // Add using class
230
+ * player.addItem(Potion, 5)
231
+ *
232
+ * // Add using string ID (must be registered in database)
233
+ * player.addItem('Potion', 3)
234
+ *
235
+ * // Add using object
236
+ * player.addItem({
237
+ * id: 'custom-potion',
238
+ * name: 'Custom Potion',
239
+ * price: 200,
240
+ * onAdd(player) {
241
+ * console.log('Custom potion added!')
242
+ * }
243
+ * }, 2)
244
+ * ```
245
+ */
246
+ addItem(item: ItemClass | ItemObject | string, nb?: number): Item;
247
+ /**
248
+ * Deletes an item from inventory
249
+ *
250
+ * Decreases the quantity by `nb`. If the quantity falls to 0 or below, the item is removed from the inventory.
251
+ * The method returns `undefined` if the item is completely removed.
252
+ *
253
+ * The `onRemove()` method is called on the ItemClass when the item is removed.
254
+ *
255
+ * @param itemClass - Item class or string identifier. If string, it's the item ID
256
+ * @param nb - Number of items to remove (default: 1)
257
+ * @returns Item instance or `undefined` if the item was completely removed
258
+ * @throws {Object} ItemLog.notInInventory - If the item is not in the inventory
259
+ * - `id`: `ITEM_NOT_INVENTORY`
260
+ * - `msg`: Error message
261
+ *
262
+ * @example
263
+ * ```ts
264
+ * import Potion from 'your-database/potion'
265
+ *
266
+ * try {
267
+ * player.removeItem(Potion, 5)
268
+ * } catch (err) {
269
+ * console.log(err) // { id: 'ITEM_NOT_INVENTORY', msg: '...' }
270
+ * }
271
+ * ```
272
+ */
273
+ removeItem(itemClass: ItemClass | string, nb?: number): Item | undefined;
274
+ /**
275
+ * Purchases an item and reduces the amount of gold
276
+ *
277
+ * The player's gold is reduced by `nb * item.price`. The item is then added to the inventory.
278
+ * The `onAdd()` method is called on the ItemClass when the item is added.
279
+ *
280
+ * @param item - Item class, object, or string identifier
281
+ * @param nb - Number of items to buy (default: 1)
282
+ * @returns Item instance added to inventory
283
+ * @throws {Object} ItemLog.haveNotPrice - If the item has no price set
284
+ * - `id`: `NOT_PRICE`
285
+ * - `msg`: Error message
286
+ * @throws {Object} ItemLog.notEnoughGold - If the player doesn't have enough gold
287
+ * - `id`: `NOT_ENOUGH_GOLD`
288
+ * - `msg`: Error message
289
+ *
290
+ * @example
291
+ * ```ts
292
+ * import Potion from 'your-database/potion'
293
+ *
294
+ * try {
295
+ * player.buyItem(Potion)
296
+ * } catch (err) {
297
+ * if (err.id === 'NOT_ENOUGH_GOLD') {
298
+ * console.log('Not enough gold!')
299
+ * } else if (err.id === 'NOT_PRICE') {
300
+ * console.log('Item has no price!')
301
+ * }
302
+ * }
303
+ * ```
304
+ */
305
+ buyItem(item: ItemClass | ItemObject | string, nb?: number): Item;
306
+ /**
307
+ * Sell an item and the player wins the amount of the item divided by 2
308
+ *
309
+ * The player receives `(item.price / 2) * nbToSell` gold. The item is removed from the inventory.
310
+ * The `onRemove()` method is called on the ItemClass when the item is removed.
311
+ *
312
+ * @param itemClass - Item class or string identifier. If string, it's the item ID
313
+ * @param nbToSell - Number of items to sell (default: 1)
314
+ * @returns Item instance that was sold
315
+ * @throws {Object} ItemLog.haveNotPrice - If the item has no price set
316
+ * - `id`: `NOT_PRICE`
317
+ * - `msg`: Error message
318
+ * @throws {Object} ItemLog.notInInventory - If the item is not in the inventory
319
+ * - `id`: `ITEM_NOT_INVENTORY`
320
+ * - `msg`: Error message
321
+ * @throws {Object} ItemLog.tooManyToSell - If trying to sell more items than available
322
+ * - `id`: `TOO_MANY_ITEM_TO_SELL`
323
+ * - `msg`: Error message
324
+ *
325
+ * @example
326
+ * ```ts
327
+ * import Potion from 'your-database/potion'
328
+ *
329
+ * try {
330
+ * player.addItem(Potion)
331
+ * player.sellItem(Potion)
332
+ * } catch (err) {
333
+ * console.log(err)
334
+ * }
335
+ * ```
336
+ */
337
+ sellItem(itemClass: ItemClass | string, nbToSell?: number): Item;
338
+ /**
339
+ * Use an object. Applies effects and states. Removes the object from the inventory
340
+ *
341
+ * When an item is used:
342
+ * - Effects are applied to the player (HP/MP restoration, etc.)
343
+ * - States are applied/removed as defined in the item
344
+ * - The item is removed from inventory (consumed)
345
+ *
346
+ * If the item has a `hitRate` property (0-1), there's a chance the usage might fail.
347
+ * If usage fails, the item is still removed and `onUseFailed()` is called instead of `onUse()`.
348
+ *
349
+ * The `onUse()` method is called on the ItemClass if the use was successful.
350
+ * The `onUseFailed()` method is called on the ItemClass if the chance roll failed.
351
+ * The `onRemove()` method is called on the ItemClass when the item is removed.
352
+ *
353
+ * @param itemClass - Item class or string identifier. If string, it's the item ID
354
+ * @returns Item instance that was used
355
+ * @throws {Object} ItemLog.restriction - If the player has the `Effect.CAN_NOT_ITEM` effect
356
+ * - `id`: `RESTRICTION_ITEM`
357
+ * - `msg`: Error message
358
+ * @throws {Object} ItemLog.notInInventory - If the item is not in the inventory
359
+ * - `id`: `ITEM_NOT_INVENTORY`
360
+ * - `msg`: Error message
361
+ * @throws {Object} ItemLog.notUseItem - If the item's `consumable` property is `false`
362
+ * - `id`: `NOT_USE_ITEM`
363
+ * - `msg`: Error message
364
+ * @throws {Object} ItemLog.chanceToUseFailed - If the chance to use the item failed (hitRate roll failed)
365
+ * - `id`: `USE_CHANCE_ITEM_FAILED`
366
+ * - `msg`: Error message
367
+ * - Note: The item is still deleted from the inventory even if usage failed
368
+ *
369
+ * @example
370
+ * ```ts
371
+ * import Potion from 'your-database/potion'
372
+ *
373
+ * try {
374
+ * player.addItem(Potion)
375
+ * player.useItem(Potion)
376
+ * } catch (err) {
377
+ * if (err.id === 'USE_CHANCE_ITEM_FAILED') {
378
+ * console.log('Item usage failed due to chance roll')
379
+ * } else {
380
+ * console.log(err)
381
+ * }
382
+ * }
383
+ * ```
384
+ */
385
+ useItem(itemClass: ItemClass | string): Item;
386
+ /**
387
+ * Equips a weapon or armor on a player
388
+ *
389
+ * Think first to add the item in the inventory with the `addItem()` method before equipping the item,
390
+ * or pass `"auto"` to add the item if it is missing and equip it.
391
+ *
392
+ * The `onEquip()` method is called on the ItemClass when the item is equipped or unequipped.
393
+ *
394
+ * @param itemId - Item identifier to resolve from the database
395
+ * @param equip - Equip the item if `true`, unequip if `false`, or `"auto"` to add then equip (default: `true`)
396
+ * @throws {Object} ItemLog.notInInventory - If the item is not in the inventory
397
+ * - `id`: `ITEM_NOT_INVENTORY`
398
+ * - `msg`: Error message
399
+ * @throws {Object} ItemLog.invalidToEquiped - If the item is not a weapon or armor (item._type is "item")
400
+ * - `id`: `INVALID_ITEM_TO_EQUIP`
401
+ * - `msg`: Error message
402
+ * @throws {Object} ItemLog.isAlreadyEquiped - If the item is already equipped
403
+ * - `id`: `ITEM_ALREADY_EQUIPED`
404
+ * - `msg`: Error message
405
+ *
406
+ * @example
407
+ * ```ts
408
+ * try {
409
+ * player.addItem('sword')
410
+ * player.equip('sword')
411
+ * // Later, unequip it
412
+ * player.equip('sword', false)
413
+ * } catch (err) {
414
+ * console.log(err)
415
+ * }
416
+ * ```
417
+ */
418
+ equip(itemId: string, equip?: boolean | 'auto'): void;
419
+ /**
420
+ * Get the player's attack (sum of items equipped)
421
+ *
422
+ * Returns the total attack value from all equipped items on the player.
423
+ *
424
+ * @returns Total attack value from equipped items
425
+ *
426
+ * @example
427
+ * ```ts
428
+ * console.log(player.atk) // 150 (sum of all equipped weapons/armors attack)
429
+ * ```
430
+ */
431
+ readonly atk: number;
432
+ /**
433
+ * Get the player's physical defense (sum of items equipped)
434
+ *
435
+ * Returns the total physical defense value from all equipped items on the player.
436
+ *
437
+ * @returns Total physical defense value from equipped items
438
+ *
439
+ * @example
440
+ * ```ts
441
+ * console.log(player.pdef) // 80 (sum of all equipped armors physical defense)
442
+ * ```
443
+ */
444
+ readonly pdef: number;
445
+ /**
446
+ * Get the player's skill defense (sum of items equipped)
447
+ *
448
+ * Returns the total skill defense value from all equipped items on the player.
449
+ *
450
+ * @returns Total skill defense value from equipped items
451
+ *
452
+ * @example
453
+ * ```ts
454
+ * console.log(player.sdef) // 60 (sum of all equipped armors skill defense)
455
+ * ```
456
+ */
457
+ readonly sdef: number;
458
+ }