@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,16 +1,41 @@
1
- import { RpgPlayer } from './Player/Player';
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
- type RpgShape = any;
5
- type RpgClassMap<T> = any;
6
- type RpgClassEvent<T> = any;
7
- type RpgEvent = any;
5
+ import { WorldMapConfig, RpgShape, MapPhysicsInitContext, MapPhysicsEntityContext } 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
- type TiledMap = any;
12
- type WorldMap = any;
13
- type MapOptions = any;
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]
@@ -394,6 +426,9 @@ export interface RpgEventHooks {
394
426
  /**
395
427
  * Map hooks interface for handling map lifecycle events
396
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
+ *
397
432
  * @interface RpgMapHooks
398
433
  * @since 4.0.0
399
434
  */
@@ -446,6 +481,109 @@ export interface RpgMapHooks {
446
481
  * ```
447
482
  */
448
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;
549
+ /**
550
+ * Called when the map physics world is initialized.
551
+ *
552
+ * This hook runs each time `loadPhysic()` prepares the physics world, after static
553
+ * map hitboxes are created and before dynamic player/event bodies are hydrated.
554
+ *
555
+ * @param {RpgMap} map - The map instance
556
+ * @param {MapPhysicsInitContext} context - Physics initialization context
557
+ * @returns {any}
558
+ * @memberof RpgMapHooks
559
+ */
560
+ onPhysicsInit?: (map: RpgMap, context: MapPhysicsInitContext) => any;
561
+ /**
562
+ * Called when a dynamic character physics body is added to the map.
563
+ *
564
+ * @param {RpgMap} map - The map instance
565
+ * @param {MapPhysicsEntityContext} context - Added entity context
566
+ * @returns {any}
567
+ * @memberof RpgMapHooks
568
+ */
569
+ onPhysicsEntityAdd?: (map: RpgMap, context: MapPhysicsEntityContext) => any;
570
+ /**
571
+ * Called when a dynamic character physics body is removed from the map.
572
+ *
573
+ * @param {RpgMap} map - The map instance
574
+ * @param {MapPhysicsEntityContext} context - Removed entity context
575
+ * @returns {any}
576
+ * @memberof RpgMapHooks
577
+ */
578
+ onPhysicsEntityRemove?: (map: RpgMap, context: MapPhysicsEntityContext) => any;
579
+ /**
580
+ * Called when the map physics world is reset (before reload).
581
+ *
582
+ * @param {RpgMap} map - The map instance
583
+ * @returns {any}
584
+ * @memberof RpgMapHooks
585
+ */
586
+ onPhysicsReset?: (map: RpgMap) => any;
449
587
  }
450
588
  export interface RpgServer {
451
589
  /**
@@ -458,14 +596,14 @@ export interface RpgServer {
458
596
  * @example
459
597
  *
460
598
  * ```ts
461
- * import { RpgServer, RpgModule } from '@rpgjs/server'
599
+ * import { RpgServer } from '@rpgjs/server'
600
+ * import { defineModule } from '@rpgjs/common'
462
601
  *
463
- * @RpgModule<RpgServer>({
602
+ * export default defineModule<RpgServer>({
464
603
  * hooks: {
465
604
  * player: ['onAuth']
466
605
  * }
467
606
  * })
468
- * class RpgServerEngine { }
469
607
  * ```
470
608
  *
471
609
  * Emit the hook:
@@ -504,18 +642,18 @@ export interface RpgServer {
504
642
  * Object containing the hooks concerning the engine
505
643
  *
506
644
  * ```ts
507
- * import { RpgServerEngine, RpgServerEngineHooks, RpgModule, RpgClient } from '@rpgjs/server'
645
+ * import { RpgServerEngine, RpgServerEngineHooks, RpgServer } from '@rpgjs/server'
646
+ * import { defineModule } from '@rpgjs/common'
508
647
  *
509
- * const engine: RpgEngineHooks = {
648
+ * const engine: RpgServerEngineHooks = {
510
649
  * onStart(server: RpgServerEngine) {
511
650
  * console.log('server is started')
512
651
  * }
513
652
  * }
514
653
  *
515
- * @RpgModule<RpgServer>({
654
+ * export default defineModule<RpgServer>({
516
655
  * engine
517
656
  * })
518
- * class RpgServerModule {}
519
657
  * ```
520
658
  *
521
659
  * @prop {RpgServerEngineHooks} [engine]
@@ -526,7 +664,8 @@ export interface RpgServer {
526
664
  * Give the `player` object hooks. Each time a player connects, an instance of `RpgPlayer` is created.
527
665
  *
528
666
  * ```ts
529
- * import { RpgPlayer, RpgServer, RpgPlayerHooks, RpgModule } from '@rpgjs/server'
667
+ * import { RpgPlayer, RpgServer, RpgPlayerHooks } from '@rpgjs/server'
668
+ * import { defineModule } from '@rpgjs/common'
530
669
  *
531
670
  * const player: RpgPlayerHooks = {
532
671
  * onConnected(player: RpgPlayer) {
@@ -534,10 +673,9 @@ export interface RpgServer {
534
673
  * }
535
674
  * }
536
675
  *
537
- * @RpgModule<RpgServer>({
676
+ * export default defineModule<RpgServer>({
538
677
  * player
539
678
  * })
540
- * class RpgServerEngine { }
541
679
  * ```
542
680
  *
543
681
  * @prop {RpgClassPlayer<RpgPlayer>} [player]
@@ -548,27 +686,29 @@ export interface RpgServer {
548
686
  * References all data in the server. it is mainly used to retrieve data according to their identifier
549
687
  *
550
688
  * ```ts
551
- * import { RpgServer, RpgModule } from '@rpgjs/server'
689
+ * import { RpgServer } from '@rpgjs/server'
690
+ * import { defineModule } from '@rpgjs/common'
552
691
  * import { Potion } from 'my-database/items/potion'
553
692
  *
554
- * @RpgModule<RpgServer>({
693
+ * export default defineModule<RpgServer>({
555
694
  * database: {
556
695
  * Potion
557
696
  * }
558
697
  * })
559
- * class RpgServerEngine { }
560
698
  * ```
561
699
  *
562
- * @prop { { [dataName]: data } } [database]
700
+ * @prop { { [dataName]: data } | (engine: RpgMap) => { [dataName]: data } | Promise<{ [dataName]: data }> } [database]
563
701
  * @memberof RpgServer
564
702
  * */
565
- database?: object | any[];
703
+ database?: object | any[] | ((engine: RpgMap) => object | any[] | Promise<object | any[]>);
566
704
  /**
567
- * Array of all maps. Each element is an `RpgMap` class
705
+ * Array of all maps. Each element can be either a class (decorated with `@MapData` or not) or a `MapOptions` object
568
706
  *
569
707
  * ```ts
570
- * import { RpgMap, MapData, RpgServer, RpgModule } from '@rpgjs/server'
708
+ * import { RpgMap, MapData, RpgServer } from '@rpgjs/server'
709
+ * import { defineModule } from '@rpgjs/common'
571
710
  *
711
+ * // Class that extends RpgMap (optional)
572
712
  * @MapData({
573
713
  * id: 'town',
574
714
  * file: require('./tmx/mymap.tmx'),
@@ -576,18 +716,29 @@ export interface RpgServer {
576
716
  * })
577
717
  * class TownMap extends RpgMap { }
578
718
  *
579
- * @RpgModule<RpgServer>({
719
+ * // Or a simple class without extending RpgMap
720
+ * @MapData({
721
+ * id: 'map',
722
+ * file: '',
723
+ * events: [{ x: 100, y: 150, event: Event() }]
724
+ * })
725
+ * class SimpleMap {}
726
+ *
727
+ * export default defineModule<RpgServer>({
580
728
  * maps: [
581
- * TownMap
729
+ * TownMap,
730
+ * SimpleMap
582
731
  * ]
583
732
  * })
584
- * class RpgServerEngine { }
585
733
  * ```
586
734
  *
587
735
  * It is possible to just give the object as well
588
736
  *
589
737
  * ```ts
590
- * @RpgModule<RpgServer>({
738
+ * import { RpgServer } from '@rpgjs/server'
739
+ * import { defineModule } from '@rpgjs/common'
740
+ *
741
+ * export default defineModule<RpgServer>({
591
742
  * maps: [
592
743
  * {
593
744
  * id: 'town',
@@ -596,24 +747,64 @@ export interface RpgServer {
596
747
  * }
597
748
  * ]
598
749
  * })
599
- * class RpgServerEngine { }
600
750
  * ```
601
751
  *
602
752
  * 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
603
753
  *
604
754
  * ```ts
605
- * @RpgModule<RpgServer>({
755
+ * import { RpgServer } from '@rpgjs/server'
756
+ * import { defineModule } from '@rpgjs/common'
757
+ *
758
+ * export default defineModule<RpgServer>({
606
759
  * maps: [
607
760
  * require('./tmx/mymap.tmx') // id is "mymap"
608
761
  * ]
609
762
  * })
610
- * class RpgServerEngine { }
611
763
  * ```
612
764
  *
613
- * @prop {RpgClassMap<RpgMap>[]} [maps]
765
+ * @prop {(new () => any) | MapOptions)[]} [maps]
614
766
  * @memberof RpgServer
615
767
  * */
616
- maps?: RpgClassMap<RpgMap>[] | MapOptions[] | string[] | TiledMap[];
768
+ maps?: ((new () => any) | MapOptions)[];
769
+ /**
770
+ * Global map hooks that apply to all maps in the game
771
+ *
772
+ * These hooks are executed for every map instance and allow you to define
773
+ * global behavior that should happen for all maps. They are different from
774
+ * map-specific hooks defined in `@MapData` which only apply to a specific map class.
775
+ *
776
+ * ```ts
777
+ * import { RpgServer, RpgMapHooks, RpgMap, RpgPlayer } from '@rpgjs/server'
778
+ * import { defineModule } from '@rpgjs/common'
779
+ *
780
+ * const mapHooks: RpgMapHooks = {
781
+ * onLoad(map: RpgMap) {
782
+ * console.log(`Map ${map.id} loaded`)
783
+ * // Initialize global map properties
784
+ * },
785
+ * onJoin(player: RpgPlayer, map: RpgMap) {
786
+ * console.log(`${player.name} joined map ${map.id}`)
787
+ * // Perform global actions when player joins any map
788
+ * },
789
+ * onLeave(player: RpgPlayer, map: RpgMap) {
790
+ * console.log(`${player.name} left map ${map.id}`)
791
+ * // Perform global cleanup when player leaves any map
792
+ * },
793
+ * onBeforeUpdate(mapData, map) {
794
+ * // Modify map data before update
795
+ * return map
796
+ * }
797
+ * }
798
+ *
799
+ * export default defineModule<RpgServer>({
800
+ * map: mapHooks
801
+ * })
802
+ * ```
803
+ *
804
+ * @prop {RpgMapHooks} [map]
805
+ * @memberof RpgServer
806
+ * @since 4.0.0
807
+ * */
617
808
  map?: RpgMapHooks;
618
809
  event?: RpgEventHooks;
619
810
  /**
@@ -626,41 +817,62 @@ export interface RpgServer {
626
817
  */
627
818
  events?: RpgClassEvent<RpgEvent>[];
628
819
  /**
629
- * Loads the content of a `.world` file from Tiled Map Editor into the map scene
820
+ * Array of world map configurations
630
821
  *
631
- * > Note, that if the map already exists (i.e. you have already defined an RpgMap), the world will retrieve the already existing map. Otherwise it will create a new map
822
+ * Loads the content of a `.world` file from Tiled Map Editor into the map scene.
823
+ * Each world contains multiple maps with their spatial relationships.
632
824
  *
633
- * @prop {object[]} [worldMaps]
634
- * object is
635
- * ```ts
636
- * {
637
- * id?: string
638
- * maps: {
639
- * id?: string
640
- * properties?: object
641
- * fileName: string;
642
- height: number;
643
- width: number;
644
- x: number;
645
- y: number;
646
- * }[],
647
- onlyShowAdjacentMaps: boolean, // only for Tiled Map Editor
648
- type: 'world' // only for Tiled Map Editor
649
- * }
650
- * ```
825
+ * > Note: If a map already exists (i.e. you have already defined an RpgMap),
826
+ * > the world will retrieve the already existing map. Otherwise it will create a new map.
827
+ *
828
+ * @prop {WorldMap[]} [worldMaps]
651
829
  * @since 3.0.0-beta.8
830
+ * @memberof RpgServer
652
831
  * @example
653
832
  * ```ts
833
+ * import { RpgServer } from '@rpgjs/server'
834
+ * import { defineModule } from '@rpgjs/common'
654
835
  * import myworld from 'myworld.world'
655
836
  *
656
- * @RpgModule<RpgServer>({
657
- * worldMaps: [
658
- * myworld
659
- * ]
837
+ * export default defineModule<RpgServer>({
838
+ * worldMaps: [
839
+ * myworld
840
+ * ]
841
+ * })
842
+ * ```
843
+ *
844
+ * @example
845
+ * ```ts
846
+ * import { RpgServer } from '@rpgjs/server'
847
+ * import { defineModule } from '@rpgjs/common'
848
+ *
849
+ * // Manual world configuration
850
+ * export default defineModule<RpgServer>({
851
+ * worldMaps: [
852
+ * {
853
+ * id: 'my-world',
854
+ * maps: [
855
+ * {
856
+ * id: 'map1',
857
+ * worldX: 0,
858
+ * worldY: 0,
859
+ * width: 800,
860
+ * height: 600,
861
+ * tileWidth: 32,
862
+ * tileHeight: 32
863
+ * },
864
+ * {
865
+ * id: 'map2',
866
+ * worldX: 800,
867
+ * worldY: 0,
868
+ * width: 800,
869
+ * height: 600
870
+ * }
871
+ * ]
872
+ * }
873
+ * ]
660
874
  * })
661
- * class RpgServerEngine { }
662
875
  * ```
663
- * @memberof RpgServer
664
876
  */
665
877
  worldMaps?: WorldMap[];
666
878
  /**
@@ -683,11 +895,12 @@ export interface RpgServer {
683
895
  * Example:
684
896
  *
685
897
  * ```ts
686
- * import { RpgModule, RpgServer, Presets } from '@rpgjs/server'
898
+ * import { RpgServer, Presets } from '@rpgjs/server'
899
+ * import { defineModule } from '@rpgjs/common'
687
900
  *
688
901
  * const { ATK, PDEF } = Presets
689
902
  *
690
- * @RpgModule<RpgServer>({
903
+ * export default defineModule<RpgServer>({
691
904
  * damageFormulas: {
692
905
  * damagePhysic(a, b) {
693
906
  * let damage = a[ATK] - b[PDEF]
@@ -696,7 +909,6 @@ export interface RpgServer {
696
909
  * }
697
910
  * }
698
911
  * })
699
- * class RpgServerEngine { }
700
912
  * ```
701
913
  * @prop {object} damageFormulas
702
914
  * @memberof RpgServer
@@ -715,5 +927,8 @@ export interface RpgServer {
715
927
  doChangeServer(store: IStoreState, matchMaker: RpgMatchMaker, player: RpgPlayer): Promise<boolean> | boolean;
716
928
  };
717
929
  };
930
+ throttleSync?: number;
931
+ throttleStorage?: number;
932
+ sessionExpiryTime?: number;
718
933
  }
719
934
  export {};
@@ -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;