@rpgjs/server 5.0.0-alpha.4 → 5.0.0-alpha.41

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 (101) hide show
  1. package/dist/Gui/DialogGui.d.ts +5 -0
  2. package/dist/Gui/GameoverGui.d.ts +23 -0
  3. package/dist/Gui/Gui.d.ts +6 -0
  4. package/dist/Gui/MenuGui.d.ts +22 -3
  5. package/dist/Gui/NotificationGui.d.ts +1 -2
  6. package/dist/Gui/SaveLoadGui.d.ts +13 -0
  7. package/dist/Gui/ShopGui.d.ts +28 -3
  8. package/dist/Gui/TitleGui.d.ts +23 -0
  9. package/dist/Gui/index.d.ts +10 -1
  10. package/dist/Player/BattleManager.d.ts +34 -12
  11. package/dist/Player/ClassManager.d.ts +46 -13
  12. package/dist/Player/ComponentManager.d.ts +123 -0
  13. package/dist/Player/Components.d.ts +345 -0
  14. package/dist/Player/EffectManager.d.ts +86 -0
  15. package/dist/Player/ElementManager.d.ts +104 -0
  16. package/dist/Player/GoldManager.d.ts +22 -0
  17. package/dist/Player/GuiManager.d.ts +259 -0
  18. package/dist/Player/ItemFixture.d.ts +6 -0
  19. package/dist/Player/ItemManager.d.ts +450 -9
  20. package/dist/Player/MoveManager.d.ts +324 -69
  21. package/dist/Player/ParameterManager.d.ts +344 -14
  22. package/dist/Player/Player.d.ts +460 -8
  23. package/dist/Player/SkillManager.d.ts +197 -15
  24. package/dist/Player/StateManager.d.ts +89 -25
  25. package/dist/Player/VariableManager.d.ts +74 -0
  26. package/dist/RpgServer.d.ts +502 -64
  27. package/dist/RpgServerEngine.d.ts +2 -1
  28. package/dist/decorators/event.d.ts +46 -0
  29. package/dist/decorators/map.d.ts +287 -0
  30. package/dist/index.d.ts +10 -0
  31. package/dist/index.js +21653 -20900
  32. package/dist/index.js.map +1 -1
  33. package/dist/logs/log.d.ts +2 -3
  34. package/dist/module.d.ts +43 -1
  35. package/dist/presets/index.d.ts +0 -9
  36. package/dist/rooms/BaseRoom.d.ts +132 -0
  37. package/dist/rooms/lobby.d.ts +10 -2
  38. package/dist/rooms/map.d.ts +1236 -17
  39. package/dist/services/save.d.ts +43 -0
  40. package/dist/storage/index.d.ts +1 -0
  41. package/dist/storage/localStorage.d.ts +23 -0
  42. package/package.json +14 -10
  43. package/src/Gui/DialogGui.ts +19 -4
  44. package/src/Gui/GameoverGui.ts +39 -0
  45. package/src/Gui/Gui.ts +23 -1
  46. package/src/Gui/MenuGui.ts +155 -6
  47. package/src/Gui/NotificationGui.ts +1 -2
  48. package/src/Gui/SaveLoadGui.ts +60 -0
  49. package/src/Gui/ShopGui.ts +146 -16
  50. package/src/Gui/TitleGui.ts +39 -0
  51. package/src/Gui/index.ts +15 -2
  52. package/src/Player/BattleManager.ts +91 -49
  53. package/src/Player/ClassManager.ts +118 -50
  54. package/src/Player/ComponentManager.ts +425 -19
  55. package/src/Player/Components.ts +380 -0
  56. package/src/Player/EffectManager.ts +81 -44
  57. package/src/Player/ElementManager.ts +109 -86
  58. package/src/Player/GoldManager.ts +32 -35
  59. package/src/Player/GuiManager.ts +308 -150
  60. package/src/Player/ItemFixture.ts +4 -5
  61. package/src/Player/ItemManager.ts +774 -355
  62. package/src/Player/MoveManager.ts +1544 -774
  63. package/src/Player/ParameterManager.ts +546 -104
  64. package/src/Player/Player.ts +1163 -88
  65. package/src/Player/SkillManager.ts +520 -195
  66. package/src/Player/StateManager.ts +170 -182
  67. package/src/Player/VariableManager.ts +101 -63
  68. package/src/RpgServer.ts +525 -63
  69. package/src/core/context.ts +1 -0
  70. package/src/decorators/event.ts +61 -0
  71. package/src/decorators/map.ts +327 -0
  72. package/src/index.ts +11 -1
  73. package/src/logs/log.ts +10 -3
  74. package/src/module.ts +126 -3
  75. package/src/presets/index.ts +1 -10
  76. package/src/rooms/BaseRoom.ts +232 -0
  77. package/src/rooms/lobby.ts +25 -7
  78. package/src/rooms/map.ts +2502 -194
  79. package/src/services/save.ts +147 -0
  80. package/src/storage/index.ts +1 -0
  81. package/src/storage/localStorage.ts +76 -0
  82. package/tests/battle.spec.ts +375 -0
  83. package/tests/change-map.spec.ts +72 -0
  84. package/tests/class.spec.ts +274 -0
  85. package/tests/effect.spec.ts +219 -0
  86. package/tests/element.spec.ts +221 -0
  87. package/tests/event.spec.ts +80 -0
  88. package/tests/gold.spec.ts +99 -0
  89. package/tests/item.spec.ts +609 -0
  90. package/tests/module.spec.ts +38 -0
  91. package/tests/move.spec.ts +601 -0
  92. package/tests/player-param.spec.ts +28 -0
  93. package/tests/prediction-reconciliation.spec.ts +182 -0
  94. package/tests/random-move.spec.ts +65 -0
  95. package/tests/skill.spec.ts +658 -0
  96. package/tests/state.spec.ts +467 -0
  97. package/tests/variable.spec.ts +185 -0
  98. package/tests/world-maps.spec.ts +896 -0
  99. package/vite.config.ts +16 -0
  100. package/dist/Player/Event.d.ts +0 -0
  101. package/src/Player/Event.ts +0 -0
@@ -0,0 +1,80 @@
1
+ import { beforeEach, test, expect, afterEach } from 'vitest'
2
+ import { testing, TestingFixture } from '@rpgjs/testing'
3
+ import { defineModule, createModule } from '@rpgjs/common'
4
+ import { RpgPlayer, RpgServer, Move } from '../src'
5
+ import { RpgClient } from '../../client/src'
6
+
7
+ const Event = () => {
8
+ return {
9
+ name: "EV-1",
10
+ onInit() {
11
+ this.setGraphic("hero");
12
+ }
13
+ }
14
+ }
15
+
16
+ // Define server module with two maps
17
+ const serverModule = defineModule<RpgServer>({
18
+ maps: [
19
+ {
20
+ id: 'map1',
21
+ events: [{ event: Event(), x: 100, y: 150 }]
22
+ },
23
+ ],
24
+ player: {
25
+ async onConnected(player) {
26
+ await player.changeMap('map1', { x: 100, y: 126 })
27
+ }
28
+ }
29
+ })
30
+
31
+ // Define client module
32
+ const clientModule = defineModule<RpgClient>({
33
+ // Client-side logic
34
+ })
35
+
36
+ let player: RpgPlayer
37
+ let client: any
38
+ let fixture: TestingFixture
39
+
40
+ beforeEach(async () => {
41
+ const myModule = createModule('TestModule', [{
42
+ server: serverModule,
43
+ client: clientModule
44
+ }])
45
+
46
+ fixture = await testing(myModule)
47
+ client = await fixture.createClient()
48
+ player = client.player
49
+ })
50
+
51
+ afterEach(() => {
52
+ fixture.clear()
53
+ })
54
+
55
+ test('Player to touch event', async () => {
56
+ player = await client.waitForMapChange('map1')
57
+ const map = player.getCurrentMap()
58
+ const event = map?.getEvents()[0]
59
+ expect(event).toBeDefined()
60
+ expect(event?.name()).toBe("EV-1")
61
+ expect(event?.x()).toBe(100)
62
+ expect(event?.y()).toBe(150)
63
+ await fixture.waitUntil(
64
+ player.moveRoutes([
65
+ Move.tileDown(2),
66
+ ], {
67
+ onStuck: () => false
68
+ })
69
+ )
70
+ expect(event?.x()).toBe(100)
71
+ expect(event?.y()).toBe(150)
72
+ await fixture.waitUntil(
73
+ event!.moveRoutes([
74
+ Move.down()
75
+ ])
76
+ )
77
+ expect(event?.x()).toBe(100)
78
+ expect(event?.y()).toBe(150 + event!.speed())
79
+
80
+ })
@@ -0,0 +1,99 @@
1
+ import { beforeEach, test, expect, afterEach, describe } from "vitest";
2
+ import { testing, TestingFixture } from "@rpgjs/testing";
3
+ import { defineModule, createModule } from "@rpgjs/common";
4
+ import { RpgPlayer } from "../src";
5
+
6
+ let player: RpgPlayer;
7
+ let fixture: TestingFixture;
8
+
9
+ const serverModule = defineModule({
10
+ maps: [{ id: "test-map", file: "" }],
11
+ player: {
12
+ async onConnected(player) {
13
+ await player.changeMap("test-map", { x: 100, y: 100 });
14
+ },
15
+ },
16
+ });
17
+
18
+ const clientModule = defineModule({});
19
+
20
+ beforeEach(async () => {
21
+ const myModule = createModule("TestModule", [
22
+ { server: serverModule, client: clientModule },
23
+ ]);
24
+ fixture = await testing(myModule);
25
+ const clientTesting = await fixture.createClient();
26
+ player = await clientTesting.waitForMapChange("test-map");
27
+ });
28
+
29
+ afterEach(async () => {
30
+ await fixture.clear();
31
+ });
32
+
33
+ describe("Gold Manager - Basic Operations", () => {
34
+ test("should have 0 gold by default", () => {
35
+ expect(player.gold).toBe(0);
36
+ });
37
+
38
+ test("should set gold to a positive value", () => {
39
+ player.gold = 100;
40
+ expect(player.gold).toBe(100);
41
+ });
42
+
43
+ test("should add gold", () => {
44
+ player.gold = 50;
45
+ player.gold += 30;
46
+ expect(player.gold).toBe(80);
47
+ });
48
+
49
+ test("should subtract gold", () => {
50
+ player.gold = 100;
51
+ player.gold -= 40;
52
+ expect(player.gold).toBe(60);
53
+ });
54
+
55
+ test("should not allow negative gold (clamp to 0)", () => {
56
+ player.gold = 50;
57
+ player.gold -= 100; // Try to go negative
58
+ expect(player.gold).toBe(0);
59
+ });
60
+
61
+ test("should set to 0 when setting negative value directly", () => {
62
+ player.gold = -50;
63
+ expect(player.gold).toBe(0);
64
+ });
65
+
66
+ test("should handle large gold values", () => {
67
+ player.gold = 999999999;
68
+ expect(player.gold).toBe(999999999);
69
+ });
70
+
71
+ test("should handle gold = 0", () => {
72
+ player.gold = 100;
73
+ player.gold = 0;
74
+ expect(player.gold).toBe(0);
75
+ });
76
+ });
77
+
78
+ describe("Gold Manager - Edge Cases", () => {
79
+ test("should handle multiple consecutive operations", () => {
80
+ player.gold = 100;
81
+ player.gold += 50;
82
+ player.gold -= 30;
83
+ player.gold += 20;
84
+ expect(player.gold).toBe(140);
85
+ });
86
+
87
+ test("should handle subtracting exactly to 0", () => {
88
+ player.gold = 100;
89
+ player.gold -= 100;
90
+ expect(player.gold).toBe(0);
91
+ });
92
+
93
+ test("should handle decimal values (floored)", () => {
94
+ player.gold = 10.5;
95
+ // Note: behavior depends on implementation
96
+ expect(player.gold).toBeGreaterThanOrEqual(10);
97
+ });
98
+ });
99
+