@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
|
@@ -2,10 +2,13 @@ import {
|
|
|
2
2
|
arrayFlat,
|
|
3
3
|
arrayUniq,
|
|
4
4
|
Constructor,
|
|
5
|
-
PlayerCtor,
|
|
6
5
|
RpgCommonPlayer,
|
|
7
6
|
} from "@rpgjs/common";
|
|
8
7
|
|
|
8
|
+
export interface IWithEffectManager {
|
|
9
|
+
effects: any[];
|
|
10
|
+
}
|
|
11
|
+
|
|
9
12
|
export enum Effect {
|
|
10
13
|
CAN_NOT_SKILL = 'CAN_NOT_SKILL',
|
|
11
14
|
CAN_NOT_ITEM = 'CAN_NOT_ITEM',
|
|
@@ -16,64 +19,23 @@ export enum Effect {
|
|
|
16
19
|
SUPER_GUARD = 'SUPER_GUARD'
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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 {
|
|
22
|
+
export function WithEffectManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
23
|
+
Base: TBase
|
|
24
|
+
) {
|
|
25
|
+
return class extends Base implements IWithEffectManager {
|
|
45
26
|
/**
|
|
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
|
|
57
27
|
* ```ts
|
|
58
28
|
* import { Effect } from '@rpgjs/database'
|
|
59
29
|
*
|
|
60
|
-
*
|
|
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);
|
|
30
|
+
* const bool = player.hasEffect(Effect.CAN_NOT_SKILL)
|
|
75
31
|
* ```
|
|
76
|
-
|
|
32
|
+
*
|
|
33
|
+
* @title Has Effect
|
|
34
|
+
* @method player.hasEffect(effect)
|
|
35
|
+
* @param {string} effect
|
|
36
|
+
* @returns {boolean}
|
|
37
|
+
* @memberof EffectManager
|
|
38
|
+
* */
|
|
77
39
|
hasEffect(effect: string): boolean {
|
|
78
40
|
return this.effects.includes(effect);
|
|
79
41
|
}
|
|
@@ -81,31 +43,13 @@ export function WithEffectManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
81
43
|
/**
|
|
82
44
|
* Retrieves a array of effects assigned to the player, state effects and effects of weapons and armors equipped with the player's own weapons.
|
|
83
45
|
*
|
|
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
|
|
93
46
|
* ```ts
|
|
94
|
-
*
|
|
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
|
-
* );
|
|
47
|
+
* console.log(player.effects)
|
|
107
48
|
* ```
|
|
108
|
-
|
|
49
|
+
* @title Get Effects
|
|
50
|
+
* @prop {Array<Effect>} player.effects
|
|
51
|
+
* @memberof EffectManager
|
|
52
|
+
* */
|
|
109
53
|
get effects(): any[] {
|
|
110
54
|
const getEffects = (prop) => {
|
|
111
55
|
return arrayFlat(this[prop]().map((el) => el.effects || []));
|
|
@@ -120,44 +64,17 @@ export function WithEffectManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
120
64
|
/**
|
|
121
65
|
* 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.
|
|
122
66
|
*
|
|
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
|
|
130
67
|
* ```ts
|
|
131
68
|
* import { Effect } from '@rpgjs/database'
|
|
132
69
|
*
|
|
133
|
-
*
|
|
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;
|
|
70
|
+
* player.effects = [Effect.CAN_NOT_SKILL]
|
|
151
71
|
* ```
|
|
152
|
-
|
|
72
|
+
* @title Set Effects
|
|
73
|
+
* @prop {Array<Effect>} player.effects
|
|
74
|
+
* @memberof EffectManager
|
|
75
|
+
* */
|
|
153
76
|
set effects(val) {
|
|
154
77
|
this._effects.set(val);
|
|
155
78
|
}
|
|
156
|
-
}
|
|
79
|
+
};
|
|
157
80
|
}
|
|
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,47 +1,17 @@
|
|
|
1
|
-
import { arrayUniq,
|
|
1
|
+
import { arrayUniq, RpgCommonPlayer } from "@rpgjs/common";
|
|
2
2
|
import { Constructor } from "@rpgjs/common";
|
|
3
3
|
import { RpgPlayer } from "./Player";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 {
|
|
5
|
+
export function WithElementManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
6
|
+
Base: TBase
|
|
7
|
+
) {
|
|
8
|
+
return class extends Base implements IWithElementManager {
|
|
31
9
|
_elementsEfficiency: { rate: number; element: any }[] = [];
|
|
32
10
|
|
|
33
11
|
/**
|
|
34
12
|
* Recovers the player's elements defense on inventory. This list is generated from the `elementsDefense` property defined on the weapons or armors equipped.
|
|
35
13
|
* If several items have the same element, only the highest rate will be taken into account.
|
|
36
14
|
*
|
|
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
|
|
45
15
|
* ```ts
|
|
46
16
|
* import { Armor } from '@rpgjs/server'
|
|
47
17
|
*
|
|
@@ -67,29 +37,19 @@ export function WithElementManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
67
37
|
* player.equip(FireShield)
|
|
68
38
|
*
|
|
69
39
|
* 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
|
-
* }
|
|
76
40
|
* ```
|
|
77
|
-
|
|
41
|
+
* @title Get Elements Defense
|
|
42
|
+
* @prop {Array<{ rate: number, element: Element}>} player.elementsDefense
|
|
43
|
+
* @readonly
|
|
44
|
+
* @memberof ElementManager
|
|
45
|
+
* */
|
|
78
46
|
get elementsDefense(): { rate: number; element: any }[] {
|
|
79
|
-
return
|
|
47
|
+
return this.getFeature("elementsDefense", "element");
|
|
80
48
|
}
|
|
81
49
|
|
|
82
50
|
/**
|
|
83
51
|
* Set or retrieves all the elements where the player is vulnerable or not.
|
|
84
52
|
*
|
|
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
|
|
93
53
|
* ```ts
|
|
94
54
|
* import { Class } from '@rpgjs/server'
|
|
95
55
|
*
|
|
@@ -111,18 +71,13 @@ export function WithElementManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
111
71
|
* player.elementsEfficiency = [{ rate: 2, element: Elements.Ice }]
|
|
112
72
|
*
|
|
113
73
|
* 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));
|
|
122
74
|
* ```
|
|
123
|
-
|
|
75
|
+
* @title Set/Get Elements Efficiency
|
|
76
|
+
* @prop {Array<{ rate: number, element: Element}>} player.elementsEfficiency
|
|
77
|
+
* @memberof ElementManager
|
|
78
|
+
* */
|
|
124
79
|
get elementsEfficiency(): { rate: number; element: any }[] {
|
|
125
|
-
if (this._class
|
|
80
|
+
if (this._class) {
|
|
126
81
|
return <any>[
|
|
127
82
|
...this._elementsEfficiency,
|
|
128
83
|
...(this._class()?.elementsEfficiency || []),
|
|
@@ -138,30 +93,14 @@ export function WithElementManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
138
93
|
/**
|
|
139
94
|
* Retrieves a array of elements assigned to the player and the elements of the weapons / armor equipped
|
|
140
95
|
*
|
|
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
|
|
148
96
|
* ```ts
|
|
149
|
-
*
|
|
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})`);
|
|
97
|
+
* console.log(player.elements)
|
|
163
98
|
* ```
|
|
164
|
-
|
|
99
|
+
* @title Get Elements
|
|
100
|
+
* @prop {Array<Element>} player.elements
|
|
101
|
+
* @readonly
|
|
102
|
+
* @memberof ElementManager
|
|
103
|
+
* */
|
|
165
104
|
get elements(): {
|
|
166
105
|
rate: number;
|
|
167
106
|
element: string;
|
|
@@ -175,42 +114,8 @@ export function WithElementManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
175
114
|
return arrayUniq(elements);
|
|
176
115
|
}
|
|
177
116
|
|
|
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
|
-
*/
|
|
212
117
|
coefficientElements(otherPlayer: RpgPlayer): number {
|
|
213
|
-
const atkPlayerElements: any =
|
|
118
|
+
const atkPlayerElements: any = otherPlayer.elements;
|
|
214
119
|
const playerElements: any = this.elementsEfficiency;
|
|
215
120
|
let coefficient = 1;
|
|
216
121
|
|
|
@@ -222,7 +127,7 @@ export function WithElementManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
222
127
|
(el) => el.element == atkElement.element
|
|
223
128
|
);
|
|
224
129
|
if (!elementPlayer) continue;
|
|
225
|
-
const fn =
|
|
130
|
+
const fn = this.getFormulas("coefficientElements");
|
|
226
131
|
if (!fn) {
|
|
227
132
|
return coefficient;
|
|
228
133
|
}
|
|
@@ -234,11 +139,5 @@ export function WithElementManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
|
234
139
|
}
|
|
235
140
|
return coefficient;
|
|
236
141
|
}
|
|
237
|
-
}
|
|
142
|
+
};
|
|
238
143
|
}
|
|
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>>;
|
|
File without changes
|
|
@@ -1,41 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Constructor } from "@rpgjs/common";
|
|
2
|
+
import { RpgCommonPlayer } from "@rpgjs/common";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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;
|
|
4
|
+
/**
|
|
5
|
+
* Interface defining what MoveManager adds to a class
|
|
6
|
+
*/
|
|
7
|
+
export interface IGoldManager {
|
|
8
|
+
|
|
17
9
|
}
|
|
18
10
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Move Manager mixin
|
|
13
|
+
*
|
|
14
|
+
* Adds methods to manage player gold
|
|
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
|
+
* */
|
|
24
33
|
set gold(val: number) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
34
|
+
if (val < 0) {
|
|
35
|
+
val = 0
|
|
36
|
+
}
|
|
37
|
+
this._gold.set(val)
|
|
29
38
|
}
|
|
30
39
|
|
|
31
40
|
get gold(): number {
|
|
32
|
-
|
|
41
|
+
return this._gold()
|
|
33
42
|
}
|
|
34
|
-
}
|
|
43
|
+
};
|
|
35
44
|
}
|
|
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>>;
|