@rpgjs/server 5.0.0-alpha.4 → 5.0.0-alpha.41
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 +5 -0
- package/dist/Gui/GameoverGui.d.ts +23 -0
- package/dist/Gui/Gui.d.ts +6 -0
- package/dist/Gui/MenuGui.d.ts +22 -3
- package/dist/Gui/NotificationGui.d.ts +1 -2
- package/dist/Gui/SaveLoadGui.d.ts +13 -0
- package/dist/Gui/ShopGui.d.ts +28 -3
- package/dist/Gui/TitleGui.d.ts +23 -0
- package/dist/Gui/index.d.ts +10 -1
- package/dist/Player/BattleManager.d.ts +34 -12
- package/dist/Player/ClassManager.d.ts +46 -13
- package/dist/Player/ComponentManager.d.ts +123 -0
- package/dist/Player/Components.d.ts +345 -0
- package/dist/Player/EffectManager.d.ts +86 -0
- package/dist/Player/ElementManager.d.ts +104 -0
- package/dist/Player/GoldManager.d.ts +22 -0
- package/dist/Player/GuiManager.d.ts +259 -0
- package/dist/Player/ItemFixture.d.ts +6 -0
- package/dist/Player/ItemManager.d.ts +450 -9
- package/dist/Player/MoveManager.d.ts +324 -69
- package/dist/Player/ParameterManager.d.ts +344 -14
- package/dist/Player/Player.d.ts +460 -8
- package/dist/Player/SkillManager.d.ts +197 -15
- package/dist/Player/StateManager.d.ts +89 -25
- package/dist/Player/VariableManager.d.ts +74 -0
- package/dist/RpgServer.d.ts +502 -64
- package/dist/RpgServerEngine.d.ts +2 -1
- package/dist/decorators/event.d.ts +46 -0
- package/dist/decorators/map.d.ts +287 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +21653 -20900
- package/dist/index.js.map +1 -1
- package/dist/logs/log.d.ts +2 -3
- package/dist/module.d.ts +43 -1
- package/dist/presets/index.d.ts +0 -9
- package/dist/rooms/BaseRoom.d.ts +132 -0
- package/dist/rooms/lobby.d.ts +10 -2
- package/dist/rooms/map.d.ts +1236 -17
- package/dist/services/save.d.ts +43 -0
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/localStorage.d.ts +23 -0
- package/package.json +14 -10
- package/src/Gui/DialogGui.ts +19 -4
- package/src/Gui/GameoverGui.ts +39 -0
- package/src/Gui/Gui.ts +23 -1
- package/src/Gui/MenuGui.ts +155 -6
- package/src/Gui/NotificationGui.ts +1 -2
- package/src/Gui/SaveLoadGui.ts +60 -0
- package/src/Gui/ShopGui.ts +146 -16
- package/src/Gui/TitleGui.ts +39 -0
- package/src/Gui/index.ts +15 -2
- package/src/Player/BattleManager.ts +91 -49
- package/src/Player/ClassManager.ts +118 -50
- package/src/Player/ComponentManager.ts +425 -19
- package/src/Player/Components.ts +380 -0
- package/src/Player/EffectManager.ts +81 -44
- package/src/Player/ElementManager.ts +109 -86
- package/src/Player/GoldManager.ts +32 -35
- package/src/Player/GuiManager.ts +308 -150
- package/src/Player/ItemFixture.ts +4 -5
- package/src/Player/ItemManager.ts +774 -355
- package/src/Player/MoveManager.ts +1544 -774
- package/src/Player/ParameterManager.ts +546 -104
- package/src/Player/Player.ts +1163 -88
- package/src/Player/SkillManager.ts +520 -195
- package/src/Player/StateManager.ts +170 -182
- package/src/Player/VariableManager.ts +101 -63
- package/src/RpgServer.ts +525 -63
- package/src/core/context.ts +1 -0
- package/src/decorators/event.ts +61 -0
- package/src/decorators/map.ts +327 -0
- package/src/index.ts +11 -1
- package/src/logs/log.ts +10 -3
- package/src/module.ts +126 -3
- package/src/presets/index.ts +1 -10
- package/src/rooms/BaseRoom.ts +232 -0
- package/src/rooms/lobby.ts +25 -7
- package/src/rooms/map.ts +2502 -194
- package/src/services/save.ts +147 -0
- package/src/storage/index.ts +1 -0
- package/src/storage/localStorage.ts +76 -0
- package/tests/battle.spec.ts +375 -0
- package/tests/change-map.spec.ts +72 -0
- package/tests/class.spec.ts +274 -0
- package/tests/effect.spec.ts +219 -0
- package/tests/element.spec.ts +221 -0
- package/tests/event.spec.ts +80 -0
- package/tests/gold.spec.ts +99 -0
- package/tests/item.spec.ts +609 -0
- package/tests/module.spec.ts +38 -0
- package/tests/move.spec.ts +601 -0
- package/tests/player-param.spec.ts +28 -0
- package/tests/prediction-reconciliation.spec.ts +182 -0
- package/tests/random-move.spec.ts +65 -0
- package/tests/skill.spec.ts +658 -0
- package/tests/state.spec.ts +467 -0
- package/tests/variable.spec.ts +185 -0
- package/tests/world-maps.spec.ts +896 -0
- package/vite.config.ts +16 -0
- package/dist/Player/Event.d.ts +0 -0
- package/src/Player/Event.ts +0 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component definitions for player UI elements
|
|
3
|
+
*
|
|
4
|
+
* This module provides factory functions to create component definitions
|
|
5
|
+
* that can be displayed above or below player graphics. Components are
|
|
6
|
+
* synchronized from server to client and rendered using CanvasEngine.
|
|
7
|
+
*
|
|
8
|
+
* ## Design
|
|
9
|
+
*
|
|
10
|
+
* Components are defined as data structures that describe UI elements
|
|
11
|
+
* (text, bars, shapes) with their properties and layout options. The
|
|
12
|
+
* server creates these definitions and they are automatically synchronized
|
|
13
|
+
* to all clients on the map.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { Components } from '@rpgjs/server';
|
|
18
|
+
*
|
|
19
|
+
* // Create a text component
|
|
20
|
+
* const nameComponent = Components.text('{name}');
|
|
21
|
+
*
|
|
22
|
+
* // Create an HP bar
|
|
23
|
+
* const hpBar = Components.hpBar();
|
|
24
|
+
*
|
|
25
|
+
* // Set components on player
|
|
26
|
+
* player.setComponentsTop([nameComponent, hpBar]);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export interface ComponentLayout {
|
|
30
|
+
/** Width of the component block in pixels */
|
|
31
|
+
width?: number;
|
|
32
|
+
/** Height of the component block in pixels */
|
|
33
|
+
height?: number;
|
|
34
|
+
/** Margin from the top of the player in pixels */
|
|
35
|
+
marginTop?: number;
|
|
36
|
+
/** Margin from the bottom of the player in pixels */
|
|
37
|
+
marginBottom?: number;
|
|
38
|
+
/** Margin from the left of the player in pixels */
|
|
39
|
+
marginLeft?: number;
|
|
40
|
+
/** Margin from the right of the player in pixels */
|
|
41
|
+
marginRight?: number;
|
|
42
|
+
}
|
|
43
|
+
export interface TextComponentOptions {
|
|
44
|
+
/** Text color in hexadecimal format (e.g., '#000000') */
|
|
45
|
+
fill?: string;
|
|
46
|
+
/** Font size in pixels */
|
|
47
|
+
fontSize?: number;
|
|
48
|
+
/** Font family */
|
|
49
|
+
fontFamily?: string;
|
|
50
|
+
/** Font style: 'normal', 'italic', 'oblique' */
|
|
51
|
+
fontStyle?: 'normal' | 'italic' | 'oblique';
|
|
52
|
+
/** Font weight: 'normal', 'bold', 'bolder', 'lighter', or numeric values */
|
|
53
|
+
fontWeight?: 'normal' | 'bold' | 'bolder' | 'lighter' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | number;
|
|
54
|
+
/** Stroke color in hexadecimal format */
|
|
55
|
+
stroke?: string;
|
|
56
|
+
/** Opacity between 0 and 1 */
|
|
57
|
+
opacity?: number;
|
|
58
|
+
/** Word wrap */
|
|
59
|
+
wordWrap?: boolean;
|
|
60
|
+
/** Text alignment */
|
|
61
|
+
align?: 'left' | 'center' | 'right' | 'justify';
|
|
62
|
+
}
|
|
63
|
+
export interface BarComponentOptions {
|
|
64
|
+
/** Background color in hexadecimal format */
|
|
65
|
+
bgColor?: string;
|
|
66
|
+
/** Fill color in hexadecimal format */
|
|
67
|
+
fillColor?: string;
|
|
68
|
+
/** Border color in hexadecimal format */
|
|
69
|
+
borderColor?: string;
|
|
70
|
+
/** Border width */
|
|
71
|
+
borderWidth?: number;
|
|
72
|
+
/** Height of the bar in pixels */
|
|
73
|
+
height?: number;
|
|
74
|
+
/** Width of the bar in pixels */
|
|
75
|
+
width?: number;
|
|
76
|
+
/** Border radius */
|
|
77
|
+
borderRadius?: number;
|
|
78
|
+
/** Opacity between 0 and 1 */
|
|
79
|
+
opacity?: number;
|
|
80
|
+
}
|
|
81
|
+
export interface ShapeComponentOptions {
|
|
82
|
+
/** Fill color in hexadecimal format */
|
|
83
|
+
fill: string;
|
|
84
|
+
/** Type of shape */
|
|
85
|
+
type: 'circle' | 'rectangle' | 'ellipse' | 'polygon' | 'line' | 'rounded-rectangle';
|
|
86
|
+
/** Radius (for circle) */
|
|
87
|
+
radius?: number | string;
|
|
88
|
+
/** Width (for rectangle, ellipse) */
|
|
89
|
+
width?: number | string;
|
|
90
|
+
/** Height (for rectangle, ellipse) */
|
|
91
|
+
height?: number | string;
|
|
92
|
+
/** X1 position (for line) */
|
|
93
|
+
x1?: number | string;
|
|
94
|
+
/** Y1 position (for line) */
|
|
95
|
+
y1?: number | string;
|
|
96
|
+
/** X2 position (for line) */
|
|
97
|
+
x2?: number | string;
|
|
98
|
+
/** Y2 position (for line) */
|
|
99
|
+
y2?: number | string;
|
|
100
|
+
/** Points array (for polygon) */
|
|
101
|
+
points?: number[];
|
|
102
|
+
/** Opacity between 0 and 1 */
|
|
103
|
+
opacity?: number | string;
|
|
104
|
+
/** Line/border style */
|
|
105
|
+
line?: {
|
|
106
|
+
color?: string;
|
|
107
|
+
width?: number;
|
|
108
|
+
alpha?: number;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export type ComponentDefinition = {
|
|
112
|
+
type: 'text';
|
|
113
|
+
value: string;
|
|
114
|
+
style?: TextComponentOptions;
|
|
115
|
+
} | {
|
|
116
|
+
type: 'hpBar';
|
|
117
|
+
style?: BarComponentOptions;
|
|
118
|
+
text?: string | null;
|
|
119
|
+
} | {
|
|
120
|
+
type: 'spBar';
|
|
121
|
+
style?: BarComponentOptions;
|
|
122
|
+
text?: string | null;
|
|
123
|
+
} | {
|
|
124
|
+
type: 'bar';
|
|
125
|
+
current: string;
|
|
126
|
+
max: string;
|
|
127
|
+
style?: BarComponentOptions;
|
|
128
|
+
text?: string | null;
|
|
129
|
+
} | {
|
|
130
|
+
type: 'shape';
|
|
131
|
+
value: ShapeComponentOptions;
|
|
132
|
+
} | {
|
|
133
|
+
type: 'image';
|
|
134
|
+
value: string;
|
|
135
|
+
} | {
|
|
136
|
+
type: 'tile';
|
|
137
|
+
value: number | string;
|
|
138
|
+
};
|
|
139
|
+
export type ComponentInput = ComponentDefinition | ComponentDefinition[] | ComponentDefinition[][];
|
|
140
|
+
/**
|
|
141
|
+
* Components factory for creating component definitions
|
|
142
|
+
*
|
|
143
|
+
* Provides factory methods to create various UI components that can be
|
|
144
|
+
* displayed above or below player graphics. Components support template
|
|
145
|
+
* strings with placeholders like {name}, {hp}, etc. that are replaced
|
|
146
|
+
* with actual player property values on the client.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* // Create a text component
|
|
151
|
+
* Components.text('Player: {name}');
|
|
152
|
+
*
|
|
153
|
+
* // Create an HP bar with custom text
|
|
154
|
+
* Components.hpBar({}, '{$percent}%');
|
|
155
|
+
*
|
|
156
|
+
* // Create a custom bar
|
|
157
|
+
* Components.bar('wood', 'param.maxWood');
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare const Components: {
|
|
161
|
+
/**
|
|
162
|
+
* Create a text component
|
|
163
|
+
*
|
|
164
|
+
* Creates a text component that displays text with optional styling.
|
|
165
|
+
* Supports template strings with placeholders like {name}, {hp}, etc.
|
|
166
|
+
* that are replaced with actual player property values.
|
|
167
|
+
*
|
|
168
|
+
* ## Design
|
|
169
|
+
*
|
|
170
|
+
* Text components use template strings to allow dynamic content without
|
|
171
|
+
* resending the entire component structure when values change. Only the
|
|
172
|
+
* property values are synchronized, reducing bandwidth usage.
|
|
173
|
+
*
|
|
174
|
+
* @param text - Text to display, can include placeholders like {name}, {hp}
|
|
175
|
+
* @param options - Text styling options
|
|
176
|
+
* @returns Component definition for text
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* // Simple text
|
|
181
|
+
* Components.text('Player Name');
|
|
182
|
+
*
|
|
183
|
+
* // Text with placeholder
|
|
184
|
+
* Components.text('{name}');
|
|
185
|
+
*
|
|
186
|
+
* // Text with styling
|
|
187
|
+
* Components.text('{name}', {
|
|
188
|
+
* fill: '#000000',
|
|
189
|
+
* fontSize: 20
|
|
190
|
+
* });
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
text(value: string, style?: TextComponentOptions): ComponentDefinition;
|
|
194
|
+
/**
|
|
195
|
+
* Create an HP bar component
|
|
196
|
+
*
|
|
197
|
+
* Creates a health point bar that automatically displays the player's
|
|
198
|
+
* current HP relative to their maximum HP. The bar updates automatically
|
|
199
|
+
* as HP changes.
|
|
200
|
+
*
|
|
201
|
+
* ## Design
|
|
202
|
+
*
|
|
203
|
+
* HP bars read from the player's hp and param.maxHp properties. The
|
|
204
|
+
* bar can optionally display text above it showing current, max, or
|
|
205
|
+
* percentage values.
|
|
206
|
+
*
|
|
207
|
+
* @param options - Bar styling options
|
|
208
|
+
* @param text - Optional text to display above the bar. Can use placeholders:
|
|
209
|
+
* - {$current} - Current HP value
|
|
210
|
+
* - {$max} - Maximum HP value
|
|
211
|
+
* - {$percent} - Percentage value
|
|
212
|
+
* Set to null to hide text
|
|
213
|
+
* @returns Component definition for HP bar
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* // Simple HP bar
|
|
218
|
+
* Components.hpBar();
|
|
219
|
+
*
|
|
220
|
+
* // HP bar with percentage text
|
|
221
|
+
* Components.hpBar({}, '{$percent}%');
|
|
222
|
+
*
|
|
223
|
+
* // HP bar with custom styling
|
|
224
|
+
* Components.hpBar({
|
|
225
|
+
* fillColor: '#ff0000',
|
|
226
|
+
* height: 8
|
|
227
|
+
* });
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
hpBar(style?: BarComponentOptions, text?: string | null): ComponentDefinition;
|
|
231
|
+
/**
|
|
232
|
+
* Create an SP bar component
|
|
233
|
+
*
|
|
234
|
+
* Creates a skill point bar that automatically displays the player's
|
|
235
|
+
* current SP relative to their maximum SP. The bar updates automatically
|
|
236
|
+
* as SP changes.
|
|
237
|
+
*
|
|
238
|
+
* @param style - Bar styling options
|
|
239
|
+
* @param text - Optional text to display above the bar. Can use placeholders:
|
|
240
|
+
* - {$current} - Current SP value
|
|
241
|
+
* - {$max} - Maximum SP value
|
|
242
|
+
* - {$percent} - Percentage value
|
|
243
|
+
* Set to null to hide text
|
|
244
|
+
* @returns Component definition for SP bar
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* // Simple SP bar
|
|
249
|
+
* Components.spBar();
|
|
250
|
+
*
|
|
251
|
+
* // SP bar with text
|
|
252
|
+
* Components.spBar({}, 'SP: {$current}/{$max}');
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
spBar(style?: BarComponentOptions, text?: string | null): ComponentDefinition;
|
|
256
|
+
/**
|
|
257
|
+
* Create a custom bar component
|
|
258
|
+
*
|
|
259
|
+
* Creates a bar that displays a custom property value relative to a maximum.
|
|
260
|
+
* Useful for displaying custom resources like wood, mana, energy, etc.
|
|
261
|
+
*
|
|
262
|
+
* @param current - Property path for current value (e.g., 'wood', 'mana')
|
|
263
|
+
* @param max - Property path for maximum value (e.g., 'param.maxWood', 'param.maxMana')
|
|
264
|
+
* @param style - Bar styling options
|
|
265
|
+
* @param text - Optional text to display above the bar. Can use placeholders:
|
|
266
|
+
* - {$current} - Current value
|
|
267
|
+
* - {$max} - Maximum value
|
|
268
|
+
* - {$percent} - Percentage value
|
|
269
|
+
* Set to null to hide text
|
|
270
|
+
* @returns Component definition for custom bar
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* // Bar for custom property
|
|
275
|
+
* Components.bar('wood', 'param.maxWood');
|
|
276
|
+
*
|
|
277
|
+
* // Bar with text
|
|
278
|
+
* Components.bar('mana', 'param.maxMana', {}, 'Mana: {$current}/{$max}');
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
bar(current: string, max: string, style?: BarComponentOptions, text?: string | null): ComponentDefinition;
|
|
282
|
+
/**
|
|
283
|
+
* Create a shape component
|
|
284
|
+
*
|
|
285
|
+
* Creates a geometric shape that can be displayed above or below the player.
|
|
286
|
+
* Useful for visual indicators, backgrounds, or decorative elements.
|
|
287
|
+
*
|
|
288
|
+
* @param value - Shape configuration options
|
|
289
|
+
* @returns Component definition for shape
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```ts
|
|
293
|
+
* // Circle shape
|
|
294
|
+
* Components.shape({
|
|
295
|
+
* fill: '#ffffff',
|
|
296
|
+
* type: 'circle',
|
|
297
|
+
* radius: 10
|
|
298
|
+
* });
|
|
299
|
+
*
|
|
300
|
+
* // Rectangle shape
|
|
301
|
+
* Components.shape({
|
|
302
|
+
* fill: '#ff0000',
|
|
303
|
+
* type: 'rectangle',
|
|
304
|
+
* width: 32,
|
|
305
|
+
* height: 32
|
|
306
|
+
* });
|
|
307
|
+
*
|
|
308
|
+
* // Using parameters
|
|
309
|
+
* Components.shape({
|
|
310
|
+
* fill: '#ffffff',
|
|
311
|
+
* type: 'circle',
|
|
312
|
+
* radius: 'hp' // radius will be the same as hp value
|
|
313
|
+
* });
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
shape(value: ShapeComponentOptions): ComponentDefinition;
|
|
317
|
+
/**
|
|
318
|
+
* Create an image component
|
|
319
|
+
*
|
|
320
|
+
* Displays an image from a URL or spritesheet identifier.
|
|
321
|
+
*
|
|
322
|
+
* @param value - Image source URL or spritesheet identifier
|
|
323
|
+
* @returns Component definition for image
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* ```ts
|
|
327
|
+
* Components.image('mygraphic.png');
|
|
328
|
+
* ```
|
|
329
|
+
*/
|
|
330
|
+
image(value: string): ComponentDefinition;
|
|
331
|
+
/**
|
|
332
|
+
* Create a tile component
|
|
333
|
+
*
|
|
334
|
+
* Displays a tile from a tileset by ID.
|
|
335
|
+
*
|
|
336
|
+
* @param value - Tile ID in the tileset
|
|
337
|
+
* @returns Component definition for tile
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
* ```ts
|
|
341
|
+
* Components.tile(3); // Use tile #3
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
tile(value: number | string): ComponentDefinition;
|
|
345
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { PlayerCtor } from '../../../common/src';
|
|
2
|
+
export declare enum Effect {
|
|
3
|
+
CAN_NOT_SKILL = "CAN_NOT_SKILL",
|
|
4
|
+
CAN_NOT_ITEM = "CAN_NOT_ITEM",
|
|
5
|
+
CAN_NOT_STATE = "CAN_NOT_STATE",
|
|
6
|
+
CAN_NOT_EQUIPMENT = "CAN_NOT_EQUIPMENT",
|
|
7
|
+
HALF_SP_COST = "HALF_SP_COST",
|
|
8
|
+
GUARD = "GUARD",
|
|
9
|
+
SUPER_GUARD = "SUPER_GUARD"
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Effect Manager Mixin
|
|
13
|
+
*
|
|
14
|
+
* Provides effect management capabilities to any class. This mixin handles
|
|
15
|
+
* player effects including restrictions, buffs, and debuffs. Effects can come
|
|
16
|
+
* from various sources like states, equipment, and temporary conditions.
|
|
17
|
+
*
|
|
18
|
+
* @param Base - The base class to extend with effect management
|
|
19
|
+
* @returns Extended class with effect management methods
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* class MyPlayer extends WithEffectManager(BasePlayer) {
|
|
24
|
+
* constructor() {
|
|
25
|
+
* super();
|
|
26
|
+
* // Effect system is automatically initialized
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* const player = new MyPlayer();
|
|
31
|
+
* player.effects = [Effect.GUARD];
|
|
32
|
+
* console.log(player.hasEffect(Effect.GUARD)); // true
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function WithEffectManager<TBase extends PlayerCtor>(Base: TBase): TBase;
|
|
36
|
+
/**
|
|
37
|
+
* Interface for Effect Manager functionality
|
|
38
|
+
*
|
|
39
|
+
* Provides effect management capabilities including restrictions, buffs, and debuffs.
|
|
40
|
+
* This interface defines the public API of the EffectManager mixin.
|
|
41
|
+
*/
|
|
42
|
+
export interface IEffectManager {
|
|
43
|
+
/**
|
|
44
|
+
* Gets all currently active effects on the player from multiple sources:
|
|
45
|
+
* - Direct effects assigned to the player
|
|
46
|
+
* - Effects from active states (buffs/debuffs)
|
|
47
|
+
* - Effects from equipped weapons and armor
|
|
48
|
+
* The returned array contains unique effects without duplicates.
|
|
49
|
+
*
|
|
50
|
+
* @returns Array of all active effects on the player
|
|
51
|
+
*/
|
|
52
|
+
effects: any[];
|
|
53
|
+
/**
|
|
54
|
+
* Check if the player has a specific effect
|
|
55
|
+
*
|
|
56
|
+
* Determines whether the player currently has the specified effect active.
|
|
57
|
+
* This includes effects from states, equipment, and temporary conditions.
|
|
58
|
+
* The effect system provides a flexible way to apply various gameplay
|
|
59
|
+
* restrictions and enhancements to the player.
|
|
60
|
+
*
|
|
61
|
+
* @param effect - The effect identifier to check for
|
|
62
|
+
* @returns true if the player has the effect, false otherwise
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { Effect } from '@rpgjs/database'
|
|
67
|
+
*
|
|
68
|
+
* // Check for skill restriction
|
|
69
|
+
* const cannotUseSkills = player.hasEffect(Effect.CAN_NOT_SKILL);
|
|
70
|
+
* if (cannotUseSkills) {
|
|
71
|
+
* console.log('Player cannot use skills right now');
|
|
72
|
+
* }
|
|
73
|
+
*
|
|
74
|
+
* // Check for guard effect
|
|
75
|
+
* const isGuarding = player.hasEffect(Effect.GUARD);
|
|
76
|
+
* if (isGuarding) {
|
|
77
|
+
* console.log('Player is in guard stance');
|
|
78
|
+
* }
|
|
79
|
+
*
|
|
80
|
+
* // Check for cost reduction
|
|
81
|
+
* const halfCost = player.hasEffect(Effect.HALF_SP_COST);
|
|
82
|
+
* const actualCost = skillCost / (halfCost ? 2 : 1);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
hasEffect(effect: string): boolean;
|
|
86
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { PlayerCtor } from '../../../common/src';
|
|
2
|
+
import { RpgPlayer } from './Player';
|
|
3
|
+
/**
|
|
4
|
+
* Element Manager Mixin
|
|
5
|
+
*
|
|
6
|
+
* Provides elemental management capabilities to any class. This mixin handles
|
|
7
|
+
* elemental resistances, vulnerabilities, and attack elements. It manages both
|
|
8
|
+
* defensive capabilities (elementsDefense) and offensive elements from equipment,
|
|
9
|
+
* as well as player-specific elemental efficiency modifiers.
|
|
10
|
+
*
|
|
11
|
+
* @param Base - The base class to extend with element management
|
|
12
|
+
* @returns Extended class with element management methods
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* class MyPlayer extends WithElementManager(BasePlayer) {
|
|
17
|
+
* constructor() {
|
|
18
|
+
* super();
|
|
19
|
+
* this.elementsEfficiency = [{ rate: 0.5, element: 'fire' }];
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* const player = new MyPlayer();
|
|
24
|
+
* const fireResistance = player.elementsDefense.find(e => e.element === 'fire');
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function WithElementManager<TBase extends PlayerCtor>(Base: TBase): TBase;
|
|
28
|
+
/**
|
|
29
|
+
* Interface for Element Manager functionality
|
|
30
|
+
*
|
|
31
|
+
* Provides elemental management capabilities including resistances, vulnerabilities,
|
|
32
|
+
* and attack elements. This interface defines the public API of the ElementManager mixin.
|
|
33
|
+
*/
|
|
34
|
+
export interface IElementManager {
|
|
35
|
+
/**
|
|
36
|
+
* Gets the defensive capabilities against various elements from equipped items.
|
|
37
|
+
* The system automatically consolidates multiple defensive items, keeping only
|
|
38
|
+
* the highest protection rate for each element type.
|
|
39
|
+
*
|
|
40
|
+
* @returns Array of element defense objects with rate and element properties
|
|
41
|
+
*/
|
|
42
|
+
elementsDefense: {
|
|
43
|
+
rate: number;
|
|
44
|
+
element: any;
|
|
45
|
+
}[];
|
|
46
|
+
/**
|
|
47
|
+
* Manages the player's elemental efficiency modifiers, which determine how
|
|
48
|
+
* effective different elements are against this player. Values greater than 1
|
|
49
|
+
* indicate vulnerability, while values less than 1 indicate resistance.
|
|
50
|
+
* This combines both class-based efficiency and player-specific modifiers.
|
|
51
|
+
*
|
|
52
|
+
* @returns Array of element efficiency objects with rate and element properties
|
|
53
|
+
*/
|
|
54
|
+
elementsEfficiency: {
|
|
55
|
+
rate: number;
|
|
56
|
+
element: any;
|
|
57
|
+
}[];
|
|
58
|
+
/**
|
|
59
|
+
* Gets all offensive elements available to the player from equipped weapons and armor.
|
|
60
|
+
* This determines what elemental damage types the player can deal in combat.
|
|
61
|
+
* The system automatically combines elements from all equipped items and removes duplicates.
|
|
62
|
+
*
|
|
63
|
+
* @returns Array of element objects with rate and element properties for offensive capabilities
|
|
64
|
+
*/
|
|
65
|
+
elements: {
|
|
66
|
+
rate: number;
|
|
67
|
+
element: string;
|
|
68
|
+
}[];
|
|
69
|
+
/**
|
|
70
|
+
* Calculate elemental damage coefficient against another player
|
|
71
|
+
*
|
|
72
|
+
* Determines the damage multiplier when this player attacks another player,
|
|
73
|
+
* taking into account the attacker's offensive elements, the defender's
|
|
74
|
+
* elemental efficiency, and elemental defense from equipment. This is used
|
|
75
|
+
* in the battle system to calculate elemental damage modifiers.
|
|
76
|
+
*
|
|
77
|
+
* @param otherPlayer - The target player to calculate coefficient against
|
|
78
|
+
* @returns Numerical coefficient to multiply base damage by
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* // Calculate elemental damage coefficient
|
|
83
|
+
* const firePlayer = new MyPlayer();
|
|
84
|
+
* const icePlayer = new MyPlayer();
|
|
85
|
+
*
|
|
86
|
+
* // Fire player attacks ice player (assuming ice is weak to fire)
|
|
87
|
+
* const coefficient = icePlayer.coefficientElements(firePlayer);
|
|
88
|
+
* console.log(`Damage multiplier: ${coefficient}`); // e.g., 2.0 for double damage
|
|
89
|
+
*
|
|
90
|
+
* // Use in damage calculation
|
|
91
|
+
* const baseDamage = 100;
|
|
92
|
+
* const finalDamage = baseDamage * coefficient;
|
|
93
|
+
* console.log(`Final damage: ${finalDamage}`);
|
|
94
|
+
*
|
|
95
|
+
* // Check for elemental advantage
|
|
96
|
+
* if (coefficient > 1) {
|
|
97
|
+
* console.log('Attacker has elemental advantage!');
|
|
98
|
+
* } else if (coefficient < 1) {
|
|
99
|
+
* console.log('Defender resists this element');
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
coefficientElements(otherPlayer: RpgPlayer): number;
|
|
104
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PlayerCtor } from '../../../common/src';
|
|
2
|
+
export interface GoldManager {
|
|
3
|
+
/**
|
|
4
|
+
* You can change the game money
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* player.gold += 100
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* @title Change Gold
|
|
11
|
+
* @prop {number} player.gold
|
|
12
|
+
* @default 0
|
|
13
|
+
* @memberof GoldManager
|
|
14
|
+
* */
|
|
15
|
+
gold: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function WithGoldManager<TBase extends PlayerCtor>(Base: TBase): new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> & GoldManager;
|
|
18
|
+
/**
|
|
19
|
+
* Type helper to extract the interface from the WithGoldManager mixin
|
|
20
|
+
* This provides the type without duplicating method signatures
|
|
21
|
+
*/
|
|
22
|
+
export type IGoldManager = InstanceType<ReturnType<typeof WithGoldManager>>;
|