@rpgjs/server 5.0.0-alpha.26 → 5.0.0-alpha.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Player/MoveManager.d.ts +62 -1
- package/dist/Player/Player.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1419 -173
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/Player/MoveManager.ts +654 -112
- package/src/Player/Player.ts +18 -1
- package/src/index.ts +2 -1
- package/src/rooms/map.ts +2 -2
- package/tests/change-map.spec.ts +2 -2
- package/tests/event.spec.ts +80 -0
- package/tests/item.spec.ts +2 -2
- package/tests/move.spec.ts +601 -0
- package/tests/random-move.spec.ts +65 -0
|
@@ -3,6 +3,51 @@ import { RpgPlayer } from './Player';
|
|
|
3
3
|
type CallbackTileMove = (player: RpgPlayer, map: any) => Direction[];
|
|
4
4
|
type CallbackTurnMove = (player: RpgPlayer, map: any) => string;
|
|
5
5
|
type Routes = (string | Promise<any> | Direction | Direction[] | Function)[];
|
|
6
|
+
/**
|
|
7
|
+
* Options for moveRoutes method
|
|
8
|
+
*/
|
|
9
|
+
export interface MoveRoutesOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Callback function called when the player gets stuck (cannot move towards target)
|
|
12
|
+
*
|
|
13
|
+
* This callback is triggered when the player is trying to move but cannot make progress
|
|
14
|
+
* towards the target position, typically due to obstacles or collisions.
|
|
15
|
+
*
|
|
16
|
+
* @param player - The player instance that is stuck
|
|
17
|
+
* @param target - The target position the player was trying to reach
|
|
18
|
+
* @param currentPosition - The current position of the player
|
|
19
|
+
* @returns If true, the route will continue; if false, the route will be cancelled
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* await player.moveRoutes([Move.right()], {
|
|
24
|
+
* onStuck: (player, target, currentPos) => {
|
|
25
|
+
* console.log('Player is stuck!');
|
|
26
|
+
* return false; // Cancel the route
|
|
27
|
+
* }
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
onStuck?: (player: RpgPlayer, target: {
|
|
32
|
+
x: number;
|
|
33
|
+
y: number;
|
|
34
|
+
}, currentPosition: {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
}) => boolean | void;
|
|
38
|
+
/**
|
|
39
|
+
* Time in milliseconds to wait before considering the player stuck (default: 500ms)
|
|
40
|
+
*
|
|
41
|
+
* The player must be unable to make progress for this duration before onStuck is called.
|
|
42
|
+
*/
|
|
43
|
+
stuckTimeout?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Minimum distance change in pixels to consider movement progress (default: 1 pixel)
|
|
46
|
+
*
|
|
47
|
+
* If the player moves less than this distance over the stuckTimeout period, they are considered stuck.
|
|
48
|
+
*/
|
|
49
|
+
stuckThreshold?: number;
|
|
50
|
+
}
|
|
6
51
|
export declare enum Frequency {
|
|
7
52
|
Lowest = 600,
|
|
8
53
|
Lower = 400,
|
|
@@ -49,6 +94,21 @@ export declare enum Speed {
|
|
|
49
94
|
* @memberof Move
|
|
50
95
|
* */
|
|
51
96
|
declare class MoveList {
|
|
97
|
+
private static perlinNoise;
|
|
98
|
+
private static randomCounter;
|
|
99
|
+
private static callCounter;
|
|
100
|
+
/**
|
|
101
|
+
* Gets a random direction index (0-3) using a hybrid approach for balanced randomness
|
|
102
|
+
*
|
|
103
|
+
* Uses a combination of hash-based pseudo-randomness and Perlin noise to ensure
|
|
104
|
+
* fair distribution of directions while maintaining smooth, natural-looking movement patterns.
|
|
105
|
+
* The hash function guarantees uniform distribution, while Perlin noise adds spatial/temporal coherence.
|
|
106
|
+
*
|
|
107
|
+
* @param player - Optional player instance for coordinate-based noise
|
|
108
|
+
* @param index - Optional index for array-based calls to ensure variation
|
|
109
|
+
* @returns Direction index (0-3) corresponding to Right, Left, Up, Down
|
|
110
|
+
*/
|
|
111
|
+
private getRandomDirectionIndex;
|
|
52
112
|
repeatMove(direction: Direction, repeat: number): Direction[];
|
|
53
113
|
private repeatTileMove;
|
|
54
114
|
right(repeat?: number): Direction[];
|
|
@@ -283,9 +343,10 @@ export interface IMoveManager {
|
|
|
283
343
|
* Give an itinerary to follow using movement strategies
|
|
284
344
|
*
|
|
285
345
|
* @param routes - Array of movement instructions to execute
|
|
346
|
+
* @param options - Optional configuration including onStuck callback
|
|
286
347
|
* @returns Promise that resolves when all routes are completed
|
|
287
348
|
*/
|
|
288
|
-
moveRoutes(routes: Routes): Promise<boolean>;
|
|
349
|
+
moveRoutes(routes: Routes, options?: MoveRoutesOptions): Promise<boolean>;
|
|
289
350
|
/**
|
|
290
351
|
* Give a path that repeats itself in a loop to a character
|
|
291
352
|
*
|
package/dist/Player/Player.d.ts
CHANGED
|
@@ -459,10 +459,12 @@ export declare class RpgPlayer extends RpgPlayer_base {
|
|
|
459
459
|
* @param schema - The schema to set
|
|
460
460
|
*/
|
|
461
461
|
setSync(schema: any): void;
|
|
462
|
+
isEvent(): boolean;
|
|
462
463
|
}
|
|
463
464
|
export declare class RpgEvent extends RpgPlayer {
|
|
464
465
|
execMethod(methodName: string, methodData?: any[], instance?: this): Promise<any>;
|
|
465
466
|
remove(): void;
|
|
467
|
+
isEvent(): boolean;
|
|
466
468
|
}
|
|
467
469
|
/**
|
|
468
470
|
* Interface extension for RpgPlayer
|
package/dist/index.d.ts
CHANGED