@rpgjs/server 5.0.0-alpha.10 → 5.0.0-alpha.2
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 +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
package/dist/rooms/map.d.ts
CHANGED
|
@@ -102,76 +102,7 @@ export declare class RpgMap extends RpgCommonMap<RpgPlayer> implements RoomOnJoi
|
|
|
102
102
|
getPlayer(playerId: string): RpgPlayer | undefined;
|
|
103
103
|
getEvents(): RpgEvent[];
|
|
104
104
|
removeEvent(eventId: string): void;
|
|
105
|
-
|
|
106
|
-
* Display a component animation at a specific position on the map
|
|
107
|
-
*
|
|
108
|
-
* This method broadcasts a component animation to all clients connected to the map,
|
|
109
|
-
* allowing temporary visual effects to be displayed at any location on the map.
|
|
110
|
-
* Component animations are custom Canvas Engine components that can display
|
|
111
|
-
* complex effects with custom logic and parameters.
|
|
112
|
-
*
|
|
113
|
-
* @param id - The ID of the component animation to display
|
|
114
|
-
* @param position - The x, y coordinates where to display the animation
|
|
115
|
-
* @param params - Parameters to pass to the component animation
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```ts
|
|
119
|
-
* // Show explosion at specific coordinates
|
|
120
|
-
* map.showComponentAnimation("explosion", { x: 300, y: 400 }, {
|
|
121
|
-
* intensity: 2.5,
|
|
122
|
-
* duration: 1500
|
|
123
|
-
* });
|
|
124
|
-
*
|
|
125
|
-
* // Show area damage effect
|
|
126
|
-
* map.showComponentAnimation("area-damage", { x: player.x, y: player.y }, {
|
|
127
|
-
* radius: 100,
|
|
128
|
-
* color: "red",
|
|
129
|
-
* damage: 50
|
|
130
|
-
* });
|
|
131
|
-
*
|
|
132
|
-
* // Show treasure spawn effect
|
|
133
|
-
* map.showComponentAnimation("treasure-spawn", { x: 150, y: 200 }, {
|
|
134
|
-
* sparkle: true,
|
|
135
|
-
* sound: "treasure-appear"
|
|
136
|
-
* });
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
showComponentAnimation(id: string, position: {
|
|
140
|
-
x: number;
|
|
141
|
-
y: number;
|
|
142
|
-
}, params: any): void;
|
|
143
|
-
/**
|
|
144
|
-
* Display a spritesheet animation at a specific position on the map
|
|
145
|
-
*
|
|
146
|
-
* This method displays a temporary visual animation using a spritesheet at any
|
|
147
|
-
* location on the map. It's a convenience method that internally uses showComponentAnimation
|
|
148
|
-
* with the built-in 'animation' component. This is useful for spell effects, environmental
|
|
149
|
-
* animations, or any visual feedback that uses predefined spritesheets.
|
|
150
|
-
*
|
|
151
|
-
* @param position - The x, y coordinates where to display the animation
|
|
152
|
-
* @param graphic - The ID of the spritesheet to use for the animation
|
|
153
|
-
* @param animationName - The name of the animation within the spritesheet (default: 'default')
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```ts
|
|
157
|
-
* // Show explosion at specific coordinates
|
|
158
|
-
* map.showAnimation({ x: 100, y: 200 }, "explosion");
|
|
159
|
-
*
|
|
160
|
-
* // Show spell effect at player position
|
|
161
|
-
* const playerPos = { x: player.x, y: player.y };
|
|
162
|
-
* map.showAnimation(playerPos, "spell-effects", "lightning");
|
|
163
|
-
*
|
|
164
|
-
* // Show environmental effect
|
|
165
|
-
* map.showAnimation({ x: 300, y: 150 }, "nature-effects", "wind-gust");
|
|
166
|
-
*
|
|
167
|
-
* // Show portal opening animation
|
|
168
|
-
* map.showAnimation({ x: 500, y: 400 }, "portals", "opening");
|
|
169
|
-
* ```
|
|
170
|
-
*/
|
|
171
|
-
showAnimation(position: {
|
|
172
|
-
x: number;
|
|
173
|
-
y: number;
|
|
174
|
-
}, graphic: string, animationName?: string): void;
|
|
105
|
+
showAnimation(animationName: string, object: RpgPlayer): void;
|
|
175
106
|
}
|
|
176
107
|
export interface RpgMap {
|
|
177
108
|
$send: (conn: MockConnection, data: any) => void;
|
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpgjs/server",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.2",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "vite build --watch",
|
|
11
|
+
"build": "vite build"
|
|
12
|
+
},
|
|
9
13
|
"keywords": [],
|
|
10
14
|
"author": "",
|
|
11
15
|
"license": "MIT",
|
|
12
16
|
"description": "",
|
|
13
17
|
"dependencies": {
|
|
14
|
-
"@rpgjs/common": "
|
|
18
|
+
"@rpgjs/common": "workspace:*",
|
|
15
19
|
"@rpgjs/database": "^4.3.0",
|
|
16
20
|
"@signe/di": "^2.3.2",
|
|
17
21
|
"@signe/reactive": "^2.3.2",
|
|
@@ -23,9 +27,5 @@
|
|
|
23
27
|
"vite": "^6.2.5",
|
|
24
28
|
"vite-plugin-dts": "^4.5.3"
|
|
25
29
|
},
|
|
26
|
-
"type": "module"
|
|
27
|
-
|
|
28
|
-
"dev": "vite build --watch",
|
|
29
|
-
"build": "vite build"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
30
|
+
"type": "module"
|
|
31
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Constructor,
|
|
1
|
+
import { Constructor, RpgCommonPlayer } from "@rpgjs/common";
|
|
2
2
|
import { RpgPlayer } from "./Player";
|
|
3
3
|
import { ATK, PDEF, SDEF } from "../presets";
|
|
4
4
|
import { Effect } from "./EffectManager";
|
|
@@ -9,68 +9,41 @@ interface PlayerWithMixins extends RpgCommonPlayer {
|
|
|
9
9
|
hasEffect(effect: string): boolean;
|
|
10
10
|
coefficientElements(attackerPlayer: RpgPlayer): number;
|
|
11
11
|
hp: number;
|
|
12
|
-
|
|
12
|
+
getFormulas(name: string): any;
|
|
13
|
+
hasEffect(effect: string): boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface IBattleManager {
|
|
17
|
+
applyDamage(attackerPlayer: RpgPlayer, skill?: any): {
|
|
18
|
+
damage: number;
|
|
19
|
+
critical: boolean;
|
|
20
|
+
elementVulnerable: boolean;
|
|
21
|
+
guard: boolean;
|
|
22
|
+
superGuard: boolean;
|
|
23
|
+
};
|
|
13
24
|
}
|
|
14
25
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* damage calculation, critical hits, elemental vulnerabilities, and guard effects.
|
|
20
|
-
* It implements a comprehensive battle system with customizable formulas and effects.
|
|
21
|
-
*
|
|
22
|
-
* @param Base - The base class to extend with battle management
|
|
23
|
-
* @returns Extended class with battle management methods
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* class MyPlayer extends WithBattleManager(BasePlayer) {
|
|
28
|
-
* constructor() {
|
|
29
|
-
* super();
|
|
30
|
-
* // Battle system is automatically initialized
|
|
31
|
-
* }
|
|
32
|
-
* }
|
|
33
|
-
*
|
|
34
|
-
* const player = new MyPlayer();
|
|
35
|
-
* const attacker = new MyPlayer();
|
|
36
|
-
* const result = player.applyDamage(attacker);
|
|
37
|
-
* console.log(`Damage dealt: ${result.damage}`);
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export function WithBattleManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
41
|
-
return class extends Base {
|
|
26
|
+
export function WithBattleManager<TBase extends Constructor<PlayerWithMixins>>(
|
|
27
|
+
Base: TBase
|
|
28
|
+
): Constructor<IBattleManager> & TBase {
|
|
29
|
+
return class extends Base implements IBattleManager {
|
|
42
30
|
/**
|
|
43
31
|
* Apply damage. Player will lose HP. the `attackerPlayer` parameter is the other player, the one who attacks.
|
|
44
32
|
*
|
|
45
33
|
* If you don't set the skill parameter, it will be a physical attack.
|
|
46
|
-
* The attack formula is already defined but you can customize it in the server options
|
|
47
|
-
* This method handles all aspects of damage calculation including critical hits,
|
|
48
|
-
* elemental vulnerabilities, guard effects, and applies the final damage to HP.
|
|
34
|
+
* The attack formula is already defined but you can customize it in the server options
|
|
49
35
|
*
|
|
50
|
-
* @param attackerPlayer - The attacking player who deals the damage
|
|
51
|
-
* @param skill - Optional skill object for magical attacks, if not provided uses physical attack
|
|
52
|
-
* @returns Object containing damage details and special effects that occurred
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
36
|
* ```ts
|
|
56
|
-
* //
|
|
57
|
-
* const result = player.applyDamage(attackerPlayer);
|
|
58
|
-
* console.log(`Physical damage: ${result.damage}, Critical: ${result.critical}`);
|
|
59
|
-
*
|
|
60
|
-
* // Magical attack with skill
|
|
61
|
-
* const fireSkill = { id: 'fire', power: 50, element: 'fire' };
|
|
62
|
-
* const magicResult = player.applyDamage(attackerPlayer, fireSkill);
|
|
63
|
-
* console.log(`Magic damage: ${magicResult.damage}, Vulnerable: ${magicResult.elementVulnerable}`);
|
|
64
|
-
*
|
|
65
|
-
* // Check for guard effects
|
|
66
|
-
* if (result.guard) {
|
|
67
|
-
* console.log('Attack was partially blocked!');
|
|
68
|
-
* }
|
|
69
|
-
* if (result.superGuard) {
|
|
70
|
-
* console.log('Attack was heavily reduced by super guard!');
|
|
71
|
-
* }
|
|
37
|
+
* player.applyDamage(attackerPlayer) // returns { damage: number }
|
|
72
38
|
* ```
|
|
73
|
-
|
|
39
|
+
*
|
|
40
|
+
* @title Apply Damage
|
|
41
|
+
* @method player.applyDamage(attackerPlayer,skill)
|
|
42
|
+
* @param {RpgPlayer} attackerPlayer The attacking player
|
|
43
|
+
* @param {any} [skill]
|
|
44
|
+
* @returns {object}
|
|
45
|
+
* @memberof BattleManager
|
|
46
|
+
* */
|
|
74
47
|
applyDamage(
|
|
75
48
|
attackerPlayer: RpgPlayer,
|
|
76
49
|
skill?: any
|
|
@@ -83,13 +56,13 @@ export function WithBattleManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
83
56
|
} {
|
|
84
57
|
const getParam = (player: RpgPlayer) => {
|
|
85
58
|
const params = {};
|
|
86
|
-
|
|
87
|
-
params[key] =
|
|
59
|
+
this.parameters.forEach((val, key) => {
|
|
60
|
+
params[key] = player.param[key];
|
|
88
61
|
});
|
|
89
62
|
return {
|
|
90
|
-
[ATK]:
|
|
91
|
-
[PDEF]:
|
|
92
|
-
[SDEF]:
|
|
63
|
+
[ATK]: player.atk,
|
|
64
|
+
[PDEF]: player.pdef,
|
|
65
|
+
[SDEF]: player.sdef,
|
|
93
66
|
...params,
|
|
94
67
|
};
|
|
95
68
|
};
|
|
@@ -114,7 +87,7 @@ export function WithBattleManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
114
87
|
throw new Error("Physic Formulas not exists");
|
|
115
88
|
}
|
|
116
89
|
damage = fn(paramA, paramB);
|
|
117
|
-
const coef =
|
|
90
|
+
const coef = this.coefficientElements(attackerPlayer);
|
|
118
91
|
if (coef >= 2) {
|
|
119
92
|
elementVulnerable = true;
|
|
120
93
|
}
|
|
@@ -128,7 +101,7 @@ export function WithBattleManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
128
101
|
damage = newDamage;
|
|
129
102
|
}
|
|
130
103
|
}
|
|
131
|
-
if (
|
|
104
|
+
if (this.hasEffect(Effect.GUARD)) {
|
|
132
105
|
fn = this.getFormulas("damageGuard");
|
|
133
106
|
if (fn) {
|
|
134
107
|
let newDamage = fn(damage, paramA, paramB);
|
|
@@ -138,11 +111,11 @@ export function WithBattleManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
138
111
|
damage = newDamage;
|
|
139
112
|
}
|
|
140
113
|
}
|
|
141
|
-
if (
|
|
114
|
+
if (this.hasEffect(Effect.SUPER_GUARD)) {
|
|
142
115
|
damage /= 4;
|
|
143
116
|
superGuard = true;
|
|
144
117
|
}
|
|
145
|
-
|
|
118
|
+
this.hp -= damage;
|
|
146
119
|
return {
|
|
147
120
|
damage,
|
|
148
121
|
critical,
|
|
@@ -152,41 +125,9 @@ export function WithBattleManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
152
125
|
};
|
|
153
126
|
}
|
|
154
127
|
|
|
155
|
-
/**
|
|
156
|
-
* Get damage formulas from the current map
|
|
157
|
-
*
|
|
158
|
-
* Retrieves the damage calculation formulas defined in the current map's configuration.
|
|
159
|
-
* These formulas are used to calculate different types of damage including physical,
|
|
160
|
-
* magical, critical hits, and guard effects. The formulas provide flexibility in
|
|
161
|
-
* customizing the battle system's damage calculations.
|
|
162
|
-
*
|
|
163
|
-
* @param name - The name of the formula to retrieve (e.g., 'damagePhysic', 'damageSkill')
|
|
164
|
-
* @returns The formula function or undefined if not found
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* ```ts
|
|
168
|
-
* // Get physical damage formula
|
|
169
|
-
* const physicFormula = player.getFormulas('damagePhysic');
|
|
170
|
-
* if (physicFormula) {
|
|
171
|
-
* const damage = physicFormula(attackerParams, defenderParams);
|
|
172
|
-
* }
|
|
173
|
-
*
|
|
174
|
-
* // Get critical damage formula
|
|
175
|
-
* const criticalFormula = player.getFormulas('damageCritical');
|
|
176
|
-
* if (criticalFormula) {
|
|
177
|
-
* const criticalDamage = criticalFormula(baseDamage, attackerParams, defenderParams);
|
|
178
|
-
* }
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
128
|
getFormulas(name: string) {
|
|
182
|
-
const map =
|
|
129
|
+
const map = this.getCurrentMap();
|
|
183
130
|
return map.damageFormulas[name];
|
|
184
131
|
}
|
|
185
|
-
}
|
|
132
|
+
};
|
|
186
133
|
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Type helper to extract the interface from the WithBattleManager mixin
|
|
190
|
-
* This provides the type without duplicating method signatures
|
|
191
|
-
*/
|
|
192
|
-
export type IBattleManager = InstanceType<ReturnType<typeof WithBattleManager>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Constructor, isString,
|
|
1
|
+
import { Constructor, isString, RpgCommonPlayer } from "@rpgjs/common";
|
|
2
2
|
|
|
3
3
|
type ClassClass = any;
|
|
4
4
|
type ActorClass = any;
|
|
@@ -10,129 +10,69 @@ interface PlayerWithMixins extends RpgCommonPlayer {
|
|
|
10
10
|
equip(item: any, equip: boolean): void;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* class MyPlayer extends WithClassManager(BasePlayer) {
|
|
26
|
-
* constructor() {
|
|
27
|
-
* super();
|
|
28
|
-
* // Class system is automatically initialized
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
*
|
|
32
|
-
* const player = new MyPlayer();
|
|
33
|
-
* player.setClass(Fighter);
|
|
34
|
-
* player.setActor(Hero);
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export function WithClassManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
38
|
-
return class extends Base {
|
|
13
|
+
export interface IClassManager {
|
|
14
|
+
setClass(_class: ClassClass | string): ClassClass;
|
|
15
|
+
setActor(actorClass: ActorClass | string): ActorClass;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function WithClassManager<TBase extends Constructor<PlayerWithMixins>>(
|
|
19
|
+
Base: TBase
|
|
20
|
+
): Constructor<IClassManager> & TBase {
|
|
21
|
+
return class extends Base implements IClassManager {
|
|
39
22
|
|
|
40
23
|
/**
|
|
41
24
|
* Assign a class to the player
|
|
42
25
|
*
|
|
43
|
-
* Sets the player's class, which defines their combat abilities, stat growth,
|
|
44
|
-
* and available skills. The class system provides the foundation for character
|
|
45
|
-
* progression and specialization. When a class is set, it automatically triggers
|
|
46
|
-
* the class's onSet method for any additional initialization.
|
|
47
|
-
*
|
|
48
|
-
* @param _class - The class constructor or class ID to assign to the player
|
|
49
|
-
* @returns The instantiated class object
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
26
|
* ```ts
|
|
53
27
|
* import { Fighter } from 'my-database/classes/fighter'
|
|
54
28
|
*
|
|
55
|
-
*
|
|
56
|
-
* const fighterClass = player.setClass(Fighter);
|
|
57
|
-
* console.log('Class set:', fighterClass.name);
|
|
58
|
-
*
|
|
59
|
-
* // Set class using string ID
|
|
60
|
-
* player.setClass('fighter');
|
|
61
|
-
*
|
|
62
|
-
* // Class affects available skills and stats
|
|
63
|
-
* console.log('Available skills:', player.skills);
|
|
64
|
-
* console.log('Class bonuses applied to stats');
|
|
65
|
-
*
|
|
66
|
-
* // Class determines level progression
|
|
67
|
-
* player.level = 5;
|
|
68
|
-
* // Skills may be automatically learned based on class definition
|
|
29
|
+
* player.setClass(Fighter)
|
|
69
30
|
* ```
|
|
70
|
-
|
|
31
|
+
*
|
|
32
|
+
* @title Set Class
|
|
33
|
+
* @method player.setClass(ClassClass)
|
|
34
|
+
* @param {ClassClass | string} class class or id
|
|
35
|
+
* @returns {instance of ClassClass}
|
|
36
|
+
* @memberof ClassManager
|
|
37
|
+
* */
|
|
71
38
|
setClass(_class: ClassClass | string) {
|
|
72
|
-
if (isString(_class)) _class =
|
|
39
|
+
if (isString(_class)) _class = this.databaseById(_class);
|
|
73
40
|
const classInstance = new (_class as ClassClass)();
|
|
74
|
-
|
|
41
|
+
this["execMethod"]("onSet", [this], classInstance);
|
|
75
42
|
return classInstance;
|
|
76
43
|
}
|
|
77
44
|
|
|
78
45
|
/**
|
|
79
46
|
* Allows to give a set of already defined properties to the player (default equipment, or a list of skills to learn according to the level)
|
|
80
47
|
*
|
|
81
|
-
* Sets up the player as a specific actor archetype, which includes predefined
|
|
82
|
-
* characteristics like starting equipment, parameters, level ranges, and associated class.
|
|
83
|
-
* This is typically used for creating pre-configured character templates or NPCs
|
|
84
|
-
* with specific roles and equipment loadouts.
|
|
85
|
-
*
|
|
86
|
-
* @param actorClass - The actor constructor or actor ID to assign to the player
|
|
87
|
-
* @returns The instantiated actor object
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
48
|
* ```ts
|
|
91
49
|
* import { Hero } from 'my-database/classes/hero'
|
|
92
50
|
*
|
|
93
|
-
*
|
|
94
|
-
* const heroActor = player.setActor(Hero);
|
|
95
|
-
* console.log('Actor configured:', heroActor.name);
|
|
96
|
-
*
|
|
97
|
-
* // Actor automatically sets up:
|
|
98
|
-
* // - Starting equipment (sword, armor, etc.)
|
|
99
|
-
* console.log('Starting equipment:', player.equipments());
|
|
100
|
-
*
|
|
101
|
-
* // - Parameter ranges and growth
|
|
102
|
-
* console.log('Level range:', player.initialLevel, '-', player.finalLevel);
|
|
103
|
-
*
|
|
104
|
-
* // - Associated class
|
|
105
|
-
* console.log('Assigned class:', player.class);
|
|
106
|
-
*
|
|
107
|
-
* // - Experience curve
|
|
108
|
-
* console.log('EXP curve:', player.expCurve);
|
|
109
|
-
*
|
|
110
|
-
* // Actor setup is comprehensive
|
|
111
|
-
* player.setActor('hero'); // Can also use string ID
|
|
51
|
+
* player.setActor(Hero)
|
|
112
52
|
* ```
|
|
113
|
-
|
|
53
|
+
*
|
|
54
|
+
* @title Set Actor
|
|
55
|
+
* @method player.setActor(ActorClass)
|
|
56
|
+
* @param {ActorClass | string} actorClass actor class or id
|
|
57
|
+
* @returns {instance of ActorClass}
|
|
58
|
+
* @memberof ClassManager
|
|
59
|
+
* */
|
|
114
60
|
setActor(actorClass: ActorClass | string) {
|
|
115
|
-
if (isString(actorClass)) actorClass =
|
|
61
|
+
if (isString(actorClass)) actorClass = this.databaseById(actorClass);
|
|
116
62
|
const actor = new (actorClass as ActorClass)();
|
|
117
63
|
["name", "initialLevel", "finalLevel", "expCurve"].forEach((key) => {
|
|
118
|
-
if (actor[key])
|
|
64
|
+
if (actor[key]) this[key] = actor[key];
|
|
119
65
|
});
|
|
120
66
|
for (let param in actor.parameters) {
|
|
121
|
-
|
|
67
|
+
this.addParameter(param, actor.parameters[param]);
|
|
122
68
|
}
|
|
123
69
|
for (let item of actor.startingEquipment) {
|
|
124
|
-
|
|
125
|
-
|
|
70
|
+
this.addItem(item);
|
|
71
|
+
this.equip(item, true);
|
|
126
72
|
}
|
|
127
73
|
if (actor.class) this.setClass(actor.class);
|
|
128
|
-
|
|
74
|
+
this["execMethod"]("onSet", [this], actor);
|
|
129
75
|
return actor;
|
|
130
76
|
}
|
|
131
|
-
}
|
|
77
|
+
};
|
|
132
78
|
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Type helper to extract the interface from the WithClassManager mixin
|
|
136
|
-
* This provides the type without duplicating method signatures
|
|
137
|
-
*/
|
|
138
|
-
export type IClassManager = InstanceType<ReturnType<typeof WithClassManager>>;
|
|
@@ -1,73 +1,29 @@
|
|
|
1
|
-
import { Constructor
|
|
1
|
+
import { type Constructor } from "@rpgjs/common";
|
|
2
2
|
import { RpgCommonPlayer } from "@rpgjs/common";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* Provides graphic management capabilities to any class. This mixin allows
|
|
8
|
-
* setting single or multiple graphics for player representation, enabling
|
|
9
|
-
* dynamic visual changes and animation sequences.
|
|
10
|
-
*
|
|
11
|
-
* @param Base - The base class to extend with component management
|
|
12
|
-
* @returns Extended class with component management methods
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* class MyPlayer extends WithComponentManager(BasePlayer) {
|
|
17
|
-
* constructor() {
|
|
18
|
-
* super();
|
|
19
|
-
* this.setGraphic("hero");
|
|
20
|
-
* }
|
|
21
|
-
* }
|
|
22
|
-
*
|
|
23
|
-
* const player = new MyPlayer();
|
|
24
|
-
* player.setGraphic(["hero_idle", "hero_walk"]);
|
|
25
|
-
* ```
|
|
5
|
+
* Interface defining what ComponentManager adds to a class
|
|
26
6
|
*/
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
setGraphic(graphic: string | string[]): void {
|
|
30
|
-
if (Array.isArray(graphic)) {
|
|
31
|
-
this.graphics.set(graphic);
|
|
32
|
-
} else {
|
|
33
|
-
this.graphics.set([graphic]);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
} as unknown as any;
|
|
7
|
+
export interface IComponentManager {
|
|
8
|
+
setGraphic(graphic: string | string[]): void;
|
|
37
9
|
}
|
|
38
10
|
|
|
39
11
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
12
|
+
* Component Manager mixin
|
|
13
|
+
*
|
|
14
|
+
* Adds methods to manage player graphics
|
|
15
|
+
*
|
|
16
|
+
* @param Base - The base class to extend
|
|
17
|
+
* @returns A new class with component management capabilities
|
|
42
18
|
*/
|
|
43
|
-
export
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* @returns void
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* // Set a single graphic for static representation
|
|
58
|
-
* player.setGraphic("hero");
|
|
59
|
-
*
|
|
60
|
-
* // Set multiple graphics for animation sequences
|
|
61
|
-
* player.setGraphic(["hero_idle", "hero_walk", "hero_run"]);
|
|
62
|
-
*
|
|
63
|
-
* // Dynamic graphic changes based on equipment
|
|
64
|
-
* if (player.hasArmor('platemail')) {
|
|
65
|
-
* player.setGraphic("hero_armored");
|
|
66
|
-
* }
|
|
67
|
-
*
|
|
68
|
-
* // Animation sequences for different actions
|
|
69
|
-
* player.setGraphic(["mage_cast_1", "mage_cast_2", "mage_cast_3"]);
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
setGraphic(graphic: string | string[]): void;
|
|
19
|
+
export function WithComponentManager<TBase extends Constructor<RpgCommonPlayer>>(Base: TBase) {
|
|
20
|
+
return class extends Base implements IComponentManager {
|
|
21
|
+
setGraphic(graphic: string | string[]) {
|
|
22
|
+
if (Array.isArray(graphic)) {
|
|
23
|
+
this.graphics.set(graphic);
|
|
24
|
+
} else {
|
|
25
|
+
this.graphics.set([graphic]);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
73
29
|
}
|