@rpgjs/common 5.0.0-alpha.4 → 5.0.0-alpha.40

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.
Files changed (62) hide show
  1. package/dist/PerlinNoise.d.ts +167 -0
  2. package/dist/Player.d.ts +92 -89
  3. package/dist/PrebuiltGui.d.ts +3 -1
  4. package/dist/Presets.d.ts +9 -0
  5. package/dist/Shape.d.ts +100 -0
  6. package/dist/Utils.d.ts +1 -0
  7. package/dist/database/Item.d.ts +17 -1
  8. package/dist/database/Skill.d.ts +21 -0
  9. package/dist/database/index.d.ts +1 -0
  10. package/dist/index.d.ts +7 -2
  11. package/dist/index.js +8869 -13605
  12. package/dist/index.js.map +1 -1
  13. package/dist/modules.d.ts +17 -0
  14. package/dist/movement/MovementManager.d.ts +16 -72
  15. package/dist/movement/MovementStrategy.d.ts +1 -39
  16. package/dist/movement/index.d.ts +3 -12
  17. package/dist/rooms/Map.d.ts +498 -21
  18. package/dist/rooms/WorldMaps.d.ts +163 -0
  19. package/dist/services/save.d.ts +12 -0
  20. package/dist/weather.d.ts +27 -0
  21. package/package.json +8 -9
  22. package/src/PerlinNoise.ts +294 -0
  23. package/src/Player.ts +126 -149
  24. package/src/PrebuiltGui.ts +4 -2
  25. package/src/Presets.ts +9 -0
  26. package/src/Shape.ts +149 -0
  27. package/src/Utils.ts +4 -0
  28. package/src/database/Item.ts +27 -6
  29. package/src/database/Skill.ts +35 -0
  30. package/src/database/index.ts +2 -1
  31. package/src/index.ts +8 -3
  32. package/src/modules.ts +29 -1
  33. package/src/movement/MovementManager.ts +38 -119
  34. package/src/movement/MovementStrategy.ts +4 -42
  35. package/src/movement/index.ts +14 -15
  36. package/src/rooms/Map.ts +1505 -85
  37. package/src/rooms/WorldMaps.ts +269 -0
  38. package/src/services/save.ts +14 -0
  39. package/src/weather.ts +29 -0
  40. package/dist/Physic.d.ts +0 -619
  41. package/dist/movement/strategies/CompositeMovement.d.ts +0 -76
  42. package/dist/movement/strategies/Dash.d.ts +0 -52
  43. package/dist/movement/strategies/IceMovement.d.ts +0 -87
  44. package/dist/movement/strategies/Knockback.d.ts +0 -50
  45. package/dist/movement/strategies/LinearMove.d.ts +0 -43
  46. package/dist/movement/strategies/LinearRepulsion.d.ts +0 -55
  47. package/dist/movement/strategies/Oscillate.d.ts +0 -60
  48. package/dist/movement/strategies/PathFollow.d.ts +0 -78
  49. package/dist/movement/strategies/ProjectileMovement.d.ts +0 -138
  50. package/dist/movement/strategies/SeekAvoid.d.ts +0 -27
  51. package/src/Physic.ts +0 -1644
  52. package/src/movement/strategies/CompositeMovement.ts +0 -173
  53. package/src/movement/strategies/Dash.ts +0 -82
  54. package/src/movement/strategies/IceMovement.ts +0 -158
  55. package/src/movement/strategies/Knockback.ts +0 -81
  56. package/src/movement/strategies/LinearMove.ts +0 -58
  57. package/src/movement/strategies/LinearRepulsion.ts +0 -128
  58. package/src/movement/strategies/Oscillate.ts +0 -144
  59. package/src/movement/strategies/PathFollow.ts +0 -156
  60. package/src/movement/strategies/ProjectileMovement.ts +0 -322
  61. package/src/movement/strategies/SeekAvoid.ts +0 -123
  62. package/tests/physic.spec.ts +0 -454
@@ -1,52 +0,0 @@
1
- import { MovementStrategy } from '../MovementStrategy';
2
- import * as Matter from 'matter-js';
3
- /**
4
- * Implements a dash movement in a specified direction for a limited time
5
- *
6
- * Dash applies high velocity movement in a direction for a short duration
7
- *
8
- * @example
9
- * ```ts
10
- * // Dash right for 200ms at speed 10
11
- * movementManager.add('player1', new Dash(10, { x: 1, y: 0 }, 200));
12
- *
13
- * // Dash diagonally (normalized)
14
- * movementManager.add('player1', new Dash(8, { x: 0.7071, y: 0.7071 }, 150));
15
- * ```
16
- */
17
- export declare class Dash implements MovementStrategy {
18
- private speed;
19
- private direction;
20
- private duration;
21
- private elapsed;
22
- private finished;
23
- /**
24
- * Create a dash movement
25
- *
26
- * @param speed - Movement speed (pixels per frame)
27
- * @param direction - Normalized direction vector { x, y }
28
- * @param duration - Duration in milliseconds
29
- */
30
- constructor(speed: number, direction: {
31
- x: number;
32
- y: number;
33
- }, duration: number);
34
- /**
35
- * Apply dash movement to the body
36
- *
37
- * @param body - Matter.js body to move
38
- * @param dt - Time delta in milliseconds
39
- */
40
- update(body: Matter.Body, dt: number): void;
41
- /**
42
- * Check if dash duration has elapsed
43
- *
44
- * @returns True if dash is complete
45
- */
46
- isFinished(): boolean;
47
- /**
48
- * Optional callback for when dash completes
49
- * Can be used to chain into another movement
50
- */
51
- onFinished(): void;
52
- }
@@ -1,87 +0,0 @@
1
- import { MovementStrategy } from '../MovementStrategy';
2
- import * as Matter from 'matter-js';
3
- /**
4
- * Implements a slippery movement for icy surfaces
5
- *
6
- * Creates a realistic ice-physics effect with:
7
- * - Slow acceleration when starting to move
8
- * - Slippery inertia when stopping
9
- * - Gradual turning with momentum
10
- *
11
- * @example
12
- * ```ts
13
- * // Apply ice movement to player on ice terrain
14
- * movementManager.add('player1', new IceMovement({ x: 1, y: 0 }, 5));
15
- *
16
- * // Update direction when player changes direction
17
- * iceMovement.setTargetDirection({ x: 0, y: 1 });
18
- * ```
19
- */
20
- export declare class IceMovement implements MovementStrategy {
21
- private targetDirection;
22
- private maxSpeed;
23
- private acceleration;
24
- private friction;
25
- private duration?;
26
- private currentVx;
27
- private currentVy;
28
- private stopped;
29
- private elapsed;
30
- /**
31
- * Create an ice movement behavior
32
- *
33
- * @param targetDirection - Desired movement direction (normalized vector)
34
- * @param maxSpeed - Maximum speed when fully accelerated
35
- * @param acceleration - Acceleration rate (0-1, lower = more slippery start)
36
- * @param friction - Friction rate (0-1, lower = more slippery stop)
37
- * @param duration - Optional duration limit for the movement
38
- */
39
- constructor(targetDirection: {
40
- x: number;
41
- y: number;
42
- }, maxSpeed?: number, acceleration?: number, friction?: number, duration?: number | undefined);
43
- /**
44
- * Update the ice movement physics
45
- *
46
- * @param body - Matter.js body to move
47
- * @param dt - Time delta in milliseconds
48
- */
49
- update(body: Matter.Body, dt: number): void;
50
- /**
51
- * Check if movement is finished
52
- * (movement is considered finished when almost stopped)
53
- *
54
- * @returns True if movement is effectively stopped
55
- */
56
- isFinished(): boolean;
57
- /**
58
- * Stop the movement (will start applying friction)
59
- */
60
- stop(): void;
61
- /**
62
- * Resume movement in the current direction
63
- */
64
- resume(): void;
65
- /**
66
- * Set a new target direction
67
- * The actual movement will gradually change toward this direction
68
- *
69
- * @param direction - New target direction
70
- */
71
- setTargetDirection(direction: {
72
- x: number;
73
- y: number;
74
- }): void;
75
- /**
76
- * Set movement parameters
77
- *
78
- * @param maxSpeed - New maximum speed
79
- * @param acceleration - New acceleration rate
80
- * @param friction - New friction rate
81
- */
82
- setParameters(maxSpeed?: number, acceleration?: number, friction?: number): void;
83
- /**
84
- * Normalize the direction vector
85
- */
86
- private normalizeDirection;
87
- }
@@ -1,50 +0,0 @@
1
- import { MovementStrategy } from '../MovementStrategy';
2
- import * as Matter from 'matter-js';
3
- /**
4
- * Implements a knockback effect with decreasing force over time
5
- *
6
- * Applies an initial velocity that gradually decreases to simulate
7
- * being pushed back by an impact
8
- *
9
- * @example
10
- * ```ts
11
- * // Knockback player to the left with force 8 for 300ms
12
- * movementManager.add('player1', new Knockback({ x: -1, y: 0 }, 8, 300));
13
- *
14
- * // Knockback with decay (resistance)
15
- * movementManager.add('enemy1', new Knockback({ x: 0, y: 1 }, 5, 200, 0.9));
16
- * ```
17
- */
18
- export declare class Knockback implements MovementStrategy {
19
- private direction;
20
- private force;
21
- private duration;
22
- private decayFactor;
23
- private elapsed;
24
- private currentSpeed;
25
- /**
26
- * Create a knockback movement
27
- *
28
- * @param direction - Normalized direction vector { x, y }
29
- * @param force - Initial force of the knockback
30
- * @param duration - Duration in milliseconds
31
- * @param decayFactor - Speed decay multiplier per frame (0.8-0.95 typical)
32
- */
33
- constructor(direction: {
34
- x: number;
35
- y: number;
36
- }, force: number, duration: number, decayFactor?: number);
37
- /**
38
- * Apply knockback movement with decreasing force
39
- *
40
- * @param body - Matter.js body to move
41
- * @param dt - Time delta in milliseconds
42
- */
43
- update(body: Matter.Body, dt: number): void;
44
- /**
45
- * Check if knockback duration has elapsed
46
- *
47
- * @returns True if knockback is complete
48
- */
49
- isFinished(): boolean;
50
- }
@@ -1,43 +0,0 @@
1
- import { MovementStrategy } from '../MovementStrategy';
2
- import * as Matter from 'matter-js';
3
- /**
4
- * Applies constant velocity movement in a specified direction
5
- *
6
- * Used for simple linear movement at a constant speed
7
- *
8
- * @example
9
- * ```ts
10
- * // Move entity right at 5 pixels per frame
11
- * movementManager.add('entity1', new LinearMove(5, 0));
12
- *
13
- * // Move diagonally
14
- * movementManager.add('entity1', new LinearMove(3, 3));
15
- * ```
16
- */
17
- export declare class LinearMove implements MovementStrategy {
18
- private vx;
19
- private vy;
20
- private duration?;
21
- /**
22
- * Create a linear movement
23
- *
24
- * @param vx - X velocity component
25
- * @param vy - Y velocity component
26
- * @param duration - Optional duration in milliseconds (if not set, movement continues indefinitely)
27
- */
28
- constructor(vx: number, vy: number, duration?: number | undefined);
29
- private elapsed;
30
- /**
31
- * Apply velocity to the body
32
- *
33
- * @param body - Matter.js body to move
34
- * @param dt - Time delta in milliseconds
35
- */
36
- update(body: Matter.Body, dt: number): void;
37
- /**
38
- * Check if movement duration has elapsed
39
- *
40
- * @returns True if movement should stop
41
- */
42
- isFinished(): boolean;
43
- }
@@ -1,55 +0,0 @@
1
- import { RpgCommonPhysic } from '../../Physic';
2
- import { MovementStrategy } from '../MovementStrategy';
3
- import * as Matter from 'matter-js';
4
- /**
5
- * Implements a seek behavior with linear obstacle avoidance
6
- *
7
- * Similar to SeekAvoid but uses a linear repulsion model instead of inverse square.
8
- * This creates a smoother avoidance field with gradual transitions.
9
- *
10
- * @example
11
- * ```ts
12
- * // Make enemy follow player with smooth avoidance
13
- * const playerPosition = () => Matter.Vector.create(player.x(), player.y());
14
- * movementManager.add('enemy1', new LinearRepulsion(physics, playerPosition, 3, 50, 5));
15
- * ```
16
- */
17
- export declare class LinearRepulsion implements MovementStrategy {
18
- private phys;
19
- private target;
20
- private maxSpeed;
21
- private repulseRadius;
22
- private repulseWeight;
23
- private repulseRadius2;
24
- /**
25
- * Create a seeking movement with linear obstacle avoidance
26
- *
27
- * @param phys - Physics system to query for nearby obstacles
28
- * @param target - Function returning the current target position
29
- * @param maxSpeed - Maximum movement speed
30
- * @param repulseRadius - Radius around entity to check for obstacles
31
- * @param repulseWeight - Strength of repulsion from obstacles
32
- */
33
- constructor(phys: RpgCommonPhysic, target: () => Matter.Vector, maxSpeed?: number, repulseRadius?: number, repulseWeight?: number);
34
- /**
35
- * Update seek and avoid behavior with linear repulsion
36
- *
37
- * @param body - Matter.js body to move
38
- * @param dt - Time delta in milliseconds
39
- */
40
- update(body: Matter.Body, dt: number): void;
41
- /**
42
- * Update the target to follow
43
- *
44
- * @param newTarget - Function returning the new target position
45
- */
46
- setTarget(newTarget: () => Matter.Vector): void;
47
- /**
48
- * Update movement parameters
49
- *
50
- * @param maxSpeed - New maximum speed
51
- * @param repulseRadius - New repulsion radius
52
- * @param repulseWeight - New repulsion weight
53
- */
54
- setParameters(maxSpeed?: number, repulseRadius?: number, repulseWeight?: number): void;
55
- }
@@ -1,60 +0,0 @@
1
- import { MovementStrategy } from '../MovementStrategy';
2
- import * as Matter from 'matter-js';
3
- /**
4
- * Implements an oscillating movement pattern
5
- *
6
- * Entity moves back and forth along a single axis or in a pattern
7
- * like sine wave, useful for patrols or ambient movements
8
- *
9
- * @example
10
- * ```ts
11
- * // Horizontal oscillation with amplitude 100 and period 3000ms
12
- * movementManager.add('entity1', new Oscillate({ x: 1, y: 0 }, 100, 3000));
13
- *
14
- * // Vertical oscillation
15
- * movementManager.add('entity1', new Oscillate({ x: 0, y: 1 }, 50, 2000));
16
- *
17
- * // Circular oscillation
18
- * movementManager.add('entity1', new Oscillate({ x: 1, y: 0 }, 100, 4000, 'circular'));
19
- * ```
20
- */
21
- export declare class Oscillate implements MovementStrategy {
22
- private direction;
23
- private amplitude;
24
- private period;
25
- private type;
26
- private duration?;
27
- private elapsed;
28
- private startPosition;
29
- private positionSet;
30
- /**
31
- * Create an oscillating movement
32
- *
33
- * @param direction - Primary axis of oscillation (normalized)
34
- * @param amplitude - Maximum distance from center position
35
- * @param period - Time in ms for a complete cycle
36
- * @param type - Oscillation pattern type ('linear', 'sine', 'circular')
37
- * @param duration - Optional total duration in ms (undefined for infinite)
38
- */
39
- constructor(direction: {
40
- x: number;
41
- y: number;
42
- }, amplitude: number, period: number, type?: 'linear' | 'sine' | 'circular', duration?: number | undefined);
43
- /**
44
- * Apply oscillating movement
45
- *
46
- * @param body - Matter.js body to move
47
- * @param dt - Time delta in milliseconds
48
- */
49
- update(body: Matter.Body, dt: number): void;
50
- /**
51
- * Check if oscillation duration has elapsed
52
- *
53
- * @returns True if movement is finished
54
- */
55
- isFinished(): boolean;
56
- /**
57
- * Reset the oscillation to start from the current position
58
- */
59
- reset(): void;
60
- }
@@ -1,78 +0,0 @@
1
- import { MovementStrategy } from '../MovementStrategy';
2
- import * as Matter from 'matter-js';
3
- /**
4
- * Implements a path following movement that navigates through waypoints
5
- *
6
- * The entity will follow a sequence of waypoints at a specified speed,
7
- * with optional looping behavior.
8
- *
9
- * @example
10
- * ```ts
11
- * // Create a patrol path for an NPC
12
- * const waypoints = [
13
- * { x: 100, y: 100 },
14
- * { x: 300, y: 100 },
15
- * { x: 300, y: 300 },
16
- * { x: 100, y: 300 }
17
- * ];
18
- *
19
- * // Follow path once
20
- * movementManager.add('npc1', new PathFollow(waypoints, 3));
21
- *
22
- * // Loop indefinitely (patrol)
23
- * movementManager.add('npc1', new PathFollow(waypoints, 3, true));
24
- * ```
25
- */
26
- export declare class PathFollow implements MovementStrategy {
27
- private waypoints;
28
- private speed;
29
- private loop;
30
- private pauseAtWaypoints;
31
- private currentWaypoint;
32
- private finished;
33
- private direction;
34
- private waypointThreshold;
35
- /**
36
- * Create a path following movement
37
- *
38
- * @param waypoints - Array of x,y positions to follow
39
- * @param speed - Movement speed in pixels per frame
40
- * @param loop - Whether to loop back to start after reaching final waypoint
41
- * @param pauseAtWaypoints - Optional time in ms to pause at each waypoint
42
- */
43
- constructor(waypoints: Array<{
44
- x: number;
45
- y: number;
46
- }>, speed: number, loop?: boolean, pauseAtWaypoints?: number);
47
- private pauseTimer;
48
- private isPaused;
49
- /**
50
- * Update path following logic
51
- *
52
- * @param body - Matter.js body to move
53
- * @param dt - Time delta in milliseconds
54
- */
55
- update(body: Matter.Body, dt: number): void;
56
- /**
57
- * Check if path has been fully traversed
58
- *
59
- * @returns True if path following is complete
60
- */
61
- isFinished(): boolean;
62
- /**
63
- * Get current waypoint index
64
- *
65
- * @returns The index of the current target waypoint
66
- */
67
- getCurrentWaypoint(): number;
68
- /**
69
- * Set a new path of waypoints
70
- *
71
- * @param waypoints - New waypoints to follow
72
- * @param resetProgress - Whether to start from the first waypoint
73
- */
74
- setWaypoints(waypoints: Array<{
75
- x: number;
76
- y: number;
77
- }>, resetProgress?: boolean): void;
78
- }
@@ -1,138 +0,0 @@
1
- import { MovementStrategy } from '../MovementStrategy';
2
- import * as Matter from 'matter-js';
3
- /**
4
- * Type of projectile trajectory
5
- */
6
- export declare enum ProjectileType {
7
- /** Straight line movement (arrows, bullets) */
8
- Straight = "straight",
9
- /** Parabolic arc (grenades, bombs) */
10
- Arc = "arc",
11
- /** Bouncing projectile (bouncing bombs, coins) */
12
- Bounce = "bounce"
13
- }
14
- /**
15
- * Projectile configuration options
16
- */
17
- export interface ProjectileOptions {
18
- /** Initial velocity in pixels per second */
19
- speed: number;
20
- /** Direction vector (will be normalized) */
21
- direction: {
22
- x: number;
23
- y: number;
24
- };
25
- /** Maximum range in pixels before projectile disappears */
26
- maxRange?: number;
27
- /** Maximum lifetime in milliseconds */
28
- lifetime?: number;
29
- /** Initial height (Z coordinate) */
30
- initialHeight?: number;
31
- /** Maximum height of arc trajectory */
32
- maxHeight?: number;
33
- /** Gravity strength (pixels/second²) */
34
- gravity?: number;
35
- /** Number of bounces allowed (for bouncing projectiles) */
36
- maxBounces?: number;
37
- /** Energy retained after each bounce (0-1) */
38
- bounciness?: number;
39
- /** Air resistance/drag (0-1) */
40
- drag?: number;
41
- }
42
- /**
43
- * Implements projectile movement with various trajectory types
44
- *
45
- * Supports:
46
- * - Straight movement (arrows, bullets)
47
- * - Parabolic arcs (thrown objects, grenades)
48
- * - Bouncing projectiles (coins, bouncing bombs)
49
- *
50
- * The z-coordinate represents height above ground for 3D effects
51
- *
52
- * @example
53
- * ```ts
54
- * // Create an arrow (straight projectile)
55
- * const arrow = new ProjectileMovement(ProjectileType.Straight, {
56
- * speed: 300,
57
- * direction: { x: 1, y: 0 },
58
- * maxRange: 500
59
- * });
60
- *
61
- * // Create a thrown bomb (arc projectile)
62
- * const bomb = new ProjectileMovement(ProjectileType.Arc, {
63
- * speed: 150,
64
- * direction: { x: 0.7, y: 0.7 },
65
- * maxHeight: 100,
66
- * gravity: 400
67
- * });
68
- *
69
- * // Create bouncing coins (random directions with bounce)
70
- * function spawnCoin(x, y) {
71
- * const randomAngle = Math.random() * Math.PI * 2;
72
- * const coin = new ProjectileMovement(ProjectileType.Bounce, {
73
- * speed: 80 + Math.random() * 40,
74
- * direction: {
75
- * x: Math.cos(randomAngle),
76
- * y: Math.sin(randomAngle)
77
- * },
78
- * initialHeight: 0,
79
- * maxHeight: 20 + Math.random() * 30,
80
- * gravity: 500,
81
- * maxBounces: 2,
82
- * bounciness: 0.6
83
- * });
84
- *
85
- * // Create coin entity and add to the world
86
- * // movementManager.add(coinId, coin);
87
- * }
88
- * ```
89
- */
90
- export declare class ProjectileMovement implements MovementStrategy {
91
- private type;
92
- private options;
93
- private elapsed;
94
- private distanceTraveled;
95
- private startPosition;
96
- private bounceCount;
97
- private stage;
98
- private finished;
99
- private currentHeight;
100
- private verticalVelocity;
101
- private normalizedDirection;
102
- private readonly defaultOptions;
103
- /**
104
- * Create a projectile movement
105
- *
106
- * @param type - Type of projectile trajectory
107
- * @param options - Projectile configuration
108
- */
109
- constructor(type: ProjectileType, options: ProjectileOptions);
110
- /**
111
- * Update projectile movement
112
- *
113
- * @param body - Matter.js body to move
114
- * @param dt - Time delta in milliseconds
115
- */
116
- update(body: Matter.Body, dt: number): void;
117
- /**
118
- * Update projectile while in flying stage
119
- */
120
- private updateFlying;
121
- /**
122
- * Update projectile while in bouncing stage (rolling/sliding)
123
- */
124
- private updateBouncing;
125
- /**
126
- * Check if projectile has completed its trajectory
127
- */
128
- isFinished(): boolean;
129
- /**
130
- * Get current height of projectile above ground
131
- */
132
- getHeight(): number;
133
- /**
134
- * Get position along trajectory (0 to 1)
135
- * Useful for animation progress
136
- */
137
- getProgress(): number;
138
- }
@@ -1,27 +0,0 @@
1
- import { RpgCommonPhysic } from '../../Physic';
2
- import { MovementStrategy } from '../MovementStrategy';
3
- import * as Matter from 'matter-js';
4
- export declare class SeekAvoid implements MovementStrategy {
5
- private phys;
6
- private targetBody?;
7
- private maxSpeed;
8
- private repulseRadius;
9
- private repulseWeight;
10
- private arriveRadius;
11
- private repulseRadius2;
12
- private arriveRadius2;
13
- /** (4 px)² : plancher pour éviter les divisions par 0 */
14
- private readonly EPS2;
15
- /**
16
- * @param phys Monde physique
17
- * @param target Fonction → position à suivre
18
- * @param maxSpeed Vitesse max (px / ms)
19
- * @param repulseRadius Rayon de répulsion
20
- * @param repulseWeight Intensité de la répulsion
21
- * @param arriveRadius Rayon dans lequel on “arrive” (≃ taille hitbox)
22
- * @param getTargetBody (optionnel) fonction → body de la cible pour l’ignorer
23
- */
24
- constructor(phys: RpgCommonPhysic, targetBody?: Matter.Body, maxSpeed?: number, repulseRadius?: number, repulseWeight?: number, arriveRadius?: number);
25
- update(body: Matter.Body, dt: number): void;
26
- setParameters(max?: number, repR?: number, repW?: number, arrR?: number): void;
27
- }