@rpgjs/server 5.0.0-alpha.2 → 5.0.0-alpha.21
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/Gui/DialogGui.d.ts +4 -0
- package/dist/Gui/index.d.ts +1 -0
- package/dist/Player/BattleManager.d.ts +32 -22
- package/dist/Player/ClassManager.d.ts +31 -18
- package/dist/Player/ComponentManager.d.ts +123 -0
- package/dist/Player/Components.d.ts +345 -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 +164 -10
- package/dist/Player/MoveManager.d.ts +32 -44
- package/dist/Player/ParameterManager.d.ts +343 -14
- package/dist/Player/Player.d.ts +266 -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 +227 -1
- package/dist/decorators/event.d.ts +46 -0
- package/dist/decorators/map.d.ts +177 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +17472 -18167
- package/dist/index.js.map +1 -1
- package/dist/rooms/map.d.ts +486 -8
- package/package.json +17 -15
- package/src/Gui/DialogGui.ts +7 -2
- package/src/Gui/index.ts +3 -1
- package/src/Player/BattleManager.ts +97 -38
- package/src/Player/ClassManager.ts +95 -35
- package/src/Player/ComponentManager.ts +425 -19
- package/src/Player/Components.ts +380 -0
- 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 +363 -48
- package/src/Player/MoveManager.ts +323 -308
- package/src/Player/ParameterManager.ts +499 -99
- package/src/Player/Player.ts +719 -80
- 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 +236 -1
- package/src/core/context.ts +1 -0
- package/src/decorators/event.ts +61 -0
- package/src/decorators/map.ts +198 -0
- package/src/index.ts +7 -1
- package/src/module.ts +24 -0
- package/src/rooms/map.ts +1054 -54
- package/dist/Player/Event.d.ts +0 -0
- package/src/Player/Event.ts +0 -0
|
@@ -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>>;
|
package/src/Player/GuiManager.ts
CHANGED
|
@@ -1,132 +1,45 @@
|
|
|
1
1
|
import { RpgPlayer } from "./Player";
|
|
2
2
|
import { Gui, DialogGui, MenuGui, ShopGui, NotificationGui } from "../Gui";
|
|
3
3
|
import { DialogOptions, Choice } from "../Gui/DialogGui";
|
|
4
|
-
import { Constructor,
|
|
4
|
+
import { Constructor, PlayerCtor } from "@rpgjs/common";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
/**
|
|
7
|
+
* GUI Manager Mixin
|
|
8
|
+
*
|
|
9
|
+
* Provides graphical user interface management capabilities to any class. This mixin handles
|
|
10
|
+
* dialog boxes, menus, notifications, shops, and custom GUI components. It manages the
|
|
11
|
+
* complete GUI system including opening, closing, and data passing between client and server.
|
|
12
|
+
*
|
|
13
|
+
* @param Base - The base class to extend with GUI management
|
|
14
|
+
* @returns Extended class with GUI management methods
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* class MyPlayer extends WithGuiManager(BasePlayer) {
|
|
19
|
+
* constructor() {
|
|
20
|
+
* super();
|
|
21
|
+
* // GUI system is automatically initialized
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* const player = new MyPlayer();
|
|
26
|
+
* await player.showText('Hello World!');
|
|
27
|
+
* player.callMainMenu();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export function WithGuiManager<TBase extends PlayerCtor>(
|
|
12
31
|
Base: TBase
|
|
13
|
-
)
|
|
14
|
-
|
|
32
|
+
): new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> &
|
|
33
|
+
IGuiManager {
|
|
34
|
+
class GuiManagerMixin extends Base {
|
|
15
35
|
_gui: { [id: string]: Gui } = {};
|
|
16
36
|
|
|
17
|
-
/**
|
|
18
|
-
* Show a text. This is a graphical interface already built. Opens the GUI named `rpg-dialog`
|
|
19
|
-
*
|
|
20
|
-
* ```ts
|
|
21
|
-
* player.showText('Hello World')
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* The method returns a promise. It is resolved when the dialog box is closed.
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* await player.showText('Hello World')
|
|
28
|
-
* // dialog box is closed, then ...
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* **Option: position**
|
|
32
|
-
*
|
|
33
|
-
* You can define how the dialog box is displayed:
|
|
34
|
-
* - top
|
|
35
|
-
* - middle
|
|
36
|
-
* - bottom
|
|
37
|
-
*
|
|
38
|
-
* (bottom by default)
|
|
39
|
-
*
|
|
40
|
-
* ```ts
|
|
41
|
-
* player.showText('Hello World', {
|
|
42
|
-
* position: 'top'
|
|
43
|
-
* })
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* **Option: fullWidth**
|
|
47
|
-
*
|
|
48
|
-
* `boolean` (true by default)
|
|
49
|
-
*
|
|
50
|
-
* Indicate that the dialog box will take the full width of the screen.
|
|
51
|
-
*
|
|
52
|
-
* ```ts
|
|
53
|
-
* player.showText('Hello World', {
|
|
54
|
-
* fullWidth: true
|
|
55
|
-
* })
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* **Option: autoClose**
|
|
59
|
-
*
|
|
60
|
-
* `boolean` (false by default)
|
|
61
|
-
*
|
|
62
|
-
* If false, the user will have to press Enter to close the dialog box.
|
|
63
|
-
*
|
|
64
|
-
* ```ts
|
|
65
|
-
* player.showText('Hello World', {
|
|
66
|
-
* autoClose: true
|
|
67
|
-
* })
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* **Option: typewriterEffect**
|
|
71
|
-
*
|
|
72
|
-
* `boolean` (true by default)
|
|
73
|
-
*
|
|
74
|
-
* Performs a typewriter effect
|
|
75
|
-
*
|
|
76
|
-
* ```ts
|
|
77
|
-
* player.showText('Hello World', {
|
|
78
|
-
* typewriterEffect: false
|
|
79
|
-
* })
|
|
80
|
-
* ```
|
|
81
|
-
*
|
|
82
|
-
* **Option: talkWith**
|
|
83
|
-
*
|
|
84
|
-
* `RpgPlayer` (nothing by default)
|
|
85
|
-
*
|
|
86
|
-
* If you specify the event or another player, the other player will stop his or her movement and look in the player's direction.
|
|
87
|
-
*
|
|
88
|
-
* ```ts
|
|
89
|
-
* // Code in an event
|
|
90
|
-
* player.showText('Hello World', {
|
|
91
|
-
* talkWith: this
|
|
92
|
-
* })
|
|
93
|
-
* ```
|
|
94
|
-
*
|
|
95
|
-
* @title Show Text
|
|
96
|
-
* @method player.showText(text,options)
|
|
97
|
-
* @param {string} text
|
|
98
|
-
* @param {object} [options] the different options, see usage below
|
|
99
|
-
* @returns {Promise}
|
|
100
|
-
* @memberof GuiManager
|
|
101
|
-
*/
|
|
102
37
|
showText(msg: string, options: DialogOptions = {}): Promise<any> {
|
|
103
38
|
const gui = new DialogGui(<any>this);
|
|
104
39
|
this._gui[gui.id] = gui;
|
|
105
40
|
return gui.openDialog(msg, options);
|
|
106
41
|
}
|
|
107
42
|
|
|
108
|
-
/**
|
|
109
|
-
* Shows a dialog box with a choice. Opens the GUI named `rpg-dialog`
|
|
110
|
-
*
|
|
111
|
-
* ```ts
|
|
112
|
-
* const choice = await player.showChoices('What color do you prefer?', [
|
|
113
|
-
* { text: 'Black', value: 'black' },
|
|
114
|
-
* { text: 'Rather the blue', value: 'blue' },
|
|
115
|
-
* { text: 'I don\'t have a preference!', value: 'none' }
|
|
116
|
-
* ])
|
|
117
|
-
*
|
|
118
|
-
* // If the player selects the first
|
|
119
|
-
* console.log(choice) // { text: 'Black', value: 'black' }
|
|
120
|
-
* ```
|
|
121
|
-
*
|
|
122
|
-
* @title Show Choices
|
|
123
|
-
* @method player.showChoices(text,choices)
|
|
124
|
-
* @param {string} text
|
|
125
|
-
* @param {Array<{ text: string, value: any }>} choices
|
|
126
|
-
* @param {object} [options] Same options as the openDialog method
|
|
127
|
-
* @returns {Promise<Choice | null>}
|
|
128
|
-
* @memberof GuiManager
|
|
129
|
-
*/
|
|
130
43
|
showChoices(
|
|
131
44
|
msg: string,
|
|
132
45
|
choices: Choice[],
|
|
@@ -141,19 +54,6 @@ export function WithGuiManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
141
54
|
});
|
|
142
55
|
}
|
|
143
56
|
|
|
144
|
-
/**
|
|
145
|
-
* Displays a notification . Opens the GUI named `rpg-notification`
|
|
146
|
-
*
|
|
147
|
-
* @title Displays a notification
|
|
148
|
-
* @method player.showNotification()
|
|
149
|
-
* @param {string} message - The message to display in the notification
|
|
150
|
-
* @param {object} options - An object containing options for the notification
|
|
151
|
-
* @param {number} options.time - The time to display the notification for (in ms). Default: 2000ms
|
|
152
|
-
* @param {string} options.icon - The icon to display in the notification. Put the identifier of the spritesheet (defined on the client side)
|
|
153
|
-
* @param {string} options.sound - The sound to play when the notification is shown. Set the sound ID (defined on the client side)
|
|
154
|
-
* @returns {void}
|
|
155
|
-
* @memberof GuiManager
|
|
156
|
-
*/
|
|
157
57
|
showNotification(
|
|
158
58
|
message: string,
|
|
159
59
|
options: { time?: number; icon?: string; sound?: string } = {}
|
|
@@ -167,14 +67,6 @@ export function WithGuiManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
167
67
|
return gui.open(data);
|
|
168
68
|
}
|
|
169
69
|
|
|
170
|
-
/**
|
|
171
|
-
* Calls main menu. Opens the GUI named `rpg-main-menu`
|
|
172
|
-
*
|
|
173
|
-
* @title Call Main Menu
|
|
174
|
-
* @method player.callMainMenu()
|
|
175
|
-
* @returns {void}
|
|
176
|
-
* @memberof GuiManager
|
|
177
|
-
*/
|
|
178
70
|
callMainMenu() {
|
|
179
71
|
const gui = new MenuGui(<any>this);
|
|
180
72
|
this._gui[gui.id] = gui;
|
|
@@ -253,11 +145,11 @@ export function WithGuiManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
253
145
|
}
|
|
254
146
|
}
|
|
255
147
|
|
|
256
|
-
|
|
148
|
+
_attachedGui(players: RpgPlayer[] | RpgPlayer, display: boolean) {
|
|
257
149
|
if (!Array.isArray(players)) {
|
|
258
150
|
players = [players] as RpgPlayer[];
|
|
259
151
|
}
|
|
260
|
-
this.emit("gui.tooltip", {
|
|
152
|
+
(this as any).emit("gui.tooltip", {
|
|
261
153
|
players: (players as RpgPlayer[]).map((player) => player.id),
|
|
262
154
|
display,
|
|
263
155
|
});
|
|
@@ -313,5 +205,160 @@ export function WithGuiManager<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
313
205
|
const _players = players || this;
|
|
314
206
|
this._attachedGui(_players as RpgPlayer[], false);
|
|
315
207
|
}
|
|
316
|
-
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return GuiManagerMixin as unknown as any;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Interface for GUI management capabilities
|
|
215
|
+
* Defines the methods that will be available on the player
|
|
216
|
+
*/
|
|
217
|
+
export interface IGuiManager {
|
|
218
|
+
/**
|
|
219
|
+
* Show a text. This is a graphical interface already built. Opens the GUI named `rpg-dialog`
|
|
220
|
+
*
|
|
221
|
+
* ```ts
|
|
222
|
+
* player.showText('Hello World')
|
|
223
|
+
* ```
|
|
224
|
+
*
|
|
225
|
+
* The method returns a promise. It is resolved when the dialog box is closed.
|
|
226
|
+
*
|
|
227
|
+
* ```ts
|
|
228
|
+
* await player.showText('Hello World')
|
|
229
|
+
* // dialog box is closed, then ...
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* **Option: position**
|
|
233
|
+
*
|
|
234
|
+
* You can define how the dialog box is displayed:
|
|
235
|
+
* - top
|
|
236
|
+
* - middle
|
|
237
|
+
* - bottom
|
|
238
|
+
*
|
|
239
|
+
* (bottom by default)
|
|
240
|
+
*
|
|
241
|
+
* ```ts
|
|
242
|
+
* player.showText('Hello World', {
|
|
243
|
+
* position: 'top'
|
|
244
|
+
* })
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* **Option: fullWidth**
|
|
248
|
+
*
|
|
249
|
+
* `boolean` (true by default)
|
|
250
|
+
*
|
|
251
|
+
* Indicate that the dialog box will take the full width of the screen.
|
|
252
|
+
*
|
|
253
|
+
* ```ts
|
|
254
|
+
* player.showText('Hello World', {
|
|
255
|
+
* fullWidth: true
|
|
256
|
+
* })
|
|
257
|
+
* ```
|
|
258
|
+
*
|
|
259
|
+
* **Option: autoClose**
|
|
260
|
+
*
|
|
261
|
+
* `boolean` (false by default)
|
|
262
|
+
*
|
|
263
|
+
* If false, the user will have to press Enter to close the dialog box.
|
|
264
|
+
*
|
|
265
|
+
* ```ts
|
|
266
|
+
* player.showText('Hello World', {
|
|
267
|
+
* autoClose: true
|
|
268
|
+
* })
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* **Option: typewriterEffect**
|
|
272
|
+
*
|
|
273
|
+
* `boolean` (true by default)
|
|
274
|
+
*
|
|
275
|
+
* Performs a typewriter effect
|
|
276
|
+
*
|
|
277
|
+
* ```ts
|
|
278
|
+
* player.showText('Hello World', {
|
|
279
|
+
* typewriterEffect: false
|
|
280
|
+
* })
|
|
281
|
+
* ```
|
|
282
|
+
*
|
|
283
|
+
* **Option: talkWith**
|
|
284
|
+
*
|
|
285
|
+
* `RpgPlayer` (nothing by default)
|
|
286
|
+
*
|
|
287
|
+
* If you specify the event or another player, the other player will stop his or her movement and look in the player's direction.
|
|
288
|
+
*
|
|
289
|
+
* ```ts
|
|
290
|
+
* // Code in an event
|
|
291
|
+
* player.showText('Hello World', {
|
|
292
|
+
* talkWith: this
|
|
293
|
+
* })
|
|
294
|
+
* ```
|
|
295
|
+
*
|
|
296
|
+
* @title Show Text
|
|
297
|
+
* @method player.showText(text,options)
|
|
298
|
+
* @param {string} text
|
|
299
|
+
* @param {object} [options] the different options, see usage below
|
|
300
|
+
* @returns {Promise}
|
|
301
|
+
* @memberof GuiManager
|
|
302
|
+
*/
|
|
303
|
+
showText(msg: string, options?: DialogOptions): Promise<any>;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Shows a dialog box with a choice. Opens the GUI named `rpg-dialog`
|
|
307
|
+
*
|
|
308
|
+
* ```ts
|
|
309
|
+
* const choice = await player.showChoices('What color do you prefer?', [
|
|
310
|
+
* { text: 'Black', value: 'black' },
|
|
311
|
+
* { text: 'Rather the blue', value: 'blue' },
|
|
312
|
+
* { text: 'I don\'t have a preference!', value: 'none' }
|
|
313
|
+
* ])
|
|
314
|
+
*
|
|
315
|
+
* // If the player selects the first
|
|
316
|
+
* console.log(choice) // { text: 'Black', value: 'black' }
|
|
317
|
+
* ```
|
|
318
|
+
*
|
|
319
|
+
* @title Show Choices
|
|
320
|
+
* @method player.showChoices(text,choices)
|
|
321
|
+
* @param {string} text
|
|
322
|
+
* @param {Array<{ text: string, value: any }>} choices
|
|
323
|
+
* @param {object} [options] Same options as the openDialog method
|
|
324
|
+
* @returns {Promise<Choice | null>}
|
|
325
|
+
* @memberof GuiManager
|
|
326
|
+
*/
|
|
327
|
+
showChoices(
|
|
328
|
+
msg: string,
|
|
329
|
+
choices: Choice[],
|
|
330
|
+
options?: DialogOptions
|
|
331
|
+
): Promise<Choice | null>;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Displays a notification . Opens the GUI named `rpg-notification`
|
|
335
|
+
*
|
|
336
|
+
* @title Displays a notification
|
|
337
|
+
* @method player.showNotification()
|
|
338
|
+
* @param {string} message - The message to display in the notification
|
|
339
|
+
* @param {object} options - An object containing options for the notification
|
|
340
|
+
* @param {number} options.time - The time to display the notification for (in ms). Default: 2000ms
|
|
341
|
+
* @param {string} options.icon - The icon to display in the notification. Put the identifier of the spritesheet (defined on the client side)
|
|
342
|
+
* @param {string} options.sound - The sound to play when the notification is shown. Set the sound ID (defined on the client side)
|
|
343
|
+
* @returns {void}
|
|
344
|
+
* @memberof GuiManager
|
|
345
|
+
*/
|
|
346
|
+
showNotification(
|
|
347
|
+
message: string,
|
|
348
|
+
options?: { time?: number; icon?: string; sound?: string }
|
|
349
|
+
): Promise<any>;
|
|
350
|
+
/**
|
|
351
|
+
* Calls main menu. Opens the GUI named `rpg-main-menu`
|
|
352
|
+
*
|
|
353
|
+
* @title Call Main Menu
|
|
354
|
+
* @method player.callMainMenu()
|
|
355
|
+
* @returns {void}
|
|
356
|
+
* @memberof GuiManager
|
|
357
|
+
*/
|
|
358
|
+
callMainMenu(): void;
|
|
359
|
+
callShop(items: any[]): void;
|
|
360
|
+
gui(guiId: string): Gui;
|
|
361
|
+
removeGui(guiId: string, data?: any): void;
|
|
362
|
+
showAttachedGui(players?: RpgPlayer[] | RpgPlayer): void;
|
|
363
|
+
hideAttachedGui(players?: RpgPlayer[] | RpgPlayer): void;
|
|
317
364
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { ItemInstance } from "@rpgjs/database";
|
|
2
|
-
import {
|
|
3
|
-
export class ItemFixture {}
|
|
2
|
+
import { PlayerCtor } from "@rpgjs/common";
|
|
4
3
|
|
|
5
|
-
export function WithItemFixture<TBase extends
|
|
4
|
+
export function WithItemFixture<TBase extends PlayerCtor>(
|
|
6
5
|
Base: TBase
|
|
7
6
|
) {
|
|
8
|
-
return class extends Base
|
|
7
|
+
return class extends Base {
|
|
9
8
|
protected getFeature(name, prop): any {
|
|
10
9
|
const array = {};
|
|
11
10
|
for (let item of this.equipments()) {
|
|
@@ -21,7 +20,7 @@ export function WithItemFixture<TBase extends Constructor<RpgCommonPlayer>>(
|
|
|
21
20
|
}
|
|
22
21
|
return Object.values(array);
|
|
23
22
|
}
|
|
24
|
-
};
|
|
23
|
+
} as unknown as TBase;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
export interface ItemFixture {
|