@rpgjs/server 5.0.0-alpha.9 → 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.
- package/dist/Gui/DialogGui.d.ts +5 -0
- package/dist/Gui/GameoverGui.d.ts +23 -0
- package/dist/Gui/Gui.d.ts +6 -0
- package/dist/Gui/MenuGui.d.ts +22 -3
- package/dist/Gui/NotificationGui.d.ts +1 -2
- package/dist/Gui/SaveLoadGui.d.ts +13 -0
- package/dist/Gui/ShopGui.d.ts +28 -3
- package/dist/Gui/TitleGui.d.ts +23 -0
- package/dist/Gui/index.d.ts +10 -1
- package/dist/Player/BattleManager.d.ts +44 -32
- package/dist/Player/ClassManager.d.ts +24 -4
- package/dist/Player/ComponentManager.d.ts +95 -32
- package/dist/Player/Components.d.ts +345 -0
- package/dist/Player/EffectManager.d.ts +50 -4
- package/dist/Player/ElementManager.d.ts +77 -4
- package/dist/Player/GoldManager.d.ts +1 -1
- package/dist/Player/GuiManager.d.ts +87 -4
- package/dist/Player/ItemFixture.d.ts +1 -1
- package/dist/Player/ItemManager.d.ts +431 -4
- package/dist/Player/MoveManager.d.ts +301 -34
- package/dist/Player/ParameterManager.d.ts +364 -28
- package/dist/Player/Player.d.ts +558 -14
- package/dist/Player/SkillManager.d.ts +187 -13
- package/dist/Player/StateManager.d.ts +75 -4
- package/dist/Player/VariableManager.d.ts +62 -4
- package/dist/RpgServer.d.ts +278 -63
- package/dist/RpgServerEngine.d.ts +2 -1
- package/dist/decorators/event.d.ts +46 -0
- package/dist/decorators/map.d.ts +299 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +17920 -29711
- package/dist/index.js.map +1 -1
- package/dist/logs/log.d.ts +2 -3
- package/dist/module-CaCW1SDh.js +11018 -0
- package/dist/module-CaCW1SDh.js.map +1 -0
- package/dist/module.d.ts +43 -1
- package/dist/node/connection.d.ts +51 -0
- package/dist/node/index.d.ts +5 -0
- package/dist/node/index.js +551 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/map.d.ts +16 -0
- package/dist/node/room.d.ts +21 -0
- package/dist/node/transport.d.ts +28 -0
- package/dist/node/types.d.ts +47 -0
- package/dist/presets/index.d.ts +0 -9
- package/dist/rooms/BaseRoom.d.ts +132 -0
- package/dist/rooms/lobby.d.ts +10 -2
- package/dist/rooms/map.d.ts +1359 -32
- package/dist/services/save.d.ts +43 -0
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/localStorage.d.ts +23 -0
- package/package.json +25 -10
- package/src/Gui/DialogGui.ts +19 -4
- package/src/Gui/GameoverGui.ts +39 -0
- package/src/Gui/Gui.ts +23 -1
- package/src/Gui/MenuGui.ts +155 -6
- package/src/Gui/NotificationGui.ts +1 -2
- package/src/Gui/SaveLoadGui.ts +60 -0
- package/src/Gui/ShopGui.ts +146 -16
- package/src/Gui/TitleGui.ts +39 -0
- package/src/Gui/index.ts +15 -2
- package/src/Player/BattleManager.ts +39 -56
- package/src/Player/ClassManager.ts +82 -74
- package/src/Player/ComponentManager.ts +394 -32
- package/src/Player/Components.ts +380 -0
- package/src/Player/EffectManager.ts +50 -96
- package/src/Player/ElementManager.ts +74 -152
- package/src/Player/GuiManager.ts +125 -14
- package/src/Player/ItemManager.ts +747 -341
- package/src/Player/MoveManager.ts +1532 -750
- package/src/Player/ParameterManager.ts +636 -106
- package/src/Player/Player.ts +1273 -79
- package/src/Player/SkillManager.ts +558 -197
- package/src/Player/StateManager.ts +131 -258
- package/src/Player/VariableManager.ts +85 -157
- package/src/RpgServer.ts +293 -62
- package/src/decorators/event.ts +61 -0
- package/src/decorators/map.ts +343 -0
- package/src/index.ts +11 -1
- package/src/logs/log.ts +10 -3
- package/src/module.ts +126 -3
- package/src/node/connection.ts +254 -0
- package/src/node/index.ts +22 -0
- package/src/node/map.ts +328 -0
- package/src/node/room.ts +63 -0
- package/src/node/transport.ts +532 -0
- package/src/node/types.ts +61 -0
- package/src/presets/index.ts +1 -10
- package/src/rooms/BaseRoom.ts +232 -0
- package/src/rooms/lobby.ts +25 -7
- package/src/rooms/map.ts +2682 -206
- package/src/services/save.ts +147 -0
- package/src/storage/index.ts +1 -0
- package/src/storage/localStorage.ts +76 -0
- package/tests/battle.spec.ts +375 -0
- package/tests/change-map.spec.ts +72 -0
- package/tests/class.spec.ts +274 -0
- package/tests/custom-websocket.spec.ts +127 -0
- package/tests/effect.spec.ts +219 -0
- package/tests/element.spec.ts +221 -0
- package/tests/event.spec.ts +80 -0
- package/tests/gold.spec.ts +99 -0
- package/tests/item.spec.ts +609 -0
- package/tests/module.spec.ts +38 -0
- package/tests/move.spec.ts +601 -0
- package/tests/node-transport.spec.ts +223 -0
- package/tests/player-param.spec.ts +45 -0
- package/tests/prediction-reconciliation.spec.ts +182 -0
- package/tests/random-move.spec.ts +65 -0
- package/tests/skill.spec.ts +658 -0
- package/tests/state.spec.ts +467 -0
- package/tests/variable.spec.ts +185 -0
- package/tests/world-maps.spec.ts +896 -0
- package/vite.config.ts +36 -3
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Constructor, PlayerCtor } from "@rpgjs/common";
|
|
2
|
+
import { signal } from "@signe/reactive";
|
|
3
|
+
import { type } from "@signe/sync";
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Variable Manager Mixin
|
|
@@ -6,6 +8,11 @@ import { Constructor, PlayerCtor } from "@rpgjs/common";
|
|
|
6
8
|
* Provides variable management capabilities to any class. Variables are key-value
|
|
7
9
|
* pairs that can store any type of data associated with the player, such as
|
|
8
10
|
* quest progress, game flags, inventory state, and custom game data.
|
|
11
|
+
*
|
|
12
|
+
* Player variables have two main roles:
|
|
13
|
+
*
|
|
14
|
+
* 1. Persist player-specific state so it can be restored from saves.
|
|
15
|
+
* 2. Carry that state across maps and map servers through the player snapshot.
|
|
9
16
|
*
|
|
10
17
|
* @param Base - The base class to extend with variable management
|
|
11
18
|
* @returns Extended class with variable management methods
|
|
@@ -25,183 +32,104 @@ import { Constructor, PlayerCtor } from "@rpgjs/common";
|
|
|
25
32
|
*/
|
|
26
33
|
export function WithVariableManager<TBase extends PlayerCtor>(Base: TBase) {
|
|
27
34
|
return class extends Base {
|
|
28
|
-
variables
|
|
35
|
+
variables = type(signal<Record<string, any>>({}) as any, 'variables', { persist: true }, this as any);
|
|
29
36
|
|
|
30
|
-
/**
|
|
31
|
-
* Assign a variable to the player
|
|
32
|
-
*
|
|
33
|
-
* Stores a key-value pair in the player's variable map. This is useful for
|
|
34
|
-
* tracking game state, quest progress, flags, and other player-specific data.
|
|
35
|
-
* The variable system provides a flexible way to store any type of data
|
|
36
|
-
* associated with the player that persists throughout the game session.
|
|
37
|
-
*
|
|
38
|
-
* @param key - The variable identifier (string key to reference the variable)
|
|
39
|
-
* @param val - The value to store (can be any type: boolean, number, string, object, array)
|
|
40
|
-
* @returns void
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* // Set different types of variables
|
|
45
|
-
* player.setVariable('CHEST_OPENED', true);
|
|
46
|
-
* player.setVariable('playerLevel', 5);
|
|
47
|
-
* player.setVariable('questProgress', { step: 1, completed: false });
|
|
48
|
-
* player.setVariable('inventory', ['sword', 'potion', 'key']);
|
|
49
|
-
* player.setVariable('lastSaveTime', new Date().toISOString());
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
37
|
setVariable(key: string, val: any): void {
|
|
53
|
-
this.variables.
|
|
38
|
+
this.variables.mutate((variables) => {
|
|
39
|
+
variables[key] = val;
|
|
40
|
+
});
|
|
54
41
|
}
|
|
55
42
|
|
|
56
|
-
/**
|
|
57
|
-
* Get a variable value
|
|
58
|
-
*
|
|
59
|
-
* Retrieves the value associated with the given key from the player's variables.
|
|
60
|
-
* Returns undefined if the variable doesn't exist. This method is type-safe
|
|
61
|
-
* and can be used with generic types for better TypeScript support.
|
|
62
|
-
*
|
|
63
|
-
* @param key - The variable identifier to retrieve
|
|
64
|
-
* @returns The stored value or undefined if not found
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```ts
|
|
68
|
-
* // Get variables with type inference
|
|
69
|
-
* const hasKey = player.getVariable('CHEST_OPENED'); // boolean | undefined
|
|
70
|
-
* const level = player.getVariable('playerLevel'); // number | undefined
|
|
71
|
-
* const quest = player.getVariable('questProgress'); // object | undefined
|
|
72
|
-
* const missing = player.getVariable('nonexistent'); // undefined
|
|
73
|
-
*
|
|
74
|
-
* // Use with default values
|
|
75
|
-
* const level = player.getVariable('playerLevel') ?? 1;
|
|
76
|
-
* const isChestOpened = player.getVariable('CHEST_OPENED') ?? false;
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
43
|
getVariable<U = any>(key: string): U | undefined {
|
|
80
|
-
return this.variables
|
|
44
|
+
return this.variables()[key];
|
|
81
45
|
}
|
|
82
46
|
|
|
83
|
-
/**
|
|
84
|
-
* Remove a variable
|
|
85
|
-
*
|
|
86
|
-
* Deletes a variable from the player's variable map. This is useful for
|
|
87
|
-
* cleaning up temporary flags, resetting certain game states, or managing
|
|
88
|
-
* memory by removing unused variables. The method returns a boolean indicating
|
|
89
|
-
* whether the variable existed and was successfully removed.
|
|
90
|
-
*
|
|
91
|
-
* @param key - The variable identifier to remove
|
|
92
|
-
* @returns true if a variable existed and has been removed, false if the variable does not exist
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```ts
|
|
96
|
-
* // Remove variables and check if they existed
|
|
97
|
-
* const removed = player.removeVariable('CHEST_OPENED'); // true if existed
|
|
98
|
-
* const notFound = player.removeVariable('nonexistent'); // false
|
|
99
|
-
*
|
|
100
|
-
* // Clean up temporary variables
|
|
101
|
-
* player.removeVariable('tempQuestFlag');
|
|
102
|
-
* player.removeVariable('battleTempData');
|
|
103
|
-
*
|
|
104
|
-
* // Conditional removal
|
|
105
|
-
* if (player.getVariable('questCompleted')) {
|
|
106
|
-
* player.removeVariable('questProgress');
|
|
107
|
-
* }
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
47
|
removeVariable(key: string): boolean {
|
|
111
|
-
|
|
48
|
+
const variables = this.variables();
|
|
49
|
+
if (!(key in variables)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
this.variables.mutate((draft) => {
|
|
53
|
+
delete draft[key];
|
|
54
|
+
});
|
|
55
|
+
return true;
|
|
112
56
|
}
|
|
113
57
|
|
|
114
|
-
/**
|
|
115
|
-
* Check if a variable exists
|
|
116
|
-
*
|
|
117
|
-
* Determines whether a variable with the given key exists in the player's
|
|
118
|
-
* variable map, regardless of its value (including falsy values like false, 0, '').
|
|
119
|
-
* This is useful when you need to distinguish between a variable that doesn't
|
|
120
|
-
* exist and one that has a falsy value.
|
|
121
|
-
*
|
|
122
|
-
* @param key - The variable identifier to check
|
|
123
|
-
* @returns true if the variable exists, false otherwise
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```ts
|
|
127
|
-
* // Check variable existence
|
|
128
|
-
* player.setVariable('flag', false);
|
|
129
|
-
* player.hasVariable('flag'); // true (even though value is false)
|
|
130
|
-
* player.hasVariable('missing'); // false
|
|
131
|
-
*
|
|
132
|
-
* // Use in conditional logic
|
|
133
|
-
* if (player.hasVariable('questStarted')) {
|
|
134
|
-
* // Quest has been started, check progress
|
|
135
|
-
* const progress = player.getVariable('questProgress');
|
|
136
|
-
* } else {
|
|
137
|
-
* // Quest not started yet
|
|
138
|
-
* player.setVariable('questStarted', true);
|
|
139
|
-
* }
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
58
|
hasVariable(key: string): boolean {
|
|
143
|
-
return this.variables
|
|
59
|
+
return key in this.variables();
|
|
144
60
|
}
|
|
145
61
|
|
|
146
|
-
/**
|
|
147
|
-
* Get all variable keys
|
|
148
|
-
*
|
|
149
|
-
* Returns an array of all variable keys currently stored for this player.
|
|
150
|
-
* This is useful for debugging, serialization, or iterating over all variables.
|
|
151
|
-
* The keys are returned in insertion order.
|
|
152
|
-
*
|
|
153
|
-
* @returns Array of all variable keys
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```ts
|
|
157
|
-
* // Get all variable keys
|
|
158
|
-
* const keys = player.getVariableKeys();
|
|
159
|
-
* console.log('Player has variables:', keys);
|
|
160
|
-
*
|
|
161
|
-
* // Iterate over all variables
|
|
162
|
-
* keys.forEach(key => {
|
|
163
|
-
* const value = player.getVariable(key);
|
|
164
|
-
* console.log(`${key}: ${value}`);
|
|
165
|
-
* });
|
|
166
|
-
*
|
|
167
|
-
* // Filter specific variable types
|
|
168
|
-
* const questKeys = keys.filter(key => key.startsWith('quest_'));
|
|
169
|
-
* ```
|
|
170
|
-
*/
|
|
171
62
|
getVariableKeys(): string[] {
|
|
172
|
-
return
|
|
63
|
+
return Object.keys(this.variables());
|
|
173
64
|
}
|
|
174
65
|
|
|
175
|
-
/**
|
|
176
|
-
* Clear all variables
|
|
177
|
-
*
|
|
178
|
-
* Removes all variables from the player's variable map. This is useful for
|
|
179
|
-
* resetting the player state, cleaning up before saving, or starting fresh.
|
|
180
|
-
* Use with caution as this operation cannot be undone.
|
|
181
|
-
*
|
|
182
|
-
* @returns void
|
|
183
|
-
*
|
|
184
|
-
* @example
|
|
185
|
-
* ```ts
|
|
186
|
-
* // Clear all variables (use with caution)
|
|
187
|
-
* player.clearVariables();
|
|
188
|
-
*
|
|
189
|
-
* // Clear variables conditionally
|
|
190
|
-
* if (gameReset) {
|
|
191
|
-
* player.clearVariables();
|
|
192
|
-
* // Re-initialize essential variables
|
|
193
|
-
* player.setVariable('gameStarted', true);
|
|
194
|
-
* }
|
|
195
|
-
* ```
|
|
196
|
-
*/
|
|
197
66
|
clearVariables(): void {
|
|
198
|
-
this.variables.
|
|
67
|
+
this.variables.set({});
|
|
199
68
|
}
|
|
200
69
|
} as unknown as TBase;
|
|
201
70
|
}
|
|
202
71
|
|
|
203
72
|
/**
|
|
204
|
-
*
|
|
205
|
-
*
|
|
73
|
+
* Interface for Variable Manager functionality
|
|
74
|
+
*
|
|
75
|
+
* Provides variable management capabilities including storing, retrieving, and managing
|
|
76
|
+
* key-value pairs for player-specific data. This interface defines the public API
|
|
77
|
+
* of the VariableManager mixin.
|
|
206
78
|
*/
|
|
207
|
-
export
|
|
79
|
+
export interface IVariableManager {
|
|
80
|
+
/**
|
|
81
|
+
* Map storing all player variables.
|
|
82
|
+
*
|
|
83
|
+
* These values belong to the player, are persisted, and travel with the
|
|
84
|
+
* player snapshot when switching maps or servers.
|
|
85
|
+
*/
|
|
86
|
+
variables: Map<string, any>;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Assign a variable to the player.
|
|
90
|
+
*
|
|
91
|
+
* Use player variables for quest flags, per-player event state, and any value
|
|
92
|
+
* that must survive saves and map transitions.
|
|
93
|
+
*
|
|
94
|
+
* @param key - The variable identifier
|
|
95
|
+
* @param val - The value to store
|
|
96
|
+
* @memberof VariableManager
|
|
97
|
+
*/
|
|
98
|
+
setVariable(key: string, val: any): void;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Get a variable value
|
|
102
|
+
*
|
|
103
|
+
* @param key - The variable identifier to retrieve
|
|
104
|
+
* @returns The stored value or undefined if not found
|
|
105
|
+
*/
|
|
106
|
+
getVariable<U = any>(key: string): U | undefined;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Remove a variable
|
|
110
|
+
*
|
|
111
|
+
* @param key - The variable identifier to remove
|
|
112
|
+
* @returns true if a variable existed and has been removed, false otherwise
|
|
113
|
+
*/
|
|
114
|
+
removeVariable(key: string): boolean;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Check if a variable exists
|
|
118
|
+
*
|
|
119
|
+
* @param key - The variable identifier to check
|
|
120
|
+
* @returns true if the variable exists, false otherwise
|
|
121
|
+
*/
|
|
122
|
+
hasVariable(key: string): boolean;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Get all variable keys
|
|
126
|
+
*
|
|
127
|
+
* @returns Array of all variable keys
|
|
128
|
+
*/
|
|
129
|
+
getVariableKeys(): string[];
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Clear all variables
|
|
133
|
+
*/
|
|
134
|
+
clearVariables(): void;
|
|
135
|
+
}
|