@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
@@ -1,5 +1,4 @@
1
- export declare class Log {
2
- private id;
3
- private msg;
1
+ export declare class Log extends Error {
2
+ readonly id: string;
4
3
  constructor(id: string, msg: string);
5
4
  }
package/dist/module.d.ts CHANGED
@@ -1,2 +1,44 @@
1
1
  import { FactoryProvider } from '@signe/di';
2
- export declare function provideServerModules(modules: any[]): FactoryProvider;
2
+ import { RpgServer } from './RpgServer';
3
+ /**
4
+ * Type for server modules that can be either:
5
+ * - An object implementing RpgServer interface
6
+ * - A class decorated with @RpgModule decorator
7
+ */
8
+ export type RpgServerModule = RpgServer | (new () => any);
9
+ /**
10
+ * Provides server modules configuration to Angular Dependency Injection
11
+ *
12
+ * This function accepts an array of server modules that can be either:
13
+ * - Objects implementing the RpgServer interface
14
+ * - Classes decorated with the @RpgModule decorator (which will be instantiated)
15
+ *
16
+ * @param modules - Array of server modules (objects or classes)
17
+ * @returns FactoryProvider configuration for Angular DI
18
+ * @example
19
+ * ```ts
20
+ * // Using an object
21
+ * provideServerModules([
22
+ * {
23
+ * player: {
24
+ * onConnected(player) {
25
+ * console.log('Player connected')
26
+ * }
27
+ * }
28
+ * }
29
+ * ])
30
+ *
31
+ * // Using a decorated class
32
+ * @RpgModule<RpgServer>({
33
+ * engine: {
34
+ * onStart(server) {
35
+ * console.log('Server started')
36
+ * }
37
+ * }
38
+ * })
39
+ * class MyServerModule {}
40
+ *
41
+ * provideServerModules([MyServerModule])
42
+ * ```
43
+ */
44
+ export declare function provideServerModules(modules: RpgServerModule[]): FactoryProvider;
@@ -1,12 +1,3 @@
1
- export declare const MAXHP: string;
2
- export declare const MAXSP: string;
3
- export declare const ATK: string;
4
- export declare const PDEF: string;
5
- export declare const SDEF: string;
6
- export declare const STR: string;
7
- export declare const AGI: string;
8
- export declare const INT: string;
9
- export declare const DEX: string;
10
1
  export declare const MAXHP_CURVE: {
11
2
  start: number;
12
3
  end: number;
@@ -0,0 +1,132 @@
1
+ import { Hooks } from '../../../common/src';
2
+ import { RpgPlayer } from '../Player/Player';
3
+ /**
4
+ * Base class for rooms that need database functionality
5
+ *
6
+ * This class provides common database management functionality that is shared
7
+ * between RpgMap and LobbyRoom. It includes methods for adding and managing
8
+ * items, classes, and other game data in the room's database.
9
+ *
10
+ * ## Architecture
11
+ *
12
+ * Both RpgMap and LobbyRoom need to store game entities (items, classes, skills, etc.)
13
+ * in a database. This base class provides the common implementation to avoid code duplication.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * class MyCustomRoom extends BaseRoom {
18
+ * // Your custom room implementation
19
+ * }
20
+ * ```
21
+ */
22
+ export declare abstract class BaseRoom {
23
+ /**
24
+ * Signal containing the room's database of items, classes, and other game data
25
+ *
26
+ * This database can be dynamically populated using `addInDatabase()` and
27
+ * `removeInDatabase()` methods. It's used to store game entities like items,
28
+ * classes, skills, etc. that are available in this room.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * // Add data to database
33
+ * room.addInDatabase('Potion', PotionClass);
34
+ *
35
+ * // Access database
36
+ * const potion = room.database()['Potion'];
37
+ * ```
38
+ */
39
+ database: import('@signe/reactive').WritableObjectSignal<{}>;
40
+ onStart(): Promise<void>;
41
+ /**
42
+ * Add data to the room's database
43
+ *
44
+ * Adds an item, class, or other game entity to the room's database.
45
+ * If the ID already exists and `force` is not enabled, the addition is ignored.
46
+ *
47
+ * ## Architecture
48
+ *
49
+ * This method is used by the item management system to store item definitions
50
+ * in the room's database. When a player adds an item, the system first checks
51
+ * if the item exists in the database, and if not, adds it using this method.
52
+ *
53
+ * @param id - Unique identifier for the data
54
+ * @param data - The data to add (can be a class, object, etc.)
55
+ * @param options - Optional configuration
56
+ * @param options.force - If true, overwrites existing data with the same ID
57
+ * @returns `true` if data was added, `false` if it was ignored (ID already exists)
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * // Add a class to the database
62
+ * room.addInDatabase('Potion', PotionClass);
63
+ *
64
+ * // Add an item object to the database
65
+ * room.addInDatabase('custom-item', {
66
+ * name: 'Custom Item',
67
+ * price: 100
68
+ * });
69
+ *
70
+ * // Force overwrite existing data
71
+ * room.addInDatabase('Potion', UpdatedPotionClass, { force: true });
72
+ * ```
73
+ */
74
+ addInDatabase(id: string, data: any, options?: {
75
+ force?: boolean;
76
+ }): boolean;
77
+ /**
78
+ * Remove data from the room's database
79
+ *
80
+ * This method allows you to remove items or data from the room's database.
81
+ *
82
+ * @param id - Unique identifier of the data to remove
83
+ * @returns `true` if data was removed, `false` if ID didn't exist
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * // Remove an item from the database
88
+ * room.removeInDatabase('Potion');
89
+ *
90
+ * // Check if removal was successful
91
+ * const removed = room.removeInDatabase('custom-item');
92
+ * if (removed) {
93
+ * console.log('Item removed successfully');
94
+ * }
95
+ * ```
96
+ */
97
+ removeInDatabase(id: string): boolean;
98
+ /**
99
+ * Get the hooks system for this map
100
+ *
101
+ * Returns the dependency-injected Hooks instance that allows you to trigger
102
+ * and listen to various game events.
103
+ *
104
+ * @returns The Hooks instance for this map
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * // Trigger a custom hook
109
+ * map.hooks.callHooks('custom-event', data).subscribe();
110
+ * ```
111
+ */
112
+ get hooks(): Hooks;
113
+ /**
114
+ * Resolve complex snapshot entries (e.g. inventory items) before load.
115
+ */
116
+ onSessionRestore({ userSnapshot, user }: {
117
+ userSnapshot: any;
118
+ user?: RpgPlayer;
119
+ }): Promise<any>;
120
+ listSaveSlots(player: RpgPlayer, value: {
121
+ requestId: string;
122
+ }): Promise<import('../../../common/src').SaveSlotList>;
123
+ saveSlot(player: RpgPlayer, value: {
124
+ requestId: string;
125
+ index: number;
126
+ meta?: any;
127
+ }): Promise<void>;
128
+ loadSlot(player: RpgPlayer, value: {
129
+ requestId: string;
130
+ index: number;
131
+ }): Promise<void>;
132
+ }
@@ -1,6 +1,14 @@
1
1
  import { MockConnection } from '@signe/room';
2
2
  import { RpgPlayer } from '../Player/Player';
3
- export declare class LobbyRoom {
3
+ import { BaseRoom } from './BaseRoom';
4
+ export declare class LobbyRoom extends BaseRoom {
4
5
  players: import('@signe/reactive').WritableObjectSignal<{}>;
5
- onJoin(player: RpgPlayer, conn: MockConnection): void;
6
+ autoSync: boolean;
7
+ constructor(room: any);
8
+ onJoin(player: RpgPlayer, conn: MockConnection): Promise<void>;
9
+ guiInteraction(player: RpgPlayer, value: {
10
+ guiId: string;
11
+ name: string;
12
+ data: any;
13
+ }): Promise<void>;
6
14
  }