@rpgjs/server 5.0.0-alpha.21 → 5.0.0-alpha.23

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.
@@ -1,8 +1,7 @@
1
- import { isInstanceOf, isString, Item, PlayerCtor, type Constructor } from "@rpgjs/common";
2
- import { RpgCommonPlayer, Matter } from "@rpgjs/common";
1
+ import { isInstanceOf, isString, Item, type PlayerCtor} from "@rpgjs/common";
3
2
  import { ATK, PDEF, SDEF } from "../presets";
4
3
  import { ItemLog } from "../logs";
5
- import { ArmorInstance, ItemClass, ItemInstance, WeaponInstance } from "@rpgjs/database";
4
+ import type { ItemClass, ItemInstance } from "@rpgjs/database";
6
5
  import { RpgPlayer } from "./Player";
7
6
 
8
7
  // Ajout des enums manquants
@@ -189,43 +188,11 @@ export type ItemObject<T extends ItemData = ItemData> = T & ItemHooks & {
189
188
  export function WithItemManager<TBase extends PlayerCtor>(Base: TBase) {
190
189
  return class extends Base {
191
190
 
192
- /**
193
- * Retrieves the information of an object: the number and the instance
194
- * @title Get Item
195
- * @method player.getItem(itemClass)
196
- * @param {ItemClass | string} itemClass Identifier of the object if the parameter is a string
197
- * @returns {{ nb: number, item: instance of ItemClass }}
198
- * @memberof ItemManager
199
- * @example
200
- *
201
- * ```ts
202
- * import Potion from 'your-database/potion'
203
- *
204
- * player.addItem(Potion, 5)
205
- * const inventory = player.getItem(Potion)
206
- * console.log(inventory) // { nb: 5, item: <instance of Potion> }
207
- * ```
208
- */
209
191
  getItem(itemClass: ItemClass | string): Item {
210
192
  const index: number = this._getItemIndex(itemClass);
211
193
  return (this as any).items()[index];
212
194
  }
213
195
 
214
- /**
215
- * Check if the player has the item in his inventory.
216
- * @title Has Item
217
- * @method player.hasItem(itemClass)
218
- * @param {ItemClass | string} itemClass Identifier of the object if the parameter is a string
219
- * @returns {boolean}
220
- * @memberof ItemManager
221
- * @example
222
- *
223
- * ```ts
224
- * import Potion from 'your-database/potion'
225
- *
226
- * player.hasItem(Potion) // false
227
- * ```
228
- */
229
196
  hasItem(itemClass: ItemClass | string): boolean {
230
197
  return !!this.getItem(itemClass);
231
198
  }
@@ -238,62 +205,6 @@ export function WithItemManager<TBase extends PlayerCtor>(Base: TBase) {
238
205
  return isInstanceOf(it, itemClass);
239
206
  });
240
207
  }
241
- /**
242
- * Add an item in the player's inventory. You can give more than one by specifying `nb`
243
- *
244
- * Supports three ways to add items:
245
- * 1. **String**: Pass a string ID to retrieve the item from the database (requires item to be registered in `@RpgModule` database).
246
- * 2. **Class**: Pass an item class (e.g., `Potion`). The class will be instantiated and automatically added to the map's database if not already present.
247
- * 3. **Object**: Pass an item object with properties and hooks directly. The object will be automatically added to the map's database if not already present.
248
- *
249
- * For classes and objects, if they don't exist in the database, they are automatically added using `map.addInDatabase()`.
250
- * This allows dynamic item creation without requiring pre-registration in the module database.
251
- *
252
- * `onAdd()` method is called on the ItemClass or ItemObject
253
- *
254
- * @title Add Item
255
- * @method player.addItem(item,nb=1)
256
- * @param {ItemClass | ItemObject | string} item - Item class, object, or string identifier
257
- * @param {number} [nb] Default 1
258
- * @returns {Item} The item instance added to inventory
259
- * @memberof ItemManager
260
- * @example
261
- *
262
- * ```ts
263
- * import Potion from 'your-database/potion'
264
- *
265
- * // Using string ID (retrieves from database - item must be in @RpgModule database)
266
- * player.addItem('Potion', 5)
267
- *
268
- * // Using class (creates instance, auto-adds to map database if not present)
269
- * player.addItem(Potion, 5)
270
- *
271
- * // Using object directly (auto-adds to map database if not present)
272
- * player.addItem({
273
- * id: 'custom-potion',
274
- * name: 'Custom Potion',
275
- * description: 'A custom potion',
276
- * price: 150,
277
- * hpValue: 50,
278
- * consumable: true,
279
- * onAdd(player) {
280
- * console.log('Custom potion added!');
281
- * },
282
- * onUse(player) {
283
- * player.hp += 50;
284
- * }
285
- * }, 3)
286
- *
287
- * // Object without ID (auto-generates ID and adds to database)
288
- * player.addItem({
289
- * name: 'Dynamic Item',
290
- * price: 100,
291
- * onUse(player) {
292
- * console.log('Dynamic item used!');
293
- * }
294
- * })
295
- * ```
296
- */
297
208
  addItem(item: ItemClass | ItemObject | string, nb: number = 1): Item {
298
209
  const map = (this as any).getCurrentMap();
299
210
  if (!map) {
@@ -387,38 +298,6 @@ export function WithItemManager<TBase extends PlayerCtor>(Base: TBase) {
387
298
  return instance;
388
299
  }
389
300
 
390
- /**
391
- * Deletes an item. Decreases the value `nb`. If the number falls to 0, then the item is removed from the inventory. The method then returns `undefined`
392
- *
393
- * `onRemove()` method is called on the ItemClass
394
- *
395
- * @title Remove Item
396
- * @method player.removeItem(item,nb=1)
397
- * @param {ItemClass | string} itemClass string is item id
398
- * @param {number} [nb] Default 1
399
- * @returns {{ nb: number, item: instance of ItemClass } | undefined}
400
- * @throws {ItemLog} notInInventory
401
- * If the object is not in the inventory, an exception is raised
402
- * ```
403
- * {
404
- * id: ITEM_NOT_INVENTORY,
405
- * msg: '...'
406
- * }
407
- * ```
408
- * @memberof ItemManager
409
- * @example
410
- *
411
- * ```ts
412
- * import Potion from 'your-database/potion'
413
- *
414
- * try {
415
- * player.removeItem(Potion, 5)
416
- * }
417
- * catch (err) {
418
- * console.log(err)
419
- * }
420
- * ```
421
- */
422
301
  removeItem(
423
302
  itemClass: ItemClass | string,
424
303
  nb: number = 1
@@ -440,50 +319,6 @@ export function WithItemManager<TBase extends PlayerCtor>(Base: TBase) {
440
319
  return this.items()[itemIndex];
441
320
  }
442
321
 
443
- /**
444
- * Purchases an item and reduces the amount of gold
445
- *
446
- * `onAdd()` method is called on the ItemClass
447
- *
448
- * @title Buy Item
449
- * @method player.buyItem(item,nb=1)
450
- * @param {ItemClass | string} itemClass Identifier of the object if the parameter is a string
451
- * @param {number} [nb] Default 1
452
- * @returns {{ nb: number, item: instance of ItemClass }}
453
- * @throws {ItemLog} haveNotPrice
454
- * If you have not set a price on the item
455
- * ```
456
- * {
457
- * id: NOT_PRICE,
458
- * msg: '...'
459
- * }
460
- * ```
461
- * @throws {ItemLog} notEnoughGold
462
- * If the player does not have enough money
463
- * ```
464
- * {
465
- * id: NOT_ENOUGH_GOLD,
466
- * msg: '...'
467
- * }
468
- * ```
469
- * @memberof ItemManager
470
- * @example
471
- *
472
- * ```ts
473
- * import Potion from 'your-database/potion'
474
- *
475
- * try {
476
- * // Using class
477
- * player.buyItem(Potion)
478
- *
479
- * // Using string ID
480
- * player.buyItem('Potion')
481
- * }
482
- * catch (err) {
483
- * console.log(err)
484
- * }
485
- * ```
486
- */
487
322
  buyItem(item: ItemClass | ItemObject | string, nb = 1): Item {
488
323
  let itemId: string;
489
324
  let data: any;
@@ -516,58 +351,6 @@ export function WithItemManager<TBase extends PlayerCtor>(Base: TBase) {
516
351
  return this.addItem(item, nb);
517
352
  }
518
353
 
519
- /**
520
- * Sell an item and the player wins the amount of the item divided by 2
521
- *
522
- * `onRemove()` method is called on the ItemClass
523
- *
524
- * @title Sell Item
525
- * @method player.sellItem(item,nb=1)
526
- * @param {ItemClass | string} itemClass Identifier of the object if the parameter is a string
527
- * @param {number} [nbToSell] Default 1
528
- * @returns {{ nb: number, item: instance of ItemClass }}
529
- * @throws {ItemLog} haveNotPrice
530
- * If you have not set a price on the item
531
- * ```
532
- * {
533
- * id: NOT_PRICE,
534
- * msg: '...'
535
- * }
536
- * ```
537
- * @throws {ItemLog} notInInventory
538
- * If the object is not in the inventory, an exception is raised
539
- * ```
540
- * {
541
- * id: ITEM_NOT_INVENTORY,
542
- * msg: '...'
543
- * }
544
- * ```
545
- * @throws {ItemLog} tooManyToSell
546
- * If the number of items for sale exceeds the number of actual items in the inventory
547
- * ```
548
- * {
549
- * id: TOO_MANY_ITEM_TO_SELL,
550
- * msg: '...'
551
- * }
552
- * ```
553
- * @memberof ItemManager
554
- * @example
555
- *
556
- * ```ts
557
- * import Potion from 'your-database/potion'
558
- *
559
- * try {
560
- * player.addItem(Potion)
561
- * // Using class
562
- * player.sellItem(Potion)
563
- * // Using string ID
564
- * player.sellItem('Potion')
565
- * }
566
- * catch (err) {
567
- * console.log(err)
568
- * }
569
- * ```
570
- */
571
354
  sellItem(itemClass: ItemClass | string, nbToSell = 1): Item {
572
355
  const itemId = isString(itemClass) ? itemClass : (itemClass as any).name;
573
356
  const data = (this as any).databaseById(itemId);
@@ -600,103 +383,18 @@ export function WithItemManager<TBase extends PlayerCtor>(Base: TBase) {
600
383
  return nb;
601
384
  }
602
385
 
603
- /**
604
- * recover the attack sum of items equipped on the player.
605
- *
606
- * @title Get the player's attack
607
- * @prop {number} player.atk
608
- * @memberof ItemManager
609
- */
610
386
  get atk(): number {
611
387
  return this.getParamItem(ATK);
612
388
  }
613
389
 
614
- /**
615
- * recover the physic defense sum of items equipped on the player.
616
- *
617
- * @title Get the player's pdef
618
- * @prop {number} player.pdef
619
- * @memberof ItemManager
620
- */
621
390
  get pdef(): number {
622
391
  return this.getParamItem(PDEF);
623
392
  }
624
393
 
625
- /**
626
- * recover the skill defense sum of items equipped on the player.
627
- *
628
- * @title Get the player's sdef
629
- * @prop {number} player.sdef
630
- * @memberof ItemManager
631
- */
632
394
  get sdef(): number {
633
395
  return this.getParamItem(SDEF);
634
396
  }
635
397
 
636
- /**
637
- * Use an object. Applies effects and states. Removes the object from the inventory then
638
- *
639
- * `onUse()` method is called on the ItemClass (If the use has worked)
640
- * `onRemove()` method is called on the ItemClass
641
- *
642
- * @title Use an Item
643
- * @method player.useItem(item,nb=1)
644
- * @param {ItemClass | string} itemClass Identifier of the object if the parameter is a string
645
- * @returns {{ nb: number, item: instance of ItemClass }}
646
- * @throws {ItemLog} restriction
647
- * If the player has the `Effect.CAN_NOT_ITEM` effect
648
- * ```
649
- * {
650
- * id: RESTRICTION_ITEM,
651
- * msg: '...'
652
- * }
653
- * ```
654
- * @throws {ItemLog} notInInventory
655
- * If the object is not in the inventory, an exception is raised
656
- * ```
657
- * {
658
- * id: ITEM_NOT_INVENTORY,
659
- * msg: '...'
660
- * }
661
- * ```
662
- * @throws {ItemLog} notUseItem
663
- * If the `consumable` property is on false
664
- * ```
665
- * {
666
- * id: NOT_USE_ITEM,
667
- * msg: '...'
668
- * }
669
- * ```
670
- * @throws {ItemLog} chanceToUseFailed
671
- * Chance to use the item has failed. Chances of use is defined with `ItemClass.hitRate`
672
- * ```
673
- * {
674
- * id: USE_CHANCE_ITEM_FAILED,
675
- * msg: '...'
676
- * }
677
- * ```
678
- * > the item is still deleted from the inventory
679
- *
680
- * `onUseFailed()` method is called on the ItemClass
681
- *
682
- * @memberof ItemManager
683
- * @example
684
- *
685
- * ```ts
686
- * import Potion from 'your-database/potion'
687
- *
688
- * try {
689
- * player.addItem(Potion)
690
- * // Using class
691
- * player.useItem(Potion)
692
- * // Using string ID
693
- * player.useItem('Potion')
694
- * }
695
- * catch (err) {
696
- * console.log(err)
697
- * }
698
- * ```
699
- */
700
398
  useItem(itemClass: ItemClass | string): Item {
701
399
  const itemId = isString(itemClass) ? itemClass : (itemClass as any).name;
702
400
  const inventory = this.getItem(itemClass);
@@ -724,58 +422,6 @@ export function WithItemManager<TBase extends PlayerCtor>(Base: TBase) {
724
422
  return inventory;
725
423
  }
726
424
 
727
- /**
728
- * Equips a weapon or armor on a player. Think first to add the item in the inventory with the `addItem()` method before equipping the item.
729
- *
730
- * `onEquip()` method is called on the ItemClass
731
- *
732
- * @title Equip Weapon or Armor
733
- * @method player.equip(itemClass,equip=true)
734
- * @param {ItemClass | string} itemClass Identifier of the object if the parameter is a string
735
- * @param {number} [equip] Equip the object if true or un-equipped if false
736
- * @returns {void}
737
- * @throws {ItemLog} notInInventory
738
- * If the item is not in the inventory
739
- * ```
740
- {
741
- id: ITEM_NOT_INVENTORY,
742
- msg: '...'
743
- }
744
- ```
745
- * @throws {ItemLog} invalidToEquiped
746
- If the item is not by a weapon or armor
747
- ```
748
- {
749
- id: INVALID_ITEM_TO_EQUIP,
750
- msg: '...'
751
- }
752
- ```
753
- * @throws {ItemLog} isAlreadyEquiped
754
- If the item Is already equipped
755
- ```
756
- {
757
- id: ITEM_ALREADY_EQUIPED,
758
- msg: '...'
759
- }
760
- ```
761
- * @memberof ItemManager
762
- * @example
763
- *
764
- * ```ts
765
- * import Sword from 'your-database/sword'
766
- *
767
- * try {
768
- * player.addItem(Sword)
769
- * // Using class
770
- * player.equip(Sword)
771
- * // Using string ID
772
- * player.equip('Sword')
773
- * }
774
- * catch (err) {
775
- * console.log(err)
776
- * }
777
- * ```
778
- */
779
425
  equip(
780
426
  itemClass: ItemClass | string,
781
427
  equip: boolean = true
@@ -821,7 +467,304 @@ export function WithItemManager<TBase extends PlayerCtor>(Base: TBase) {
821
467
  }
822
468
 
823
469
  /**
824
- * Type helper to extract the interface from the WithItemManager mixin
825
- * This provides the type without duplicating method signatures
470
+ * Interface for Item Manager functionality
471
+ *
472
+ * Provides comprehensive item management capabilities including inventory management,
473
+ * item usage, equipment, buying/selling, and item effects. This interface defines
474
+ * the public API of the ItemManager mixin.
826
475
  */
827
- export type IItemManager = InstanceType<ReturnType<typeof WithItemManager>>;
476
+ export interface IItemManager {
477
+ /**
478
+ * Retrieves the information of an object: the number and the instance
479
+ *
480
+ * The returned Item instance contains the quantity information accessible via `quantity()` method.
481
+ *
482
+ * @param itemClass - Item class or string identifier. If string, it's the item ID
483
+ * @returns Item instance containing quantity and item data
484
+ *
485
+ * @example
486
+ * ```ts
487
+ * import Potion from 'your-database/potion'
488
+ *
489
+ * player.addItem(Potion, 5)
490
+ * const inventory = player.getItem(Potion)
491
+ * console.log(inventory.quantity()) // 5
492
+ * console.log(inventory) // <instance of Item>
493
+ * ```
494
+ */
495
+ getItem(itemClass: ItemClass | string): Item;
496
+
497
+ /**
498
+ * Check if the player has the item in his inventory
499
+ *
500
+ * @param itemClass - Item class or string identifier. If string, it's the item ID
501
+ * @returns `true` if player has the item, `false` otherwise
502
+ *
503
+ * @example
504
+ * ```ts
505
+ * import Potion from 'your-database/potion'
506
+ *
507
+ * player.hasItem(Potion) // false
508
+ * player.addItem(Potion, 1)
509
+ * player.hasItem(Potion) // true
510
+ * ```
511
+ */
512
+ hasItem(itemClass: ItemClass | string): boolean;
513
+
514
+ /**
515
+ * Add an item in the player's inventory
516
+ *
517
+ * You can add items using:
518
+ * - Item class (automatically registered in database if needed)
519
+ * - Item object (automatically registered in database if needed)
520
+ * - String ID (must be pre-registered in database)
521
+ *
522
+ * The `onAdd()` method is called on the ItemClass or ItemObject when the item is added.
523
+ *
524
+ * @param item - Item class, object, or string identifier
525
+ * @param nb - Number of items to add (default: 1)
526
+ * @returns The item instance added to inventory
527
+ *
528
+ * @example
529
+ * ```ts
530
+ * import Potion from 'your-database/potion'
531
+ *
532
+ * // Add using class
533
+ * player.addItem(Potion, 5)
534
+ *
535
+ * // Add using string ID (must be registered in database)
536
+ * player.addItem('Potion', 3)
537
+ *
538
+ * // Add using object
539
+ * player.addItem({
540
+ * id: 'custom-potion',
541
+ * name: 'Custom Potion',
542
+ * price: 200,
543
+ * onAdd(player) {
544
+ * console.log('Custom potion added!')
545
+ * }
546
+ * }, 2)
547
+ * ```
548
+ */
549
+ addItem(item: ItemClass | ItemObject | string, nb?: number): Item;
550
+
551
+ /**
552
+ * Deletes an item from inventory
553
+ *
554
+ * Decreases the quantity by `nb`. If the quantity falls to 0 or below, the item is removed from the inventory.
555
+ * The method returns `undefined` if the item is completely removed.
556
+ *
557
+ * The `onRemove()` method is called on the ItemClass when the item is removed.
558
+ *
559
+ * @param itemClass - Item class or string identifier. If string, it's the item ID
560
+ * @param nb - Number of items to remove (default: 1)
561
+ * @returns Item instance or `undefined` if the item was completely removed
562
+ * @throws {Object} ItemLog.notInInventory - If the item is not in the inventory
563
+ * - `id`: `ITEM_NOT_INVENTORY`
564
+ * - `msg`: Error message
565
+ *
566
+ * @example
567
+ * ```ts
568
+ * import Potion from 'your-database/potion'
569
+ *
570
+ * try {
571
+ * player.removeItem(Potion, 5)
572
+ * } catch (err) {
573
+ * console.log(err) // { id: 'ITEM_NOT_INVENTORY', msg: '...' }
574
+ * }
575
+ * ```
576
+ */
577
+ removeItem(itemClass: ItemClass | string, nb?: number): Item | undefined;
578
+
579
+ /**
580
+ * Purchases an item and reduces the amount of gold
581
+ *
582
+ * The player's gold is reduced by `nb * item.price`. The item is then added to the inventory.
583
+ * The `onAdd()` method is called on the ItemClass when the item is added.
584
+ *
585
+ * @param item - Item class, object, or string identifier
586
+ * @param nb - Number of items to buy (default: 1)
587
+ * @returns Item instance added to inventory
588
+ * @throws {Object} ItemLog.haveNotPrice - If the item has no price set
589
+ * - `id`: `NOT_PRICE`
590
+ * - `msg`: Error message
591
+ * @throws {Object} ItemLog.notEnoughGold - If the player doesn't have enough gold
592
+ * - `id`: `NOT_ENOUGH_GOLD`
593
+ * - `msg`: Error message
594
+ *
595
+ * @example
596
+ * ```ts
597
+ * import Potion from 'your-database/potion'
598
+ *
599
+ * try {
600
+ * player.buyItem(Potion)
601
+ * } catch (err) {
602
+ * if (err.id === 'NOT_ENOUGH_GOLD') {
603
+ * console.log('Not enough gold!')
604
+ * } else if (err.id === 'NOT_PRICE') {
605
+ * console.log('Item has no price!')
606
+ * }
607
+ * }
608
+ * ```
609
+ */
610
+ buyItem(item: ItemClass | ItemObject | string, nb?: number): Item;
611
+
612
+ /**
613
+ * Sell an item and the player wins the amount of the item divided by 2
614
+ *
615
+ * The player receives `(item.price / 2) * nbToSell` gold. The item is removed from the inventory.
616
+ * The `onRemove()` method is called on the ItemClass when the item is removed.
617
+ *
618
+ * @param itemClass - Item class or string identifier. If string, it's the item ID
619
+ * @param nbToSell - Number of items to sell (default: 1)
620
+ * @returns Item instance that was sold
621
+ * @throws {Object} ItemLog.haveNotPrice - If the item has no price set
622
+ * - `id`: `NOT_PRICE`
623
+ * - `msg`: Error message
624
+ * @throws {Object} ItemLog.notInInventory - If the item is not in the inventory
625
+ * - `id`: `ITEM_NOT_INVENTORY`
626
+ * - `msg`: Error message
627
+ * @throws {Object} ItemLog.tooManyToSell - If trying to sell more items than available
628
+ * - `id`: `TOO_MANY_ITEM_TO_SELL`
629
+ * - `msg`: Error message
630
+ *
631
+ * @example
632
+ * ```ts
633
+ * import Potion from 'your-database/potion'
634
+ *
635
+ * try {
636
+ * player.addItem(Potion)
637
+ * player.sellItem(Potion)
638
+ * } catch (err) {
639
+ * console.log(err)
640
+ * }
641
+ * ```
642
+ */
643
+ sellItem(itemClass: ItemClass | string, nbToSell?: number): Item;
644
+
645
+ /**
646
+ * Use an object. Applies effects and states. Removes the object from the inventory
647
+ *
648
+ * When an item is used:
649
+ * - Effects are applied to the player (HP/MP restoration, etc.)
650
+ * - States are applied/removed as defined in the item
651
+ * - The item is removed from inventory (consumed)
652
+ *
653
+ * If the item has a `hitRate` property (0-1), there's a chance the usage might fail.
654
+ * If usage fails, the item is still removed and `onUseFailed()` is called instead of `onUse()`.
655
+ *
656
+ * The `onUse()` method is called on the ItemClass if the use was successful.
657
+ * The `onUseFailed()` method is called on the ItemClass if the chance roll failed.
658
+ * The `onRemove()` method is called on the ItemClass when the item is removed.
659
+ *
660
+ * @param itemClass - Item class or string identifier. If string, it's the item ID
661
+ * @returns Item instance that was used
662
+ * @throws {Object} ItemLog.restriction - If the player has the `Effect.CAN_NOT_ITEM` effect
663
+ * - `id`: `RESTRICTION_ITEM`
664
+ * - `msg`: Error message
665
+ * @throws {Object} ItemLog.notInInventory - If the item is not in the inventory
666
+ * - `id`: `ITEM_NOT_INVENTORY`
667
+ * - `msg`: Error message
668
+ * @throws {Object} ItemLog.notUseItem - If the item's `consumable` property is `false`
669
+ * - `id`: `NOT_USE_ITEM`
670
+ * - `msg`: Error message
671
+ * @throws {Object} ItemLog.chanceToUseFailed - If the chance to use the item failed (hitRate roll failed)
672
+ * - `id`: `USE_CHANCE_ITEM_FAILED`
673
+ * - `msg`: Error message
674
+ * - Note: The item is still deleted from the inventory even if usage failed
675
+ *
676
+ * @example
677
+ * ```ts
678
+ * import Potion from 'your-database/potion'
679
+ *
680
+ * try {
681
+ * player.addItem(Potion)
682
+ * player.useItem(Potion)
683
+ * } catch (err) {
684
+ * if (err.id === 'USE_CHANCE_ITEM_FAILED') {
685
+ * console.log('Item usage failed due to chance roll')
686
+ * } else {
687
+ * console.log(err)
688
+ * }
689
+ * }
690
+ * ```
691
+ */
692
+ useItem(itemClass: ItemClass | string): Item;
693
+
694
+ /**
695
+ * Equips a weapon or armor on a player
696
+ *
697
+ * Think first to add the item in the inventory with the `addItem()` method before equipping the item.
698
+ *
699
+ * The `onEquip()` method is called on the ItemClass when the item is equipped or unequipped.
700
+ *
701
+ * @param itemClass - Item class or string identifier. If string, it's the item ID
702
+ * @param equip - Equip the item if `true`, unequip if `false` (default: `true`)
703
+ * @throws {Object} ItemLog.notInInventory - If the item is not in the inventory
704
+ * - `id`: `ITEM_NOT_INVENTORY`
705
+ * - `msg`: Error message
706
+ * @throws {Object} ItemLog.invalidToEquiped - If the item is not a weapon or armor (item._type is "item")
707
+ * - `id`: `INVALID_ITEM_TO_EQUIP`
708
+ * - `msg`: Error message
709
+ * @throws {Object} ItemLog.isAlreadyEquiped - If the item is already equipped
710
+ * - `id`: `ITEM_ALREADY_EQUIPED`
711
+ * - `msg`: Error message
712
+ *
713
+ * @example
714
+ * ```ts
715
+ * import Sword from 'your-database/sword'
716
+ *
717
+ * try {
718
+ * player.addItem(Sword)
719
+ * player.equip(Sword)
720
+ * // Later, unequip it
721
+ * player.equip(Sword, false)
722
+ * } catch (err) {
723
+ * console.log(err)
724
+ * }
725
+ * ```
726
+ */
727
+ equip(itemClass: ItemClass | string, equip?: boolean): void;
728
+
729
+ /**
730
+ * Get the player's attack (sum of items equipped)
731
+ *
732
+ * Returns the total attack value from all equipped items on the player.
733
+ *
734
+ * @returns Total attack value from equipped items
735
+ *
736
+ * @example
737
+ * ```ts
738
+ * console.log(player.atk) // 150 (sum of all equipped weapons/armors attack)
739
+ * ```
740
+ */
741
+ readonly atk: number;
742
+
743
+ /**
744
+ * Get the player's physical defense (sum of items equipped)
745
+ *
746
+ * Returns the total physical defense value from all equipped items on the player.
747
+ *
748
+ * @returns Total physical defense value from equipped items
749
+ *
750
+ * @example
751
+ * ```ts
752
+ * console.log(player.pdef) // 80 (sum of all equipped armors physical defense)
753
+ * ```
754
+ */
755
+ readonly pdef: number;
756
+
757
+ /**
758
+ * Get the player's skill defense (sum of items equipped)
759
+ *
760
+ * Returns the total skill defense value from all equipped items on the player.
761
+ *
762
+ * @returns Total skill defense value from equipped items
763
+ *
764
+ * @example
765
+ * ```ts
766
+ * console.log(player.sdef) // 60 (sum of all equipped armors skill defense)
767
+ * ```
768
+ */
769
+ readonly sdef: number;
770
+ }