@rpgjs/server 5.0.0-alpha.9 → 5.0.0-beta.1
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 +44 -32
- package/dist/Player/ClassManager.d.ts +24 -4
- package/dist/Player/ComponentManager.d.ts +95 -32
- package/dist/Player/Components.d.ts +345 -0
- package/dist/Player/EffectManager.d.ts +50 -4
- package/dist/Player/ElementManager.d.ts +77 -4
- package/dist/Player/GoldManager.d.ts +1 -1
- package/dist/Player/GuiManager.d.ts +87 -4
- package/dist/Player/ItemFixture.d.ts +1 -1
- package/dist/Player/ItemManager.d.ts +431 -4
- package/dist/Player/MoveManager.d.ts +301 -34
- package/dist/Player/ParameterManager.d.ts +364 -28
- package/dist/Player/Player.d.ts +558 -14
- package/dist/Player/SkillManager.d.ts +187 -13
- package/dist/Player/StateManager.d.ts +75 -4
- package/dist/Player/VariableManager.d.ts +62 -4
- package/dist/RpgServer.d.ts +278 -63
- package/dist/RpgServerEngine.d.ts +2 -1
- package/dist/decorators/event.d.ts +46 -0
- package/dist/decorators/map.d.ts +299 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +17920 -29711
- package/dist/index.js.map +1 -1
- package/dist/logs/log.d.ts +2 -3
- package/dist/module-CaCW1SDh.js +11018 -0
- package/dist/module-CaCW1SDh.js.map +1 -0
- package/dist/module.d.ts +43 -1
- package/dist/node/connection.d.ts +51 -0
- package/dist/node/index.d.ts +5 -0
- package/dist/node/index.js +551 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/map.d.ts +16 -0
- package/dist/node/room.d.ts +21 -0
- package/dist/node/transport.d.ts +28 -0
- package/dist/node/types.d.ts +47 -0
- 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 +1359 -32
- 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 +25 -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 +39 -56
- package/src/Player/ClassManager.ts +82 -74
- package/src/Player/ComponentManager.ts +394 -32
- package/src/Player/Components.ts +380 -0
- package/src/Player/EffectManager.ts +50 -96
- package/src/Player/ElementManager.ts +74 -152
- package/src/Player/GuiManager.ts +125 -14
- package/src/Player/ItemManager.ts +747 -341
- package/src/Player/MoveManager.ts +1532 -750
- package/src/Player/ParameterManager.ts +636 -106
- package/src/Player/Player.ts +1273 -79
- package/src/Player/SkillManager.ts +558 -197
- package/src/Player/StateManager.ts +131 -258
- package/src/Player/VariableManager.ts +85 -157
- package/src/RpgServer.ts +293 -62
- package/src/decorators/event.ts +61 -0
- package/src/decorators/map.ts +343 -0
- package/src/index.ts +11 -1
- package/src/logs/log.ts +10 -3
- package/src/module.ts +126 -3
- package/src/node/connection.ts +254 -0
- package/src/node/index.ts +22 -0
- package/src/node/map.ts +328 -0
- package/src/node/room.ts +63 -0
- package/src/node/transport.ts +532 -0
- package/src/node/types.ts +61 -0
- 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 +2682 -206
- 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/custom-websocket.spec.ts +127 -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/node-transport.spec.ts +223 -0
- package/tests/player-param.spec.ts +45 -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 +36 -3
package/dist/Player/Player.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { RpgCommonPlayer,
|
|
1
|
+
import { Hooks, RpgCommonPlayer, Constructor, Direction, AttachShapeOptions, RpgShape } from '../../../common/src';
|
|
2
|
+
import { Vector2 } from '../../../physic/src';
|
|
2
3
|
import { IComponentManager } from './ComponentManager';
|
|
3
4
|
import { RpgMap } from '../rooms/map';
|
|
4
5
|
import { Context } from '@signe/di';
|
|
@@ -15,16 +16,8 @@ import { ISkillManager } from './SkillManager';
|
|
|
15
16
|
import { IBattleManager } from './BattleManager';
|
|
16
17
|
import { IClassManager } from './ClassManager';
|
|
17
18
|
import { IStateManager } from './StateManager';
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
y?: number;
|
|
21
|
-
radius: number;
|
|
22
|
-
angle?: number;
|
|
23
|
-
direction?: any;
|
|
24
|
-
linkedTo?: string;
|
|
25
|
-
limitedByWalls?: boolean;
|
|
26
|
-
}
|
|
27
|
-
declare const RpgPlayer_base: typeof RpgCommonPlayer;
|
|
19
|
+
import { SaveRequestContext, SaveSlotIndex, SaveSlotMeta } from '../services/save';
|
|
20
|
+
declare const RpgPlayer_base: Constructor<RpgCommonPlayer>;
|
|
28
21
|
/**
|
|
29
22
|
* RPG Player class with component management capabilities
|
|
30
23
|
*
|
|
@@ -48,8 +41,94 @@ export declare class RpgPlayer extends RpgPlayer_base {
|
|
|
48
41
|
map: RpgMap | null;
|
|
49
42
|
context?: Context;
|
|
50
43
|
conn: MockConnection | null;
|
|
44
|
+
touchSide: boolean;
|
|
45
|
+
private _clientListeners;
|
|
46
|
+
/**
|
|
47
|
+
* Computed signal for world X position
|
|
48
|
+
*
|
|
49
|
+
* Calculates the absolute world X position from the map's world position
|
|
50
|
+
* plus the player's local X position. Returns 0 if no map is assigned.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const worldX = player.worldX();
|
|
55
|
+
* console.log(`Player is at world X: ${worldX}`);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
get worldPositionX(): any;
|
|
59
|
+
/**
|
|
60
|
+
* Computed signal for world Y position
|
|
61
|
+
*
|
|
62
|
+
* Calculates the absolute world Y position from the map's world position
|
|
63
|
+
* plus the player's local Y position. Returns 0 if no map is assigned.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* const worldY = player.worldY();
|
|
68
|
+
* console.log(`Player is at world Y: ${worldY}`);
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
get worldPositionY(): any;
|
|
72
|
+
private _worldPositionSignals;
|
|
73
|
+
private _getComputedWorldPosition;
|
|
74
|
+
/** Internal: Shapes attached to this player */
|
|
75
|
+
private _attachedShapes;
|
|
76
|
+
/** Internal: Shapes where this player is currently located */
|
|
77
|
+
private _inShapes;
|
|
78
|
+
/** Last processed client input timestamp for reconciliation */
|
|
79
|
+
lastProcessedInputTs: number;
|
|
80
|
+
/** Last processed client input frame for reconciliation with server tick */
|
|
81
|
+
_lastFramePositions: {
|
|
82
|
+
frame: number;
|
|
83
|
+
position: {
|
|
84
|
+
x: number;
|
|
85
|
+
y: number;
|
|
86
|
+
direction: Direction;
|
|
87
|
+
};
|
|
88
|
+
serverTick?: number;
|
|
89
|
+
} | null;
|
|
90
|
+
frames: {
|
|
91
|
+
x: number;
|
|
92
|
+
y: number;
|
|
93
|
+
ts: number;
|
|
94
|
+
}[];
|
|
51
95
|
events: import('@signe/reactive').WritableArraySignal<RpgEvent[]>;
|
|
52
96
|
constructor();
|
|
97
|
+
private _getClientListenerBucket;
|
|
98
|
+
_dispatchClientEvent(key: string, data: any): Promise<void>;
|
|
99
|
+
_onInit(): void;
|
|
100
|
+
/**
|
|
101
|
+
* Apply the built-in default parameter curves to this player.
|
|
102
|
+
*
|
|
103
|
+
* Use this when you want RPGJS to provide the initial parameter setup
|
|
104
|
+
* instead of restoring values from your own database or a saved snapshot.
|
|
105
|
+
*
|
|
106
|
+
* This method only defines the parameter curves and related defaults.
|
|
107
|
+
* It does not restore custom persisted data for you.
|
|
108
|
+
*
|
|
109
|
+
* @method player.applyDefaultParameters()
|
|
110
|
+
* @returns {void}
|
|
111
|
+
*/
|
|
112
|
+
applyDefaultParameters(): void;
|
|
113
|
+
/**
|
|
114
|
+
* Initialize the built-in default player stats.
|
|
115
|
+
*
|
|
116
|
+
* This applies the default parameter curves and then restores HP/SP to their
|
|
117
|
+
* current maximum values so the client receives coherent bars on first load.
|
|
118
|
+
*
|
|
119
|
+
* Call this manually in `onConnected()` or `onStart()` when your game relies
|
|
120
|
+
* on the built-in defaults. Do not call it after loading a snapshot or
|
|
121
|
+
* hydrating player data from your own database unless you explicitly want to
|
|
122
|
+
* overwrite those values.
|
|
123
|
+
*
|
|
124
|
+
* @method player.initializeDefaultStats()
|
|
125
|
+
* @returns {void}
|
|
126
|
+
*/
|
|
127
|
+
initializeDefaultStats(): void;
|
|
128
|
+
get hooks(): Hooks;
|
|
129
|
+
get server(): RpgMap | null;
|
|
130
|
+
setMap(map: RpgMap): void;
|
|
131
|
+
applyFrames(): void;
|
|
53
132
|
execMethod(method: string, methodData?: any[], target?: any): Promise<any>;
|
|
54
133
|
/**
|
|
55
134
|
* Change the map for this player
|
|
@@ -72,13 +151,180 @@ export declare class RpgPlayer extends RpgPlayer_base {
|
|
|
72
151
|
y: number;
|
|
73
152
|
z?: number;
|
|
74
153
|
} | string): Promise<any | null | boolean>;
|
|
154
|
+
autoChangeMap(nextPosition: Vector2): Promise<boolean>;
|
|
75
155
|
teleport(positions: {
|
|
76
156
|
x: number;
|
|
77
157
|
y: number;
|
|
78
158
|
}): Promise<false | undefined>;
|
|
79
159
|
getCurrentMap<T extends RpgMap = RpgMap>(): T | null;
|
|
160
|
+
/**
|
|
161
|
+
* Send a custom event to the current player's client.
|
|
162
|
+
*
|
|
163
|
+
* Use this to push arbitrary websocket payloads to one client only.
|
|
164
|
+
* On the client side, receive the event by injecting `WebSocketToken`
|
|
165
|
+
* and subscribing with `socket.on(...)`.
|
|
166
|
+
*
|
|
167
|
+
* @method player.emit(type, value)
|
|
168
|
+
* @param type - Custom event name sent to the client
|
|
169
|
+
* @param value - Payload sent with the event
|
|
170
|
+
* @returns {void}
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* player.emit("inventory:updated", {
|
|
175
|
+
* slots: player.items().length,
|
|
176
|
+
* });
|
|
177
|
+
* ```
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* import { inject } from "@rpgjs/client";
|
|
182
|
+
* import { WebSocketToken, type AbstractWebsocket } from "@rpgjs/client";
|
|
183
|
+
*
|
|
184
|
+
* const socket = inject<AbstractWebsocket>(WebSocketToken);
|
|
185
|
+
*
|
|
186
|
+
* socket.on("inventory:updated", (payload) => {
|
|
187
|
+
* console.log(payload.slots);
|
|
188
|
+
* });
|
|
189
|
+
* ```
|
|
190
|
+
*/
|
|
80
191
|
emit(type: string, value?: any): void;
|
|
81
|
-
|
|
192
|
+
snapshot(): Record<string, any>;
|
|
193
|
+
applySnapshot(snapshot: string | object): Promise<any>;
|
|
194
|
+
save(slot?: SaveSlotIndex, meta?: SaveSlotMeta, context?: SaveRequestContext): Promise<{
|
|
195
|
+
index: number;
|
|
196
|
+
meta: import('../../../common/src').SaveSlotMeta;
|
|
197
|
+
} | null>;
|
|
198
|
+
load(slot?: SaveSlotIndex, context?: SaveRequestContext, options?: {
|
|
199
|
+
changeMap?: boolean;
|
|
200
|
+
}): Promise<{
|
|
201
|
+
ok: boolean;
|
|
202
|
+
slot?: undefined;
|
|
203
|
+
index?: undefined;
|
|
204
|
+
} | {
|
|
205
|
+
ok: boolean;
|
|
206
|
+
slot: {
|
|
207
|
+
[key: string]: any;
|
|
208
|
+
level?: number;
|
|
209
|
+
exp?: number;
|
|
210
|
+
map?: string;
|
|
211
|
+
date?: string;
|
|
212
|
+
};
|
|
213
|
+
index: number;
|
|
214
|
+
}>;
|
|
215
|
+
/**
|
|
216
|
+
* @deprecated Use setGraphicAnimation instead.
|
|
217
|
+
* @param animationName - The name of the animation to play (e.g., 'attack', 'skill', 'walk')
|
|
218
|
+
* @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)
|
|
219
|
+
*/
|
|
220
|
+
setAnimation(animationName: string, nbTimes?: number): void;
|
|
221
|
+
/**
|
|
222
|
+
* @deprecated Use setGraphicAnimation instead.
|
|
223
|
+
* @param graphic - The graphic to use for the animation (e.g., 'attack', 'skill', 'walk')
|
|
224
|
+
* @param animationName - The name of the animation to play (e.g., 'attack', 'skill', 'walk')
|
|
225
|
+
* @param replaceGraphic - Whether to replace the player's graphic (default: false)
|
|
226
|
+
*/
|
|
227
|
+
showAnimation(graphic: string, animationName: string, replaceGraphic?: boolean): void;
|
|
228
|
+
/**
|
|
229
|
+
* Listen to custom data sent by the current player's client.
|
|
230
|
+
*
|
|
231
|
+
* This listens to websocket actions emitted from the client with
|
|
232
|
+
* `socket.emit(key, data)`. It is intended for custom client events
|
|
233
|
+
* that are not already handled by built-in server actions such as
|
|
234
|
+
* `move`, `action`, or GUI interactions.
|
|
235
|
+
*
|
|
236
|
+
* @title Listen to data from the client
|
|
237
|
+
* @method player.on(key, cb)
|
|
238
|
+
* @param key - Event name emitted by the client
|
|
239
|
+
* @param cb - Callback invoked with the payload sent by the client
|
|
240
|
+
* @returns {void}
|
|
241
|
+
* @since 3.0.0-beta.5
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```ts
|
|
245
|
+
* player.on("chat:message", ({ text }) => {
|
|
246
|
+
* console.log("Client says:", text);
|
|
247
|
+
* });
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* import { inject } from "@rpgjs/client";
|
|
253
|
+
* import { WebSocketToken, type AbstractWebsocket } from "@rpgjs/client";
|
|
254
|
+
*
|
|
255
|
+
* const socket = inject<AbstractWebsocket>(WebSocketToken);
|
|
256
|
+
* socket.emit("chat:message", { text: "Hello server" });
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
on(key: string, cb: (data: any) => void | Promise<void>): void;
|
|
260
|
+
/**
|
|
261
|
+
* Listen one time to custom data sent by the current player's client.
|
|
262
|
+
*
|
|
263
|
+
* After the first matching event is received, the listener is removed
|
|
264
|
+
* automatically.
|
|
265
|
+
*
|
|
266
|
+
* @title Listen one-time to data from the client
|
|
267
|
+
* @method player.once(key, cb)
|
|
268
|
+
* @param key - Event name emitted by the client
|
|
269
|
+
* @param cb - Callback invoked only once with the payload sent by the client
|
|
270
|
+
* @returns {void}
|
|
271
|
+
* @since 3.0.0-beta.5
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* ```ts
|
|
275
|
+
* player.once("tutorial:ready", (payload) => {
|
|
276
|
+
* console.log("Ready once:", payload.step);
|
|
277
|
+
* });
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
once(key: string, cb: (data: any) => void | Promise<void>): void;
|
|
281
|
+
/**
|
|
282
|
+
* Remove all listeners for a custom client event on this player.
|
|
283
|
+
*
|
|
284
|
+
* @title Remove listeners of the client event
|
|
285
|
+
* @method player.off(key)
|
|
286
|
+
* @param key - Event name to clear
|
|
287
|
+
* @returns {void}
|
|
288
|
+
* @since 3.0.0-beta.5
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```ts
|
|
292
|
+
* player.off("chat:message");
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
off(key: string): void;
|
|
296
|
+
/**
|
|
297
|
+
* Set the current animation of the player's sprite
|
|
298
|
+
*
|
|
299
|
+
* This method changes the animation state of the player's current sprite.
|
|
300
|
+
* It's used to trigger character animations like attack, skill, or custom movements.
|
|
301
|
+
* When `nbTimes` is set to a finite number, the animation will play that many times
|
|
302
|
+
* before returning to the previous animation state.
|
|
303
|
+
*
|
|
304
|
+
* If `animationFixed` is true, this method will not change the animation.
|
|
305
|
+
*
|
|
306
|
+
* @param animationName - The name of the animation to play (e.g., 'attack', 'skill', 'walk')
|
|
307
|
+
* @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)
|
|
308
|
+
*/
|
|
309
|
+
setGraphicAnimation(animationName: string, nbTimes: number): void;
|
|
310
|
+
/**
|
|
311
|
+
* Set the current animation of the player's sprite with a temporary graphic change
|
|
312
|
+
*
|
|
313
|
+
* This method changes the animation state of the player's current sprite and temporarily
|
|
314
|
+
* changes the player's graphic (sprite sheet) during the animation. The graphic is
|
|
315
|
+
* automatically reset when the animation finishes.
|
|
316
|
+
*
|
|
317
|
+
* When `nbTimes` is set to a finite number, the animation will play that many times
|
|
318
|
+
* before returning to the previous animation state and graphic.
|
|
319
|
+
*
|
|
320
|
+
* If `animationFixed` is true, this method will not change the animation.
|
|
321
|
+
*
|
|
322
|
+
* @param animationName - The name of the animation to play (e.g., 'attack', 'skill', 'walk')
|
|
323
|
+
* @param graphic - The graphic(s) to temporarily use during the animation
|
|
324
|
+
* @param nbTimes - Number of times to repeat the animation (default: Infinity for continuous)
|
|
325
|
+
*/
|
|
326
|
+
setGraphicAnimation(animationName: string, graphic: string | string[], nbTimes: number): void;
|
|
327
|
+
setGraphicAnimation(animationName: string, graphic: string | string[]): void;
|
|
82
328
|
/**
|
|
83
329
|
* Run the change detection cycle. Normally, as soon as a hook is called in a class, the cycle is started. But you can start it manually
|
|
84
330
|
* The method calls the `onChanges` method on events and synchronizes all map data with the client.
|
|
@@ -91,13 +337,311 @@ export declare class RpgPlayer extends RpgPlayer_base {
|
|
|
91
337
|
syncChanges(): void;
|
|
92
338
|
databaseById(id: string): any;
|
|
93
339
|
private _eventChanges;
|
|
94
|
-
|
|
95
|
-
|
|
340
|
+
/**
|
|
341
|
+
* Attach a zone shape to this player using the physic zone system
|
|
342
|
+
*
|
|
343
|
+
* This method creates a zone attached to the player's entity in the physics engine.
|
|
344
|
+
* The zone can be circular or cone-shaped and will detect other entities (players/events)
|
|
345
|
+
* entering or exiting the zone.
|
|
346
|
+
*
|
|
347
|
+
* @param id - Optional zone identifier. If not provided, a unique ID will be generated
|
|
348
|
+
* @param options - Zone configuration options
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```ts
|
|
352
|
+
* // Create a circular detection zone
|
|
353
|
+
* player.attachShape("vision", {
|
|
354
|
+
* radius: 150,
|
|
355
|
+
* angle: 360,
|
|
356
|
+
* });
|
|
357
|
+
*
|
|
358
|
+
* // Create a cone-shaped vision zone
|
|
359
|
+
* player.attachShape("vision", {
|
|
360
|
+
* radius: 200,
|
|
361
|
+
* angle: 120,
|
|
362
|
+
* direction: Direction.Right,
|
|
363
|
+
* limitedByWalls: true,
|
|
364
|
+
* });
|
|
365
|
+
*
|
|
366
|
+
* // Create a zone with width/height (radius calculated automatically)
|
|
367
|
+
* player.attachShape({
|
|
368
|
+
* width: 100,
|
|
369
|
+
* height: 100,
|
|
370
|
+
* positioning: "center",
|
|
371
|
+
* });
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
attachShape(idOrOptions: string | AttachShapeOptions, options?: AttachShapeOptions): RpgShape | undefined;
|
|
375
|
+
/**
|
|
376
|
+
* Get all shapes attached to this player
|
|
377
|
+
*
|
|
378
|
+
* Returns all shapes that were created using `attachShape()` on this player.
|
|
379
|
+
*
|
|
380
|
+
* @returns Array of RpgShape instances attached to this player
|
|
381
|
+
*
|
|
382
|
+
* @example
|
|
383
|
+
* ```ts
|
|
384
|
+
* player.attachShape("vision", { radius: 150 });
|
|
385
|
+
* player.attachShape("detection", { radius: 100 });
|
|
386
|
+
*
|
|
387
|
+
* const shapes = player.getShapes();
|
|
388
|
+
* console.log(shapes.length); // 2
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
getShapes(): RpgShape[];
|
|
392
|
+
/**
|
|
393
|
+
* Get all shapes where this player is currently located
|
|
394
|
+
*
|
|
395
|
+
* Returns all shapes (from any player/event) where this player is currently inside.
|
|
396
|
+
* This is updated automatically when the player enters or exits shapes.
|
|
397
|
+
*
|
|
398
|
+
* @returns Array of RpgShape instances where this player is located
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* ```ts
|
|
402
|
+
* // Another player has a detection zone
|
|
403
|
+
* otherPlayer.attachShape("detection", { radius: 200 });
|
|
404
|
+
*
|
|
405
|
+
* // Check if this player is in any shape
|
|
406
|
+
* const inShapes = player.getInShapes();
|
|
407
|
+
* if (inShapes.length > 0) {
|
|
408
|
+
* console.log("Player is being detected!");
|
|
409
|
+
* }
|
|
410
|
+
* ```
|
|
411
|
+
*/
|
|
412
|
+
getInShapes(): RpgShape[];
|
|
413
|
+
/**
|
|
414
|
+
* Show a temporary component animation on this player
|
|
415
|
+
*
|
|
416
|
+
* This method broadcasts a component animation to all clients, allowing
|
|
417
|
+
* temporary visual effects like hit indicators, spell effects, or status animations
|
|
418
|
+
* to be displayed on the player.
|
|
419
|
+
*
|
|
420
|
+
* @param id - The ID of the component animation to display
|
|
421
|
+
* @param params - Parameters to pass to the component animation
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
* ```ts
|
|
425
|
+
* // Show a hit animation with damage text
|
|
426
|
+
* player.showComponentAnimation("hit", {
|
|
427
|
+
* text: "150",
|
|
428
|
+
* color: "red"
|
|
429
|
+
* });
|
|
430
|
+
*
|
|
431
|
+
* // Show a heal animation
|
|
432
|
+
* player.showComponentAnimation("heal", {
|
|
433
|
+
* amount: 50
|
|
434
|
+
* });
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
showComponentAnimation(id: string, params?: any): void;
|
|
96
438
|
showHit(text: string): void;
|
|
439
|
+
/**
|
|
440
|
+
* Play a sound on the client side for this player only
|
|
441
|
+
*
|
|
442
|
+
* This method emits an event to play a sound only for this specific player.
|
|
443
|
+
* The sound must be defined on the client side (in the client module configuration).
|
|
444
|
+
*
|
|
445
|
+
* ## Design
|
|
446
|
+
*
|
|
447
|
+
* The sound is sent only to this player's client connection, making it ideal
|
|
448
|
+
* for personal feedback sounds like UI interactions, notifications, or personal
|
|
449
|
+
* achievements. For map-wide sounds that all players should hear, use `map.playSound()` instead.
|
|
450
|
+
*
|
|
451
|
+
* @param soundId - Sound identifier, defined on the client side
|
|
452
|
+
* @param options - Optional sound configuration
|
|
453
|
+
* @param options.volume - Volume level (0.0 to 1.0, default: 1.0)
|
|
454
|
+
* @param options.loop - Whether the sound should loop (default: false)
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```ts
|
|
458
|
+
* // Play a sound for this player only (default behavior)
|
|
459
|
+
* player.playSound("item-pickup");
|
|
460
|
+
*
|
|
461
|
+
* // Play a sound with volume and loop
|
|
462
|
+
* player.playSound("background-music", {
|
|
463
|
+
* volume: 0.5,
|
|
464
|
+
* loop: true
|
|
465
|
+
* });
|
|
466
|
+
*
|
|
467
|
+
* // Play a notification sound at low volume
|
|
468
|
+
* player.playSound("notification", { volume: 0.3 });
|
|
469
|
+
* ```
|
|
470
|
+
*/
|
|
471
|
+
playSound(soundId: string, options?: {
|
|
472
|
+
volume?: number;
|
|
473
|
+
loop?: boolean;
|
|
474
|
+
}): void;
|
|
475
|
+
/**
|
|
476
|
+
* Stop a sound that is currently playing for this player
|
|
477
|
+
*
|
|
478
|
+
* This method stops a sound that was previously started with `playSound()`.
|
|
479
|
+
* The sound must be defined on the client side.
|
|
480
|
+
*
|
|
481
|
+
* @param soundId - Sound identifier to stop
|
|
482
|
+
*
|
|
483
|
+
* @example
|
|
484
|
+
* ```ts
|
|
485
|
+
* // Start a looping background music
|
|
486
|
+
* player.playSound("background-music", { loop: true });
|
|
487
|
+
*
|
|
488
|
+
* // Later, stop it
|
|
489
|
+
* player.stopSound("background-music");
|
|
490
|
+
* ```
|
|
491
|
+
*/
|
|
492
|
+
stopSound(soundId: string): void;
|
|
493
|
+
/**
|
|
494
|
+
* Stop all currently playing sounds for this player
|
|
495
|
+
*
|
|
496
|
+
* This method stops all sounds that are currently playing for the player.
|
|
497
|
+
* Useful when changing maps to prevent sound overlap.
|
|
498
|
+
*
|
|
499
|
+
* @example
|
|
500
|
+
* ```ts
|
|
501
|
+
* // Stop all sounds before changing map
|
|
502
|
+
* player.stopAllSounds();
|
|
503
|
+
* await player.changeMap("new-map");
|
|
504
|
+
* ```
|
|
505
|
+
*/
|
|
506
|
+
stopAllSounds(): void;
|
|
507
|
+
/**
|
|
508
|
+
* Make the camera follow another player or event
|
|
509
|
+
*
|
|
510
|
+
* This method sends an instruction to the client to fix the viewport on another sprite.
|
|
511
|
+
* The camera will follow the specified player or event, with optional smooth animation.
|
|
512
|
+
*
|
|
513
|
+
* ## Design
|
|
514
|
+
*
|
|
515
|
+
* The camera follow instruction is sent only to this player's client connection.
|
|
516
|
+
* This allows each player to have their own camera target, useful for cutscenes,
|
|
517
|
+
* following NPCs, or focusing on specific events.
|
|
518
|
+
*
|
|
519
|
+
* @param otherPlayer - The player or event that the camera should follow
|
|
520
|
+
* @param options - Camera follow options
|
|
521
|
+
* @param options.smoothMove - Enable smooth animation. Can be a boolean (default: true) or an object with animation parameters
|
|
522
|
+
* @param options.smoothMove.time - Time duration for the animation in milliseconds (optional)
|
|
523
|
+
* @param options.smoothMove.ease - Easing function name. Visit https://easings.net for available functions (optional)
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```ts
|
|
527
|
+
* // Follow another player with default smooth animation
|
|
528
|
+
* player.cameraFollow(otherPlayer, { smoothMove: true });
|
|
529
|
+
*
|
|
530
|
+
* // Follow an event with custom smooth animation
|
|
531
|
+
* player.cameraFollow(npcEvent, {
|
|
532
|
+
* smoothMove: {
|
|
533
|
+
* time: 1000,
|
|
534
|
+
* ease: "easeInOutQuad"
|
|
535
|
+
* }
|
|
536
|
+
* });
|
|
537
|
+
*
|
|
538
|
+
* // Follow without animation (instant)
|
|
539
|
+
* player.cameraFollow(targetPlayer, { smoothMove: false });
|
|
540
|
+
* ```
|
|
541
|
+
*/
|
|
542
|
+
cameraFollow(otherPlayer: RpgPlayer | RpgEvent, options?: {
|
|
543
|
+
smoothMove?: boolean | {
|
|
544
|
+
time?: number;
|
|
545
|
+
ease?: string;
|
|
546
|
+
};
|
|
547
|
+
}): void;
|
|
548
|
+
/**
|
|
549
|
+
* Trigger a flash animation on this player
|
|
550
|
+
*
|
|
551
|
+
* This method sends a flash animation event to the client, creating a visual
|
|
552
|
+
* feedback effect on the player's sprite. The flash can be configured with
|
|
553
|
+
* various options including type (alpha, tint, or both), duration, cycles, and color.
|
|
554
|
+
*
|
|
555
|
+
* ## Design
|
|
556
|
+
*
|
|
557
|
+
* The flash is sent as a broadcast event to all clients viewing this player.
|
|
558
|
+
* This is useful for visual feedback when the player takes damage, receives
|
|
559
|
+
* a buff, or when an important event occurs.
|
|
560
|
+
*
|
|
561
|
+
* @param options - Flash configuration options
|
|
562
|
+
* @param options.type - Type of flash effect: 'alpha' (opacity), 'tint' (color), or 'both' (default: 'alpha')
|
|
563
|
+
* @param options.duration - Duration of the flash animation in milliseconds (default: 300)
|
|
564
|
+
* @param options.cycles - Number of flash cycles (flash on/off) (default: 1)
|
|
565
|
+
* @param options.alpha - Alpha value when flashing, from 0 to 1 (default: 0.3)
|
|
566
|
+
* @param options.tint - Tint color when flashing as hex value or color name (default: 0xffffff - white)
|
|
567
|
+
*
|
|
568
|
+
* @example
|
|
569
|
+
* ```ts
|
|
570
|
+
* // Simple flash with default settings (alpha flash)
|
|
571
|
+
* player.flash();
|
|
572
|
+
*
|
|
573
|
+
* // Flash with red tint when taking damage
|
|
574
|
+
* player.flash({ type: 'tint', tint: 0xff0000 });
|
|
575
|
+
*
|
|
576
|
+
* // Flash with both alpha and tint for dramatic effect
|
|
577
|
+
* player.flash({
|
|
578
|
+
* type: 'both',
|
|
579
|
+
* alpha: 0.5,
|
|
580
|
+
* tint: 0xff0000,
|
|
581
|
+
* duration: 200,
|
|
582
|
+
* cycles: 2
|
|
583
|
+
* });
|
|
584
|
+
*
|
|
585
|
+
* // Quick damage flash
|
|
586
|
+
* player.flash({
|
|
587
|
+
* type: 'tint',
|
|
588
|
+
* tint: 'red',
|
|
589
|
+
* duration: 150,
|
|
590
|
+
* cycles: 1
|
|
591
|
+
* });
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
flash(options?: {
|
|
595
|
+
type?: 'alpha' | 'tint' | 'both';
|
|
596
|
+
duration?: number;
|
|
597
|
+
cycles?: number;
|
|
598
|
+
alpha?: number;
|
|
599
|
+
tint?: number | string;
|
|
600
|
+
}): void;
|
|
601
|
+
/**
|
|
602
|
+
* Set the hitbox of the player for collision detection
|
|
603
|
+
*
|
|
604
|
+
* This method defines the hitbox used for collision detection in the physics engine.
|
|
605
|
+
* The hitbox can be smaller or larger than the visual representation of the player,
|
|
606
|
+
* allowing for precise collision detection.
|
|
607
|
+
*
|
|
608
|
+
* ## Design
|
|
609
|
+
*
|
|
610
|
+
* The hitbox is used by the physics engine to detect collisions with other entities,
|
|
611
|
+
* static obstacles, and shapes. Changing the hitbox will immediately update the
|
|
612
|
+
* collision detection without affecting the visual appearance of the player.
|
|
613
|
+
*
|
|
614
|
+
* @param width - Width of the hitbox in pixels
|
|
615
|
+
* @param height - Height of the hitbox in pixels
|
|
616
|
+
*
|
|
617
|
+
* @example
|
|
618
|
+
* ```ts
|
|
619
|
+
* // Set a 20x20 hitbox for precise collision detection
|
|
620
|
+
* player.setHitbox(20, 20);
|
|
621
|
+
*
|
|
622
|
+
* // Set a larger hitbox for easier collision detection
|
|
623
|
+
* player.setHitbox(40, 40);
|
|
624
|
+
* ```
|
|
625
|
+
*/
|
|
626
|
+
setHitbox(width: number, height: number): void;
|
|
627
|
+
/**
|
|
628
|
+
* Set the sync schema for the map
|
|
629
|
+
* @param schema - The schema to set
|
|
630
|
+
*/
|
|
631
|
+
setSync(schema: any): void;
|
|
632
|
+
isEvent(): boolean;
|
|
97
633
|
}
|
|
98
634
|
export declare class RpgEvent extends RpgPlayer {
|
|
635
|
+
constructor();
|
|
99
636
|
execMethod(methodName: string, methodData?: any[], instance?: this): Promise<any>;
|
|
637
|
+
/**
|
|
638
|
+
* Remove this event from the map
|
|
639
|
+
*
|
|
640
|
+
* Stops all movements before removing to prevent "unable to resolve entity" errors
|
|
641
|
+
* from the MovementManager when the entity is destroyed while moving.
|
|
642
|
+
*/
|
|
100
643
|
remove(): void;
|
|
644
|
+
isEvent(): boolean;
|
|
101
645
|
}
|
|
102
646
|
/**
|
|
103
647
|
* Interface extension for RpgPlayer
|