@rpgjs/server 5.0.0-alpha.8 → 5.0.0-beta.1

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 (116) 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 +44 -32
  11. package/dist/Player/ClassManager.d.ts +24 -4
  12. package/dist/Player/ComponentManager.d.ts +100 -7
  13. package/dist/Player/Components.d.ts +345 -0
  14. package/dist/Player/EffectManager.d.ts +50 -4
  15. package/dist/Player/ElementManager.d.ts +77 -4
  16. package/dist/Player/GoldManager.d.ts +1 -1
  17. package/dist/Player/GuiManager.d.ts +233 -5
  18. package/dist/Player/ItemFixture.d.ts +1 -1
  19. package/dist/Player/ItemManager.d.ts +431 -4
  20. package/dist/Player/MoveManager.d.ts +301 -34
  21. package/dist/Player/ParameterManager.d.ts +364 -28
  22. package/dist/Player/Player.d.ts +558 -14
  23. package/dist/Player/SkillManager.d.ts +187 -13
  24. package/dist/Player/StateManager.d.ts +75 -4
  25. package/dist/Player/VariableManager.d.ts +62 -4
  26. package/dist/RpgServer.d.ts +278 -63
  27. package/dist/RpgServerEngine.d.ts +2 -1
  28. package/dist/decorators/event.d.ts +46 -0
  29. package/dist/decorators/map.d.ts +299 -0
  30. package/dist/index.d.ts +10 -0
  31. package/dist/index.js +17920 -29866
  32. package/dist/index.js.map +1 -1
  33. package/dist/logs/log.d.ts +2 -3
  34. package/dist/module-CaCW1SDh.js +11018 -0
  35. package/dist/module-CaCW1SDh.js.map +1 -0
  36. package/dist/module.d.ts +43 -1
  37. package/dist/node/connection.d.ts +51 -0
  38. package/dist/node/index.d.ts +5 -0
  39. package/dist/node/index.js +551 -0
  40. package/dist/node/index.js.map +1 -0
  41. package/dist/node/map.d.ts +16 -0
  42. package/dist/node/room.d.ts +21 -0
  43. package/dist/node/transport.d.ts +28 -0
  44. package/dist/node/types.d.ts +47 -0
  45. package/dist/presets/index.d.ts +0 -9
  46. package/dist/rooms/BaseRoom.d.ts +132 -0
  47. package/dist/rooms/lobby.d.ts +10 -2
  48. package/dist/rooms/map.d.ts +1359 -32
  49. package/dist/services/save.d.ts +43 -0
  50. package/dist/storage/index.d.ts +1 -0
  51. package/dist/storage/localStorage.d.ts +23 -0
  52. package/package.json +25 -10
  53. package/src/Gui/DialogGui.ts +19 -4
  54. package/src/Gui/GameoverGui.ts +39 -0
  55. package/src/Gui/Gui.ts +23 -1
  56. package/src/Gui/MenuGui.ts +155 -6
  57. package/src/Gui/NotificationGui.ts +1 -2
  58. package/src/Gui/SaveLoadGui.ts +60 -0
  59. package/src/Gui/ShopGui.ts +146 -16
  60. package/src/Gui/TitleGui.ts +39 -0
  61. package/src/Gui/index.ts +15 -2
  62. package/src/Player/BattleManager.ts +39 -56
  63. package/src/Player/ClassManager.ts +82 -74
  64. package/src/Player/ComponentManager.ts +401 -37
  65. package/src/Player/Components.ts +380 -0
  66. package/src/Player/EffectManager.ts +50 -96
  67. package/src/Player/ElementManager.ts +74 -152
  68. package/src/Player/GuiManager.ts +284 -149
  69. package/src/Player/ItemManager.ts +747 -341
  70. package/src/Player/MoveManager.ts +1532 -750
  71. package/src/Player/ParameterManager.ts +636 -106
  72. package/src/Player/Player.ts +1273 -79
  73. package/src/Player/SkillManager.ts +558 -197
  74. package/src/Player/StateManager.ts +131 -258
  75. package/src/Player/VariableManager.ts +85 -157
  76. package/src/RpgServer.ts +293 -62
  77. package/src/decorators/event.ts +61 -0
  78. package/src/decorators/map.ts +343 -0
  79. package/src/index.ts +11 -1
  80. package/src/logs/log.ts +10 -3
  81. package/src/module.ts +126 -3
  82. package/src/node/connection.ts +254 -0
  83. package/src/node/index.ts +22 -0
  84. package/src/node/map.ts +328 -0
  85. package/src/node/room.ts +63 -0
  86. package/src/node/transport.ts +532 -0
  87. package/src/node/types.ts +61 -0
  88. package/src/presets/index.ts +1 -10
  89. package/src/rooms/BaseRoom.ts +232 -0
  90. package/src/rooms/lobby.ts +25 -7
  91. package/src/rooms/map.ts +2682 -206
  92. package/src/services/save.ts +147 -0
  93. package/src/storage/index.ts +1 -0
  94. package/src/storage/localStorage.ts +76 -0
  95. package/tests/battle.spec.ts +375 -0
  96. package/tests/change-map.spec.ts +72 -0
  97. package/tests/class.spec.ts +274 -0
  98. package/tests/custom-websocket.spec.ts +127 -0
  99. package/tests/effect.spec.ts +219 -0
  100. package/tests/element.spec.ts +221 -0
  101. package/tests/event.spec.ts +80 -0
  102. package/tests/gold.spec.ts +99 -0
  103. package/tests/item.spec.ts +609 -0
  104. package/tests/module.spec.ts +38 -0
  105. package/tests/move.spec.ts +601 -0
  106. package/tests/node-transport.spec.ts +223 -0
  107. package/tests/player-param.spec.ts +45 -0
  108. package/tests/prediction-reconciliation.spec.ts +182 -0
  109. package/tests/random-move.spec.ts +65 -0
  110. package/tests/skill.spec.ts +658 -0
  111. package/tests/state.spec.ts +467 -0
  112. package/tests/variable.spec.ts +185 -0
  113. package/tests/world-maps.spec.ts +896 -0
  114. package/vite.config.ts +36 -3
  115. package/dist/Player/Event.d.ts +0 -0
  116. package/src/Player/Event.ts +0 -0
@@ -1,4 +1,124 @@
1
- import { PlayerCtor } from '@rpgjs/common';
1
+ import { PlayerCtor } from '../../../common/src';
2
+ import { RpgPlayer } from './Player';
3
+ /**
4
+ * Type for skill class constructor
5
+ */
6
+ type SkillClass = {
7
+ new (...args: any[]): any;
8
+ };
9
+ /**
10
+ * Interface defining the hooks that can be implemented on skill classes or objects
11
+ *
12
+ * These hooks are called at specific moments during the skill lifecycle:
13
+ * - `onLearn`: When the skill is learned by the player
14
+ * - `onUse`: When the skill is successfully used
15
+ * - `onUseFailed`: When the skill usage fails (e.g., chance roll failed)
16
+ * - `onForget`: When the skill is forgotten
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const skillHooks: SkillHooks = {
21
+ * onLearn(player) {
22
+ * console.log('Skill learned!');
23
+ * },
24
+ * onUse(player, target) {
25
+ * console.log('Skill used on target');
26
+ * }
27
+ * };
28
+ * ```
29
+ */
30
+ export interface SkillHooks {
31
+ /**
32
+ * Called when the skill is learned by the player
33
+ *
34
+ * @param player - The player learning the skill
35
+ */
36
+ onLearn?: (player: RpgPlayer) => void | Promise<void>;
37
+ /**
38
+ * Called when the skill is successfully used
39
+ *
40
+ * @param player - The player using the skill
41
+ * @param target - The target player(s) if any
42
+ */
43
+ onUse?: (player: RpgPlayer, target?: RpgPlayer | RpgPlayer[]) => void | Promise<void>;
44
+ /**
45
+ * Called when the skill usage fails (e.g., chance roll failed)
46
+ *
47
+ * @param player - The player attempting to use the skill
48
+ * @param target - The intended target player(s) if any
49
+ */
50
+ onUseFailed?: (player: RpgPlayer, target?: RpgPlayer | RpgPlayer[]) => void | Promise<void>;
51
+ /**
52
+ * Called when the skill is forgotten
53
+ *
54
+ * @param player - The player forgetting the skill
55
+ */
56
+ onForget?: (player: RpgPlayer) => void | Promise<void>;
57
+ }
58
+ /**
59
+ * Interface for skill object definition
60
+ *
61
+ * Defines the properties that a skill can have when defined as an object.
62
+ * Skills can be defined as objects, classes, or string IDs referencing the database.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * const fireSkill: SkillObject = {
67
+ * id: 'fire',
68
+ * name: 'Fire',
69
+ * description: 'A basic fire spell',
70
+ * spCost: 10,
71
+ * hitRate: 0.9,
72
+ * power: 50,
73
+ * onUse(player) {
74
+ * console.log('Fire spell cast!');
75
+ * }
76
+ * };
77
+ *
78
+ * player.learnSkill(fireSkill);
79
+ * ```
80
+ */
81
+ export interface SkillObject extends SkillHooks {
82
+ /**
83
+ * Unique identifier for the skill
84
+ * If not provided, one will be auto-generated
85
+ */
86
+ id?: string;
87
+ /**
88
+ * Display name of the skill
89
+ */
90
+ name?: string;
91
+ /**
92
+ * Description of the skill
93
+ */
94
+ description?: string;
95
+ /**
96
+ * SP (Skill Points) cost to use the skill
97
+ * @default 0
98
+ */
99
+ spCost?: number;
100
+ /**
101
+ * Hit rate (0-1) - probability of successful skill usage
102
+ * @default 1
103
+ */
104
+ hitRate?: number;
105
+ /**
106
+ * Base power of the skill for damage calculation
107
+ */
108
+ power?: number;
109
+ /**
110
+ * Coefficient multipliers for damage calculation
111
+ */
112
+ coefficient?: Record<string, number>;
113
+ /**
114
+ * Type marker for database
115
+ */
116
+ _type?: 'skill';
117
+ /**
118
+ * Allow additional properties
119
+ */
120
+ [key: string]: any;
121
+ }
2
122
  /**
3
123
  * Skill Manager Mixin
4
124
  *
@@ -6,26 +126,80 @@ import { PlayerCtor } from '@rpgjs/common';
6
126
  * learning, forgetting, and using skills, including SP cost management,
7
127
  * hit rate calculations, and skill effects application.
8
128
  *
129
+ * Supports three input formats for skills:
130
+ * - **String ID**: References a skill in the database
131
+ * - **Class**: A skill class that will be instantiated
132
+ * - **Object**: A skill object with properties and hooks
133
+ *
9
134
  * @param Base - The base class to extend with skill management
10
135
  * @returns Extended class with skill management methods
11
136
  *
12
137
  * @example
13
138
  * ```ts
14
- * class MyPlayer extends WithSkillManager(BasePlayer) {
15
- * constructor() {
16
- * super();
17
- * // Skill system is automatically initialized
18
- * }
19
- * }
139
+ * // Using string ID (from database)
140
+ * player.learnSkill('fire');
20
141
  *
21
- * const player = new MyPlayer();
22
- * player.learnSkill(Fire);
23
- * player.useSkill(Fire, targetPlayer);
142
+ * // Using skill class
143
+ * player.learnSkill(FireSkill);
144
+ *
145
+ * // Using skill object
146
+ * player.learnSkill({
147
+ * id: 'ice',
148
+ * name: 'Ice',
149
+ * spCost: 15,
150
+ * onUse(player) {
151
+ * console.log('Ice spell cast!');
152
+ * }
153
+ * });
24
154
  * ```
25
155
  */
26
156
  export declare function WithSkillManager<TBase extends PlayerCtor>(Base: TBase): TBase;
27
157
  /**
28
- * Type helper to extract the interface from the WithSkillManager mixin
29
- * This provides the type without duplicating method signatures
158
+ * Interface for Skill Manager functionality
159
+ *
160
+ * Provides skill management capabilities including learning, forgetting, and using skills.
161
+ * This interface defines the public API of the SkillManager mixin.
30
162
  */
31
- export type ISkillManager = InstanceType<ReturnType<typeof WithSkillManager>>;
163
+ export interface ISkillManager {
164
+ /**
165
+ * Retrieves a learned skill. Returns null if not found
166
+ *
167
+ * @param skillInput - Skill class, object, or data id
168
+ * @returns The skill data or null
169
+ */
170
+ getSkill(skillInput: SkillClass | SkillObject | string): any | null;
171
+ /**
172
+ * Learn a skill
173
+ *
174
+ * Supports three input formats:
175
+ * - String ID: Retrieves from database
176
+ * - Class: Creates instance and adds to database
177
+ * - Object: Uses directly and adds to database
178
+ *
179
+ * @param skillInput - Skill class, object, or data id
180
+ * @returns The learned skill data
181
+ * @throws SkillLog.alreadyLearned if the player already knows the skill
182
+ */
183
+ learnSkill(skillInput: SkillClass | SkillObject | string): any;
184
+ /**
185
+ * Forget a skill
186
+ *
187
+ * @param skillInput - Skill class, object, or data id
188
+ * @returns The forgotten skill data
189
+ * @throws SkillLog.notLearned if trying to forget a skill not learned
190
+ */
191
+ forgetSkill(skillInput: SkillClass | SkillObject | string): any;
192
+ /**
193
+ * Use a skill
194
+ *
195
+ * @param skillInput - Skill class, object, or data id
196
+ * @param otherPlayer - Optional target player(s) to apply skill to
197
+ * @returns The used skill data
198
+ * @throws SkillLog.restriction if player has Effect.CAN_NOT_SKILL
199
+ * @throws SkillLog.notLearned if player tries to use an unlearned skill
200
+ * @throws SkillLog.notEnoughSp if player does not have enough SP
201
+ * @throws SkillLog.chanceToUseFailed if the chance to use the skill has failed
202
+ */
203
+ useSkill(skillInput: SkillClass | SkillObject | string, otherPlayer?: RpgPlayer | RpgPlayer[]): any;
204
+ }
205
+ export {};
@@ -1,4 +1,8 @@
1
- import { PlayerCtor } from '@rpgjs/common';
1
+ import { PlayerCtor } from '../../../common/src';
2
+ import { RpgPlayer } from './Player';
3
+ type StateClass = {
4
+ new (...args: any[]): any;
5
+ };
2
6
  /**
3
7
  * State Manager Mixin
4
8
  *
@@ -26,7 +30,74 @@ import { PlayerCtor } from '@rpgjs/common';
26
30
  */
27
31
  export declare function WithStateManager<TBase extends PlayerCtor>(Base: TBase): TBase;
28
32
  /**
29
- * Type helper to extract the interface from the WithStateManager mixin
30
- * This provides the type without duplicating method signatures
33
+ * Interface for State Manager functionality
34
+ *
35
+ * Provides state management capabilities including state defense, efficiency modifiers,
36
+ * and state application/removal. This interface defines the public API of the StateManager mixin.
31
37
  */
32
- export type IStateManager = InstanceType<ReturnType<typeof WithStateManager>>;
38
+ export interface IStateManager {
39
+ /**
40
+ * Gets the defensive capabilities against various states from equipped items
41
+ *
42
+ * @returns Array of state defense objects with rate and state properties
43
+ */
44
+ statesDefense: {
45
+ rate: number;
46
+ state: any;
47
+ }[];
48
+ /**
49
+ * Manages the player's state efficiency modifiers
50
+ *
51
+ * @returns Signal containing array of state efficiency objects
52
+ */
53
+ statesEfficiency: any;
54
+ /**
55
+ * Apply states to a player from skill or item effects
56
+ *
57
+ * @param player - The target player to apply states to
58
+ * @param states - Object containing arrays of states to add or remove
59
+ */
60
+ applyStates(player: RpgPlayer, states: {
61
+ addStates?: Array<{
62
+ state: any;
63
+ rate: number;
64
+ }>;
65
+ removeStates?: Array<{
66
+ state: any;
67
+ rate: number;
68
+ }>;
69
+ }): void;
70
+ /**
71
+ * Get a state to the player. Returns null if the state is not present
72
+ *
73
+ * @param stateClass - The state class constructor or state ID to search for
74
+ * @returns The state instance if found, null otherwise
75
+ */
76
+ getState(stateClass: StateClass | string): any | null;
77
+ /**
78
+ * Adds a state to the player
79
+ *
80
+ * @param stateClass - The state class constructor or state ID to apply
81
+ * @param chance - Probability of successful application (0-1, default 1)
82
+ * @returns The state instance if successfully applied, null if already present
83
+ * @throws StateLog.addFailed if the chance roll fails
84
+ */
85
+ addState(stateClass: StateClass | string, chance?: number): object | null;
86
+ /**
87
+ * Remove a state to the player
88
+ *
89
+ * @param stateClass - The state class constructor or state ID to remove
90
+ * @param chance - Probability of successful removal (0-1, default 1)
91
+ * @throws StateLog.removeFailed if the chance roll fails
92
+ * @throws StateLog.notApplied if the state is not currently active
93
+ */
94
+ removeState(stateClass: StateClass | string, chance?: number): void;
95
+ /**
96
+ * Find state efficiency modifier for a specific state class
97
+ *
98
+ * @param stateClass - The state class to find efficiency for
99
+ * @returns The efficiency object if found, undefined otherwise
100
+ */
101
+ findStateEfficiency(stateClass: any): any | undefined;
102
+ }
103
+ export {};
@@ -1,4 +1,4 @@
1
- import { PlayerCtor } from '@rpgjs/common';
1
+ import { PlayerCtor } from '../../../common/src';
2
2
  /**
3
3
  * Variable Manager Mixin
4
4
  *
@@ -6,6 +6,11 @@ import { PlayerCtor } from '@rpgjs/common';
6
6
  * pairs that can store any type of data associated with the player, such as
7
7
  * quest progress, game flags, inventory state, and custom game data.
8
8
  *
9
+ * Player variables have two main roles:
10
+ *
11
+ * 1. Persist player-specific state so it can be restored from saves.
12
+ * 2. Carry that state across maps and map servers through the player snapshot.
13
+ *
9
14
  * @param Base - The base class to extend with variable management
10
15
  * @returns Extended class with variable management methods
11
16
  *
@@ -24,7 +29,60 @@ import { PlayerCtor } from '@rpgjs/common';
24
29
  */
25
30
  export declare function WithVariableManager<TBase extends PlayerCtor>(Base: TBase): TBase;
26
31
  /**
27
- * Type helper to extract the interface from the WithVariableManager mixin
28
- * This provides the type without duplicating method signatures
32
+ * Interface for Variable Manager functionality
33
+ *
34
+ * Provides variable management capabilities including storing, retrieving, and managing
35
+ * key-value pairs for player-specific data. This interface defines the public API
36
+ * of the VariableManager mixin.
29
37
  */
30
- export type IVariableManager = InstanceType<ReturnType<typeof WithVariableManager>>;
38
+ export interface IVariableManager {
39
+ /**
40
+ * Map storing all player variables.
41
+ *
42
+ * These values belong to the player, are persisted, and travel with the
43
+ * player snapshot when switching maps or servers.
44
+ */
45
+ variables: Map<string, any>;
46
+ /**
47
+ * Assign a variable to the player.
48
+ *
49
+ * Use player variables for quest flags, per-player event state, and any value
50
+ * that must survive saves and map transitions.
51
+ *
52
+ * @param key - The variable identifier
53
+ * @param val - The value to store
54
+ * @memberof VariableManager
55
+ */
56
+ setVariable(key: string, val: any): void;
57
+ /**
58
+ * Get a variable value
59
+ *
60
+ * @param key - The variable identifier to retrieve
61
+ * @returns The stored value or undefined if not found
62
+ */
63
+ getVariable<U = any>(key: string): U | undefined;
64
+ /**
65
+ * Remove a variable
66
+ *
67
+ * @param key - The variable identifier to remove
68
+ * @returns true if a variable existed and has been removed, false otherwise
69
+ */
70
+ removeVariable(key: string): boolean;
71
+ /**
72
+ * Check if a variable exists
73
+ *
74
+ * @param key - The variable identifier to check
75
+ * @returns true if the variable exists, false otherwise
76
+ */
77
+ hasVariable(key: string): boolean;
78
+ /**
79
+ * Get all variable keys
80
+ *
81
+ * @returns Array of all variable keys
82
+ */
83
+ getVariableKeys(): string[];
84
+ /**
85
+ * Clear all variables
86
+ */
87
+ clearVariables(): void;
88
+ }