@rpgjs/server 5.0.0-alpha.1 → 5.0.0-alpha.10
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 +32 -22
- package/dist/Player/ClassManager.d.ts +31 -18
- package/dist/Player/ComponentManager.d.ts +60 -0
- package/dist/Player/EffectManager.d.ts +40 -0
- package/dist/Player/ElementManager.d.ts +31 -0
- package/dist/Player/GoldManager.d.ts +22 -0
- package/dist/Player/GuiManager.d.ts +176 -0
- package/dist/Player/ItemFixture.d.ts +6 -0
- package/dist/Player/ItemManager.d.ts +27 -13
- package/dist/Player/MoveManager.d.ts +31 -43
- package/dist/Player/ParameterManager.d.ts +27 -19
- package/dist/Player/Player.d.ts +123 -8
- package/dist/Player/SkillManager.d.ts +27 -19
- package/dist/Player/StateManager.d.ts +28 -35
- package/dist/Player/VariableManager.d.ts +30 -0
- package/dist/RpgServer.d.ts +224 -1
- package/dist/index.js +1097 -636
- package/dist/index.js.map +1 -1
- package/dist/rooms/map.d.ts +70 -1
- package/package.json +8 -8
- package/src/Player/BattleManager.ts +97 -38
- package/src/Player/ClassManager.ts +95 -35
- package/src/Player/ComponentManager.ts +64 -20
- package/src/Player/EffectManager.ts +110 -27
- package/src/Player/ElementManager.ts +126 -25
- package/src/Player/GoldManager.ts +32 -35
- package/src/Player/GuiManager.ts +187 -140
- package/src/Player/ItemFixture.ts +4 -5
- package/src/Player/ItemManager.ts +39 -26
- package/src/Player/MoveManager.ts +40 -31
- package/src/Player/ParameterManager.ts +35 -25
- package/src/Player/Player.ts +184 -39
- package/src/Player/SkillManager.ts +44 -23
- package/src/Player/StateManager.ts +210 -95
- package/src/Player/VariableManager.ts +180 -48
- package/src/RpgServer.ts +232 -1
- package/src/core/context.ts +1 -0
- package/src/rooms/map.ts +76 -8
- package/dist/Player/Event.d.ts +0 -0
- package/src/Player/Event.ts +0 -0
|
@@ -2,13 +2,10 @@ import {
|
|
|
2
2
|
arrayFlat,
|
|
3
3
|
arrayUniq,
|
|
4
4
|
Constructor,
|
|
5
|
+
PlayerCtor,
|
|
5
6
|
RpgCommonPlayer,
|
|
6
7
|
} from "@rpgjs/common";
|
|
7
8
|
|
|
8
|
-
export interface IWithEffectManager {
|
|
9
|
-
effects: any[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
9
|
export enum Effect {
|
|
13
10
|
CAN_NOT_SKILL = 'CAN_NOT_SKILL',
|
|
14
11
|
CAN_NOT_ITEM = 'CAN_NOT_ITEM',
|
|
@@ -19,23 +16,64 @@ export enum Effect {
|
|
|
19
16
|
SUPER_GUARD = 'SUPER_GUARD'
|
|
20
17
|
}
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Effect Manager Mixin
|
|
21
|
+
*
|
|
22
|
+
* Provides effect management capabilities to any class. This mixin handles
|
|
23
|
+
* player effects including restrictions, buffs, and debuffs. Effects can come
|
|
24
|
+
* from various sources like states, equipment, and temporary conditions.
|
|
25
|
+
*
|
|
26
|
+
* @param Base - The base class to extend with effect management
|
|
27
|
+
* @returns Extended class with effect management methods
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* class MyPlayer extends WithEffectManager(BasePlayer) {
|
|
32
|
+
* constructor() {
|
|
33
|
+
* super();
|
|
34
|
+
* // Effect system is automatically initialized
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* const player = new MyPlayer();
|
|
39
|
+
* player.effects = [Effect.GUARD];
|
|
40
|
+
* console.log(player.hasEffect(Effect.GUARD)); // true
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export function WithEffectManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
44
|
+
return class extends Base {
|
|
26
45
|
/**
|
|
46
|
+
* Check if the player has a specific effect
|
|
47
|
+
*
|
|
48
|
+
* Determines whether the player currently has the specified effect active.
|
|
49
|
+
* This includes effects from states, equipment, and temporary conditions.
|
|
50
|
+
* The effect system provides a flexible way to apply various gameplay
|
|
51
|
+
* restrictions and enhancements to the player.
|
|
52
|
+
*
|
|
53
|
+
* @param effect - The effect identifier to check for
|
|
54
|
+
* @returns true if the player has the effect, false otherwise
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
27
57
|
* ```ts
|
|
28
58
|
* import { Effect } from '@rpgjs/database'
|
|
29
59
|
*
|
|
30
|
-
*
|
|
60
|
+
* // Check for skill restriction
|
|
61
|
+
* const cannotUseSkills = player.hasEffect(Effect.CAN_NOT_SKILL);
|
|
62
|
+
* if (cannotUseSkills) {
|
|
63
|
+
* console.log('Player cannot use skills right now');
|
|
64
|
+
* }
|
|
65
|
+
*
|
|
66
|
+
* // Check for guard effect
|
|
67
|
+
* const isGuarding = player.hasEffect(Effect.GUARD);
|
|
68
|
+
* if (isGuarding) {
|
|
69
|
+
* console.log('Player is in guard stance');
|
|
70
|
+
* }
|
|
71
|
+
*
|
|
72
|
+
* // Check for cost reduction
|
|
73
|
+
* const halfCost = player.hasEffect(Effect.HALF_SP_COST);
|
|
74
|
+
* const actualCost = skillCost / (halfCost ? 2 : 1);
|
|
31
75
|
* ```
|
|
32
|
-
|
|
33
|
-
* @title Has Effect
|
|
34
|
-
* @method player.hasEffect(effect)
|
|
35
|
-
* @param {string} effect
|
|
36
|
-
* @returns {boolean}
|
|
37
|
-
* @memberof EffectManager
|
|
38
|
-
* */
|
|
76
|
+
*/
|
|
39
77
|
hasEffect(effect: string): boolean {
|
|
40
78
|
return this.effects.includes(effect);
|
|
41
79
|
}
|
|
@@ -43,13 +81,31 @@ export function WithEffectManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
43
81
|
/**
|
|
44
82
|
* Retrieves a array of effects assigned to the player, state effects and effects of weapons and armors equipped with the player's own weapons.
|
|
45
83
|
*
|
|
84
|
+
* Gets all currently active effects on the player from multiple sources:
|
|
85
|
+
* - Direct effects assigned to the player
|
|
86
|
+
* - Effects from active states (buffs/debuffs)
|
|
87
|
+
* - Effects from equipped weapons and armor
|
|
88
|
+
* The returned array contains unique effects without duplicates.
|
|
89
|
+
*
|
|
90
|
+
* @returns Array of all active effects on the player
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
46
93
|
* ```ts
|
|
47
|
-
*
|
|
94
|
+
* // Get all active effects
|
|
95
|
+
* console.log(player.effects); // ['GUARD', 'HALF_SP_COST', ...]
|
|
96
|
+
*
|
|
97
|
+
* // Check multiple effects
|
|
98
|
+
* const effects = player.effects;
|
|
99
|
+
* const hasRestrictions = effects.some(effect =>
|
|
100
|
+
* effect.startsWith('CAN_NOT_')
|
|
101
|
+
* );
|
|
102
|
+
*
|
|
103
|
+
* // Count beneficial effects
|
|
104
|
+
* const beneficialEffects = effects.filter(effect =>
|
|
105
|
+
* ['GUARD', 'SUPER_GUARD', 'HALF_SP_COST'].includes(effect)
|
|
106
|
+
* );
|
|
48
107
|
* ```
|
|
49
|
-
|
|
50
|
-
* @prop {Array<Effect>} player.effects
|
|
51
|
-
* @memberof EffectManager
|
|
52
|
-
* */
|
|
108
|
+
*/
|
|
53
109
|
get effects(): any[] {
|
|
54
110
|
const getEffects = (prop) => {
|
|
55
111
|
return arrayFlat(this[prop]().map((el) => el.effects || []));
|
|
@@ -64,17 +120,44 @@ export function WithEffectManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
64
120
|
/**
|
|
65
121
|
* Assigns effects to the player. If you give a array, it does not change the effects of the player's states and armor/weapons equipped.
|
|
66
122
|
*
|
|
123
|
+
* Sets the direct effects on the player. This only affects the player's own effects
|
|
124
|
+
* and does not modify effects from states or equipment. The total effects will be
|
|
125
|
+
* the combination of these direct effects plus any effects from states and equipment.
|
|
126
|
+
*
|
|
127
|
+
* @param val - Array of effect identifiers to assign to the player
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
67
130
|
* ```ts
|
|
68
131
|
* import { Effect } from '@rpgjs/database'
|
|
69
132
|
*
|
|
70
|
-
* player
|
|
133
|
+
* // Set direct player effects
|
|
134
|
+
* player.effects = [Effect.CAN_NOT_SKILL];
|
|
135
|
+
*
|
|
136
|
+
* // Add multiple effects
|
|
137
|
+
* player.effects = [
|
|
138
|
+
* Effect.GUARD,
|
|
139
|
+
* Effect.HALF_SP_COST,
|
|
140
|
+
* Effect.CAN_NOT_ITEM
|
|
141
|
+
* ];
|
|
142
|
+
*
|
|
143
|
+
* // Clear direct effects (equipment/state effects remain)
|
|
144
|
+
* player.effects = [];
|
|
145
|
+
*
|
|
146
|
+
* // Temporary effect application
|
|
147
|
+
* const originalEffects = player.effects;
|
|
148
|
+
* player.effects = [...originalEffects, Effect.SUPER_GUARD];
|
|
149
|
+
* // Later restore
|
|
150
|
+
* player.effects = originalEffects;
|
|
71
151
|
* ```
|
|
72
|
-
|
|
73
|
-
* @prop {Array<Effect>} player.effects
|
|
74
|
-
* @memberof EffectManager
|
|
75
|
-
* */
|
|
152
|
+
*/
|
|
76
153
|
set effects(val) {
|
|
77
154
|
this._effects.set(val);
|
|
78
155
|
}
|
|
79
|
-
};
|
|
156
|
+
} as unknown as TBase;
|
|
80
157
|
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Type helper to extract the interface from the WithEffectManager mixin
|
|
161
|
+
* This provides the type without duplicating method signatures
|
|
162
|
+
*/
|
|
163
|
+
export type IEffectManager = InstanceType<ReturnType<typeof WithEffectManager>>;
|
|
@@ -1,17 +1,47 @@
|
|
|
1
|
-
import { arrayUniq, RpgCommonPlayer } from "@rpgjs/common";
|
|
1
|
+
import { arrayUniq, PlayerCtor, RpgCommonPlayer } from "@rpgjs/common";
|
|
2
2
|
import { Constructor } from "@rpgjs/common";
|
|
3
3
|
import { RpgPlayer } from "./Player";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Element Manager Mixin
|
|
7
|
+
*
|
|
8
|
+
* Provides elemental management capabilities to any class. This mixin handles
|
|
9
|
+
* elemental resistances, vulnerabilities, and attack elements. It manages both
|
|
10
|
+
* defensive capabilities (elementsDefense) and offensive elements from equipment,
|
|
11
|
+
* as well as player-specific elemental efficiency modifiers.
|
|
12
|
+
*
|
|
13
|
+
* @param Base - The base class to extend with element management
|
|
14
|
+
* @returns Extended class with element management methods
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* class MyPlayer extends WithElementManager(BasePlayer) {
|
|
19
|
+
* constructor() {
|
|
20
|
+
* super();
|
|
21
|
+
* this.elementsEfficiency = [{ rate: 0.5, element: 'fire' }];
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* const player = new MyPlayer();
|
|
26
|
+
* const fireResistance = player.elementsDefense.find(e => e.element === 'fire');
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function WithElementManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
30
|
+
return class extends Base {
|
|
9
31
|
_elementsEfficiency: { rate: number; element: any }[] = [];
|
|
10
32
|
|
|
11
33
|
/**
|
|
12
34
|
* Recovers the player's elements defense on inventory. This list is generated from the `elementsDefense` property defined on the weapons or armors equipped.
|
|
13
35
|
* If several items have the same element, only the highest rate will be taken into account.
|
|
14
36
|
*
|
|
37
|
+
* Gets the defensive capabilities against various elements from equipped items.
|
|
38
|
+
* The system automatically consolidates multiple defensive items, keeping only
|
|
39
|
+
* the highest protection rate for each element type. This provides a comprehensive
|
|
40
|
+
* view of the player's elemental resistances from all equipped gear.
|
|
41
|
+
*
|
|
42
|
+
* @returns Array of element defense objects with rate and element properties
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
15
45
|
* ```ts
|
|
16
46
|
* import { Armor } from '@rpgjs/server'
|
|
17
47
|
*
|
|
@@ -37,19 +67,29 @@ export function WithElementManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
37
67
|
* player.equip(FireShield)
|
|
38
68
|
*
|
|
39
69
|
* console.log(player.elementsDefense) // [{ rate: 1, element: 'fire' }]
|
|
70
|
+
*
|
|
71
|
+
* // Check specific element defense
|
|
72
|
+
* const fireDefense = player.elementsDefense.find(def => def.element === 'fire');
|
|
73
|
+
* if (fireDefense) {
|
|
74
|
+
* console.log(`Fire defense rate: ${fireDefense.rate}`);
|
|
75
|
+
* }
|
|
40
76
|
* ```
|
|
41
|
-
|
|
42
|
-
* @prop {Array<{ rate: number, element: Element}>} player.elementsDefense
|
|
43
|
-
* @readonly
|
|
44
|
-
* @memberof ElementManager
|
|
45
|
-
* */
|
|
77
|
+
*/
|
|
46
78
|
get elementsDefense(): { rate: number; element: any }[] {
|
|
47
|
-
return this.getFeature("elementsDefense", "element");
|
|
79
|
+
return (this as any).getFeature("elementsDefense", "element");
|
|
48
80
|
}
|
|
49
81
|
|
|
50
82
|
/**
|
|
51
83
|
* Set or retrieves all the elements where the player is vulnerable or not.
|
|
52
84
|
*
|
|
85
|
+
* Manages the player's elemental efficiency modifiers, which determine how
|
|
86
|
+
* effective different elements are against this player. Values greater than 1
|
|
87
|
+
* indicate vulnerability, while values less than 1 indicate resistance.
|
|
88
|
+
* This combines both class-based efficiency and player-specific modifiers.
|
|
89
|
+
*
|
|
90
|
+
* @returns Array of element efficiency objects with rate and element properties
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
53
93
|
* ```ts
|
|
54
94
|
* import { Class } from '@rpgjs/server'
|
|
55
95
|
*
|
|
@@ -71,13 +111,18 @@ export function WithElementManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
71
111
|
* player.elementsEfficiency = [{ rate: 2, element: Elements.Ice }]
|
|
72
112
|
*
|
|
73
113
|
* console.log(player.elementsEfficiency) // [{ rate: 1, element: 'fire' }, { rate: 2, element: 'ice' }]
|
|
114
|
+
*
|
|
115
|
+
* // Check for vulnerabilities
|
|
116
|
+
* const vulnerabilities = player.elementsEfficiency.filter(eff => eff.rate > 1);
|
|
117
|
+
* console.log('Vulnerable to:', vulnerabilities.map(v => v.element));
|
|
118
|
+
*
|
|
119
|
+
* // Check for resistances
|
|
120
|
+
* const resistances = player.elementsEfficiency.filter(eff => eff.rate < 1);
|
|
121
|
+
* console.log('Resistant to:', resistances.map(r => r.element));
|
|
74
122
|
* ```
|
|
75
|
-
|
|
76
|
-
* @prop {Array<{ rate: number, element: Element}>} player.elementsEfficiency
|
|
77
|
-
* @memberof ElementManager
|
|
78
|
-
* */
|
|
123
|
+
*/
|
|
79
124
|
get elementsEfficiency(): { rate: number; element: any }[] {
|
|
80
|
-
if (this._class) {
|
|
125
|
+
if (this._class()) {
|
|
81
126
|
return <any>[
|
|
82
127
|
...this._elementsEfficiency,
|
|
83
128
|
...(this._class()?.elementsEfficiency || []),
|
|
@@ -93,14 +138,30 @@ export function WithElementManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
93
138
|
/**
|
|
94
139
|
* Retrieves a array of elements assigned to the player and the elements of the weapons / armor equipped
|
|
95
140
|
*
|
|
141
|
+
* Gets all offensive elements available to the player from equipped weapons and armor.
|
|
142
|
+
* This determines what elemental damage types the player can deal in combat.
|
|
143
|
+
* The system automatically combines elements from all equipped items and removes duplicates.
|
|
144
|
+
*
|
|
145
|
+
* @returns Array of element objects with rate and element properties for offensive capabilities
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
96
148
|
* ```ts
|
|
97
|
-
*
|
|
149
|
+
* // Get all offensive elements
|
|
150
|
+
* console.log(player.elements); // [{ rate: 1.5, element: 'fire' }, { rate: 1.2, element: 'ice' }]
|
|
151
|
+
*
|
|
152
|
+
* // Check if player can deal fire damage
|
|
153
|
+
* const hasFireElement = player.elements.some(el => el.element === 'fire');
|
|
154
|
+
* if (hasFireElement) {
|
|
155
|
+
* console.log('Player can deal fire damage');
|
|
156
|
+
* }
|
|
157
|
+
*
|
|
158
|
+
* // Get strongest element
|
|
159
|
+
* const strongestElement = player.elements.reduce((max, current) =>
|
|
160
|
+
* current.rate > max.rate ? current : max
|
|
161
|
+
* );
|
|
162
|
+
* console.log(`Strongest element: ${strongestElement.element} (${strongestElement.rate})`);
|
|
98
163
|
* ```
|
|
99
|
-
|
|
100
|
-
* @prop {Array<Element>} player.elements
|
|
101
|
-
* @readonly
|
|
102
|
-
* @memberof ElementManager
|
|
103
|
-
* */
|
|
164
|
+
*/
|
|
104
165
|
get elements(): {
|
|
105
166
|
rate: number;
|
|
106
167
|
element: string;
|
|
@@ -114,8 +175,42 @@ export function WithElementManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
114
175
|
return arrayUniq(elements);
|
|
115
176
|
}
|
|
116
177
|
|
|
178
|
+
/**
|
|
179
|
+
* Calculate elemental damage coefficient against another player
|
|
180
|
+
*
|
|
181
|
+
* Determines the damage multiplier when this player attacks another player,
|
|
182
|
+
* taking into account the attacker's offensive elements, the defender's
|
|
183
|
+
* elemental efficiency, and elemental defense from equipment. This is used
|
|
184
|
+
* in the battle system to calculate elemental damage modifiers.
|
|
185
|
+
*
|
|
186
|
+
* @param otherPlayer - The target player to calculate coefficient against
|
|
187
|
+
* @returns Numerical coefficient to multiply base damage by
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* // Calculate elemental damage coefficient
|
|
192
|
+
* const firePlayer = new MyPlayer();
|
|
193
|
+
* const icePlayer = new MyPlayer();
|
|
194
|
+
*
|
|
195
|
+
* // Fire player attacks ice player (assuming ice is weak to fire)
|
|
196
|
+
* const coefficient = icePlayer.coefficientElements(firePlayer);
|
|
197
|
+
* console.log(`Damage multiplier: ${coefficient}`); // e.g., 2.0 for double damage
|
|
198
|
+
*
|
|
199
|
+
* // Use in damage calculation
|
|
200
|
+
* const baseDamage = 100;
|
|
201
|
+
* const finalDamage = baseDamage * coefficient;
|
|
202
|
+
* console.log(`Final damage: ${finalDamage}`);
|
|
203
|
+
*
|
|
204
|
+
* // Check for elemental advantage
|
|
205
|
+
* if (coefficient > 1) {
|
|
206
|
+
* console.log('Attacker has elemental advantage!');
|
|
207
|
+
* } else if (coefficient < 1) {
|
|
208
|
+
* console.log('Defender resists this element');
|
|
209
|
+
* }
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
117
212
|
coefficientElements(otherPlayer: RpgPlayer): number {
|
|
118
|
-
const atkPlayerElements: any = otherPlayer.elements;
|
|
213
|
+
const atkPlayerElements: any = (otherPlayer as any).elements;
|
|
119
214
|
const playerElements: any = this.elementsEfficiency;
|
|
120
215
|
let coefficient = 1;
|
|
121
216
|
|
|
@@ -127,7 +222,7 @@ export function WithElementManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
127
222
|
(el) => el.element == atkElement.element
|
|
128
223
|
);
|
|
129
224
|
if (!elementPlayer) continue;
|
|
130
|
-
const fn = this.getFormulas("coefficientElements");
|
|
225
|
+
const fn = (this as any).getFormulas("coefficientElements");
|
|
131
226
|
if (!fn) {
|
|
132
227
|
return coefficient;
|
|
133
228
|
}
|
|
@@ -139,5 +234,11 @@ export function WithElementManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
139
234
|
}
|
|
140
235
|
return coefficient;
|
|
141
236
|
}
|
|
142
|
-
};
|
|
237
|
+
} as unknown as TBase;
|
|
143
238
|
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Type helper to extract the interface from the WithElementManager mixin
|
|
242
|
+
* This provides the type without duplicating method signatures
|
|
243
|
+
*/
|
|
244
|
+
export type IElementManager = InstanceType<ReturnType<typeof WithElementManager>>;
|
|
@@ -1,44 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { RpgCommonPlayer } from "@rpgjs/common";
|
|
1
|
+
import { PlayerCtor } from "@rpgjs/common";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export interface GoldManager {
|
|
4
|
+
/**
|
|
5
|
+
* You can change the game money
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* player.gold += 100
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @title Change Gold
|
|
12
|
+
* @prop {number} player.gold
|
|
13
|
+
* @default 0
|
|
14
|
+
* @memberof GoldManager
|
|
15
|
+
* */
|
|
16
|
+
gold: number;
|
|
9
17
|
}
|
|
10
18
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* @param Base - The base class to extend
|
|
17
|
-
* @returns A new class with gold management capabilities
|
|
18
|
-
*/
|
|
19
|
-
export function WithGoldManager<TBase extends Constructor<RpgCommonPlayer>>(Base: TBase) {
|
|
20
|
-
return class extends Base implements IGoldManager {
|
|
21
|
-
/**
|
|
22
|
-
* You can change the game money
|
|
23
|
-
*
|
|
24
|
-
* ```ts
|
|
25
|
-
* player.gold += 100
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @title Change Gold
|
|
29
|
-
* @prop {number} player.gold
|
|
30
|
-
* @default 0
|
|
31
|
-
* @memberof GoldManager
|
|
32
|
-
* */
|
|
19
|
+
export function WithGoldManager<TBase extends PlayerCtor>(
|
|
20
|
+
Base: TBase
|
|
21
|
+
): new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> &
|
|
22
|
+
GoldManager {
|
|
23
|
+
return class extends Base {
|
|
33
24
|
set gold(val: number) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
if (val < 0) {
|
|
26
|
+
val = 0;
|
|
27
|
+
}
|
|
28
|
+
this._gold.set(val);
|
|
38
29
|
}
|
|
39
30
|
|
|
40
31
|
get gold(): number {
|
|
41
|
-
|
|
32
|
+
return this._gold();
|
|
42
33
|
}
|
|
43
|
-
};
|
|
34
|
+
} as unknown as any;
|
|
44
35
|
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Type helper to extract the interface from the WithGoldManager mixin
|
|
39
|
+
* This provides the type without duplicating method signatures
|
|
40
|
+
*/
|
|
41
|
+
export type IGoldManager = InstanceType<ReturnType<typeof WithGoldManager>>;
|