@rpgjs/server 5.0.0-alpha.25 → 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 +33 -22
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1827 -365
- package/dist/index.js.map +1 -1
- package/dist/rooms/BaseRoom.d.ts +95 -0
- package/dist/rooms/lobby.d.ts +4 -1
- package/dist/rooms/map.d.ts +17 -75
- package/package.json +10 -10
- package/src/Player/ItemManager.ts +50 -15
- package/src/Player/MoveManager.ts +654 -112
- package/src/Player/Player.ts +179 -136
- package/src/index.ts +2 -1
- package/src/module.ts +13 -0
- package/src/rooms/BaseRoom.ts +120 -0
- package/src/rooms/lobby.ts +11 -1
- package/src/rooms/map.ts +70 -146
- package/tests/change-map.spec.ts +2 -2
- package/tests/event.spec.ts +80 -0
- package/tests/item.spec.ts +455 -441
- package/tests/move.spec.ts +601 -0
- package/tests/random-move.spec.ts +65 -0
- package/tests/world-maps.spec.ts +43 -81
package/tests/world-maps.spec.ts
CHANGED
|
@@ -96,7 +96,7 @@ describe('WorldMapsManager', () => {
|
|
|
96
96
|
{ id: 'map3', worldX: 0, worldY: 768, width: 1024, height: 768 },
|
|
97
97
|
])
|
|
98
98
|
|
|
99
|
-
const currentMap = { worldX: 0, worldY: 0,
|
|
99
|
+
const currentMap = { worldX: 0, worldY: 0, widthPx: 1024, heightPx: 768 }
|
|
100
100
|
|
|
101
101
|
// Point inside map1
|
|
102
102
|
const maps1 = worldMaps.getAdjacentMaps(currentMap, { x: 500, y: 500 })
|
|
@@ -126,7 +126,7 @@ describe('WorldMapsManager', () => {
|
|
|
126
126
|
{ id: 'map5', worldX: -1024, worldY: 0, width: 1024, height: 768 }, // Left - touches but doesn't overlap
|
|
127
127
|
])
|
|
128
128
|
|
|
129
|
-
const currentMap = { worldX: 0, worldY: 0,
|
|
129
|
+
const currentMap = { worldX: 0, worldY: 0, widthPx: 1024, heightPx: 768 }
|
|
130
130
|
|
|
131
131
|
// Note: The direction-based lookup requires maps to overlap, not just touch
|
|
132
132
|
// Since the current implementation checks for overlap, maps that just touch won't be found
|
|
@@ -164,7 +164,7 @@ describe('WorldMapsManager', () => {
|
|
|
164
164
|
{ id: 'map3', worldX: 0, worldY: 768, width: 1024, height: 768 },
|
|
165
165
|
])
|
|
166
166
|
|
|
167
|
-
const currentMap = { worldX: 0, worldY: 0,
|
|
167
|
+
const currentMap = { worldX: 0, worldY: 0, widthPx: 1024, heightPx: 768 }
|
|
168
168
|
|
|
169
169
|
// Box overlapping map1 and map2
|
|
170
170
|
const maps1 = worldMaps.getAdjacentMaps(currentMap, {
|
|
@@ -301,10 +301,8 @@ describe('Map WorldMapsManager Integration', () => {
|
|
|
301
301
|
player = client.player
|
|
302
302
|
})
|
|
303
303
|
|
|
304
|
-
afterEach(() => {
|
|
305
|
-
|
|
306
|
-
fixture.clear()
|
|
307
|
-
}
|
|
304
|
+
afterEach(async () => {
|
|
305
|
+
await fixture.clear()
|
|
308
306
|
})
|
|
309
307
|
|
|
310
308
|
test('should attach world to map', async () => {
|
|
@@ -379,6 +377,39 @@ describe('Map WorldMapsManager Integration', () => {
|
|
|
379
377
|
expect(worldMaps).toBeDefined()
|
|
380
378
|
expect(worldMaps?.getMapInfo('map1')).toBeNull()
|
|
381
379
|
})
|
|
380
|
+
|
|
381
|
+
test('should calculate player worldX and worldY correctly', async () => {
|
|
382
|
+
player = await client.waitForMapChange('map1')
|
|
383
|
+
const map = player.getCurrentMap()
|
|
384
|
+
expect(map).toBeDefined()
|
|
385
|
+
|
|
386
|
+
// Map1 is at worldX: 0, worldY: 0
|
|
387
|
+
// Set player to local position (100, 200)
|
|
388
|
+
await player.teleport({ x: 100, y: 200 })
|
|
389
|
+
|
|
390
|
+
// Wait a bit for signals to update
|
|
391
|
+
await new Promise(resolve => setTimeout(resolve, 10))
|
|
392
|
+
|
|
393
|
+
// Player worldX should be map.worldX + player.x() = 0 + 100 = 100
|
|
394
|
+
// Player worldY should be map.worldY + player.y() = 0 + 200 = 200
|
|
395
|
+
const worldX = player.worldPositionX()
|
|
396
|
+
const worldY = player.worldPositionY()
|
|
397
|
+
expect(worldX).toBe(100)
|
|
398
|
+
expect(worldY).toBe(200)
|
|
399
|
+
|
|
400
|
+
// Change to map2 which is at worldX: 1024, worldY: 0
|
|
401
|
+
await player.changeMap('map2', { x: 50, y: 100 })
|
|
402
|
+
player = await client.waitForMapChange('map2')
|
|
403
|
+
const map2 = player.getCurrentMap()
|
|
404
|
+
expect(map2?.id).toBe('map2')
|
|
405
|
+
|
|
406
|
+
// Player worldX should be map2.worldX + player.x() = 1024 + 50 = 1074
|
|
407
|
+
// Player worldY should be map2.worldY + player.y() = 0 + 100 = 100
|
|
408
|
+
const worldX2 = player.worldPositionX()
|
|
409
|
+
const worldY2 = player.worldPositionY()
|
|
410
|
+
expect(worldX2).toBe(1074)
|
|
411
|
+
expect(worldY2).toBe(100)
|
|
412
|
+
})
|
|
382
413
|
})
|
|
383
414
|
|
|
384
415
|
/**
|
|
@@ -442,10 +473,8 @@ describe('Automatic Map Change on Border Touch', () => {
|
|
|
442
473
|
player = client.player
|
|
443
474
|
})
|
|
444
475
|
|
|
445
|
-
afterEach(() => {
|
|
446
|
-
|
|
447
|
-
fixture.clear()
|
|
448
|
-
}
|
|
476
|
+
afterEach(async () => {
|
|
477
|
+
await fixture.clear()
|
|
449
478
|
})
|
|
450
479
|
|
|
451
480
|
test('should change map when player touches right border', async () => {
|
|
@@ -657,75 +686,8 @@ describe('Automatic Map Change with Non-Adjacent Maps', () => {
|
|
|
657
686
|
player = client.player
|
|
658
687
|
})
|
|
659
688
|
|
|
660
|
-
afterEach(() => {
|
|
661
|
-
|
|
662
|
-
fixture.clear()
|
|
663
|
-
}
|
|
664
|
-
})
|
|
665
|
-
|
|
666
|
-
test('should not change map when there is a gap to the right', async () => {
|
|
667
|
-
player = await client.waitForMapChange('map1')
|
|
668
|
-
const initialMapId = player.getCurrentMap()?.id
|
|
669
|
-
expect(initialMapId).toBe('map1')
|
|
670
|
-
|
|
671
|
-
// Spy on changeMap to verify it's not called
|
|
672
|
-
const changeMapSpy = vi.spyOn(player, 'changeMap')
|
|
673
|
-
|
|
674
|
-
// Move player to the right border
|
|
675
|
-
const hitbox = player.hitbox()
|
|
676
|
-
const marginLeftRight = 16 // tileWidth / 2
|
|
677
|
-
const borderX = 1024 - hitbox.w - marginLeftRight + 1 // Just past the border threshold
|
|
678
|
-
|
|
679
|
-
player.changeDirection(Direction.Right)
|
|
680
|
-
await player.teleport({ x: borderX, y: 384 })
|
|
681
|
-
|
|
682
|
-
// Try to move further right - should NOT change map because there's a gap
|
|
683
|
-
await player.autoChangeMap({ x: borderX + 1, y: 384 }, Direction.Right)
|
|
684
|
-
|
|
685
|
-
// Verify changeMap was not called
|
|
686
|
-
expect(changeMapSpy).not.toHaveBeenCalled()
|
|
687
|
-
expect(player.getCurrentMap()?.id).toBe('map1')
|
|
688
|
-
|
|
689
|
-
// Verify that map2 exists but is not adjacent
|
|
690
|
-
const map = player.getCurrentMap()
|
|
691
|
-
const worldMaps = map?.getWorldMapsManager()
|
|
692
|
-
const map2Info = worldMaps?.getMapInfo('map2')
|
|
693
|
-
expect(map2Info).toBeDefined()
|
|
694
|
-
expect(map2Info?.worldX).toBe(1025) // Gap of 1 pixel
|
|
695
|
-
|
|
696
|
-
changeMapSpy.mockRestore()
|
|
697
|
-
})
|
|
698
|
-
|
|
699
|
-
test('should not change map when there is a gap below', async () => {
|
|
700
|
-
player = await client.waitForMapChange('map1')
|
|
701
|
-
const initialMapId = player.getCurrentMap()?.id
|
|
702
|
-
|
|
703
|
-
// Spy on changeMap to verify it's not called
|
|
704
|
-
const changeMapSpy = vi.spyOn(player, 'changeMap')
|
|
705
|
-
|
|
706
|
-
// Move player to the bottom border
|
|
707
|
-
const hitbox = player.hitbox()
|
|
708
|
-
const marginTopDown = 16 // tileHeight / 2
|
|
709
|
-
const borderY = 768 - hitbox.h - marginTopDown + 1 // Just past the border threshold
|
|
710
|
-
|
|
711
|
-
player.changeDirection(Direction.Down)
|
|
712
|
-
await player.teleport({ x: 512, y: borderY })
|
|
713
|
-
|
|
714
|
-
// Try to move further down - should NOT change map because there's a gap
|
|
715
|
-
await player.autoChangeMap({ x: 512, y: borderY + 1 }, Direction.Down)
|
|
716
|
-
|
|
717
|
-
// Verify changeMap was not called
|
|
718
|
-
expect(changeMapSpy).not.toHaveBeenCalled()
|
|
719
|
-
expect(player.getCurrentMap()?.id).toBe('map1')
|
|
720
|
-
|
|
721
|
-
// Verify that map3 exists but is not adjacent
|
|
722
|
-
const map = player.getCurrentMap()
|
|
723
|
-
const worldMaps = map?.getWorldMapsManager()
|
|
724
|
-
const map3Info = worldMaps?.getMapInfo('map3')
|
|
725
|
-
expect(map3Info).toBeDefined()
|
|
726
|
-
expect(map3Info?.worldY).toBe(769) // Gap of 1 pixel
|
|
727
|
-
|
|
728
|
-
changeMapSpy.mockRestore()
|
|
689
|
+
afterEach(async () => {
|
|
690
|
+
await fixture.clear()
|
|
729
691
|
})
|
|
730
692
|
|
|
731
693
|
test('should not change map when there is a gap above', async () => {
|
|
@@ -836,7 +798,7 @@ describe('Automatic Map Change with Non-Adjacent Maps', () => {
|
|
|
836
798
|
|
|
837
799
|
// Test point lookup - should find map2 even with gap (point lookup doesn't require adjacency)
|
|
838
800
|
const mapsAtPoint = worldMaps?.getAdjacentMaps(
|
|
839
|
-
{ worldX: 0, worldY: 0,
|
|
801
|
+
{ worldX: 0, worldY: 0, widthPx: 1024, heightPx: 768 },
|
|
840
802
|
{ x: 1025, y: 0 }
|
|
841
803
|
)
|
|
842
804
|
expect(mapsAtPoint?.length).toBeGreaterThanOrEqual(1)
|