@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,6 @@
1
1
  import { Server } from '@signe/room';
2
+ import { RpgMap } from './rooms/map';
2
3
  import { LobbyRoom } from './rooms/lobby';
3
4
  export declare class RpgServerEngine extends Server {
4
- rooms: (typeof LobbyRoom)[];
5
+ rooms: (typeof RpgMap | typeof LobbyRoom)[];
5
6
  }
@@ -0,0 +1,46 @@
1
+ export declare enum EventMode {
2
+ Shared = "shared",
3
+ Scenario = "scenario"
4
+ }
5
+ export interface EventOptions {
6
+ /**
7
+ * The mode of the event, shared evening or scenario
8
+ *
9
+ * The scenario mode allows you to have events specific to the player. Thus, the graphics, the positions of the event will be different for each player. Beware of performance! The event is duplicated by each player.
10
+ *
11
+ * `shared` mode by default
12
+ *
13
+ * ```ts
14
+ * import { RpgEvent, EventData, RpgPlayer, EventMode } from '@rpgjs/server'
15
+ * @EventData({
16
+ * name: 'EV-1',
17
+ * mode: EventMode.Scenario // or EventMode.Shared
18
+ * })
19
+ * export class CharaEvent extends RpgEvent { }
20
+ * ```
21
+ *
22
+ * @prop {string} [mode] Either "shared" or "scenario".
23
+ * @memberof EventData
24
+ * */
25
+ mode?: EventMode;
26
+ width?: number;
27
+ height?: number;
28
+ /**
29
+ * The hitbox of the event. By default, this is the size of the tile of the map
30
+ *
31
+ * @prop { { width: number, height: number }} [hitbox]
32
+ * @memberof EventData
33
+ * */
34
+ hitbox?: {
35
+ width?: number;
36
+ height?: number;
37
+ };
38
+ /**
39
+ * Name of the event. This is its identifier. it allows you to retrieve an event and place it on the map
40
+ *
41
+ * @prop {string} name
42
+ * @memberof EventData
43
+ * */
44
+ name: string;
45
+ }
46
+ export declare function EventData(options: EventOptions): (target: any) => void;
@@ -0,0 +1,287 @@
1
+ import { WeatherState } from '../../../common/src';
2
+ export interface MapOptions {
3
+ /**
4
+ * Map identifier. Allows to go to the map (for example with player.changeMap())
5
+ *
6
+ * @prop {string} [id]
7
+ * @memberof MapData
8
+ * */
9
+ id?: string;
10
+ /**
11
+ * the path to the .tmx file (Tiled Map Editor)
12
+ *
13
+ * Remember to use `require()` function
14
+ *
15
+ * ```ts
16
+ * import { MapData, RpgMap } from '@rpgjs/server'
17
+ *
18
+ * @MapData({
19
+ * id: 'town',
20
+ * file: require('./tmx/town.tmx')
21
+ * })
22
+ * class TownMap extends RpgMap { }
23
+ * ```
24
+ * @prop {string} file
25
+ * @memberof MapData
26
+ * */
27
+ file?: any;
28
+ /**
29
+ * The name of the map.
30
+ * @prop {string} [name]
31
+ * @memberof MapData
32
+ * */
33
+ name?: string;
34
+ /**
35
+ * Map events. This is an array containing `RpgEvent` classes.
36
+ * You can also give an object that will indicate the positions of the event on the map.
37
+ *
38
+ * ```ts
39
+ * import { MapData, RpgMap, EventData, RpgEvent } from '@rpgjs/server'
40
+ *
41
+ * @EventData({
42
+ * name: 'Ev-1'
43
+ * })
44
+ * class NpcEvent extends RpgEvent { }
45
+ *
46
+ * @MapData({
47
+ * id: 'medieval',
48
+ * file: require('./tmx/town.tmx'),
49
+ * events: [NpcEvent]
50
+ * })
51
+ * class TownMap extends RpgMap {}
52
+ * ```
53
+ *
54
+ * If the positions are not defined, the event will be placed on a Tiled Map Editor shape ([/guide/create-event.html#position-the-event-on-the-map](Guide)). Otherwise, it will be placed at `{x:0, y:0 }`
55
+ *
56
+ * You can give positions:
57
+ *
58
+ * ```ts
59
+ * events: [{ event: NpcEvent, x: 10, y: 30 }]
60
+ * ```
61
+ *
62
+ * @prop {Class of RpgEvent[] | { event: Class RpgEvent, x: number, y: number }} [events]
63
+ * @memberof MapData
64
+ * */
65
+ events?: {
66
+ event: any;
67
+ x: number;
68
+ y: number;
69
+ }[] | any[];
70
+ /**
71
+ * The sounds that will be played when the map is open. Sounds must be defined on the client side. Then, put the name of the sound identifier
72
+ *
73
+ * So, it is possible to play several sounds (in loop or not) on the card. You can put a background music (BGM) and a background noise (BGS) for example
74
+ *
75
+ * ```ts
76
+ * sounds: ['my-bgm', 'my-bgs']
77
+ * ```
78
+ *
79
+ * And client side:
80
+ *
81
+ * ```ts
82
+ * import { Sound } from '@rpgjs/client'
83
+ *
84
+ * @Sound({
85
+ * sounds: {
86
+ * 'my-bgm': require('./assets/bgm.ogg'),
87
+ * 'my-bgs': require('./assets/bgs.ogg')
88
+ * },
89
+ * loop: true
90
+ * })
91
+ * export class Sounds {}
92
+ * ```
93
+ *
94
+ * See [https://docs.rpgjs.dev/classes/sound.html#properties](RpgSound Decorator)
95
+ *
96
+ * @prop {Array<string>} [sounds]
97
+ * @memberof MapData
98
+ * */
99
+ sounds?: string[];
100
+ /**
101
+ * Initial weather state for this map.
102
+ *
103
+ * This value is applied when the map is loaded and can later be updated
104
+ * at runtime with `map.setWeather()` from server logic.
105
+ *
106
+ * ```ts
107
+ * @MapData({
108
+ * id: 'forest',
109
+ * file: require('./tmx/forest.tmx'),
110
+ * weather: {
111
+ * effect: 'fog',
112
+ * preset: 'rpgForestFog',
113
+ * params: { density: 1.2, height: 0.75 },
114
+ * transitionMs: 1200
115
+ * }
116
+ * })
117
+ * class ForestMap extends RpgMap {}
118
+ * ```
119
+ */
120
+ weather?: WeatherState | null;
121
+ /**
122
+ * Whether to stop all sounds before playing the map sounds when a player joins.
123
+ *
124
+ * If set to `true`, all currently playing sounds will be stopped before playing the new map sounds.
125
+ * This prevents sound overlap when changing maps.
126
+ *
127
+ * By default, this is `false`, meaning sounds from the previous map will continue playing.
128
+ *
129
+ * ```ts
130
+ * @MapData({
131
+ * id: 'battle-map',
132
+ * sounds: ['battle-theme'],
133
+ * stopAllSoundsBeforeJoin: true // Stop all sounds before playing battle theme
134
+ * })
135
+ * class BattleMap extends RpgMap {}
136
+ * ```
137
+ *
138
+ * @prop {boolean} [stopAllSoundsBeforeJoin=false]
139
+ * @memberof MapData
140
+ * @since 5.0.0
141
+ * */
142
+ stopAllSoundsBeforeJoin?: boolean;
143
+ /**
144
+ * Specify which properties will be synchronized with the client. On the client side, you can retrieve the values synchronized with the valueChanges property on the scene
145
+ *
146
+ * You must create the schema:
147
+ *
148
+ * ```ts
149
+ * import { MapData, RpgMap } from '@rpgjs/server'
150
+ *
151
+ * @MapData({
152
+ * id: 'medieval',
153
+ * file: require('./tmx/town.tmx'),
154
+ * syncSchema: {
155
+ * count: Number
156
+ * }
157
+ * })
158
+ * export class TownMap extends RpgMap {
159
+ * count: number = 0
160
+ *
161
+ * onLoad() {}
162
+ *
163
+ * onJoin() {
164
+ * this.count++
165
+ * }
166
+ *
167
+ * onLeave(player) {
168
+ * super.onLeave(player)
169
+ * this.count--
170
+ * }
171
+ * }
172
+ *
173
+ * ```
174
+ *
175
+ * If you want to change the scheme of players and events, consider overwriting the existing scheme
176
+ *
177
+ * ```ts
178
+ * import { MapData, RpgMap, RpgPlayer } from '@rpgjs/server'
179
+ *
180
+ *
181
+ * declare module '@rpgjs/server' {
182
+ * export interface RpgPlayer {
183
+ * customProp: string
184
+ * }
185
+ * }
186
+ *
187
+ * @MapData({
188
+ * id: 'medieval',
189
+ * file: require('./tmx/town.tmx'),
190
+ * syncSchema: {
191
+ * users: [
192
+ * {
193
+ * customProp: String,
194
+ * ...RpgPlayer.schemas
195
+ * }
196
+ * ]
197
+ * }
198
+ * })
199
+ * export class TownMap extends RpgMap {}
200
+ * ```
201
+ *
202
+ * The properties are called `users` and `events`. Their scheme is identical and defined in `RpgPlayer.schemas`. To write schematics, refer to the [documentation of the simple-room](https://github.com/RSamaium/simple-room) module
203
+ *
204
+ * @prop {object} [syncSchema]
205
+ * @memberof MapData
206
+ * */
207
+ syncSchema?: any;
208
+ /**
209
+ * Decreases the RAM of the map. In this case, some instructions will be different.
210
+ *
211
+ * `map.getTileByIndex()` will not return all tiles of an index but only the tile of the highest layer
212
+ *
213
+ * > You can also use the `low-memory` property in Tiled maps
214
+ *
215
+ * @prop {boolean} [lowMemory=false]
216
+ * @since 3.1.0
217
+ * @memberof MapData
218
+ * */
219
+ lowMemory?: boolean;
220
+ /**
221
+ * Called when the map is loaded and initialized
222
+ *
223
+ * This hook is executed once when the map data is loaded and ready.
224
+ * Use this to initialize map-specific properties or setup.
225
+ *
226
+ * @prop { () => any } [onLoad]
227
+ * @memberof MapData
228
+ * @example
229
+ * ```ts
230
+ * @MapData({
231
+ * id: 'town',
232
+ * file: require('./tmx/town.tmx'),
233
+ * onLoad() {
234
+ * console.log('Town map loaded')
235
+ * // Initialize map properties
236
+ * }
237
+ * })
238
+ * class TownMap extends RpgMap {}
239
+ * ```
240
+ * */
241
+ onLoad?: () => any;
242
+ /**
243
+ * Called when a player joins the map
244
+ *
245
+ * This hook is executed each time a player joins the map.
246
+ * Use this to perform actions when a player enters the map.
247
+ *
248
+ * @prop { (player: RpgPlayer) => any } [onJoin]
249
+ * @memberof MapData
250
+ * @example
251
+ * ```ts
252
+ * @MapData({
253
+ * id: 'town',
254
+ * file: require('./tmx/town.tmx'),
255
+ * onJoin(player: RpgPlayer) {
256
+ * console.log(`${player.name} joined the town`)
257
+ * // Perform actions when player joins
258
+ * }
259
+ * })
260
+ * class TownMap extends RpgMap {}
261
+ * ```
262
+ * */
263
+ onJoin?: (player: RpgPlayer) => any;
264
+ /**
265
+ * Called when a player leaves the map
266
+ *
267
+ * This hook is executed each time a player leaves the map.
268
+ * Use this to perform cleanup or actions when a player exits the map.
269
+ *
270
+ * @prop { (player: RpgPlayer) => any } [onLeave]
271
+ * @memberof MapData
272
+ * @example
273
+ * ```ts
274
+ * @MapData({
275
+ * id: 'town',
276
+ * file: require('./tmx/town.tmx'),
277
+ * onLeave(player: RpgPlayer) {
278
+ * console.log(`${player.name} left the town`)
279
+ * // Perform cleanup when player leaves
280
+ * }
281
+ * })
282
+ * class TownMap extends RpgMap {}
283
+ * ```
284
+ * */
285
+ onLeave?: (player: RpgPlayer) => any;
286
+ }
287
+ export declare function MapData(options: MapOptions): (target: any) => void;
package/dist/index.d.ts CHANGED
@@ -4,6 +4,16 @@ export * from './RpgServer';
4
4
  export * from './core/setup';
5
5
  export * from './core/inject';
6
6
  export * from './Player/Player';
7
+ export * from './Player/Components';
7
8
  export * from './module';
8
9
  export * from './rooms/map';
9
10
  export * from './presets';
11
+ export * from '@signe/reactive';
12
+ export * from './Gui';
13
+ export * from './services/save';
14
+ export * from './storage';
15
+ export { RpgShape, RpgModule, MAXHP, MAXSP, ATK, PDEF, SDEF, STR, AGI, INT, DEX } from '../../common/src';
16
+ export * from './decorators/event';
17
+ export * from './decorators/map';
18
+ export * from './Player/MoveManager';
19
+ export * from './presets';