@rpgjs/server 5.0.0-alpha.21 → 5.0.0-alpha.22
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.
- package/dist/Player/BattleManager.d.ts +43 -31
- package/dist/Player/ClassManager.d.ts +23 -3
- package/dist/Player/EffectManager.d.ts +49 -3
- package/dist/Player/ElementManager.d.ts +76 -3
- package/dist/Player/ItemManager.d.ts +292 -4
- package/dist/Player/MoveManager.d.ts +145 -4
- package/dist/Player/Player.d.ts +135 -0
- package/dist/Player/SkillManager.d.ts +42 -3
- package/dist/Player/StateManager.d.ts +74 -3
- package/dist/Player/VariableManager.d.ts +47 -3
- package/dist/RpgServer.d.ts +228 -61
- package/dist/decorators/map.d.ts +89 -1
- package/dist/index.js +804 -1703
- package/dist/index.js.map +1 -1
- package/dist/module.d.ts +43 -1
- package/dist/rooms/map.d.ts +676 -12
- package/package.json +3 -3
- package/src/Player/BattleManager.ts +38 -55
- package/src/Player/ClassManager.ts +21 -71
- package/src/Player/EffectManager.ts +50 -96
- package/src/Player/ElementManager.ts +74 -152
- package/src/Player/ItemManager.ts +302 -359
- package/src/Player/MoveManager.ts +141 -438
- package/src/Player/Player.ts +217 -0
- package/src/Player/SkillManager.ts +44 -147
- package/src/Player/StateManager.ts +63 -259
- package/src/Player/VariableManager.ts +53 -150
- package/src/RpgServer.ts +237 -60
- package/src/decorators/map.ts +105 -1
- package/src/module.ts +81 -2
- package/src/rooms/map.ts +757 -23
|
@@ -1,32 +1,44 @@
|
|
|
1
1
|
import { PlayerCtor } from '@rpgjs/common';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
2
|
+
import { RpgPlayer } from './Player';
|
|
3
|
+
export interface IBattleManager {
|
|
4
|
+
/**
|
|
5
|
+
* Apply damage. Player will lose HP. the `attackerPlayer` parameter is the other player, the one who attacks.
|
|
6
|
+
*
|
|
7
|
+
* If you don't set the skill parameter, it will be a physical attack.
|
|
8
|
+
* The attack formula is already defined but you can customize it in the server options.
|
|
9
|
+
* This method handles all aspects of damage calculation including critical hits,
|
|
10
|
+
* elemental vulnerabilities, guard effects, and applies the final damage to HP.
|
|
11
|
+
*
|
|
12
|
+
* @param attackerPlayer - The attacking player who deals the damage
|
|
13
|
+
* @param skill - Optional skill object for magical attacks, if not provided uses physical attack
|
|
14
|
+
* @returns Object containing damage details and special effects that occurred
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* // Physical attack
|
|
19
|
+
* const result = player.applyDamage(attackerPlayer);
|
|
20
|
+
* console.log(`Physical damage: ${result.damage}, Critical: ${result.critical}`);
|
|
21
|
+
*
|
|
22
|
+
* // Magical attack with skill
|
|
23
|
+
* const fireSkill = { id: 'fire', power: 50, element: 'fire' };
|
|
24
|
+
* const magicResult = player.applyDamage(attackerPlayer, fireSkill);
|
|
25
|
+
* console.log(`Magic damage: ${magicResult.damage}, Vulnerable: ${magicResult.elementVulnerable}`);
|
|
26
|
+
*
|
|
27
|
+
* // Check for guard effects
|
|
28
|
+
* if (result.guard) {
|
|
29
|
+
* console.log('Attack was partially blocked!');
|
|
30
|
+
* }
|
|
31
|
+
* if (result.superGuard) {
|
|
32
|
+
* console.log('Attack was heavily reduced by super guard!');
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
applyDamage(attackerPlayer: RpgPlayer, skill?: any): {
|
|
37
|
+
damage: number;
|
|
38
|
+
critical: boolean;
|
|
39
|
+
elementVulnerable: boolean;
|
|
40
|
+
guard: boolean;
|
|
41
|
+
superGuard: boolean;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export declare function WithBattleManager<TBase extends PlayerCtor>(Base: TBase): new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> & IBattleManager;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { PlayerCtor } from '@rpgjs/common';
|
|
2
|
+
type ClassClass = any;
|
|
3
|
+
type ActorClass = any;
|
|
2
4
|
/**
|
|
3
5
|
* Class Manager Mixin
|
|
4
6
|
*
|
|
@@ -25,7 +27,25 @@ import { PlayerCtor } from '@rpgjs/common';
|
|
|
25
27
|
*/
|
|
26
28
|
export declare function WithClassManager<TBase extends PlayerCtor>(Base: TBase): TBase;
|
|
27
29
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
+
* Interface for Class Manager functionality
|
|
31
|
+
*
|
|
32
|
+
* Provides class and actor management capabilities including character class assignment
|
|
33
|
+
* and actor setup. This interface defines the public API of the ClassManager mixin.
|
|
30
34
|
*/
|
|
31
|
-
export
|
|
35
|
+
export interface IClassManager {
|
|
36
|
+
/**
|
|
37
|
+
* Assign a class to the player
|
|
38
|
+
*
|
|
39
|
+
* @param _class - The class constructor or class ID to assign to the player
|
|
40
|
+
* @returns The instantiated class object
|
|
41
|
+
*/
|
|
42
|
+
setClass(_class: ClassClass | string): any;
|
|
43
|
+
/**
|
|
44
|
+
* Set up the player as a specific actor archetype
|
|
45
|
+
*
|
|
46
|
+
* @param actorClass - The actor constructor or actor ID to assign to the player
|
|
47
|
+
* @returns The instantiated actor object
|
|
48
|
+
*/
|
|
49
|
+
setActor(actorClass: ActorClass | string): any;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
@@ -34,7 +34,53 @@ export declare enum Effect {
|
|
|
34
34
|
*/
|
|
35
35
|
export declare function WithEffectManager<TBase extends PlayerCtor>(Base: TBase): TBase;
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
37
|
+
* Interface for Effect Manager functionality
|
|
38
|
+
*
|
|
39
|
+
* Provides effect management capabilities including restrictions, buffs, and debuffs.
|
|
40
|
+
* This interface defines the public API of the EffectManager mixin.
|
|
39
41
|
*/
|
|
40
|
-
export
|
|
42
|
+
export interface IEffectManager {
|
|
43
|
+
/**
|
|
44
|
+
* Gets all currently active effects on the player from multiple sources:
|
|
45
|
+
* - Direct effects assigned to the player
|
|
46
|
+
* - Effects from active states (buffs/debuffs)
|
|
47
|
+
* - Effects from equipped weapons and armor
|
|
48
|
+
* The returned array contains unique effects without duplicates.
|
|
49
|
+
*
|
|
50
|
+
* @returns Array of all active effects on the player
|
|
51
|
+
*/
|
|
52
|
+
effects: any[];
|
|
53
|
+
/**
|
|
54
|
+
* Check if the player has a specific effect
|
|
55
|
+
*
|
|
56
|
+
* Determines whether the player currently has the specified effect active.
|
|
57
|
+
* This includes effects from states, equipment, and temporary conditions.
|
|
58
|
+
* The effect system provides a flexible way to apply various gameplay
|
|
59
|
+
* restrictions and enhancements to the player.
|
|
60
|
+
*
|
|
61
|
+
* @param effect - The effect identifier to check for
|
|
62
|
+
* @returns true if the player has the effect, false otherwise
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { Effect } from '@rpgjs/database'
|
|
67
|
+
*
|
|
68
|
+
* // Check for skill restriction
|
|
69
|
+
* const cannotUseSkills = player.hasEffect(Effect.CAN_NOT_SKILL);
|
|
70
|
+
* if (cannotUseSkills) {
|
|
71
|
+
* console.log('Player cannot use skills right now');
|
|
72
|
+
* }
|
|
73
|
+
*
|
|
74
|
+
* // Check for guard effect
|
|
75
|
+
* const isGuarding = player.hasEffect(Effect.GUARD);
|
|
76
|
+
* if (isGuarding) {
|
|
77
|
+
* console.log('Player is in guard stance');
|
|
78
|
+
* }
|
|
79
|
+
*
|
|
80
|
+
* // Check for cost reduction
|
|
81
|
+
* const halfCost = player.hasEffect(Effect.HALF_SP_COST);
|
|
82
|
+
* const actualCost = skillCost / (halfCost ? 2 : 1);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
hasEffect(effect: string): boolean;
|
|
86
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PlayerCtor } from '@rpgjs/common';
|
|
2
|
+
import { RpgPlayer } from './Player';
|
|
2
3
|
/**
|
|
3
4
|
* Element Manager Mixin
|
|
4
5
|
*
|
|
@@ -25,7 +26,79 @@ import { PlayerCtor } from '@rpgjs/common';
|
|
|
25
26
|
*/
|
|
26
27
|
export declare function WithElementManager<TBase extends PlayerCtor>(Base: TBase): TBase;
|
|
27
28
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
29
|
+
* Interface for Element Manager functionality
|
|
30
|
+
*
|
|
31
|
+
* Provides elemental management capabilities including resistances, vulnerabilities,
|
|
32
|
+
* and attack elements. This interface defines the public API of the ElementManager mixin.
|
|
30
33
|
*/
|
|
31
|
-
export
|
|
34
|
+
export interface IElementManager {
|
|
35
|
+
/**
|
|
36
|
+
* Gets the defensive capabilities against various elements from equipped items.
|
|
37
|
+
* The system automatically consolidates multiple defensive items, keeping only
|
|
38
|
+
* the highest protection rate for each element type.
|
|
39
|
+
*
|
|
40
|
+
* @returns Array of element defense objects with rate and element properties
|
|
41
|
+
*/
|
|
42
|
+
elementsDefense: {
|
|
43
|
+
rate: number;
|
|
44
|
+
element: any;
|
|
45
|
+
}[];
|
|
46
|
+
/**
|
|
47
|
+
* Manages the player's elemental efficiency modifiers, which determine how
|
|
48
|
+
* effective different elements are against this player. Values greater than 1
|
|
49
|
+
* indicate vulnerability, while values less than 1 indicate resistance.
|
|
50
|
+
* This combines both class-based efficiency and player-specific modifiers.
|
|
51
|
+
*
|
|
52
|
+
* @returns Array of element efficiency objects with rate and element properties
|
|
53
|
+
*/
|
|
54
|
+
elementsEfficiency: {
|
|
55
|
+
rate: number;
|
|
56
|
+
element: any;
|
|
57
|
+
}[];
|
|
58
|
+
/**
|
|
59
|
+
* Gets all offensive elements available to the player from equipped weapons and armor.
|
|
60
|
+
* This determines what elemental damage types the player can deal in combat.
|
|
61
|
+
* The system automatically combines elements from all equipped items and removes duplicates.
|
|
62
|
+
*
|
|
63
|
+
* @returns Array of element objects with rate and element properties for offensive capabilities
|
|
64
|
+
*/
|
|
65
|
+
elements: {
|
|
66
|
+
rate: number;
|
|
67
|
+
element: string;
|
|
68
|
+
}[];
|
|
69
|
+
/**
|
|
70
|
+
* Calculate elemental damage coefficient against another player
|
|
71
|
+
*
|
|
72
|
+
* Determines the damage multiplier when this player attacks another player,
|
|
73
|
+
* taking into account the attacker's offensive elements, the defender's
|
|
74
|
+
* elemental efficiency, and elemental defense from equipment. This is used
|
|
75
|
+
* in the battle system to calculate elemental damage modifiers.
|
|
76
|
+
*
|
|
77
|
+
* @param otherPlayer - The target player to calculate coefficient against
|
|
78
|
+
* @returns Numerical coefficient to multiply base damage by
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* // Calculate elemental damage coefficient
|
|
83
|
+
* const firePlayer = new MyPlayer();
|
|
84
|
+
* const icePlayer = new MyPlayer();
|
|
85
|
+
*
|
|
86
|
+
* // Fire player attacks ice player (assuming ice is weak to fire)
|
|
87
|
+
* const coefficient = icePlayer.coefficientElements(firePlayer);
|
|
88
|
+
* console.log(`Damage multiplier: ${coefficient}`); // e.g., 2.0 for double damage
|
|
89
|
+
*
|
|
90
|
+
* // Use in damage calculation
|
|
91
|
+
* const baseDamage = 100;
|
|
92
|
+
* const finalDamage = baseDamage * coefficient;
|
|
93
|
+
* console.log(`Final damage: ${finalDamage}`);
|
|
94
|
+
*
|
|
95
|
+
* // Check for elemental advantage
|
|
96
|
+
* if (coefficient > 1) {
|
|
97
|
+
* console.log('Attacker has elemental advantage!');
|
|
98
|
+
* } else if (coefficient < 1) {
|
|
99
|
+
* console.log('Defender resists this element');
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
coefficientElements(otherPlayer: RpgPlayer): number;
|
|
104
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { PlayerCtor } from '@rpgjs/common';
|
|
1
|
+
import { Item, PlayerCtor } from '@rpgjs/common';
|
|
2
|
+
import { ItemClass } from '@rpgjs/database';
|
|
2
3
|
import { RpgPlayer } from './Player';
|
|
3
4
|
/**
|
|
4
5
|
* Interface defining the hooks that can be implemented on item classes or objects
|
|
@@ -165,7 +166,294 @@ export type ItemObject<T extends ItemData = ItemData> = T & ItemHooks & {
|
|
|
165
166
|
*/
|
|
166
167
|
export declare function WithItemManager<TBase extends PlayerCtor>(Base: TBase): TBase;
|
|
167
168
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
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.
|
|
170
174
|
*/
|
|
171
|
-
export
|
|
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
|
+
*
|
|
391
|
+
* The `onEquip()` method is called on the ItemClass when the item is equipped or unequipped.
|
|
392
|
+
*
|
|
393
|
+
* @param itemClass - Item class or string identifier. If string, it's the item ID
|
|
394
|
+
* @param equip - Equip the item if `true`, unequip if `false` (default: `true`)
|
|
395
|
+
* @throws {Object} ItemLog.notInInventory - If the item is not in the inventory
|
|
396
|
+
* - `id`: `ITEM_NOT_INVENTORY`
|
|
397
|
+
* - `msg`: Error message
|
|
398
|
+
* @throws {Object} ItemLog.invalidToEquiped - If the item is not a weapon or armor (item._type is "item")
|
|
399
|
+
* - `id`: `INVALID_ITEM_TO_EQUIP`
|
|
400
|
+
* - `msg`: Error message
|
|
401
|
+
* @throws {Object} ItemLog.isAlreadyEquiped - If the item is already equipped
|
|
402
|
+
* - `id`: `ITEM_ALREADY_EQUIPED`
|
|
403
|
+
* - `msg`: Error message
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* ```ts
|
|
407
|
+
* import Sword from 'your-database/sword'
|
|
408
|
+
*
|
|
409
|
+
* try {
|
|
410
|
+
* player.addItem(Sword)
|
|
411
|
+
* player.equip(Sword)
|
|
412
|
+
* // Later, unequip it
|
|
413
|
+
* player.equip(Sword, false)
|
|
414
|
+
* } catch (err) {
|
|
415
|
+
* console.log(err)
|
|
416
|
+
* }
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
equip(itemClass: ItemClass | string, equip?: boolean): void;
|
|
420
|
+
/**
|
|
421
|
+
* Get the player's attack (sum of items equipped)
|
|
422
|
+
*
|
|
423
|
+
* Returns the total attack value from all equipped items on the player.
|
|
424
|
+
*
|
|
425
|
+
* @returns Total attack value from equipped items
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```ts
|
|
429
|
+
* console.log(player.atk) // 150 (sum of all equipped weapons/armors attack)
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
readonly atk: number;
|
|
433
|
+
/**
|
|
434
|
+
* Get the player's physical defense (sum of items equipped)
|
|
435
|
+
*
|
|
436
|
+
* Returns the total physical defense value from all equipped items on the player.
|
|
437
|
+
*
|
|
438
|
+
* @returns Total physical defense value from equipped items
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```ts
|
|
442
|
+
* console.log(player.pdef) // 80 (sum of all equipped armors physical defense)
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
readonly pdef: number;
|
|
446
|
+
/**
|
|
447
|
+
* Get the player's skill defense (sum of items equipped)
|
|
448
|
+
*
|
|
449
|
+
* Returns the total skill defense value from all equipped items on the player.
|
|
450
|
+
*
|
|
451
|
+
* @returns Total skill defense value from equipped items
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* ```ts
|
|
455
|
+
* console.log(player.sdef) // 60 (sum of all equipped armors skill defense)
|
|
456
|
+
* ```
|
|
457
|
+
*/
|
|
458
|
+
readonly sdef: number;
|
|
459
|
+
}
|