@rpgjs/server 3.3.2 → 4.0.0-beta.3

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 (152) hide show
  1. package/LICENSE +19 -0
  2. package/lib/Game/Map.d.ts +58 -5
  3. package/lib/Game/Map.js +185 -80
  4. package/lib/Game/Map.js.map +1 -1
  5. package/lib/Game/WorldMaps.d.ts +3 -2
  6. package/lib/Game/WorldMaps.js +6 -11
  7. package/lib/Game/WorldMaps.js.map +1 -1
  8. package/lib/Gui/DialogGui.d.ts +1 -1
  9. package/lib/Gui/DialogGui.js +12 -13
  10. package/lib/Gui/DialogGui.js.map +1 -1
  11. package/lib/Gui/Gui.js +2 -6
  12. package/lib/Gui/Gui.js.map +1 -1
  13. package/lib/Gui/MenuGui.js +4 -8
  14. package/lib/Gui/MenuGui.js.map +1 -1
  15. package/lib/Gui/NotificationGui.js +4 -8
  16. package/lib/Gui/NotificationGui.js.map +1 -1
  17. package/lib/Gui/ShopGui.js +4 -8
  18. package/lib/Gui/ShopGui.js.map +1 -1
  19. package/lib/Gui/index.js +6 -13
  20. package/lib/Gui/index.js.map +1 -1
  21. package/lib/Interfaces/Gui.js +1 -2
  22. package/lib/Interfaces/StateStore.js +1 -2
  23. package/lib/MatchMaker.js +28 -46
  24. package/lib/MatchMaker.js.map +1 -1
  25. package/lib/Monitor/index.js +3 -5
  26. package/lib/Monitor/index.js.map +1 -1
  27. package/lib/Player/BattleManager.js +17 -16
  28. package/lib/Player/BattleManager.js.map +1 -1
  29. package/lib/Player/ClassManager.js +6 -10
  30. package/lib/Player/ClassManager.js.map +1 -1
  31. package/lib/Player/ComponentManager.d.ts +4 -4
  32. package/lib/Player/ComponentManager.js +37 -24
  33. package/lib/Player/ComponentManager.js.map +1 -1
  34. package/lib/Player/EffectManager.js +8 -12
  35. package/lib/Player/EffectManager.js.map +1 -1
  36. package/lib/Player/ElementManager.js +5 -9
  37. package/lib/Player/ElementManager.js.map +1 -1
  38. package/lib/Player/GoldManager.js +1 -5
  39. package/lib/Player/GoldManager.js.map +1 -1
  40. package/lib/Player/GuiManager.js +17 -15
  41. package/lib/Player/GuiManager.js.map +1 -1
  42. package/lib/Player/ItemFixture.js +1 -5
  43. package/lib/Player/ItemFixture.js.map +1 -1
  44. package/lib/Player/ItemManager.d.ts +3 -3
  45. package/lib/Player/ItemManager.js +29 -31
  46. package/lib/Player/ItemManager.js.map +1 -1
  47. package/lib/Player/MoveManager.d.ts +7 -6
  48. package/lib/Player/MoveManager.js +67 -74
  49. package/lib/Player/MoveManager.js.map +1 -1
  50. package/lib/Player/ParameterManager.js +10 -14
  51. package/lib/Player/ParameterManager.js.map +1 -1
  52. package/lib/Player/Player.d.ts +7 -1
  53. package/lib/Player/Player.js +193 -191
  54. package/lib/Player/Player.js.map +1 -1
  55. package/lib/Player/SkillManager.js +18 -22
  56. package/lib/Player/SkillManager.js.map +1 -1
  57. package/lib/Player/StateManager.js +9 -13
  58. package/lib/Player/StateManager.js.map +1 -1
  59. package/lib/Player/VariableManager.js +1 -5
  60. package/lib/Player/VariableManager.js.map +1 -1
  61. package/lib/Query.d.ts +2 -1
  62. package/lib/Query.js +19 -15
  63. package/lib/Query.js.map +1 -1
  64. package/lib/RpgServer.d.ts +11 -3
  65. package/lib/RpgServer.js +1 -2
  66. package/lib/Scenes/Map.d.ts +27 -4
  67. package/lib/Scenes/Map.js +117 -122
  68. package/lib/Scenes/Map.js.map +1 -1
  69. package/lib/decorators/event.js +4 -7
  70. package/lib/decorators/event.js.map +1 -1
  71. package/lib/decorators/map.d.ts +1 -1
  72. package/lib/decorators/map.js +5 -9
  73. package/lib/decorators/map.js.map +1 -1
  74. package/lib/entry-point.js +59 -65
  75. package/lib/entry-point.js.map +1 -1
  76. package/lib/express/api.d.ts +3 -0
  77. package/lib/express/api.js +105 -0
  78. package/lib/express/api.js.map +1 -0
  79. package/lib/express/errors/NotAuthorized.d.ts +4 -0
  80. package/lib/express/errors/NotAuthorized.js +7 -0
  81. package/lib/express/errors/NotAuthorized.js.map +1 -0
  82. package/lib/express/errors/NotFound.d.ts +4 -0
  83. package/lib/express/errors/NotFound.js +7 -0
  84. package/lib/express/errors/NotFound.js.map +1 -0
  85. package/lib/express/server.js +20 -5
  86. package/lib/express/server.js.map +1 -1
  87. package/lib/index.js +15 -68
  88. package/lib/index.js.map +1 -1
  89. package/lib/logs/index.js +5 -11
  90. package/lib/logs/index.js.map +1 -1
  91. package/lib/logs/item.js +11 -15
  92. package/lib/logs/item.js.map +1 -1
  93. package/lib/logs/log.js +1 -5
  94. package/lib/logs/log.js.map +1 -1
  95. package/lib/logs/skill.js +6 -10
  96. package/lib/logs/skill.js.map +1 -1
  97. package/lib/logs/state.js +5 -9
  98. package/lib/logs/state.js.map +1 -1
  99. package/lib/models/Item.js +1 -2
  100. package/lib/presets/index.js +28 -36
  101. package/lib/presets/index.js.map +1 -1
  102. package/lib/server.d.ts +23 -2
  103. package/lib/server.js +227 -134
  104. package/lib/server.js.map +1 -1
  105. package/package.json +24 -16
  106. package/src/Game/Map.ts +513 -0
  107. package/src/Game/WorldMaps.ts +45 -0
  108. package/src/Gui/DialogGui.ts +67 -0
  109. package/src/Gui/Gui.ts +45 -0
  110. package/src/Gui/MenuGui.ts +26 -0
  111. package/src/Gui/NotificationGui.ts +10 -0
  112. package/src/Gui/ShopGui.ts +43 -0
  113. package/src/Gui/index.ts +13 -0
  114. package/src/Interfaces/Gui.ts +4 -0
  115. package/src/Interfaces/StateStore.ts +5 -0
  116. package/src/MatchMaker.ts +63 -0
  117. package/src/Monitor/index.ts +78 -0
  118. package/src/Player/BattleManager.ts +123 -0
  119. package/src/Player/ClassManager.ts +72 -0
  120. package/src/Player/ComponentManager.ts +538 -0
  121. package/src/Player/EffectManager.ts +94 -0
  122. package/src/Player/ElementManager.ts +142 -0
  123. package/src/Player/GoldManager.ts +26 -0
  124. package/src/Player/GuiManager.ts +308 -0
  125. package/src/Player/ItemFixture.ts +24 -0
  126. package/src/Player/ItemManager.ts +474 -0
  127. package/src/Player/MoveManager.ts +635 -0
  128. package/src/Player/ParameterManager.ts +468 -0
  129. package/src/Player/Player.ts +931 -0
  130. package/src/Player/SkillManager.ts +229 -0
  131. package/src/Player/StateManager.ts +230 -0
  132. package/src/Player/VariableManager.ts +55 -0
  133. package/src/Query.ts +172 -0
  134. package/src/RpgServer.ts +429 -0
  135. package/src/Scenes/Map.ts +302 -0
  136. package/src/decorators/event.ts +57 -0
  137. package/src/decorators/map.ts +223 -0
  138. package/src/entry-point.ts +102 -0
  139. package/src/express/api.ts +118 -0
  140. package/src/express/errors/NotAuthorized.ts +6 -0
  141. package/src/express/errors/NotFound.ts +6 -0
  142. package/src/express/server.ts +93 -0
  143. package/src/index.ts +28 -0
  144. package/src/logs/index.ts +11 -0
  145. package/src/logs/item.ts +31 -0
  146. package/src/logs/log.ts +3 -0
  147. package/src/logs/skill.ts +16 -0
  148. package/src/logs/state.ts +13 -0
  149. package/src/models/Item.ts +11 -0
  150. package/src/presets/index.ts +71 -0
  151. package/src/server.ts +394 -0
  152. package/tsconfig.json +27 -0
@@ -0,0 +1,474 @@
1
+ import { Utils } from '@rpgjs/common'
2
+ import { Effect, ItemOptions } from '@rpgjs/database'
3
+ import { ItemLog } from '../logs'
4
+ import { ItemModel } from '../models/Item'
5
+ import { EffectManager } from './EffectManager'
6
+ import { GoldManager } from './GoldManager'
7
+ import { StateManager } from './StateManager'
8
+
9
+ import {
10
+ ATK,
11
+ PDEF,
12
+ SDEF
13
+ } from '../presets'
14
+
15
+ const {
16
+ isString,
17
+ isInstanceOf,
18
+ applyMixins
19
+ } = Utils
20
+
21
+ type ItemClass = { new(...args: any[]), price?: number, _type?: string }
22
+ type Inventory = { nb: number, item: ItemModel }
23
+
24
+ export class ItemManager {
25
+
26
+ items: Inventory[]
27
+ equipments: ItemModel[] = []
28
+
29
+ /**
30
+ * Retrieves the information of an object: the number and the instance
31
+ * @title Get Item
32
+ * @method player.getItem(itemClass)
33
+ * @param {ItemClass | string} itemClass Identifier of the object if the parameter is a string
34
+ * @returns {{ nb: number, item: instance of ItemClass }}
35
+ * @memberof ItemManager
36
+ * @example
37
+ *
38
+ * ```ts
39
+ * import Potion from 'your-database/potion'
40
+ *
41
+ * player.addItem(Potion, 5)
42
+ * const inventory = player.getItem(Potion)
43
+ * console.log(inventory) // { nb: 5, item: <instance of Potion> }
44
+ * ```
45
+ */
46
+ getItem(itemClass: ItemClass | string): Inventory {
47
+ const index: number = this._getItemIndex(itemClass)
48
+ return this.items[index]
49
+ }
50
+
51
+ /**
52
+ * Check if the player has the item in his inventory.
53
+ * @title Has Item
54
+ * @method player.hasItem(itemClass)
55
+ * @param {ItemClass | string} itemClass Identifier of the object if the parameter is a string
56
+ * @returns {boolean}
57
+ * @memberof ItemManager
58
+ * @example
59
+ *
60
+ * ```ts
61
+ * import Potion from 'your-database/potion'
62
+ *
63
+ * player.hasItem(Potion) // false
64
+ * ```
65
+ */
66
+ hasItem(itemClass: ItemClass | string): boolean {
67
+ return !!this.getItem(itemClass)
68
+ }
69
+
70
+ _getItemIndex(itemClass: ItemClass | string): number {
71
+ return this.items.findIndex((it: Inventory): boolean => {
72
+ if (isString(itemClass)) {
73
+ return it.item.id == itemClass
74
+ }
75
+ return isInstanceOf(it.item, itemClass)
76
+ })
77
+ }
78
+ /**
79
+ * Add an item in the player's inventory. You can give more than one by specifying `nb`
80
+ *
81
+ * `onAdd()` method is called on the ItemClass
82
+ *
83
+ * @title Add Item
84
+ * @method player.addItem(item,nb=1)
85
+ * @param {ItemClass} itemClass
86
+ * @param {number} [nb] Default 1
87
+ * @returns {{ nb: number, item: instance of ItemClass }}
88
+ * @memberof ItemManager
89
+ * @example
90
+ *
91
+ * ```ts
92
+ * import Potion from 'your-database/potion'
93
+ * player.addItem(Potion, 5)
94
+ * ```
95
+ */
96
+ addItem(itemClass: ItemClass | string, nb: number = 1): Inventory {
97
+ if (isString(itemClass)) itemClass = this.databaseById(itemClass)
98
+ let itemIndex: number = this._getItemIndex(itemClass)
99
+ if (itemIndex != -1) {
100
+ this.items[itemIndex].nb += nb
101
+ }
102
+ else {
103
+ const instance = new (itemClass as ItemClass)()
104
+ this.items.push({
105
+ item: instance,
106
+ nb
107
+ })
108
+ itemIndex = this.items.length - 1
109
+ }
110
+ const { item } = this.items[itemIndex]
111
+ this['execMethod']('onAdd', [this], item)
112
+ return this.items[itemIndex]
113
+ }
114
+
115
+ /**
116
+ * 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`
117
+ *
118
+ * `onRemove()` method is called on the ItemClass
119
+ *
120
+ * @title Remove Item
121
+ * @method player.removeItem(item,nb=1)
122
+ * @param {ItemClass | string} itemClass string is item id
123
+ * @param {number} [nb] Default 1
124
+ * @returns {{ nb: number, item: instance of ItemClass } | undefined}
125
+ * @throws {ItemLog} notInInventory
126
+ * If the object is not in the inventory, an exception is raised
127
+ * ```
128
+ * {
129
+ * id: ITEM_NOT_INVENTORY,
130
+ * msg: '...'
131
+ * }
132
+ * ```
133
+ * @memberof ItemManager
134
+ * @example
135
+ *
136
+ * ```ts
137
+ * import Potion from 'your-database/potion'
138
+ *
139
+ * try {
140
+ * player.removeItem(Potion, 5)
141
+ * }
142
+ * catch (err) {
143
+ * console.log(err)
144
+ * }
145
+ * ```
146
+ */
147
+ removeItem(itemClass: ItemClass | string, nb: number = 1): Inventory | undefined {
148
+ const itemIndex: number = this._getItemIndex(itemClass)
149
+ if (itemIndex == -1) {
150
+ throw ItemLog.notInInventory(itemClass)
151
+ }
152
+ const currentNb: number = this.items[itemIndex].nb
153
+ const { item } = this.items[itemIndex]
154
+ if (currentNb - nb <= 0) {
155
+ this.items.splice(itemIndex, 1)
156
+ }
157
+ else {
158
+ this.items[itemIndex].nb -= nb
159
+ }
160
+ this['execMethod']('onRemove', [this], item)
161
+ return this.items[itemIndex]
162
+ }
163
+
164
+ /**
165
+ * Purchases an item and reduces the amount of gold
166
+ *
167
+ * `onAdd()` method is called on the ItemClass
168
+ *
169
+ * @title Buy Item
170
+ * @method player.buyItem(item,nb=1)
171
+ * @param {ItemClass | string} itemClass string is item id
172
+ * @param {number} [nb] Default 1
173
+ * @returns {{ nb: number, item: instance of ItemClass }}
174
+ * @throws {ItemLog} haveNotPrice
175
+ * If you have not set a price on the item
176
+ * ```
177
+ * {
178
+ * id: NOT_PRICE,
179
+ * msg: '...'
180
+ * }
181
+ * ```
182
+ * @throws {ItemLog} notEnoughGold
183
+ * If the player does not have enough money
184
+ * ```
185
+ * {
186
+ * id: NOT_ENOUGH_GOLD,
187
+ * msg: '...'
188
+ * }
189
+ * ```
190
+ * @memberof ItemManager
191
+ * @example
192
+ *
193
+ * ```ts
194
+ * import Potion from 'your-database/potion'
195
+ *
196
+ * try {
197
+ * player.buyItem(Potion)
198
+ * }
199
+ * catch (err) {
200
+ * console.log(err)
201
+ * }
202
+ * ```
203
+ */
204
+ buyItem(itemClass: ItemClass | string, nb = 1): Inventory {
205
+ if (isString(itemClass)) itemClass = this.databaseById(itemClass)
206
+ const ItemClass = itemClass as ItemClass
207
+ if (!ItemClass.price) {
208
+ throw ItemLog.haveNotPrice(itemClass)
209
+ }
210
+ const totalPrice = nb * ItemClass.price
211
+ if (this.gold < totalPrice) {
212
+ throw ItemLog.notEnoughGold(itemClass, nb)
213
+ }
214
+ this.gold -= totalPrice
215
+ return this.addItem(ItemClass, nb)
216
+ }
217
+
218
+ /**
219
+ * Sell an item and the player wins the amount of the item divided by 2
220
+ *
221
+ * `onRemove()` method is called on the ItemClass
222
+ *
223
+ * @title Sell Item
224
+ * @method player.sellItem(item,nb=1)
225
+ * @param {ItemClass | string} itemClass string is item id
226
+ * @param {number} [nbToSell] Default 1
227
+ * @returns {{ nb: number, item: instance of ItemClass }}
228
+ * @throws {ItemLog} haveNotPrice
229
+ * If you have not set a price on the item
230
+ * ```
231
+ * {
232
+ * id: NOT_PRICE,
233
+ * msg: '...'
234
+ * }
235
+ * ```
236
+ * @throws {ItemLog} notInInventory
237
+ * If the object is not in the inventory, an exception is raised
238
+ * ```
239
+ * {
240
+ * id: ITEM_NOT_INVENTORY,
241
+ * msg: '...'
242
+ * }
243
+ * ```
244
+ * @throws {ItemLog} tooManyToSell
245
+ * If the number of items for sale exceeds the number of actual items in the inventory
246
+ * ```
247
+ * {
248
+ * id: TOO_MANY_ITEM_TO_SELL,
249
+ * msg: '...'
250
+ * }
251
+ * ```
252
+ * @memberof ItemManager
253
+ * @example
254
+ *
255
+ * ```ts
256
+ * import Potion from 'your-database/potion'
257
+ *
258
+ * try {
259
+ * player.addItem(Potion)
260
+ * player.sellItem(Potion)
261
+ * }
262
+ * catch (err) {
263
+ * console.log(err)
264
+ * }
265
+ * ```
266
+ */
267
+ sellItem(itemClass: ItemClass | string, nbToSell = 1): Inventory {
268
+ if (isString(itemClass)) itemClass = this.databaseById(itemClass)
269
+ const ItemClass = itemClass as ItemClass
270
+ const inventory = this.getItem(ItemClass)
271
+ if (!inventory) {
272
+ throw ItemLog.notInInventory(itemClass)
273
+ }
274
+ const { item, nb } = inventory
275
+ if (nb - nbToSell < 0) {
276
+ throw ItemLog.tooManyToSell(itemClass, nbToSell, nb)
277
+ }
278
+ if (!ItemClass.price) {
279
+ throw ItemLog.haveNotPrice(itemClass)
280
+ }
281
+ this.gold += (ItemClass.price / 2) * nbToSell
282
+ this.removeItem(ItemClass, nbToSell)
283
+ return inventory
284
+ }
285
+
286
+ private getParamItem(name) {
287
+ let nb = 0
288
+ for (let item of this.equipments) {
289
+ nb += item[name] || 0
290
+ }
291
+ const modifier = this.paramsModifier[name]
292
+ if (modifier) {
293
+ if (modifier.value) nb += modifier.value
294
+ if (modifier.rate) nb *= modifier.rate
295
+ }
296
+ return nb
297
+ }
298
+
299
+ get atk(): number {
300
+ return this.getParamItem(ATK)
301
+ }
302
+
303
+ get pdef(): number {
304
+ return this.getParamItem(PDEF)
305
+ }
306
+
307
+ get sdef(): number {
308
+ return this.getParamItem(SDEF)
309
+ }
310
+
311
+ /**
312
+ * Use an object. Applies effects and states. Removes the object from the inventory then
313
+ *
314
+ * `onUse()` method is called on the ItemClass (If the use has worked)
315
+ * `onRemove()` method is called on the ItemClass
316
+ *
317
+ * @title Use an Item
318
+ * @method player.useItem(item,nb=1)
319
+ * @param {ItemClass | string} itemClass string is item id
320
+ * @returns {{ nb: number, item: instance of ItemClass }}
321
+ * @throws {ItemLog} restriction
322
+ * If the player has the `Effect.CAN_NOT_ITEM` effect
323
+ * ```
324
+ * {
325
+ * id: RESTRICTION_ITEM,
326
+ * msg: '...'
327
+ * }
328
+ * ```
329
+ * @throws {ItemLog} notInInventory
330
+ * If the object is not in the inventory, an exception is raised
331
+ * ```
332
+ * {
333
+ * id: ITEM_NOT_INVENTORY,
334
+ * msg: '...'
335
+ * }
336
+ * ```
337
+ * @throws {ItemLog} notUseItem
338
+ * If the `consumable` property is on false
339
+ * ```
340
+ * {
341
+ * id: NOT_USE_ITEM,
342
+ * msg: '...'
343
+ * }
344
+ * ```
345
+ * @throws {ItemLog} chanceToUseFailed
346
+ * Chance to use the item has failed. Chances of use is defined with `ItemClass.hitRate`
347
+ * ```
348
+ * {
349
+ * id: USE_CHANCE_ITEM_FAILED,
350
+ * msg: '...'
351
+ * }
352
+ * ```
353
+ * > the item is still deleted from the inventory
354
+ *
355
+ * `onUseFailed()` method is called on the ItemClass
356
+ *
357
+ * @memberof ItemManager
358
+ * @example
359
+ *
360
+ * ```ts
361
+ * import Potion from 'your-database/potion'
362
+ *
363
+ * try {
364
+ * player.addItem(Potion)
365
+ * player.useItem(Potion)
366
+ * }
367
+ * catch (err) {
368
+ * console.log(err)
369
+ * }
370
+ * ```
371
+ */
372
+ useItem(itemClass: ItemClass | string): Inventory {
373
+ const inventory = this.getItem(itemClass)
374
+ if (this.hasEffect(Effect.CAN_NOT_ITEM)) {
375
+ throw ItemLog.restriction(itemClass)
376
+ }
377
+ if (!inventory) {
378
+ throw ItemLog.notInInventory(itemClass)
379
+ }
380
+ const { item } = inventory
381
+ if (item.consumable === false) {
382
+ throw ItemLog.notUseItem(itemClass)
383
+ }
384
+ const hitRate = item.hitRate || 1
385
+ if (Math.random() > hitRate) {
386
+ this.removeItem(itemClass)
387
+ this['execMethod']('onUseFailed', [this], item)
388
+ throw ItemLog.chanceToUseFailed(itemClass)
389
+ }
390
+ this.applyEffect(item)
391
+ this.applyStates(<any>this, <any>item)
392
+ this['execMethod']('onUse', [this], item)
393
+ this.removeItem(itemClass)
394
+ return inventory
395
+ }
396
+
397
+ /**
398
+ * 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.
399
+ *
400
+ * `onEquip()` method is called on the ItemClass
401
+ *
402
+ * @title Equip Weapon or Armor
403
+ * @method player.equip(itemClass,equip=true)
404
+ * @param {ItemClass | string} itemClass string is item id
405
+ * @param {number} [equip] Equip the object if true or un-equipped if false
406
+ * @returns {void}
407
+ * @throws {ItemLog} notInInventory
408
+ * If the item is not in the inventory
409
+ * ```
410
+ {
411
+ id: ITEM_NOT_INVENTORY,
412
+ msg: '...'
413
+ }
414
+ ```
415
+ * @throws {ItemLog} invalidToEquiped
416
+ If the item is not by a weapon or armor
417
+ ```
418
+ {
419
+ id: INVALID_ITEM_TO_EQUIP,
420
+ msg: '...'
421
+ }
422
+ ```
423
+ * @throws {ItemLog} isAlreadyEquiped
424
+ If the item Is already equipped
425
+ ```
426
+ {
427
+ id: ITEM_ALREADY_EQUIPED,
428
+ msg: '...'
429
+ }
430
+ ```
431
+ * @memberof ItemManager
432
+ * @example
433
+ *
434
+ * ```ts
435
+ * import Sword from 'your-database/sword'
436
+ *
437
+ * try {
438
+ * player.addItem(Sword)
439
+ * player.equip(Sword)
440
+ * }
441
+ * catch (err) {
442
+ * console.log(err)
443
+ * }
444
+ * ```
445
+ */
446
+ equip(itemClass: ItemClass | string, equip: boolean = true): void {
447
+ const inventory: Inventory = this.getItem(itemClass)
448
+ if (!inventory) {
449
+ throw ItemLog.notInInventory(itemClass)
450
+ }
451
+ if ((itemClass as ItemClass)._type == 'item') {
452
+ throw ItemLog.invalidToEquiped(itemClass)
453
+ }
454
+ const { item } = inventory
455
+ if (item.equipped && equip) {
456
+ throw ItemLog.isAlreadyEquiped(itemClass)
457
+ }
458
+ item.equipped = equip
459
+ if (!equip) {
460
+ const index = this.equipments.findIndex(it => it.id == item.id)
461
+ this.equipments.splice(index, 1)
462
+ }
463
+ else {
464
+ this.equipments.push(item)
465
+ }
466
+ this['execMethod']('onEquip', [this, equip], item)
467
+ }
468
+ }
469
+
470
+ applyMixins(ItemManager, [GoldManager, StateManager, EffectManager])
471
+
472
+ export interface ItemManager extends GoldManager, StateManager, EffectManager {
473
+ databaseById(itemClass: any),
474
+ }