@rpgjs/server 5.0.0-alpha.10 → 5.0.0-alpha.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.
- package/CHANGELOG.md +9 -0
- package/dist/Player/BattleManager.d.ts +22 -32
- package/dist/Player/ClassManager.d.ts +18 -31
- package/dist/Player/Event.d.ts +0 -0
- package/dist/Player/ItemManager.d.ts +13 -27
- package/dist/Player/MoveManager.d.ts +43 -31
- package/dist/Player/ParameterManager.d.ts +19 -27
- package/dist/Player/Player.d.ts +8 -123
- package/dist/Player/SkillManager.d.ts +19 -27
- package/dist/Player/StateManager.d.ts +35 -28
- package/dist/RpgServer.d.ts +1 -224
- package/dist/index.js +647 -1108
- package/dist/index.js.map +1 -1
- package/dist/rooms/map.d.ts +1 -70
- package/package.json +8 -8
- package/src/Player/BattleManager.ts +38 -97
- package/src/Player/ClassManager.ts +35 -95
- package/src/Player/ComponentManager.ts +20 -64
- package/src/Player/EffectManager.ts +27 -110
- package/src/Player/ElementManager.ts +25 -126
- package/src/Player/Event.ts +0 -0
- package/src/Player/GoldManager.ts +35 -32
- package/src/Player/GuiManager.ts +140 -187
- package/src/Player/ItemFixture.ts +5 -4
- package/src/Player/ItemManager.ts +26 -39
- package/src/Player/MoveManager.ts +31 -40
- package/src/Player/ParameterManager.ts +25 -35
- package/src/Player/Player.ts +39 -184
- package/src/Player/SkillManager.ts +23 -44
- package/src/Player/StateManager.ts +95 -210
- package/src/Player/VariableManager.ts +48 -180
- package/src/RpgServer.ts +1 -232
- package/src/core/context.ts +0 -1
- package/src/rooms/map.ts +8 -76
- package/dist/Player/ComponentManager.d.ts +0 -60
- package/dist/Player/EffectManager.d.ts +0 -40
- package/dist/Player/ElementManager.d.ts +0 -31
- package/dist/Player/GoldManager.d.ts +0 -22
- package/dist/Player/GuiManager.d.ts +0 -176
- package/dist/Player/ItemFixture.d.ts +0 -6
- package/dist/Player/VariableManager.d.ts +0 -30
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
import { isString,
|
|
1
|
+
import { Constructor, isString, RpgCommonPlayer } from "@rpgjs/common";
|
|
2
2
|
import { MAXHP, MAXSP } from "../presets";
|
|
3
3
|
|
|
4
|
+
export interface IWithParameterManager {
|
|
5
|
+
parameters: Map<string, any>
|
|
6
|
+
hp: number
|
|
7
|
+
sp: number
|
|
8
|
+
exp: number
|
|
9
|
+
level: number
|
|
10
|
+
expForNextlevel: number
|
|
11
|
+
param: { [key: string]: number }
|
|
12
|
+
paramsModifier: { [key: string]: { value?: number, rate?: number } }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface PlayerWithMixins extends RpgCommonPlayer {
|
|
16
|
+
databaseById?(id: string): any;
|
|
17
|
+
}
|
|
4
18
|
|
|
5
19
|
/**
|
|
6
20
|
* Mixin that adds parameter management functionality to a player class.
|
|
@@ -25,40 +39,18 @@ import { MAXHP, MAXSP } from "../presets";
|
|
|
25
39
|
* }
|
|
26
40
|
* ```
|
|
27
41
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* and parameter modifiers for temporary stat changes.
|
|
34
|
-
*
|
|
35
|
-
* @param Base - The base class to extend with parameter management
|
|
36
|
-
* @returns Extended class with parameter management methods
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* class MyPlayer extends WithParameterManager(BasePlayer) {
|
|
41
|
-
* constructor() {
|
|
42
|
-
* super();
|
|
43
|
-
* this.addParameter('strength', { start: 10, end: 100 });
|
|
44
|
-
* }
|
|
45
|
-
* }
|
|
46
|
-
*
|
|
47
|
-
* const player = new MyPlayer();
|
|
48
|
-
* player.hp = 100;
|
|
49
|
-
* player.level = 5;
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
export function WithParameterManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
53
|
-
return class extends Base {
|
|
54
|
-
_paramsModifier: {
|
|
42
|
+
export function WithParameterManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
43
|
+
Base: TBase
|
|
44
|
+
): TBase & Constructor<IWithParameterManager> {
|
|
45
|
+
return class extends Base implements IWithParameterManager {
|
|
46
|
+
private _paramsModifier: {
|
|
55
47
|
[key: string]: {
|
|
56
48
|
value?: number,
|
|
57
49
|
rate?: number
|
|
58
50
|
}
|
|
59
51
|
} = {}
|
|
60
52
|
|
|
61
|
-
_parameters: Map<string, {
|
|
53
|
+
private _parameters: Map<string, {
|
|
62
54
|
start: number,
|
|
63
55
|
end: number
|
|
64
56
|
}> = new Map()
|
|
@@ -135,11 +127,11 @@ export function WithParameterManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
135
127
|
this['execMethod']('onDead')
|
|
136
128
|
val = 0
|
|
137
129
|
}
|
|
138
|
-
|
|
130
|
+
this._hp.set(val)
|
|
139
131
|
}
|
|
140
132
|
|
|
141
133
|
get hp(): number {
|
|
142
|
-
return
|
|
134
|
+
return this._hp()
|
|
143
135
|
}
|
|
144
136
|
|
|
145
137
|
/**
|
|
@@ -505,7 +497,5 @@ export function WithParameterManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
505
497
|
allRecovery(): void {
|
|
506
498
|
this.recovery({ hp: 1, sp: 1 })
|
|
507
499
|
}
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
export type IParameterManager = InstanceType<ReturnType<typeof WithParameterManager>>;
|
|
500
|
+
}
|
|
501
|
+
}
|
package/src/Player/Player.ts
CHANGED
|
@@ -5,42 +5,33 @@ import {
|
|
|
5
5
|
RpgCommonPlayer,
|
|
6
6
|
ShowAnimationParams,
|
|
7
7
|
Constructor,
|
|
8
|
+
ZoneOptions,
|
|
8
9
|
} from "@rpgjs/common";
|
|
9
|
-
import {
|
|
10
|
+
import { WithComponentManager, IComponentManager } from "./ComponentManager";
|
|
10
11
|
import { RpgMap } from "../rooms/map";
|
|
11
12
|
import { Context, inject } from "@signe/di";
|
|
12
13
|
import { IGuiManager, WithGuiManager } from "./GuiManager";
|
|
13
14
|
import { MockConnection } from "@signe/room";
|
|
14
15
|
import { IMoveManager, WithMoveManager } from "./MoveManager";
|
|
15
16
|
import { IGoldManager, WithGoldManager } from "./GoldManager";
|
|
16
|
-
import {
|
|
17
|
+
import { IWithVariableManager, WithVariableManager } from "./VariableManager";
|
|
17
18
|
import { sync } from "@signe/sync";
|
|
18
19
|
import { signal } from "@signe/reactive";
|
|
19
20
|
import {
|
|
20
|
-
|
|
21
|
+
IWithParameterManager,
|
|
21
22
|
WithParameterManager,
|
|
22
23
|
} from "./ParameterManager";
|
|
23
24
|
import { WithItemFixture } from "./ItemFixture";
|
|
24
|
-
import {
|
|
25
|
+
import { WithStateManager } from "./StateManager";
|
|
26
|
+
import { WithItemManager } from "./ItemManager";
|
|
25
27
|
import { lastValueFrom } from "rxjs";
|
|
26
|
-
import {
|
|
28
|
+
import { WithBattleManager } from "./BattleManager";
|
|
29
|
+
import { WithEffectManager } from "./EffectManager";
|
|
30
|
+
import { WithSkillManager, IWithSkillManager } from "./SkillManager";
|
|
27
31
|
import { AGI, AGI_CURVE, DEX, DEX_CURVE, INT, INT_CURVE, MAXHP, MAXHP_CURVE, MAXSP, MAXSP_CURVE, STR, STR_CURVE } from "../presets";
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import { IBattleManager, WithBattleManager } from "./BattleManager";
|
|
31
|
-
import { IClassManager, WithClassManager } from "./ClassManager";
|
|
32
|
-
import { IStateManager, WithStateManager } from "./StateManager";
|
|
32
|
+
import { WithClassManager } from "./ClassManager";
|
|
33
|
+
import { WithElementManager } from "./ElementManager";
|
|
33
34
|
|
|
34
|
-
// Local interface for ZoneOptions to avoid import issues
|
|
35
|
-
interface ZoneOptions {
|
|
36
|
-
x?: number;
|
|
37
|
-
y?: number;
|
|
38
|
-
radius: number;
|
|
39
|
-
angle?: number;
|
|
40
|
-
direction?: any;
|
|
41
|
-
linkedTo?: string;
|
|
42
|
-
limitedByWalls?: boolean;
|
|
43
|
-
}
|
|
44
35
|
|
|
45
36
|
/**
|
|
46
37
|
* Combines multiple RpgCommonPlayer mixins into one
|
|
@@ -55,44 +46,27 @@ function combinePlayerMixins<T extends Constructor<RpgCommonPlayer>>(
|
|
|
55
46
|
mixins.reduce((ExtendedClass, mixin) => mixin(ExtendedClass), Base);
|
|
56
47
|
}
|
|
57
48
|
|
|
58
|
-
|
|
59
|
-
const BasicPlayerMixins = combinePlayerMixins([
|
|
49
|
+
const PlayerMixins = combinePlayerMixins([
|
|
60
50
|
WithComponentManager,
|
|
61
51
|
WithEffectManager,
|
|
62
52
|
WithGuiManager,
|
|
63
53
|
WithMoveManager,
|
|
64
54
|
WithGoldManager,
|
|
55
|
+
WithVariableManager,
|
|
65
56
|
WithParameterManager,
|
|
66
57
|
WithItemFixture,
|
|
67
|
-
WithItemManager,
|
|
68
|
-
WithElementManager,
|
|
69
|
-
WithVariableManager,
|
|
70
58
|
WithStateManager,
|
|
71
|
-
|
|
59
|
+
WithItemManager,
|
|
72
60
|
WithSkillManager,
|
|
61
|
+
WithClassManager,
|
|
73
62
|
WithBattleManager,
|
|
63
|
+
WithElementManager,
|
|
74
64
|
]);
|
|
75
65
|
|
|
76
66
|
/**
|
|
77
67
|
* RPG Player class with component management capabilities
|
|
78
|
-
*
|
|
79
|
-
* Combines all player mixins to provide a complete player implementation
|
|
80
|
-
* with graphics, movement, inventory, skills, and battle capabilities.
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```ts
|
|
84
|
-
* // Create a new player
|
|
85
|
-
* const player = new RpgPlayer();
|
|
86
|
-
*
|
|
87
|
-
* // Set player graphics
|
|
88
|
-
* player.setGraphic("hero");
|
|
89
|
-
*
|
|
90
|
-
* // Add parameters and items
|
|
91
|
-
* player.addParameter("strength", { start: 10, end: 100 });
|
|
92
|
-
* player.addItem(sword);
|
|
93
|
-
* ```
|
|
94
68
|
*/
|
|
95
|
-
export class RpgPlayer extends
|
|
69
|
+
export class RpgPlayer extends PlayerMixins(RpgCommonPlayer) {
|
|
96
70
|
map: RpgMap | null = null;
|
|
97
71
|
context?: Context;
|
|
98
72
|
conn: MockConnection | null = null;
|
|
@@ -101,21 +75,20 @@ export class RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
101
75
|
|
|
102
76
|
constructor() {
|
|
103
77
|
super();
|
|
104
|
-
|
|
105
|
-
(this as any).expCurve = {
|
|
78
|
+
this.expCurve = {
|
|
106
79
|
basis: 30,
|
|
107
80
|
extra: 20,
|
|
108
81
|
accelerationA: 30,
|
|
109
82
|
accelerationB: 30
|
|
110
|
-
}
|
|
83
|
+
}
|
|
111
84
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
85
|
+
this.addParameter(MAXHP, MAXHP_CURVE)
|
|
86
|
+
this.addParameter(MAXSP, MAXSP_CURVE)
|
|
87
|
+
this.addParameter(STR, STR_CURVE)
|
|
88
|
+
this.addParameter(INT, INT_CURVE)
|
|
89
|
+
this.addParameter(DEX, DEX_CURVE)
|
|
90
|
+
this.addParameter(AGI, AGI_CURVE)
|
|
91
|
+
this.allRecovery()
|
|
119
92
|
}
|
|
120
93
|
|
|
121
94
|
async execMethod(method: string, methodData: any[] = [], target?: any) {
|
|
@@ -178,50 +151,7 @@ export class RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
178
151
|
});
|
|
179
152
|
}
|
|
180
153
|
|
|
181
|
-
|
|
182
|
-
* Set the current animation of the player's sprite
|
|
183
|
-
*
|
|
184
|
-
* This method changes the animation state of the player's current sprite.
|
|
185
|
-
* It's used to trigger character animations like attack, skill, or custom movements.
|
|
186
|
-
* When `nbTimes` is set to a finite number, the animation will play that many times
|
|
187
|
-
* before returning to the previous animation state.
|
|
188
|
-
*
|
|
189
|
-
* @param animationName - The name of the animation to play (e.g., 'attack', 'skill', 'walk')
|
|
190
|
-
* @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)
|
|
191
|
-
*
|
|
192
|
-
* @example
|
|
193
|
-
* ```ts
|
|
194
|
-
* // Set continuous walk animation
|
|
195
|
-
* player.setAnimation('walk');
|
|
196
|
-
*
|
|
197
|
-
* // Play attack animation 3 times then return to previous state
|
|
198
|
-
* player.setAnimation('attack', 3);
|
|
199
|
-
*
|
|
200
|
-
* // Play skill animation once
|
|
201
|
-
* player.setAnimation('skill', 1);
|
|
202
|
-
*
|
|
203
|
-
* // Set idle/stand animation
|
|
204
|
-
* player.setAnimation('stand');
|
|
205
|
-
* ```
|
|
206
|
-
*/
|
|
207
|
-
setAnimation(animationName: string, nbTimes: number = Infinity) {
|
|
208
|
-
const map = this.getCurrentMap();
|
|
209
|
-
if (!map) return;
|
|
210
|
-
if (nbTimes === Infinity) {
|
|
211
|
-
this.animationName.set(animationName);
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
map.$broadcast({
|
|
215
|
-
type: "setAnimation",
|
|
216
|
-
value: {
|
|
217
|
-
animationName,
|
|
218
|
-
nbTimes,
|
|
219
|
-
object: this.id,
|
|
220
|
-
},
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
154
|
+
showAnimation(params: ShowAnimationParams) {}
|
|
225
155
|
|
|
226
156
|
/**
|
|
227
157
|
* Run the change detection cycle. Normally, as soon as a hook is called in a class, the cycle is started. But you can start it manually
|
|
@@ -298,35 +228,11 @@ export class RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
298
228
|
);
|
|
299
229
|
}
|
|
300
230
|
|
|
301
|
-
|
|
302
|
-
* Show a temporary component animation on this player
|
|
303
|
-
*
|
|
304
|
-
* This method broadcasts a component animation to all clients, allowing
|
|
305
|
-
* temporary visual effects like hit indicators, spell effects, or status animations
|
|
306
|
-
* to be displayed on the player.
|
|
307
|
-
*
|
|
308
|
-
* @param id - The ID of the component animation to display
|
|
309
|
-
* @param params - Parameters to pass to the component animation
|
|
310
|
-
*
|
|
311
|
-
* @example
|
|
312
|
-
* ```ts
|
|
313
|
-
* // Show a hit animation with damage text
|
|
314
|
-
* player.showComponentAnimation("hit", {
|
|
315
|
-
* text: "150",
|
|
316
|
-
* color: "red"
|
|
317
|
-
* });
|
|
318
|
-
*
|
|
319
|
-
* // Show a heal animation
|
|
320
|
-
* player.showComponentAnimation("heal", {
|
|
321
|
-
* amount: 50
|
|
322
|
-
* });
|
|
323
|
-
* ```
|
|
324
|
-
*/
|
|
325
|
-
showComponentAnimation(id: string, params: any) {
|
|
231
|
+
broadcastEffect(id: string, params: any) {
|
|
326
232
|
const map = this.getCurrentMap();
|
|
327
233
|
if (!map) return;
|
|
328
234
|
map.$broadcast({
|
|
329
|
-
type: "
|
|
235
|
+
type: "showEffect",
|
|
330
236
|
value: {
|
|
331
237
|
id,
|
|
332
238
|
params,
|
|
@@ -335,46 +241,8 @@ export class RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
335
241
|
});
|
|
336
242
|
}
|
|
337
243
|
|
|
338
|
-
/**
|
|
339
|
-
* Display a spritesheet animation on the player
|
|
340
|
-
*
|
|
341
|
-
* This method displays a temporary visual animation using a spritesheet.
|
|
342
|
-
* The animation can either be displayed as an overlay on the player or replace
|
|
343
|
-
* the player's current graphic temporarily. This is useful for spell effects,
|
|
344
|
-
* transformations, or other visual feedback that uses predefined spritesheets.
|
|
345
|
-
*
|
|
346
|
-
* @param graphic - The ID of the spritesheet to use for the animation
|
|
347
|
-
* @param animationName - The name of the animation within the spritesheet (default: 'default')
|
|
348
|
-
* @param replaceGraphic - Whether to replace the player's sprite with the animation (default: false)
|
|
349
|
-
*
|
|
350
|
-
* @example
|
|
351
|
-
* ```ts
|
|
352
|
-
* // Show explosion animation as overlay on player
|
|
353
|
-
* player.showAnimation("explosion");
|
|
354
|
-
*
|
|
355
|
-
* // Show specific spell effect animation
|
|
356
|
-
* player.showAnimation("spell-effects", "fireball");
|
|
357
|
-
*
|
|
358
|
-
* // Transform player graphic temporarily with animation
|
|
359
|
-
* player.showAnimation("transformation", "werewolf", true);
|
|
360
|
-
*
|
|
361
|
-
* // Show healing effect on player
|
|
362
|
-
* player.showAnimation("healing-effects", "holy-light");
|
|
363
|
-
* ```
|
|
364
|
-
*/
|
|
365
|
-
showAnimation(graphic: string, animationName: string = 'default', replaceGraphic: boolean = false) {
|
|
366
|
-
if (replaceGraphic) {
|
|
367
|
-
this.setAnimation(animationName, 1);
|
|
368
|
-
return
|
|
369
|
-
}
|
|
370
|
-
this.showComponentAnimation("animation", {
|
|
371
|
-
graphic,
|
|
372
|
-
animationName,
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
|
|
376
244
|
showHit(text: string) {
|
|
377
|
-
this.
|
|
245
|
+
this.broadcastEffect("hit", {
|
|
378
246
|
text,
|
|
379
247
|
direction: this.direction(),
|
|
380
248
|
});
|
|
@@ -400,25 +268,12 @@ export class RpgEvent extends RpgPlayer {
|
|
|
400
268
|
}
|
|
401
269
|
}
|
|
402
270
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
IMoveManager,
|
|
413
|
-
IGoldManager,
|
|
414
|
-
IComponentManager,
|
|
415
|
-
IGuiManager,
|
|
416
|
-
IItemManager,
|
|
417
|
-
IEffectManager,
|
|
418
|
-
IParameterManager,
|
|
419
|
-
IElementManager,
|
|
420
|
-
ISkillManager,
|
|
421
|
-
IBattleManager,
|
|
422
|
-
IClassManager,
|
|
423
|
-
IStateManager
|
|
424
|
-
{}
|
|
271
|
+
export interface RpgPlayer
|
|
272
|
+
extends RpgCommonPlayer,
|
|
273
|
+
IComponentManager,
|
|
274
|
+
IGuiManager,
|
|
275
|
+
IMoveManager,
|
|
276
|
+
IGoldManager,
|
|
277
|
+
IWithVariableManager,
|
|
278
|
+
IWithParameterManager,
|
|
279
|
+
IWithSkillManager {}
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
isArray,
|
|
4
4
|
isInstanceOf,
|
|
5
5
|
isString,
|
|
6
|
-
PlayerCtor,
|
|
7
6
|
RpgCommonPlayer,
|
|
8
7
|
} from "@rpgjs/common";
|
|
9
8
|
import { SkillLog } from "../logs";
|
|
@@ -21,36 +20,22 @@ interface SkillManagerDependencies {
|
|
|
21
20
|
applyStates(player: RpgPlayer, skill: any): void;
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
23
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* Provides skill management capabilities to any class. This mixin handles
|
|
30
|
-
* learning, forgetting, and using skills, including SP cost management,
|
|
31
|
-
* hit rate calculations, and skill effects application.
|
|
32
|
-
*
|
|
33
|
-
* @param Base - The base class to extend with skill management
|
|
34
|
-
* @returns Extended class with skill management methods
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* class MyPlayer extends WithSkillManager(BasePlayer) {
|
|
39
|
-
* constructor() {
|
|
40
|
-
* super();
|
|
41
|
-
* // Skill system is automatically initialized
|
|
42
|
-
* }
|
|
43
|
-
* }
|
|
44
|
-
*
|
|
45
|
-
* const player = new MyPlayer();
|
|
46
|
-
* player.learnSkill(Fire);
|
|
47
|
-
* player.useSkill(Fire, targetPlayer);
|
|
48
|
-
* ```
|
|
24
|
+
* Interface defining what SkillManager adds to a class
|
|
49
25
|
*/
|
|
50
|
-
export
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
26
|
+
export interface IWithSkillManager {
|
|
27
|
+
getSkill(skillClass: any | string): any;
|
|
28
|
+
learnSkill(skillId: any | string): any;
|
|
29
|
+
forgetSkill(skillId: any | string): any;
|
|
30
|
+
useSkill(skillId: any | string, otherPlayer?: RpgPlayer | RpgPlayer[]): any;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function WithSkillManager<TBase extends Constructor<RpgCommonPlayer & SkillManagerDependencies>>(
|
|
34
|
+
Base: TBase
|
|
35
|
+
): Constructor<IWithSkillManager> & TBase {
|
|
36
|
+
return class extends Base implements IWithSkillManager {
|
|
37
|
+
private _getSkillIndex(skillClass: any | string) {
|
|
38
|
+
return this.skills().findIndex((skill) => {
|
|
54
39
|
if (isString(skill)) {
|
|
55
40
|
return skill.id == skillClass;
|
|
56
41
|
}
|
|
@@ -109,7 +94,7 @@ export function WithSkillManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
109
94
|
if (this.getSkill(skillId)) {
|
|
110
95
|
throw SkillLog.alreadyLearned(skillId);
|
|
111
96
|
}
|
|
112
|
-
const instance =
|
|
97
|
+
const instance = this.databaseById(skillId);
|
|
113
98
|
this.skills().push(instance);
|
|
114
99
|
this["execMethod"]("onLearn", [this], instance);
|
|
115
100
|
return instance;
|
|
@@ -146,7 +131,7 @@ export function WithSkillManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
146
131
|
* @memberof SkillManager
|
|
147
132
|
*/
|
|
148
133
|
forgetSkill(skillId: any | string) {
|
|
149
|
-
if (isString(skillId)) skillId =
|
|
134
|
+
if (isString(skillId)) skillId = this.databaseById(skillId);
|
|
150
135
|
const index = this._getSkillIndex(skillId);
|
|
151
136
|
if (index == -1) {
|
|
152
137
|
throw SkillLog.notLearned(skillId);
|
|
@@ -234,16 +219,16 @@ export function WithSkillManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
234
219
|
*/
|
|
235
220
|
useSkill(skillId: any | string, otherPlayer?: RpgPlayer | RpgPlayer[]) {
|
|
236
221
|
const skill = this.getSkill(skillId);
|
|
237
|
-
if (
|
|
222
|
+
if (this.hasEffect(Effect.CAN_NOT_SKILL)) {
|
|
238
223
|
throw SkillLog.restriction(skillId);
|
|
239
224
|
}
|
|
240
225
|
if (!skill) {
|
|
241
226
|
throw SkillLog.notLearned(skillId);
|
|
242
227
|
}
|
|
243
|
-
if (skill.spCost >
|
|
244
|
-
throw SkillLog.notEnoughSp(skillId, skill.spCost,
|
|
228
|
+
if (skill.spCost > this.sp) {
|
|
229
|
+
throw SkillLog.notEnoughSp(skillId, skill.spCost, this.sp);
|
|
245
230
|
}
|
|
246
|
-
|
|
231
|
+
this.sp -= skill.spCost / (this.hasEffect(Effect.HALF_SP_COST) ? 2 : 1);
|
|
247
232
|
const hitRate = skill.hitRate ?? 1;
|
|
248
233
|
if (Math.random() > hitRate) {
|
|
249
234
|
this["execMethod"]("onUseFailed", [this, otherPlayer], skill);
|
|
@@ -255,18 +240,12 @@ export function WithSkillManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
255
240
|
players = [otherPlayer];
|
|
256
241
|
}
|
|
257
242
|
for (let player of players) {
|
|
258
|
-
|
|
259
|
-
|
|
243
|
+
this.applyStates(player, skill);
|
|
244
|
+
player.applyDamage(this, skill);
|
|
260
245
|
}
|
|
261
246
|
}
|
|
262
247
|
this["execMethod"]("onUse", [this, otherPlayer], skill);
|
|
263
248
|
return skill;
|
|
264
249
|
}
|
|
265
|
-
}
|
|
250
|
+
};
|
|
266
251
|
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Type helper to extract the interface from the WithSkillManager mixin
|
|
270
|
-
* This provides the type without duplicating method signatures
|
|
271
|
-
*/
|
|
272
|
-
export type ISkillManager = InstanceType<ReturnType<typeof WithSkillManager>>;
|