@rpgjs/server 5.0.0-alpha.21 → 5.0.0-alpha.23

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.
@@ -1,7 +1,8 @@
1
- import { PlayerCtor, Direction } from '@rpgjs/common';
1
+ import { PlayerCtor, ProjectileType, RpgCommonPlayer, Direction, MovementStrategy } from '@rpgjs/common';
2
2
  import { RpgPlayer } from './Player';
3
3
  type CallbackTileMove = (player: RpgPlayer, map: any) => Direction[];
4
4
  type CallbackTurnMove = (player: RpgPlayer, map: any) => string;
5
+ type Routes = (string | Promise<any> | Direction | Direction[] | Function)[];
5
6
  export declare enum Frequency {
6
7
  Lowest = 600,
7
8
  Lower = 400,
@@ -158,8 +159,148 @@ export declare const Move: MoveList;
158
159
  */
159
160
  export declare function WithMoveManager<TBase extends PlayerCtor>(Base: TBase): PlayerCtor;
160
161
  /**
161
- * Type helper to extract the interface from the WithMoveManager mixin
162
- * This provides the type without duplicating method signatures
162
+ * Interface for Move Manager functionality
163
+ *
164
+ * Provides comprehensive movement management capabilities including pathfinding,
165
+ * physics-based movement, route following, and advanced movement strategies.
166
+ * This interface defines the public API of the MoveManager mixin.
163
167
  */
164
- export type IMoveManager = InstanceType<ReturnType<typeof WithMoveManager>>;
168
+ export interface IMoveManager {
169
+ /** Whether the player passes through other players */
170
+ throughOtherPlayer: boolean;
171
+ /** Whether the player goes through events or other players */
172
+ through: boolean;
173
+ /** Frequency for movement timing (milliseconds between movements) */
174
+ frequency: number;
175
+ /**
176
+ * Add a custom movement strategy to this entity
177
+ *
178
+ * @param strategy - The movement strategy to add
179
+ */
180
+ addMovement(strategy: MovementStrategy): void;
181
+ /**
182
+ * Remove a specific movement strategy from this entity
183
+ *
184
+ * @param strategy - The strategy instance to remove
185
+ * @returns True if the strategy was found and removed
186
+ */
187
+ removeMovement(strategy: MovementStrategy): boolean;
188
+ /**
189
+ * Remove all active movement strategies from this entity
190
+ */
191
+ clearMovements(): void;
192
+ /**
193
+ * Check if this entity has any active movement strategies
194
+ *
195
+ * @returns True if entity has active movements
196
+ */
197
+ hasActiveMovements(): boolean;
198
+ /**
199
+ * Get all active movement strategies for this entity
200
+ *
201
+ * @returns Array of active movement strategies
202
+ */
203
+ getActiveMovements(): MovementStrategy[];
204
+ /**
205
+ * Move toward a target player or position using AI pathfinding
206
+ *
207
+ * @param target - Target player or position to move toward
208
+ */
209
+ moveTo(target: RpgCommonPlayer | {
210
+ x: number;
211
+ y: number;
212
+ }): void;
213
+ /**
214
+ * Stop the current moveTo behavior
215
+ */
216
+ stopMoveTo(): void;
217
+ /**
218
+ * Perform a dash movement in the specified direction
219
+ *
220
+ * @param direction - Normalized direction vector
221
+ * @param speed - Movement speed (default: 8)
222
+ * @param duration - Duration in milliseconds (default: 200)
223
+ */
224
+ dash(direction: {
225
+ x: number;
226
+ y: number;
227
+ }, speed?: number, duration?: number): void;
228
+ /**
229
+ * Apply knockback effect in the specified direction
230
+ *
231
+ * @param direction - Normalized direction vector
232
+ * @param force - Initial knockback force (default: 5)
233
+ * @param duration - Duration in milliseconds (default: 300)
234
+ */
235
+ knockback(direction: {
236
+ x: number;
237
+ y: number;
238
+ }, force?: number, duration?: number): void;
239
+ /**
240
+ * Follow a sequence of waypoints
241
+ *
242
+ * @param waypoints - Array of x,y positions to follow
243
+ * @param speed - Movement speed (default: 2)
244
+ * @param loop - Whether to loop back to start (default: false)
245
+ */
246
+ followPath(waypoints: Array<{
247
+ x: number;
248
+ y: number;
249
+ }>, speed?: number, loop?: boolean): void;
250
+ /**
251
+ * Apply oscillating movement pattern
252
+ *
253
+ * @param direction - Primary oscillation axis (normalized)
254
+ * @param amplitude - Maximum distance from center (default: 50)
255
+ * @param period - Time for complete cycle in ms (default: 2000)
256
+ */
257
+ oscillate(direction: {
258
+ x: number;
259
+ y: number;
260
+ }, amplitude?: number, period?: number): void;
261
+ /**
262
+ * Apply ice movement physics
263
+ *
264
+ * @param direction - Target movement direction
265
+ * @param maxSpeed - Maximum speed when fully accelerated (default: 4)
266
+ */
267
+ applyIceMovement(direction: {
268
+ x: number;
269
+ y: number;
270
+ }, maxSpeed?: number): void;
271
+ /**
272
+ * Shoot a projectile in the specified direction
273
+ *
274
+ * @param type - Type of projectile trajectory
275
+ * @param direction - Normalized direction vector
276
+ * @param speed - Projectile speed (default: 200)
277
+ */
278
+ shootProjectile(type: ProjectileType, direction: {
279
+ x: number;
280
+ y: number;
281
+ }, speed?: number): void;
282
+ /**
283
+ * Give an itinerary to follow using movement strategies
284
+ *
285
+ * @param routes - Array of movement instructions to execute
286
+ * @returns Promise that resolves when all routes are completed
287
+ */
288
+ moveRoutes(routes: Routes): Promise<boolean>;
289
+ /**
290
+ * Give a path that repeats itself in a loop to a character
291
+ *
292
+ * @param routes - Array of movement instructions to repeat infinitely
293
+ */
294
+ infiniteMoveRoute(routes: Routes): void;
295
+ /**
296
+ * Stop an infinite movement
297
+ *
298
+ * @param force - Forces the stop of the infinite movement immediately
299
+ */
300
+ breakRoutes(force?: boolean): void;
301
+ /**
302
+ * Replay an infinite movement
303
+ */
304
+ replayRoutes(): void;
305
+ }
165
306
  export {};
@@ -65,6 +65,7 @@ export declare class RpgPlayer extends RpgPlayer_base {
65
65
  constructor();
66
66
  _onInit(): void;
67
67
  get hooks(): Hooks;
68
+ get server(): RpgMap | null;
68
69
  applyFrames(): void;
69
70
  execMethod(method: string, methodData?: any[], target?: any): Promise<any>;
70
71
  /**
@@ -310,6 +311,140 @@ export declare class RpgPlayer extends RpgPlayer_base {
310
311
  * ```
311
312
  */
312
313
  stopSound(soundId: string): void;
314
+ /**
315
+ * Stop all currently playing sounds for this player
316
+ *
317
+ * This method stops all sounds that are currently playing for the player.
318
+ * Useful when changing maps to prevent sound overlap.
319
+ *
320
+ * @example
321
+ * ```ts
322
+ * // Stop all sounds before changing map
323
+ * player.stopAllSounds();
324
+ * await player.changeMap("new-map");
325
+ * ```
326
+ */
327
+ stopAllSounds(): void;
328
+ /**
329
+ * Make the camera follow another player or event
330
+ *
331
+ * This method sends an instruction to the client to fix the viewport on another sprite.
332
+ * The camera will follow the specified player or event, with optional smooth animation.
333
+ *
334
+ * ## Design
335
+ *
336
+ * The camera follow instruction is sent only to this player's client connection.
337
+ * This allows each player to have their own camera target, useful for cutscenes,
338
+ * following NPCs, or focusing on specific events.
339
+ *
340
+ * @param otherPlayer - The player or event that the camera should follow
341
+ * @param options - Camera follow options
342
+ * @param options.smoothMove - Enable smooth animation. Can be a boolean (default: true) or an object with animation parameters
343
+ * @param options.smoothMove.time - Time duration for the animation in milliseconds (optional)
344
+ * @param options.smoothMove.ease - Easing function name. Visit https://easings.net for available functions (optional)
345
+ *
346
+ * @example
347
+ * ```ts
348
+ * // Follow another player with default smooth animation
349
+ * player.cameraFollow(otherPlayer, { smoothMove: true });
350
+ *
351
+ * // Follow an event with custom smooth animation
352
+ * player.cameraFollow(npcEvent, {
353
+ * smoothMove: {
354
+ * time: 1000,
355
+ * ease: "easeInOutQuad"
356
+ * }
357
+ * });
358
+ *
359
+ * // Follow without animation (instant)
360
+ * player.cameraFollow(targetPlayer, { smoothMove: false });
361
+ * ```
362
+ */
363
+ cameraFollow(otherPlayer: RpgPlayer | RpgEvent, options?: {
364
+ smoothMove?: boolean | {
365
+ time?: number;
366
+ ease?: string;
367
+ };
368
+ }): void;
369
+ /**
370
+ * Trigger a flash animation on this player
371
+ *
372
+ * This method sends a flash animation event to the client, creating a visual
373
+ * feedback effect on the player's sprite. The flash can be configured with
374
+ * various options including type (alpha, tint, or both), duration, cycles, and color.
375
+ *
376
+ * ## Design
377
+ *
378
+ * The flash is sent as a broadcast event to all clients viewing this player.
379
+ * This is useful for visual feedback when the player takes damage, receives
380
+ * a buff, or when an important event occurs.
381
+ *
382
+ * @param options - Flash configuration options
383
+ * @param options.type - Type of flash effect: 'alpha' (opacity), 'tint' (color), or 'both' (default: 'alpha')
384
+ * @param options.duration - Duration of the flash animation in milliseconds (default: 300)
385
+ * @param options.cycles - Number of flash cycles (flash on/off) (default: 1)
386
+ * @param options.alpha - Alpha value when flashing, from 0 to 1 (default: 0.3)
387
+ * @param options.tint - Tint color when flashing as hex value or color name (default: 0xffffff - white)
388
+ *
389
+ * @example
390
+ * ```ts
391
+ * // Simple flash with default settings (alpha flash)
392
+ * player.flash();
393
+ *
394
+ * // Flash with red tint when taking damage
395
+ * player.flash({ type: 'tint', tint: 0xff0000 });
396
+ *
397
+ * // Flash with both alpha and tint for dramatic effect
398
+ * player.flash({
399
+ * type: 'both',
400
+ * alpha: 0.5,
401
+ * tint: 0xff0000,
402
+ * duration: 200,
403
+ * cycles: 2
404
+ * });
405
+ *
406
+ * // Quick damage flash
407
+ * player.flash({
408
+ * type: 'tint',
409
+ * tint: 'red',
410
+ * duration: 150,
411
+ * cycles: 1
412
+ * });
413
+ * ```
414
+ */
415
+ flash(options?: {
416
+ type?: 'alpha' | 'tint' | 'both';
417
+ duration?: number;
418
+ cycles?: number;
419
+ alpha?: number;
420
+ tint?: number | string;
421
+ }): void;
422
+ /**
423
+ * Set the hitbox of the player for collision detection
424
+ *
425
+ * This method defines the hitbox used for collision detection in the physics engine.
426
+ * The hitbox can be smaller or larger than the visual representation of the player,
427
+ * allowing for precise collision detection.
428
+ *
429
+ * ## Design
430
+ *
431
+ * The hitbox is used by the physics engine to detect collisions with other entities,
432
+ * static obstacles, and shapes. Changing the hitbox will immediately update the
433
+ * collision detection without affecting the visual appearance of the player.
434
+ *
435
+ * @param width - Width of the hitbox in pixels
436
+ * @param height - Height of the hitbox in pixels
437
+ *
438
+ * @example
439
+ * ```ts
440
+ * // Set a 20x20 hitbox for precise collision detection
441
+ * player.setHitbox(20, 20);
442
+ *
443
+ * // Set a larger hitbox for easier collision detection
444
+ * player.setHitbox(40, 40);
445
+ * ```
446
+ */
447
+ setHitbox(width: number, height: number): void;
313
448
  /**
314
449
  * Set the sync schema for the map
315
450
  * @param schema - The schema to set
@@ -1,4 +1,5 @@
1
1
  import { PlayerCtor } from '@rpgjs/common';
2
+ import { RpgPlayer } from './Player';
2
3
  /**
3
4
  * Skill Manager Mixin
4
5
  *
@@ -25,7 +26,45 @@ import { PlayerCtor } from '@rpgjs/common';
25
26
  */
26
27
  export declare function WithSkillManager<TBase extends PlayerCtor>(Base: TBase): TBase;
27
28
  /**
28
- * Type helper to extract the interface from the WithSkillManager mixin
29
- * This provides the type without duplicating method signatures
29
+ * Interface for Skill Manager functionality
30
+ *
31
+ * Provides skill management capabilities including learning, forgetting, and using skills.
32
+ * This interface defines the public API of the SkillManager mixin.
30
33
  */
31
- export type ISkillManager = InstanceType<ReturnType<typeof WithSkillManager>>;
34
+ export interface ISkillManager {
35
+ /**
36
+ * Retrieves a learned skill. Returns null if not found
37
+ *
38
+ * @param skillClass - Skill class or data id
39
+ * @returns Instance of SkillClass or null
40
+ */
41
+ getSkill(skillClass: any | string): any | null;
42
+ /**
43
+ * Learn a skill
44
+ *
45
+ * @param skillId - Skill class or data id
46
+ * @returns Instance of SkillClass
47
+ * @throws SkillLog.alreadyLearned if the player already knows the skill
48
+ */
49
+ learnSkill(skillId: any | string): any;
50
+ /**
51
+ * Forget a skill
52
+ *
53
+ * @param skillId - Skill class or data id
54
+ * @returns Instance of SkillClass
55
+ * @throws SkillLog.notLearned if trying to forget a skill not learned
56
+ */
57
+ forgetSkill(skillId: any | string): any;
58
+ /**
59
+ * Using a skill
60
+ *
61
+ * @param skillId - Skill class or data id
62
+ * @param otherPlayer - Optional target player(s) to apply skill to
63
+ * @returns Instance of SkillClass
64
+ * @throws SkillLog.restriction if player has Effect.CAN_NOT_SKILL
65
+ * @throws SkillLog.notLearned if player tries to use an unlearned skill
66
+ * @throws SkillLog.notEnoughSp if player does not have enough SP
67
+ * @throws SkillLog.chanceToUseFailed if the chance to use the skill has failed
68
+ */
69
+ useSkill(skillId: any | string, otherPlayer?: RpgPlayer | RpgPlayer[]): any;
70
+ }
@@ -1,4 +1,8 @@
1
1
  import { PlayerCtor } from '@rpgjs/common';
2
+ import { RpgPlayer } from './Player';
3
+ type StateClass = {
4
+ new (...args: any[]): any;
5
+ };
2
6
  /**
3
7
  * State Manager Mixin
4
8
  *
@@ -26,7 +30,74 @@ import { PlayerCtor } from '@rpgjs/common';
26
30
  */
27
31
  export declare function WithStateManager<TBase extends PlayerCtor>(Base: TBase): TBase;
28
32
  /**
29
- * Type helper to extract the interface from the WithStateManager mixin
30
- * This provides the type without duplicating method signatures
33
+ * Interface for State Manager functionality
34
+ *
35
+ * Provides state management capabilities including state defense, efficiency modifiers,
36
+ * and state application/removal. This interface defines the public API of the StateManager mixin.
31
37
  */
32
- export type IStateManager = InstanceType<ReturnType<typeof WithStateManager>>;
38
+ export interface IStateManager {
39
+ /**
40
+ * Gets the defensive capabilities against various states from equipped items
41
+ *
42
+ * @returns Array of state defense objects with rate and state properties
43
+ */
44
+ statesDefense: {
45
+ rate: number;
46
+ state: any;
47
+ }[];
48
+ /**
49
+ * Manages the player's state efficiency modifiers
50
+ *
51
+ * @returns Signal containing array of state efficiency objects
52
+ */
53
+ statesEfficiency: any;
54
+ /**
55
+ * Apply states to a player from skill or item effects
56
+ *
57
+ * @param player - The target player to apply states to
58
+ * @param states - Object containing arrays of states to add or remove
59
+ */
60
+ applyStates(player: RpgPlayer, states: {
61
+ addStates?: Array<{
62
+ state: any;
63
+ rate: number;
64
+ }>;
65
+ removeStates?: Array<{
66
+ state: any;
67
+ rate: number;
68
+ }>;
69
+ }): void;
70
+ /**
71
+ * Get a state to the player. Returns null if the state is not present
72
+ *
73
+ * @param stateClass - The state class constructor or state ID to search for
74
+ * @returns The state instance if found, null otherwise
75
+ */
76
+ getState(stateClass: StateClass | string): any | null;
77
+ /**
78
+ * Adds a state to the player
79
+ *
80
+ * @param stateClass - The state class constructor or state ID to apply
81
+ * @param chance - Probability of successful application (0-1, default 1)
82
+ * @returns The state instance if successfully applied, null if already present
83
+ * @throws StateLog.addFailed if the chance roll fails
84
+ */
85
+ addState(stateClass: StateClass | string, chance?: number): object | null;
86
+ /**
87
+ * Remove a state to the player
88
+ *
89
+ * @param stateClass - The state class constructor or state ID to remove
90
+ * @param chance - Probability of successful removal (0-1, default 1)
91
+ * @throws StateLog.removeFailed if the chance roll fails
92
+ * @throws StateLog.notApplied if the state is not currently active
93
+ */
94
+ removeState(stateClass: StateClass | string, chance?: number): void;
95
+ /**
96
+ * Find state efficiency modifier for a specific state class
97
+ *
98
+ * @param stateClass - The state class to find efficiency for
99
+ * @returns The efficiency object if found, undefined otherwise
100
+ */
101
+ findStateEfficiency(stateClass: any): any | undefined;
102
+ }
103
+ export {};
@@ -24,7 +24,51 @@ import { PlayerCtor } from '@rpgjs/common';
24
24
  */
25
25
  export declare function WithVariableManager<TBase extends PlayerCtor>(Base: TBase): TBase;
26
26
  /**
27
- * Type helper to extract the interface from the WithVariableManager mixin
28
- * This provides the type without duplicating method signatures
27
+ * Interface for Variable Manager functionality
28
+ *
29
+ * Provides variable management capabilities including storing, retrieving, and managing
30
+ * key-value pairs for player-specific data. This interface defines the public API
31
+ * of the VariableManager mixin.
29
32
  */
30
- export type IVariableManager = InstanceType<ReturnType<typeof WithVariableManager>>;
33
+ export interface IVariableManager {
34
+ /** Map storing all player variables */
35
+ variables: Map<string, any>;
36
+ /**
37
+ * Assign a variable to the player
38
+ *
39
+ * @param key - The variable identifier
40
+ * @param val - The value to store
41
+ */
42
+ setVariable(key: string, val: any): void;
43
+ /**
44
+ * Get a variable value
45
+ *
46
+ * @param key - The variable identifier to retrieve
47
+ * @returns The stored value or undefined if not found
48
+ */
49
+ getVariable<U = any>(key: string): U | undefined;
50
+ /**
51
+ * Remove a variable
52
+ *
53
+ * @param key - The variable identifier to remove
54
+ * @returns true if a variable existed and has been removed, false otherwise
55
+ */
56
+ removeVariable(key: string): boolean;
57
+ /**
58
+ * Check if a variable exists
59
+ *
60
+ * @param key - The variable identifier to check
61
+ * @returns true if the variable exists, false otherwise
62
+ */
63
+ hasVariable(key: string): boolean;
64
+ /**
65
+ * Get all variable keys
66
+ *
67
+ * @returns Array of all variable keys
68
+ */
69
+ getVariableKeys(): string[];
70
+ /**
71
+ * Clear all variables
72
+ */
73
+ clearVariables(): void;
74
+ }