@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,23 +1,205 @@
1
- import { Constructor, RpgCommonPlayer } from '@rpgjs/common';
1
+ import { PlayerCtor } from '../../../common/src';
2
2
  import { RpgPlayer } from './Player';
3
3
  /**
4
- * Interface defining dependencies from other mixins that SkillManager needs
4
+ * Type for skill class constructor
5
5
  */
6
- interface SkillManagerDependencies {
7
- sp: number;
8
- skills(): any[];
9
- hasEffect(effect: string): boolean;
10
- databaseById(id: string): any;
11
- applyStates(player: RpgPlayer, skill: any): void;
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>;
12
57
  }
13
58
  /**
14
- * Interface defining what SkillManager adds to a class
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
+ }
122
+ /**
123
+ * Skill Manager Mixin
124
+ *
125
+ * Provides skill management capabilities to any class. This mixin handles
126
+ * learning, forgetting, and using skills, including SP cost management,
127
+ * hit rate calculations, and skill effects application.
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
+ *
134
+ * @param Base - The base class to extend with skill management
135
+ * @returns Extended class with skill management methods
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * // Using string ID (from database)
140
+ * player.learnSkill('fire');
141
+ *
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
+ * });
154
+ * ```
155
+ */
156
+ export declare function WithSkillManager<TBase extends PlayerCtor>(Base: TBase): TBase;
157
+ /**
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.
15
162
  */
16
- export interface IWithSkillManager {
17
- getSkill(skillClass: any | string): any;
18
- learnSkill(skillId: any | string): any;
19
- forgetSkill(skillId: any | string): any;
20
- useSkill(skillId: any | string, otherPlayer?: RpgPlayer | RpgPlayer[]): any;
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;
21
204
  }
22
- export declare function WithSkillManager<TBase extends Constructor<RpgCommonPlayer & SkillManagerDependencies>>(Base: TBase): Constructor<IWithSkillManager> & TBase;
23
205
  export {};
@@ -1,39 +1,103 @@
1
- import { Constructor, RpgCommonPlayer } from '@rpgjs/common';
2
- import { WritableArraySignal } from '@signe/reactive';
1
+ import { PlayerCtor } from '../../../common/src';
3
2
  import { RpgPlayer } from './Player';
4
- interface StateManagerDependencies {
5
- equipments(): any[];
6
- databaseById(id: string | StateClass): any;
7
- addState(stateClass: StateClass | string, chance?: number): object | null;
8
- removeState(stateClass: StateClass | string, chance?: number): void;
9
- }
3
+ type StateClass = {
4
+ new (...args: any[]): any;
5
+ };
6
+ /**
7
+ * State Manager Mixin
8
+ *
9
+ * Provides state management capabilities to any class. This mixin handles
10
+ * player states (buffs/debuffs), state defense from equipment, and state
11
+ * efficiency modifiers. It manages the complete state system including
12
+ * application, removal, and resistance mechanics.
13
+ *
14
+ * @param Base - The base class to extend with state management
15
+ * @returns Extended class with state management methods
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * class MyPlayer extends WithStateManager(BasePlayer) {
20
+ * constructor() {
21
+ * super();
22
+ * // State system is automatically initialized
23
+ * }
24
+ * }
25
+ *
26
+ * const player = new MyPlayer();
27
+ * player.addState(Paralyze);
28
+ * console.log(player.getState(Paralyze));
29
+ * ```
30
+ */
31
+ export declare function WithStateManager<TBase extends PlayerCtor>(Base: TBase): TBase;
10
32
  /**
11
- * Interface defining what MoveManager adds to a class
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.
12
37
  */
13
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
+ */
14
44
  statesDefense: {
15
45
  rate: number;
16
46
  state: any;
17
47
  }[];
18
- statesEfficiency: WritableArraySignal<any[]>;
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
+ */
19
60
  applyStates(player: RpgPlayer, states: {
20
- addStates?: any[];
21
- removeStates?: any[];
61
+ addStates?: Array<{
62
+ state: any;
63
+ rate: number;
64
+ }>;
65
+ removeStates?: Array<{
66
+ state: any;
67
+ rate: number;
68
+ }>;
22
69
  }): void;
23
- getState(stateClass: StateClass | string): any;
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
+ */
24
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
+ */
25
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;
26
102
  }
27
- type StateClass = {
28
- new (...args: any[]): any;
29
- };
30
- /**
31
- * Move Manager mixin
32
- *
33
- * Adds methods to manage player movement
34
- *
35
- * @param Base - The base class to extend
36
- * @returns A new class with move management capabilities
37
- */
38
- export declare function WithStateManager<TBase extends Constructor<RpgCommonPlayer & StateManagerDependencies>>(Base: TBase): Constructor<IStateManager> & TBase;
39
103
  export {};
@@ -0,0 +1,74 @@
1
+ import { PlayerCtor } from '../../../common/src';
2
+ /**
3
+ * Variable Manager Mixin
4
+ *
5
+ * Provides variable management capabilities to any class. Variables are key-value
6
+ * pairs that can store any type of data associated with the player, such as
7
+ * quest progress, game flags, inventory state, and custom game data.
8
+ *
9
+ * @param Base - The base class to extend with variable management
10
+ * @returns Extended class with variable management methods
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * class MyPlayer extends WithVariableManager(BasePlayer) {
15
+ * constructor() {
16
+ * super();
17
+ * // Variables are automatically initialized
18
+ * }
19
+ * }
20
+ *
21
+ * const player = new MyPlayer();
22
+ * player.setVariable('questCompleted', true);
23
+ * ```
24
+ */
25
+ export declare function WithVariableManager<TBase extends PlayerCtor>(Base: TBase): TBase;
26
+ /**
27
+ * Interface for Variable Manager functionality
28
+ *
29
+ * Provides variable management capabilities including storing, retrieving, and managing
30
+ * key-value pairs for player-specific data. This interface defines the public API
31
+ * of the VariableManager mixin.
32
+ */
33
+ export interface IVariableManager {
34
+ /** Map storing all player variables */
35
+ variables: Map<string, any>;
36
+ /**
37
+ * Assign a variable to the player
38
+ *
39
+ * @param key - The variable identifier
40
+ * @param val - The value to store
41
+ */
42
+ setVariable(key: string, val: any): void;
43
+ /**
44
+ * Get a variable value
45
+ *
46
+ * @param key - The variable identifier to retrieve
47
+ * @returns The stored value or undefined if not found
48
+ */
49
+ getVariable<U = any>(key: string): U | undefined;
50
+ /**
51
+ * Remove a variable
52
+ *
53
+ * @param key - The variable identifier to remove
54
+ * @returns true if a variable existed and has been removed, false otherwise
55
+ */
56
+ removeVariable(key: string): boolean;
57
+ /**
58
+ * Check if a variable exists
59
+ *
60
+ * @param key - The variable identifier to check
61
+ * @returns true if the variable exists, false otherwise
62
+ */
63
+ hasVariable(key: string): boolean;
64
+ /**
65
+ * Get all variable keys
66
+ *
67
+ * @returns Array of all variable keys
68
+ */
69
+ getVariableKeys(): string[];
70
+ /**
71
+ * Clear all variables
72
+ */
73
+ clearVariables(): void;
74
+ }