@rpgjs/server 5.0.0-alpha.4 → 5.0.0-alpha.40
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 +34 -12
- package/dist/Player/ClassManager.d.ts +46 -13
- package/dist/Player/ComponentManager.d.ts +123 -0
- package/dist/Player/Components.d.ts +345 -0
- package/dist/Player/EffectManager.d.ts +86 -0
- package/dist/Player/ElementManager.d.ts +104 -0
- package/dist/Player/GoldManager.d.ts +22 -0
- package/dist/Player/GuiManager.d.ts +259 -0
- package/dist/Player/ItemFixture.d.ts +6 -0
- package/dist/Player/ItemManager.d.ts +450 -9
- package/dist/Player/MoveManager.d.ts +324 -69
- package/dist/Player/ParameterManager.d.ts +344 -14
- package/dist/Player/Player.d.ts +460 -8
- package/dist/Player/SkillManager.d.ts +197 -15
- package/dist/Player/StateManager.d.ts +89 -25
- package/dist/Player/VariableManager.d.ts +74 -0
- package/dist/RpgServer.d.ts +464 -64
- package/dist/RpgServerEngine.d.ts +2 -1
- package/dist/decorators/event.d.ts +46 -0
- package/dist/decorators/map.d.ts +287 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +21491 -20802
- package/dist/index.js.map +1 -1
- package/dist/logs/log.d.ts +2 -3
- package/dist/module.d.ts +43 -1
- 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 +1232 -17
- 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 +14 -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 +91 -49
- package/src/Player/ClassManager.ts +118 -50
- package/src/Player/ComponentManager.ts +425 -19
- package/src/Player/Components.ts +380 -0
- package/src/Player/EffectManager.ts +81 -44
- package/src/Player/ElementManager.ts +109 -86
- package/src/Player/GoldManager.ts +32 -35
- package/src/Player/GuiManager.ts +308 -150
- package/src/Player/ItemFixture.ts +4 -5
- package/src/Player/ItemManager.ts +774 -355
- package/src/Player/MoveManager.ts +1544 -774
- package/src/Player/ParameterManager.ts +546 -104
- package/src/Player/Player.ts +1163 -88
- package/src/Player/SkillManager.ts +520 -195
- package/src/Player/StateManager.ts +170 -182
- package/src/Player/VariableManager.ts +101 -63
- package/src/RpgServer.ts +483 -63
- package/src/core/context.ts +1 -0
- package/src/decorators/event.ts +61 -0
- package/src/decorators/map.ts +327 -0
- package/src/index.ts +11 -1
- package/src/logs/log.ts +10 -3
- package/src/module.ts +126 -3
- 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 +2473 -194
- 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/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/player-param.spec.ts +28 -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 +16 -0
- package/dist/Player/Event.d.ts +0 -0
- package/src/Player/Event.ts +0 -0
package/dist/RpgServer.d.ts
CHANGED
|
@@ -1,16 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MapOptions } from './decorators/map';
|
|
2
|
+
import { RpgPlayer, RpgEvent } from './Player/Player';
|
|
2
3
|
import { RpgMap } from './rooms/map';
|
|
3
4
|
import { RpgServerEngine } from './RpgServerEngine';
|
|
4
|
-
|
|
5
|
-
type RpgClassMap<T> =
|
|
6
|
-
type RpgClassEvent<T> =
|
|
7
|
-
type RpgEvent = any;
|
|
5
|
+
import { WorldMapConfig, RpgShape } from '../../common/src';
|
|
6
|
+
type RpgClassMap<T> = new () => T;
|
|
7
|
+
type RpgClassEvent<T> = RpgEvent;
|
|
8
8
|
type MatchMakerOption = any;
|
|
9
9
|
type RpgMatchMaker = any;
|
|
10
10
|
type IStoreState = any;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Interface for world map configuration
|
|
13
|
+
*
|
|
14
|
+
* Represents a world that contains multiple maps with their spatial relationships.
|
|
15
|
+
* This is typically used with Tiled Map Editor's world files.
|
|
16
|
+
*
|
|
17
|
+
* @interface WorldMap
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const worldMap: WorldMap = {
|
|
21
|
+
* id: 'my-world',
|
|
22
|
+
* maps: [
|
|
23
|
+
* { id: 'map1', worldX: 0, worldY: 0, width: 800, height: 600 },
|
|
24
|
+
* { id: 'map2', worldX: 800, worldY: 0, width: 800, height: 600 }
|
|
25
|
+
* ]
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export interface WorldMap {
|
|
30
|
+
/** Optional world identifier */
|
|
31
|
+
id?: string;
|
|
32
|
+
/** Array of map configurations that belong to this world */
|
|
33
|
+
maps: WorldMapConfig[];
|
|
34
|
+
/** Only show adjacent maps (used by Tiled Map Editor) */
|
|
35
|
+
onlyShowAdjacentMaps?: boolean;
|
|
36
|
+
/** Type identifier (used by Tiled Map Editor, should be 'world') */
|
|
37
|
+
type?: 'world';
|
|
38
|
+
}
|
|
14
39
|
export interface RpgServerEngineHooks {
|
|
15
40
|
/**
|
|
16
41
|
* When the server starts
|
|
@@ -143,6 +168,13 @@ export interface RpgPlayerHooks {
|
|
|
143
168
|
*/
|
|
144
169
|
onConnected?: (player: RpgPlayer) => any;
|
|
145
170
|
/**
|
|
171
|
+
* When the player starts the game from the lobby
|
|
172
|
+
*
|
|
173
|
+
* @prop { (player: RpgPlayer) => any } [onStart]
|
|
174
|
+
* @memberof RpgPlayerHooks
|
|
175
|
+
*/
|
|
176
|
+
onStart?: (player: RpgPlayer) => any;
|
|
177
|
+
/**
|
|
146
178
|
* When the player presses a key on the client side
|
|
147
179
|
*
|
|
148
180
|
* @prop { (player: RpgPlayer, data: { input: Direction | Control | string, moving: boolean }) => any } [onInput]
|
|
@@ -210,19 +242,310 @@ export interface RpgPlayerHooks {
|
|
|
210
242
|
*/
|
|
211
243
|
canChangeMap?: (player: RpgPlayer, nextMap: RpgClassMap<RpgMap>) => boolean | Promise<boolean>;
|
|
212
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Event hooks interface for handling various event lifecycle methods
|
|
247
|
+
*
|
|
248
|
+
* @interface RpgEventHooks
|
|
249
|
+
* @since 4.0.0
|
|
250
|
+
*/
|
|
213
251
|
export interface RpgEventHooks {
|
|
252
|
+
/**
|
|
253
|
+
* Called as soon as the event is created on the map
|
|
254
|
+
*
|
|
255
|
+
* @param {RpgEvent} event - The event instance being initialized
|
|
256
|
+
* @returns {any}
|
|
257
|
+
* @memberof RpgEventHooks
|
|
258
|
+
* @example
|
|
259
|
+
* ```ts
|
|
260
|
+
* const eventHooks: RpgEventHooks = {
|
|
261
|
+
* onInit(event) {
|
|
262
|
+
* console.log(`Event ${event.name} initialized`)
|
|
263
|
+
* event.graphic('default-sprite')
|
|
264
|
+
* }
|
|
265
|
+
* }
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
214
268
|
onInit?: (event: RpgEvent) => any;
|
|
269
|
+
/**
|
|
270
|
+
* Called when the event collides with a player and the player presses the action key
|
|
271
|
+
*
|
|
272
|
+
* @param {RpgEvent} event - The event being interacted with
|
|
273
|
+
* @param {RpgPlayer} player - The player performing the action
|
|
274
|
+
* @returns {any}
|
|
275
|
+
* @memberof RpgEventHooks
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* const eventHooks: RpgEventHooks = {
|
|
279
|
+
* onAction(event, player) {
|
|
280
|
+
* player.showText('You activated the chest!')
|
|
281
|
+
* player.addItem('POTION', 1)
|
|
282
|
+
* }
|
|
283
|
+
* }
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
215
286
|
onAction?: (event: RpgEvent, player: RpgPlayer) => any;
|
|
287
|
+
/**
|
|
288
|
+
* Called before an event object is created and added to the map
|
|
289
|
+
* Allows modification of event properties before instantiation
|
|
290
|
+
*
|
|
291
|
+
* @param {any} object - The event object data before creation
|
|
292
|
+
* @param {RpgMap} map - The map where the event will be created
|
|
293
|
+
* @returns {any}
|
|
294
|
+
* @memberof RpgEventHooks
|
|
295
|
+
* @example
|
|
296
|
+
* ```ts
|
|
297
|
+
* const eventHooks: RpgEventHooks = {
|
|
298
|
+
* onBeforeCreated(object, map) {
|
|
299
|
+
* // Modify event properties based on map conditions
|
|
300
|
+
* if (map.id === 'dungeon') {
|
|
301
|
+
* object.graphic = 'monster-sprite'
|
|
302
|
+
* }
|
|
303
|
+
* }
|
|
304
|
+
* }
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
216
307
|
onBeforeCreated?: (object: any, map: RpgMap) => any;
|
|
308
|
+
/**
|
|
309
|
+
* Called when a player or another event enters a shape attached to this event
|
|
310
|
+
*
|
|
311
|
+
* @param {RpgEvent} event - The event with the attached shape
|
|
312
|
+
* @param {RpgPlayer} player - The player entering the shape
|
|
313
|
+
* @param {RpgShape} shape - The shape being entered
|
|
314
|
+
* @returns {any}
|
|
315
|
+
* @since 4.1.0
|
|
316
|
+
* @memberof RpgEventHooks
|
|
317
|
+
* @example
|
|
318
|
+
* ```ts
|
|
319
|
+
* const eventHooks: RpgEventHooks = {
|
|
320
|
+
* onDetectInShape(event, player, shape) {
|
|
321
|
+
* console.log(`Player ${player.name} entered detection zone`)
|
|
322
|
+
* player.showText('You are being watched...')
|
|
323
|
+
* }
|
|
324
|
+
* }
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
217
327
|
onDetectInShape?: (event: RpgEvent, player: RpgPlayer, shape: RpgShape) => any;
|
|
328
|
+
/**
|
|
329
|
+
* Called when a player or another event leaves a shape attached to this event
|
|
330
|
+
*
|
|
331
|
+
* @param {RpgEvent} event - The event with the attached shape
|
|
332
|
+
* @param {RpgPlayer} player - The player leaving the shape
|
|
333
|
+
* @param {RpgShape} shape - The shape being left
|
|
334
|
+
* @returns {any}
|
|
335
|
+
* @since 4.1.0
|
|
336
|
+
* @memberof RpgEventHooks
|
|
337
|
+
* @example
|
|
338
|
+
* ```ts
|
|
339
|
+
* const eventHooks: RpgEventHooks = {
|
|
340
|
+
* onDetectOutShape(event, player, shape) {
|
|
341
|
+
* console.log(`Player ${player.name} left detection zone`)
|
|
342
|
+
* player.showText('You escaped the watch...')
|
|
343
|
+
* }
|
|
344
|
+
* }
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
218
347
|
onDetectOutShape?: (event: RpgEvent, player: RpgPlayer, shape: RpgShape) => any;
|
|
348
|
+
/**
|
|
349
|
+
* Called when the event enters a shape on the map
|
|
350
|
+
*
|
|
351
|
+
* @param {RpgEvent} event - The event entering the shape
|
|
352
|
+
* @param {RpgShape} shape - The shape being entered
|
|
353
|
+
* @returns {any}
|
|
354
|
+
* @memberof RpgEventHooks
|
|
355
|
+
* @example
|
|
356
|
+
* ```ts
|
|
357
|
+
* const eventHooks: RpgEventHooks = {
|
|
358
|
+
* onInShape(event, shape) {
|
|
359
|
+
* console.log(`Event entered shape: ${shape.id}`)
|
|
360
|
+
* event.speed = 1 // Slow down in this area
|
|
361
|
+
* }
|
|
362
|
+
* }
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
219
365
|
onInShape?: (event: RpgEvent, shape: RpgShape) => any;
|
|
366
|
+
/**
|
|
367
|
+
* Called when the event leaves a shape on the map
|
|
368
|
+
*
|
|
369
|
+
* @param {RpgEvent} event - The event leaving the shape
|
|
370
|
+
* @param {RpgShape} shape - The shape being left
|
|
371
|
+
* @returns {any}
|
|
372
|
+
* @memberof RpgEventHooks
|
|
373
|
+
* @example
|
|
374
|
+
* ```ts
|
|
375
|
+
* const eventHooks: RpgEventHooks = {
|
|
376
|
+
* onOutShape(event, shape) {
|
|
377
|
+
* console.log(`Event left shape: ${shape.id}`)
|
|
378
|
+
* event.speed = 3 // Resume normal speed
|
|
379
|
+
* }
|
|
380
|
+
* }
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
220
383
|
onOutShape?: (event: RpgEvent, shape: RpgShape) => any;
|
|
384
|
+
/**
|
|
385
|
+
* Called when the event collides with a player (without requiring action key press)
|
|
386
|
+
*
|
|
387
|
+
* @param {RpgEvent} event - The event touching the player
|
|
388
|
+
* @param {RpgPlayer} player - The player being touched
|
|
389
|
+
* @returns {any}
|
|
390
|
+
* @memberof RpgEventHooks
|
|
391
|
+
* @example
|
|
392
|
+
* ```ts
|
|
393
|
+
* const eventHooks: RpgEventHooks = {
|
|
394
|
+
* onPlayerTouch(event, player) {
|
|
395
|
+
* player.hp -= 10 // Damage on touch
|
|
396
|
+
* player.showText('Ouch! You touched a spike!')
|
|
397
|
+
* }
|
|
398
|
+
* }
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
221
401
|
onPlayerTouch?: (event: RpgEvent, player: RpgPlayer) => any;
|
|
402
|
+
/**
|
|
403
|
+
* Called whenever any event on the map (including itself) is executed or changes state
|
|
404
|
+
* Useful for creating reactive events that respond to map state changes
|
|
405
|
+
*
|
|
406
|
+
* @param {RpgEvent} event - The event listening for changes
|
|
407
|
+
* @param {RpgPlayer} player - The player involved in the change
|
|
408
|
+
* @returns {any}
|
|
409
|
+
* @memberof RpgEventHooks
|
|
410
|
+
* @example
|
|
411
|
+
* ```ts
|
|
412
|
+
* const eventHooks: RpgEventHooks = {
|
|
413
|
+
* onChanges(event, player) {
|
|
414
|
+
* // Change chest graphic based on game state
|
|
415
|
+
* if (player.getVariable('BATTLE_END')) {
|
|
416
|
+
* event.graphic('chest-open')
|
|
417
|
+
* } else {
|
|
418
|
+
* event.graphic('chest-close')
|
|
419
|
+
* }
|
|
420
|
+
* }
|
|
421
|
+
* }
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
222
424
|
onChanges?: (event: RpgEvent, player: RpgPlayer) => any;
|
|
223
425
|
}
|
|
426
|
+
/**
|
|
427
|
+
* Map hooks interface for handling map lifecycle events
|
|
428
|
+
*
|
|
429
|
+
* These hooks are global hooks that apply to all maps in the game.
|
|
430
|
+
* They are defined in the RpgModule configuration and executed for every map instance.
|
|
431
|
+
*
|
|
432
|
+
* @interface RpgMapHooks
|
|
433
|
+
* @since 4.0.0
|
|
434
|
+
*/
|
|
224
435
|
export interface RpgMapHooks {
|
|
225
|
-
|
|
436
|
+
/**
|
|
437
|
+
* Called before a map is updated with new data
|
|
438
|
+
* Allows modification of map data before the update is applied
|
|
439
|
+
*
|
|
440
|
+
* The `mapData` parameter contains the loaded map data (retrieved from request body)
|
|
441
|
+
* You can modify the map before the update is processed
|
|
442
|
+
*
|
|
443
|
+
* @template T - Type of the incoming map data
|
|
444
|
+
* @template U - Type of the map instance (defaults to RpgMap)
|
|
445
|
+
* @param {T} mapData - The map data loaded from external source (e.g., request body)
|
|
446
|
+
* @param {U} map - The current map instance being updated
|
|
447
|
+
* @returns {U | Promise<U>} The modified map instance or a promise resolving to it
|
|
448
|
+
* @memberof RpgMapHooks
|
|
449
|
+
* @example
|
|
450
|
+
* ```ts
|
|
451
|
+
* const mapHooks: RpgMapHooks = {
|
|
452
|
+
* onBeforeUpdate(mapData, map) {
|
|
453
|
+
* // Modify map properties based on incoming data
|
|
454
|
+
* if (mapData.weather === 'rain') {
|
|
455
|
+
* map.setWeatherEffect('rain')
|
|
456
|
+
* }
|
|
457
|
+
*
|
|
458
|
+
* // Add custom properties from external data
|
|
459
|
+
* map.customProperty = mapData.customValue
|
|
460
|
+
*
|
|
461
|
+
* return map
|
|
462
|
+
* }
|
|
463
|
+
* }
|
|
464
|
+
* ```
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```ts
|
|
468
|
+
* // Async example with database operations
|
|
469
|
+
* const mapHooks: RpgMapHooks = {
|
|
470
|
+
* async onBeforeUpdate(mapData, map) {
|
|
471
|
+
* // Load additional data from database
|
|
472
|
+
* const additionalData = await database.getMapExtras(map.id)
|
|
473
|
+
*
|
|
474
|
+
* // Apply modifications
|
|
475
|
+
* map.events = [...map.events, ...additionalData.events]
|
|
476
|
+
* map.npcs = additionalData.npcs
|
|
477
|
+
*
|
|
478
|
+
* return map
|
|
479
|
+
* }
|
|
480
|
+
* }
|
|
481
|
+
* ```
|
|
482
|
+
*/
|
|
483
|
+
onBeforeUpdate<T, U = RpgMap>(mapData: T, map: U): U | Promise<U>;
|
|
484
|
+
/**
|
|
485
|
+
* Called when a map is loaded and initialized
|
|
486
|
+
*
|
|
487
|
+
* This hook is executed once when the map data is loaded and ready.
|
|
488
|
+
* It applies to all maps globally. Use this to initialize map-specific properties
|
|
489
|
+
* or setup that should happen for every map.
|
|
490
|
+
*
|
|
491
|
+
* @param {RpgMap} map - The map instance that was loaded
|
|
492
|
+
* @returns {any}
|
|
493
|
+
* @memberof RpgMapHooks
|
|
494
|
+
* @example
|
|
495
|
+
* ```ts
|
|
496
|
+
* const mapHooks: RpgMapHooks = {
|
|
497
|
+
* onLoad(map: RpgMap) {
|
|
498
|
+
* console.log(`Map ${map.id} loaded`)
|
|
499
|
+
* // Initialize global map properties
|
|
500
|
+
* }
|
|
501
|
+
* }
|
|
502
|
+
* ```
|
|
503
|
+
*/
|
|
504
|
+
onLoad?: (map: RpgMap) => any;
|
|
505
|
+
/**
|
|
506
|
+
* Called when a player joins any map
|
|
507
|
+
*
|
|
508
|
+
* This hook is executed each time a player joins any map in the game.
|
|
509
|
+
* It applies globally to all maps. Use this to perform actions that should
|
|
510
|
+
* happen whenever a player enters any map.
|
|
511
|
+
*
|
|
512
|
+
* @param {RpgPlayer} player - The player joining the map
|
|
513
|
+
* @param {RpgMap} map - The map instance the player joined
|
|
514
|
+
* @returns {any}
|
|
515
|
+
* @memberof RpgMapHooks
|
|
516
|
+
* @example
|
|
517
|
+
* ```ts
|
|
518
|
+
* const mapHooks: RpgMapHooks = {
|
|
519
|
+
* onJoin(player: RpgPlayer, map: RpgMap) {
|
|
520
|
+
* console.log(`${player.name} joined map ${map.id}`)
|
|
521
|
+
* // Perform global actions when player joins any map
|
|
522
|
+
* }
|
|
523
|
+
* }
|
|
524
|
+
* ```
|
|
525
|
+
*/
|
|
526
|
+
onJoin?: (player: RpgPlayer, map: RpgMap) => any;
|
|
527
|
+
/**
|
|
528
|
+
* Called when a player leaves any map
|
|
529
|
+
*
|
|
530
|
+
* This hook is executed each time a player leaves any map in the game.
|
|
531
|
+
* It applies globally to all maps. Use this to perform cleanup or actions
|
|
532
|
+
* that should happen whenever a player exits any map.
|
|
533
|
+
*
|
|
534
|
+
* @param {RpgPlayer} player - The player leaving the map
|
|
535
|
+
* @param {RpgMap} map - The map instance the player left
|
|
536
|
+
* @returns {any}
|
|
537
|
+
* @memberof RpgMapHooks
|
|
538
|
+
* @example
|
|
539
|
+
* ```ts
|
|
540
|
+
* const mapHooks: RpgMapHooks = {
|
|
541
|
+
* onLeave(player: RpgPlayer, map: RpgMap) {
|
|
542
|
+
* console.log(`${player.name} left map ${map.id}`)
|
|
543
|
+
* // Perform global cleanup when player leaves any map
|
|
544
|
+
* }
|
|
545
|
+
* }
|
|
546
|
+
* ```
|
|
547
|
+
*/
|
|
548
|
+
onLeave?: (player: RpgPlayer, map: RpgMap) => any;
|
|
226
549
|
}
|
|
227
550
|
export interface RpgServer {
|
|
228
551
|
/**
|
|
@@ -235,14 +558,14 @@ export interface RpgServer {
|
|
|
235
558
|
* @example
|
|
236
559
|
*
|
|
237
560
|
* ```ts
|
|
238
|
-
* import { RpgServer
|
|
561
|
+
* import { RpgServer } from '@rpgjs/server'
|
|
562
|
+
* import { defineModule } from '@rpgjs/common'
|
|
239
563
|
*
|
|
240
|
-
*
|
|
564
|
+
* export default defineModule<RpgServer>({
|
|
241
565
|
* hooks: {
|
|
242
566
|
* player: ['onAuth']
|
|
243
567
|
* }
|
|
244
568
|
* })
|
|
245
|
-
* class RpgServerEngine { }
|
|
246
569
|
* ```
|
|
247
570
|
*
|
|
248
571
|
* Emit the hook:
|
|
@@ -281,18 +604,18 @@ export interface RpgServer {
|
|
|
281
604
|
* Object containing the hooks concerning the engine
|
|
282
605
|
*
|
|
283
606
|
* ```ts
|
|
284
|
-
* import { RpgServerEngine, RpgServerEngineHooks,
|
|
607
|
+
* import { RpgServerEngine, RpgServerEngineHooks, RpgServer } from '@rpgjs/server'
|
|
608
|
+
* import { defineModule } from '@rpgjs/common'
|
|
285
609
|
*
|
|
286
|
-
* const engine:
|
|
610
|
+
* const engine: RpgServerEngineHooks = {
|
|
287
611
|
* onStart(server: RpgServerEngine) {
|
|
288
612
|
* console.log('server is started')
|
|
289
613
|
* }
|
|
290
614
|
* }
|
|
291
615
|
*
|
|
292
|
-
*
|
|
616
|
+
* export default defineModule<RpgServer>({
|
|
293
617
|
* engine
|
|
294
618
|
* })
|
|
295
|
-
* class RpgServerModule {}
|
|
296
619
|
* ```
|
|
297
620
|
*
|
|
298
621
|
* @prop {RpgServerEngineHooks} [engine]
|
|
@@ -303,7 +626,8 @@ export interface RpgServer {
|
|
|
303
626
|
* Give the `player` object hooks. Each time a player connects, an instance of `RpgPlayer` is created.
|
|
304
627
|
*
|
|
305
628
|
* ```ts
|
|
306
|
-
* import { RpgPlayer, RpgServer, RpgPlayerHooks
|
|
629
|
+
* import { RpgPlayer, RpgServer, RpgPlayerHooks } from '@rpgjs/server'
|
|
630
|
+
* import { defineModule } from '@rpgjs/common'
|
|
307
631
|
*
|
|
308
632
|
* const player: RpgPlayerHooks = {
|
|
309
633
|
* onConnected(player: RpgPlayer) {
|
|
@@ -311,10 +635,9 @@ export interface RpgServer {
|
|
|
311
635
|
* }
|
|
312
636
|
* }
|
|
313
637
|
*
|
|
314
|
-
*
|
|
638
|
+
* export default defineModule<RpgServer>({
|
|
315
639
|
* player
|
|
316
640
|
* })
|
|
317
|
-
* class RpgServerEngine { }
|
|
318
641
|
* ```
|
|
319
642
|
*
|
|
320
643
|
* @prop {RpgClassPlayer<RpgPlayer>} [player]
|
|
@@ -325,27 +648,29 @@ export interface RpgServer {
|
|
|
325
648
|
* References all data in the server. it is mainly used to retrieve data according to their identifier
|
|
326
649
|
*
|
|
327
650
|
* ```ts
|
|
328
|
-
* import { RpgServer
|
|
651
|
+
* import { RpgServer } from '@rpgjs/server'
|
|
652
|
+
* import { defineModule } from '@rpgjs/common'
|
|
329
653
|
* import { Potion } from 'my-database/items/potion'
|
|
330
654
|
*
|
|
331
|
-
*
|
|
655
|
+
* export default defineModule<RpgServer>({
|
|
332
656
|
* database: {
|
|
333
657
|
* Potion
|
|
334
658
|
* }
|
|
335
659
|
* })
|
|
336
|
-
* class RpgServerEngine { }
|
|
337
660
|
* ```
|
|
338
661
|
*
|
|
339
|
-
* @prop { { [dataName]: data } } [database]
|
|
662
|
+
* @prop { { [dataName]: data } | (engine: RpgMap) => { [dataName]: data } | Promise<{ [dataName]: data }> } [database]
|
|
340
663
|
* @memberof RpgServer
|
|
341
664
|
* */
|
|
342
|
-
database?: object | any[];
|
|
665
|
+
database?: object | any[] | ((engine: RpgMap) => object | any[] | Promise<object | any[]>);
|
|
343
666
|
/**
|
|
344
|
-
* Array of all maps. Each element
|
|
667
|
+
* Array of all maps. Each element can be either a class (decorated with `@MapData` or not) or a `MapOptions` object
|
|
345
668
|
*
|
|
346
669
|
* ```ts
|
|
347
|
-
* import { RpgMap, MapData, RpgServer
|
|
670
|
+
* import { RpgMap, MapData, RpgServer } from '@rpgjs/server'
|
|
671
|
+
* import { defineModule } from '@rpgjs/common'
|
|
348
672
|
*
|
|
673
|
+
* // Class that extends RpgMap (optional)
|
|
349
674
|
* @MapData({
|
|
350
675
|
* id: 'town',
|
|
351
676
|
* file: require('./tmx/mymap.tmx'),
|
|
@@ -353,18 +678,29 @@ export interface RpgServer {
|
|
|
353
678
|
* })
|
|
354
679
|
* class TownMap extends RpgMap { }
|
|
355
680
|
*
|
|
356
|
-
*
|
|
681
|
+
* // Or a simple class without extending RpgMap
|
|
682
|
+
* @MapData({
|
|
683
|
+
* id: 'map',
|
|
684
|
+
* file: '',
|
|
685
|
+
* events: [{ event: Event() }]
|
|
686
|
+
* })
|
|
687
|
+
* class SimpleMap {}
|
|
688
|
+
*
|
|
689
|
+
* export default defineModule<RpgServer>({
|
|
357
690
|
* maps: [
|
|
358
|
-
* TownMap
|
|
691
|
+
* TownMap,
|
|
692
|
+
* SimpleMap
|
|
359
693
|
* ]
|
|
360
694
|
* })
|
|
361
|
-
* class RpgServerEngine { }
|
|
362
695
|
* ```
|
|
363
696
|
*
|
|
364
697
|
* It is possible to just give the object as well
|
|
365
698
|
*
|
|
366
699
|
* ```ts
|
|
367
|
-
* @
|
|
700
|
+
* import { RpgServer } from '@rpgjs/server'
|
|
701
|
+
* import { defineModule } from '@rpgjs/common'
|
|
702
|
+
*
|
|
703
|
+
* export default defineModule<RpgServer>({
|
|
368
704
|
* maps: [
|
|
369
705
|
* {
|
|
370
706
|
* id: 'town',
|
|
@@ -373,24 +709,64 @@ export interface RpgServer {
|
|
|
373
709
|
* }
|
|
374
710
|
* ]
|
|
375
711
|
* })
|
|
376
|
-
* class RpgServerEngine { }
|
|
377
712
|
* ```
|
|
378
713
|
*
|
|
379
714
|
* Since version 3.0.0-beta.8, you can just pass the path to the file. The identifier will then be the name of the file
|
|
380
715
|
*
|
|
381
716
|
* ```ts
|
|
382
|
-
* @
|
|
717
|
+
* import { RpgServer } from '@rpgjs/server'
|
|
718
|
+
* import { defineModule } from '@rpgjs/common'
|
|
719
|
+
*
|
|
720
|
+
* export default defineModule<RpgServer>({
|
|
383
721
|
* maps: [
|
|
384
722
|
* require('./tmx/mymap.tmx') // id is "mymap"
|
|
385
723
|
* ]
|
|
386
724
|
* })
|
|
387
|
-
* class RpgServerEngine { }
|
|
388
725
|
* ```
|
|
389
726
|
*
|
|
390
|
-
* @prop {
|
|
727
|
+
* @prop {(new () => any) | MapOptions)[]} [maps]
|
|
728
|
+
* @memberof RpgServer
|
|
729
|
+
* */
|
|
730
|
+
maps?: ((new () => any) | MapOptions)[];
|
|
731
|
+
/**
|
|
732
|
+
* Global map hooks that apply to all maps in the game
|
|
733
|
+
*
|
|
734
|
+
* These hooks are executed for every map instance and allow you to define
|
|
735
|
+
* global behavior that should happen for all maps. They are different from
|
|
736
|
+
* map-specific hooks defined in `@MapData` which only apply to a specific map class.
|
|
737
|
+
*
|
|
738
|
+
* ```ts
|
|
739
|
+
* import { RpgServer, RpgMapHooks, RpgMap, RpgPlayer } from '@rpgjs/server'
|
|
740
|
+
* import { defineModule } from '@rpgjs/common'
|
|
741
|
+
*
|
|
742
|
+
* const mapHooks: RpgMapHooks = {
|
|
743
|
+
* onLoad(map: RpgMap) {
|
|
744
|
+
* console.log(`Map ${map.id} loaded`)
|
|
745
|
+
* // Initialize global map properties
|
|
746
|
+
* },
|
|
747
|
+
* onJoin(player: RpgPlayer, map: RpgMap) {
|
|
748
|
+
* console.log(`${player.name} joined map ${map.id}`)
|
|
749
|
+
* // Perform global actions when player joins any map
|
|
750
|
+
* },
|
|
751
|
+
* onLeave(player: RpgPlayer, map: RpgMap) {
|
|
752
|
+
* console.log(`${player.name} left map ${map.id}`)
|
|
753
|
+
* // Perform global cleanup when player leaves any map
|
|
754
|
+
* },
|
|
755
|
+
* onBeforeUpdate(mapData, map) {
|
|
756
|
+
* // Modify map data before update
|
|
757
|
+
* return map
|
|
758
|
+
* }
|
|
759
|
+
* }
|
|
760
|
+
*
|
|
761
|
+
* export default defineModule<RpgServer>({
|
|
762
|
+
* map: mapHooks
|
|
763
|
+
* })
|
|
764
|
+
* ```
|
|
765
|
+
*
|
|
766
|
+
* @prop {RpgMapHooks} [map]
|
|
391
767
|
* @memberof RpgServer
|
|
768
|
+
* @since 4.0.0
|
|
392
769
|
* */
|
|
393
|
-
maps?: RpgClassMap<RpgMap>[] | MapOptions[] | string[] | TiledMap[];
|
|
394
770
|
map?: RpgMapHooks;
|
|
395
771
|
event?: RpgEventHooks;
|
|
396
772
|
/**
|
|
@@ -403,41 +779,62 @@ export interface RpgServer {
|
|
|
403
779
|
*/
|
|
404
780
|
events?: RpgClassEvent<RpgEvent>[];
|
|
405
781
|
/**
|
|
406
|
-
*
|
|
782
|
+
* Array of world map configurations
|
|
407
783
|
*
|
|
408
|
-
*
|
|
784
|
+
* Loads the content of a `.world` file from Tiled Map Editor into the map scene.
|
|
785
|
+
* Each world contains multiple maps with their spatial relationships.
|
|
409
786
|
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
* {
|
|
414
|
-
* id?: string
|
|
415
|
-
* maps: {
|
|
416
|
-
* id?: string
|
|
417
|
-
* properties?: object
|
|
418
|
-
* fileName: string;
|
|
419
|
-
height: number;
|
|
420
|
-
width: number;
|
|
421
|
-
x: number;
|
|
422
|
-
y: number;
|
|
423
|
-
* }[],
|
|
424
|
-
onlyShowAdjacentMaps: boolean, // only for Tiled Map Editor
|
|
425
|
-
type: 'world' // only for Tiled Map Editor
|
|
426
|
-
* }
|
|
427
|
-
* ```
|
|
787
|
+
* > Note: If a map already exists (i.e. you have already defined an RpgMap),
|
|
788
|
+
* > the world will retrieve the already existing map. Otherwise it will create a new map.
|
|
789
|
+
*
|
|
790
|
+
* @prop {WorldMap[]} [worldMaps]
|
|
428
791
|
* @since 3.0.0-beta.8
|
|
792
|
+
* @memberof RpgServer
|
|
429
793
|
* @example
|
|
430
794
|
* ```ts
|
|
795
|
+
* import { RpgServer } from '@rpgjs/server'
|
|
796
|
+
* import { defineModule } from '@rpgjs/common'
|
|
431
797
|
* import myworld from 'myworld.world'
|
|
432
798
|
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
*
|
|
799
|
+
* export default defineModule<RpgServer>({
|
|
800
|
+
* worldMaps: [
|
|
801
|
+
* myworld
|
|
802
|
+
* ]
|
|
803
|
+
* })
|
|
804
|
+
* ```
|
|
805
|
+
*
|
|
806
|
+
* @example
|
|
807
|
+
* ```ts
|
|
808
|
+
* import { RpgServer } from '@rpgjs/server'
|
|
809
|
+
* import { defineModule } from '@rpgjs/common'
|
|
810
|
+
*
|
|
811
|
+
* // Manual world configuration
|
|
812
|
+
* export default defineModule<RpgServer>({
|
|
813
|
+
* worldMaps: [
|
|
814
|
+
* {
|
|
815
|
+
* id: 'my-world',
|
|
816
|
+
* maps: [
|
|
817
|
+
* {
|
|
818
|
+
* id: 'map1',
|
|
819
|
+
* worldX: 0,
|
|
820
|
+
* worldY: 0,
|
|
821
|
+
* width: 800,
|
|
822
|
+
* height: 600,
|
|
823
|
+
* tileWidth: 32,
|
|
824
|
+
* tileHeight: 32
|
|
825
|
+
* },
|
|
826
|
+
* {
|
|
827
|
+
* id: 'map2',
|
|
828
|
+
* worldX: 800,
|
|
829
|
+
* worldY: 0,
|
|
830
|
+
* width: 800,
|
|
831
|
+
* height: 600
|
|
832
|
+
* }
|
|
833
|
+
* ]
|
|
834
|
+
* }
|
|
835
|
+
* ]
|
|
437
836
|
* })
|
|
438
|
-
* class RpgServerEngine { }
|
|
439
837
|
* ```
|
|
440
|
-
* @memberof RpgServer
|
|
441
838
|
*/
|
|
442
839
|
worldMaps?: WorldMap[];
|
|
443
840
|
/**
|
|
@@ -460,11 +857,12 @@ export interface RpgServer {
|
|
|
460
857
|
* Example:
|
|
461
858
|
*
|
|
462
859
|
* ```ts
|
|
463
|
-
* import {
|
|
860
|
+
* import { RpgServer, Presets } from '@rpgjs/server'
|
|
861
|
+
* import { defineModule } from '@rpgjs/common'
|
|
464
862
|
*
|
|
465
863
|
* const { ATK, PDEF } = Presets
|
|
466
864
|
*
|
|
467
|
-
*
|
|
865
|
+
* export default defineModule<RpgServer>({
|
|
468
866
|
* damageFormulas: {
|
|
469
867
|
* damagePhysic(a, b) {
|
|
470
868
|
* let damage = a[ATK] - b[PDEF]
|
|
@@ -473,7 +871,6 @@ export interface RpgServer {
|
|
|
473
871
|
* }
|
|
474
872
|
* }
|
|
475
873
|
* })
|
|
476
|
-
* class RpgServerEngine { }
|
|
477
874
|
* ```
|
|
478
875
|
* @prop {object} damageFormulas
|
|
479
876
|
* @memberof RpgServer
|
|
@@ -492,5 +889,8 @@ export interface RpgServer {
|
|
|
492
889
|
doChangeServer(store: IStoreState, matchMaker: RpgMatchMaker, player: RpgPlayer): Promise<boolean> | boolean;
|
|
493
890
|
};
|
|
494
891
|
};
|
|
892
|
+
throttleSync?: number;
|
|
893
|
+
throttleStorage?: number;
|
|
894
|
+
sessionExpiryTime?: number;
|
|
495
895
|
}
|
|
496
896
|
export {};
|