@rpgjs/server 5.0.0-alpha.33 → 5.0.0-alpha.35

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.
@@ -410,6 +410,47 @@ describe('Map WorldMapsManager Integration', () => {
410
410
  expect(worldX2).toBe(1074)
411
411
  expect(worldY2).toBe(100)
412
412
  })
413
+
414
+ test('should keep movement sync after returning to initial map', async () => {
415
+ player = await client.waitForMapChange('map1')
416
+
417
+ await player.changeMap('map2', { x: 50, y: 100 })
418
+ player = await client.waitForMapChange('map2')
419
+ expect(player.getCurrentMap()?.id).toBe('map2')
420
+
421
+ await player.changeMap('map1', { x: 100, y: 100 })
422
+ player = await client.waitForMapChange('map1')
423
+ const map = player.getCurrentMap()
424
+ expect(map?.id).toBe('map1')
425
+
426
+ const beforeX = player.x()
427
+ await map?.movePlayer(player as any, Direction.Right)
428
+ map?.nextTick(16)
429
+ await new Promise(resolve => setTimeout(resolve, 10))
430
+
431
+ expect(player.x()).toBeGreaterThan(beforeX)
432
+ })
433
+
434
+ test('should keep restored player position after loadPhysic rebuild', async () => {
435
+ player = await client.waitForMapChange('map1')
436
+ const map = player.getCurrentMap()
437
+ expect(map).toBeDefined()
438
+
439
+ await player.teleport({ x: 0, y: 0 })
440
+ map?.loadPhysic()
441
+
442
+ // Simulate a late position restore (e.g. session transfer snapshot hydration).
443
+ player.x.set(100)
444
+ player.y.set(100)
445
+ await new Promise(resolve => setTimeout(resolve, 10))
446
+
447
+ const topLeft = map?.getBodyPosition(player.id, 'top-left')
448
+ expect(topLeft).toBeDefined()
449
+ expect(Math.round(topLeft!.x)).toBe(100)
450
+ expect(Math.round(topLeft!.y)).toBe(100)
451
+ expect(player.x()).toBe(100)
452
+ expect(player.y()).toBe(100)
453
+ })
413
454
  })
414
455
 
415
456
  /**
@@ -588,6 +629,47 @@ describe('Automatic Map Change on Border Touch', () => {
588
629
  }
589
630
  })
590
631
 
632
+ test('should not immediately bounce back after returning from adjacent map', async () => {
633
+ player = await client.waitForMapChange('map1')
634
+ await player.autoChangeMap({ x: 513, y: 384 }, Direction.Right)
635
+
636
+ const hitbox = player.hitbox()
637
+ const marginTopDown = 16 // tileHeight / 2
638
+ const topBorderY = marginTopDown - 1
639
+
640
+ player.changeDirection(Direction.Up)
641
+ await player.teleport({ x: 512, y: topBorderY })
642
+ const movedUp = await player.autoChangeMap({ x: 512, y: topBorderY - 1 }, Direction.Up)
643
+ expect(movedUp).toBe(true)
644
+
645
+ player = await client.waitForMapChange('map4')
646
+ expect(player.getCurrentMap()?.id).toBe('map4')
647
+
648
+ const map4 = player.getCurrentMap()
649
+ const bottomBorderY = (map4?.heightPx ?? 768) - hitbox.h - marginTopDown + 1
650
+
651
+ player.changeDirection(Direction.Down)
652
+ await player.teleport({ x: 512, y: bottomBorderY })
653
+ // First downward move after return should be blocked to avoid ping-pong map swaps.
654
+ const firstDownAttempt = await player.autoChangeMap({ x: 512, y: bottomBorderY + 1 }, Direction.Down)
655
+ expect(firstDownAttempt).toBe(false)
656
+
657
+ // Move away from border to unlock transitions, then touch border again.
658
+ await player.teleport({ x: 512, y: 384 })
659
+ player.changeDirection(Direction.Up)
660
+ await player.autoChangeMap({ x: 512, y: 383 }, Direction.Up)
661
+
662
+ const mapAfterUnlock = player.getCurrentMap()
663
+ const downBorderY = (mapAfterUnlock?.heightPx ?? 768) - hitbox.h - marginTopDown + 1
664
+ await player.teleport({ x: 512, y: downBorderY })
665
+ player.changeDirection(Direction.Down)
666
+ const movedDown = await player.autoChangeMap({ x: 512, y: downBorderY + 1 }, Direction.Down)
667
+ expect(movedDown).toBe(true)
668
+
669
+ player = await client.waitForMapChange('map1')
670
+ expect(player.getCurrentMap()?.id).toBe('map1')
671
+ })
672
+
591
673
  test('should not change map when player is not at border', async () => {
592
674
  player = await client.waitForMapChange('map1')
593
675
  const initialMapId = player.getCurrentMap()?.id
@@ -811,4 +893,4 @@ describe('Automatic Map Change with Non-Adjacent Maps', () => {
811
893
  expect(map2Info).toBeDefined()
812
894
  expect(map2Info?.worldX).toBe(1025) // Gap exists
813
895
  })
814
- })
896
+ })