@rpgjs/server 5.0.0-alpha.15 → 5.0.0-alpha.16
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/index.js +126 -14
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/Player/Player.ts +4 -1
package/dist/index.js
CHANGED
|
@@ -12545,6 +12545,48 @@ class Entity {
|
|
|
12545
12545
|
this.force.set(0, 0);
|
|
12546
12546
|
this.torque = 0;
|
|
12547
12547
|
}
|
|
12548
|
+
/**
|
|
12549
|
+
* Stops all movement immediately
|
|
12550
|
+
*
|
|
12551
|
+
* Completely stops the entity's movement by:
|
|
12552
|
+
* - Setting velocity to zero
|
|
12553
|
+
* - Setting angular velocity to zero
|
|
12554
|
+
* - Clearing accumulated forces and torques
|
|
12555
|
+
* - Waking up the entity if it was sleeping
|
|
12556
|
+
* - Notifying movement state change
|
|
12557
|
+
*
|
|
12558
|
+
* Unlike `freeze()`, this method keeps the entity dynamic and does not
|
|
12559
|
+
* change its state. It's useful for stopping movement when changing maps,
|
|
12560
|
+
* teleporting, or when you need to halt an entity without making it static.
|
|
12561
|
+
*
|
|
12562
|
+
* @returns This entity for chaining
|
|
12563
|
+
*
|
|
12564
|
+
* @example
|
|
12565
|
+
* ```ts
|
|
12566
|
+
* // Stop movement when changing maps
|
|
12567
|
+
* if (mapChanged) {
|
|
12568
|
+
* entity.stopMovement();
|
|
12569
|
+
* }
|
|
12570
|
+
*
|
|
12571
|
+
* // Stop movement after teleporting
|
|
12572
|
+
* entity.position.set(100, 200);
|
|
12573
|
+
* entity.stopMovement();
|
|
12574
|
+
*
|
|
12575
|
+
* // Stop movement when player dies
|
|
12576
|
+
* if (player.isDead()) {
|
|
12577
|
+
* playerEntity.stopMovement();
|
|
12578
|
+
* }
|
|
12579
|
+
* ```
|
|
12580
|
+
*/
|
|
12581
|
+
stopMovement() {
|
|
12582
|
+
this.velocity.set(0, 0);
|
|
12583
|
+
this.angularVelocity = 0;
|
|
12584
|
+
this.clearForces();
|
|
12585
|
+
this.wakeUp();
|
|
12586
|
+
this.notifyMovementChange();
|
|
12587
|
+
this.notifyDirectionChange();
|
|
12588
|
+
return this;
|
|
12589
|
+
}
|
|
12548
12590
|
/**
|
|
12549
12591
|
* Clamps velocities to maximum values
|
|
12550
12592
|
*/
|
|
@@ -15404,6 +15446,47 @@ let MovementManager$1 = class MovementManager {
|
|
|
15404
15446
|
const body = this.resolveTarget(target);
|
|
15405
15447
|
this.entries.delete(body.id);
|
|
15406
15448
|
}
|
|
15449
|
+
/**
|
|
15450
|
+
* Stops all movement for an entity immediately
|
|
15451
|
+
*
|
|
15452
|
+
* This method completely stops an entity's movement by:
|
|
15453
|
+
* - Removing all active movement strategies (dash, linear moves, etc.)
|
|
15454
|
+
* - Stopping the entity's velocity and angular velocity
|
|
15455
|
+
* - Clearing accumulated forces
|
|
15456
|
+
* - Waking up the entity if it was sleeping
|
|
15457
|
+
*
|
|
15458
|
+
* This is useful when changing maps, teleporting, or when you need
|
|
15459
|
+
* to halt an entity's movement completely without making it static.
|
|
15460
|
+
*
|
|
15461
|
+
* @param target - Entity, MovementBody, or identifier
|
|
15462
|
+
*
|
|
15463
|
+
* @example
|
|
15464
|
+
* ```ts
|
|
15465
|
+
* // Stop movement when changing maps
|
|
15466
|
+
* if (mapChanged) {
|
|
15467
|
+
* movement.stopMovement(playerEntity);
|
|
15468
|
+
* }
|
|
15469
|
+
*
|
|
15470
|
+
* // Stop movement after teleporting
|
|
15471
|
+
* entity.position.set(100, 200);
|
|
15472
|
+
* movement.stopMovement(entity);
|
|
15473
|
+
*
|
|
15474
|
+
* // Stop movement when player dies
|
|
15475
|
+
* if (player.isDead()) {
|
|
15476
|
+
* movement.stopMovement(playerEntity);
|
|
15477
|
+
* }
|
|
15478
|
+
* ```
|
|
15479
|
+
*/
|
|
15480
|
+
stopMovement(target) {
|
|
15481
|
+
const body = this.resolveTarget(target);
|
|
15482
|
+
this.clear(target);
|
|
15483
|
+
if ("getEntity" in body && typeof body.getEntity === "function") {
|
|
15484
|
+
const entity = body.getEntity();
|
|
15485
|
+
if (entity && typeof entity.stopMovement === "function") {
|
|
15486
|
+
entity.stopMovement();
|
|
15487
|
+
}
|
|
15488
|
+
}
|
|
15489
|
+
}
|
|
15407
15490
|
/**
|
|
15408
15491
|
* Checks if an entity has active strategies.
|
|
15409
15492
|
*
|
|
@@ -17004,6 +17087,9 @@ class MovementManager {
|
|
|
17004
17087
|
clear(id) {
|
|
17005
17088
|
this.core.clear(id);
|
|
17006
17089
|
}
|
|
17090
|
+
stopMovement(id) {
|
|
17091
|
+
this.core.stopMovement(id);
|
|
17092
|
+
}
|
|
17007
17093
|
hasActiveStrategies(id) {
|
|
17008
17094
|
return this.core.hasActiveStrategies(id);
|
|
17009
17095
|
}
|
|
@@ -17192,6 +17278,7 @@ class RpgCommonMap {
|
|
|
17192
17278
|
if (typeof player.autoChangeMap === "function") {
|
|
17193
17279
|
const mapChanged = await player.autoChangeMap({ x: nextX, y: nextY }, direction);
|
|
17194
17280
|
if (mapChanged) {
|
|
17281
|
+
this.stopMovement(player);
|
|
17195
17282
|
return;
|
|
17196
17283
|
}
|
|
17197
17284
|
}
|
|
@@ -17564,11 +17651,12 @@ class RpgCommonMap {
|
|
|
17564
17651
|
if (!options || typeof options.owner?.id !== "string") {
|
|
17565
17652
|
throw new Error("Character requires an owner object with a string id");
|
|
17566
17653
|
}
|
|
17567
|
-
const
|
|
17568
|
-
const
|
|
17654
|
+
const owner = options.owner;
|
|
17655
|
+
const id = owner.id;
|
|
17656
|
+
const radius = owner.hitbox?.w ?? options.radius ?? 25;
|
|
17569
17657
|
const diameter = radius * 2;
|
|
17570
|
-
const topLeftX =
|
|
17571
|
-
const topLeftY =
|
|
17658
|
+
const topLeftX = owner.x() - radius;
|
|
17659
|
+
const topLeftY = owner.y() - radius;
|
|
17572
17660
|
const centerX = topLeftX + diameter / 2;
|
|
17573
17661
|
const centerY = topLeftY + diameter / 2;
|
|
17574
17662
|
const isStatic = !!options.isStatic;
|
|
@@ -17587,17 +17675,15 @@ class RpgCommonMap {
|
|
|
17587
17675
|
} else {
|
|
17588
17676
|
entity.unfreeze();
|
|
17589
17677
|
}
|
|
17590
|
-
entity.owner =
|
|
17678
|
+
entity.owner = owner;
|
|
17591
17679
|
entity.onDirectionChange(({ cardinalDirection }) => {
|
|
17592
17680
|
if (!("$send" in this)) return;
|
|
17593
|
-
const
|
|
17594
|
-
if (!
|
|
17681
|
+
const owner2 = entity.owner;
|
|
17682
|
+
if (!owner2) return;
|
|
17595
17683
|
if (cardinalDirection === "idle") return;
|
|
17596
|
-
|
|
17684
|
+
owner2.changeDirection(cardinalDirection);
|
|
17597
17685
|
});
|
|
17598
17686
|
entity.onMovementChange(({ isMoving, intensity }) => {
|
|
17599
|
-
const owner = entity.owner;
|
|
17600
|
-
if (!owner) return;
|
|
17601
17687
|
const LOW_INTENSITY_THRESHOLD = 10;
|
|
17602
17688
|
if (isMoving && intensity > LOW_INTENSITY_THRESHOLD) {
|
|
17603
17689
|
owner.animationName.set("walk");
|
|
@@ -17606,8 +17692,6 @@ class RpgCommonMap {
|
|
|
17606
17692
|
}
|
|
17607
17693
|
});
|
|
17608
17694
|
entity.onPositionChange(({ x, y }) => {
|
|
17609
|
-
const owner = entity.owner;
|
|
17610
|
-
if (!owner) return;
|
|
17611
17695
|
const width = entity.width || (entity.radius ? entity.radius * 2 : 32);
|
|
17612
17696
|
const height = entity.height || (entity.radius ? entity.radius * 2 : 32);
|
|
17613
17697
|
const topLeftX2 = x - width / 2;
|
|
@@ -17700,15 +17784,40 @@ class RpgCommonMap {
|
|
|
17700
17784
|
}
|
|
17701
17785
|
/**
|
|
17702
17786
|
* Stop movement for a player
|
|
17787
|
+
*
|
|
17788
|
+
* Completely stops all movement for a player, including:
|
|
17789
|
+
* - Clearing all active movement strategies (dash, linear moves, etc.)
|
|
17790
|
+
* - Setting velocity to zero
|
|
17791
|
+
* - Resetting intended direction
|
|
17792
|
+
*
|
|
17793
|
+
* This method is particularly useful when changing maps to ensure
|
|
17794
|
+
* the player doesn't carry over movement from the previous map.
|
|
17795
|
+
*
|
|
17796
|
+
* @param player - The player to stop
|
|
17797
|
+
* @returns True if the player was found and movement was stopped
|
|
17798
|
+
*
|
|
17799
|
+
* @example
|
|
17800
|
+
* ```ts
|
|
17801
|
+
* // Stop player movement when changing maps
|
|
17802
|
+
* if (mapChanged) {
|
|
17803
|
+
* map.stopMovement(player);
|
|
17804
|
+
* }
|
|
17805
|
+
*
|
|
17806
|
+
* // Stop movement when player dies
|
|
17807
|
+
* if (player.isDead()) {
|
|
17808
|
+
* map.stopMovement(player);
|
|
17809
|
+
* }
|
|
17810
|
+
* ```
|
|
17703
17811
|
* @protected
|
|
17704
17812
|
*/
|
|
17705
17813
|
stopMovement(player) {
|
|
17706
17814
|
const entity = this.physic.getEntityByUUID(player.id);
|
|
17707
17815
|
if (!entity) return false;
|
|
17816
|
+
this.moveManager.stopMovement(player.id);
|
|
17708
17817
|
if (typeof player.setIntendedDirection === "function") {
|
|
17709
17818
|
player.setIntendedDirection(null);
|
|
17710
17819
|
}
|
|
17711
|
-
|
|
17820
|
+
player.pendingInputs = [];
|
|
17712
17821
|
return true;
|
|
17713
17822
|
}
|
|
17714
17823
|
/**
|
|
@@ -22376,7 +22485,10 @@ const _RpgPlayer = class _RpgPlayer extends BasicPlayerMixins(RpgCommonPlayer) {
|
|
|
22376
22485
|
async teleport(positions) {
|
|
22377
22486
|
if (!this.map) return false;
|
|
22378
22487
|
if (this.map.physic) {
|
|
22379
|
-
this.map.physic.
|
|
22488
|
+
const entity = this.map.physic.getEntityByUUID(this.id);
|
|
22489
|
+
if (entity) {
|
|
22490
|
+
this.map.physic.teleport(entity, { x: positions.x, y: positions.y });
|
|
22491
|
+
}
|
|
22380
22492
|
} else {
|
|
22381
22493
|
this.x.set(positions.x);
|
|
22382
22494
|
this.y.set(positions.y);
|