@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
package/src/RpgServer.ts
CHANGED
|
@@ -1,17 +1,45 @@
|
|
|
1
|
+
import { MapOptions } from "./decorators/map"
|
|
1
2
|
import { RpgPlayer } from "./Player/Player"
|
|
2
3
|
import { type RpgMap } from "./rooms/map"
|
|
3
4
|
import { RpgServerEngine } from "./RpgServerEngine"
|
|
5
|
+
import { WorldMapConfig, RpgShape, type MapPhysicsInitContext, type MapPhysicsEntityContext } from "@rpgjs/common"
|
|
6
|
+
import { RpgEvent } from "./Player/Player"
|
|
4
7
|
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
type RpgClassEvent<T> = any
|
|
8
|
-
type RpgEvent = any
|
|
8
|
+
type RpgClassMap<T> = new () => T
|
|
9
|
+
type RpgClassEvent<T> = RpgEvent
|
|
9
10
|
type MatchMakerOption = any
|
|
10
11
|
type RpgMatchMaker = any
|
|
11
12
|
type IStoreState = any
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Interface for world map configuration
|
|
16
|
+
*
|
|
17
|
+
* Represents a world that contains multiple maps with their spatial relationships.
|
|
18
|
+
* This is typically used with Tiled Map Editor's world files.
|
|
19
|
+
*
|
|
20
|
+
* @interface WorldMap
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const worldMap: WorldMap = {
|
|
24
|
+
* id: 'my-world',
|
|
25
|
+
* maps: [
|
|
26
|
+
* { id: 'map1', worldX: 0, worldY: 0, width: 800, height: 600 },
|
|
27
|
+
* { id: 'map2', worldX: 800, worldY: 0, width: 800, height: 600 }
|
|
28
|
+
* ]
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export interface WorldMap {
|
|
33
|
+
/** Optional world identifier */
|
|
34
|
+
id?: string;
|
|
35
|
+
/** Array of map configurations that belong to this world */
|
|
36
|
+
maps: WorldMapConfig[];
|
|
37
|
+
/** Only show adjacent maps (used by Tiled Map Editor) */
|
|
38
|
+
onlyShowAdjacentMaps?: boolean;
|
|
39
|
+
/** Type identifier (used by Tiled Map Editor, should be 'world') */
|
|
40
|
+
type?: 'world';
|
|
41
|
+
}
|
|
42
|
+
|
|
15
43
|
|
|
16
44
|
export interface RpgServerEngineHooks {
|
|
17
45
|
/**
|
|
@@ -150,6 +178,14 @@ export interface RpgPlayerHooks {
|
|
|
150
178
|
*/
|
|
151
179
|
onConnected?: (player: RpgPlayer) => any
|
|
152
180
|
|
|
181
|
+
/**
|
|
182
|
+
* When the player starts the game from the lobby
|
|
183
|
+
*
|
|
184
|
+
* @prop { (player: RpgPlayer) => any } [onStart]
|
|
185
|
+
* @memberof RpgPlayerHooks
|
|
186
|
+
*/
|
|
187
|
+
onStart?: (player: RpgPlayer) => any
|
|
188
|
+
|
|
153
189
|
/**
|
|
154
190
|
* When the player presses a key on the client side
|
|
155
191
|
*
|
|
@@ -420,6 +456,9 @@ export interface RpgEventHooks {
|
|
|
420
456
|
/**
|
|
421
457
|
* Map hooks interface for handling map lifecycle events
|
|
422
458
|
*
|
|
459
|
+
* These hooks are global hooks that apply to all maps in the game.
|
|
460
|
+
* They are defined in the RpgModule configuration and executed for every map instance.
|
|
461
|
+
*
|
|
423
462
|
* @interface RpgMapHooks
|
|
424
463
|
* @since 4.0.0
|
|
425
464
|
*/
|
|
@@ -472,6 +511,116 @@ export interface RpgMapHooks {
|
|
|
472
511
|
* ```
|
|
473
512
|
*/
|
|
474
513
|
onBeforeUpdate<T, U = RpgMap>(mapData: T, map: U): U | Promise<U>
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Called when a map is loaded and initialized
|
|
517
|
+
*
|
|
518
|
+
* This hook is executed once when the map data is loaded and ready.
|
|
519
|
+
* It applies to all maps globally. Use this to initialize map-specific properties
|
|
520
|
+
* or setup that should happen for every map.
|
|
521
|
+
*
|
|
522
|
+
* @param {RpgMap} map - The map instance that was loaded
|
|
523
|
+
* @returns {any}
|
|
524
|
+
* @memberof RpgMapHooks
|
|
525
|
+
* @example
|
|
526
|
+
* ```ts
|
|
527
|
+
* const mapHooks: RpgMapHooks = {
|
|
528
|
+
* onLoad(map: RpgMap) {
|
|
529
|
+
* console.log(`Map ${map.id} loaded`)
|
|
530
|
+
* // Initialize global map properties
|
|
531
|
+
* }
|
|
532
|
+
* }
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
onLoad?: (map: RpgMap) => any
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Called when a player joins any map
|
|
539
|
+
*
|
|
540
|
+
* This hook is executed each time a player joins any map in the game.
|
|
541
|
+
* It applies globally to all maps. Use this to perform actions that should
|
|
542
|
+
* happen whenever a player enters any map.
|
|
543
|
+
*
|
|
544
|
+
* @param {RpgPlayer} player - The player joining the map
|
|
545
|
+
* @param {RpgMap} map - The map instance the player joined
|
|
546
|
+
* @returns {any}
|
|
547
|
+
* @memberof RpgMapHooks
|
|
548
|
+
* @example
|
|
549
|
+
* ```ts
|
|
550
|
+
* const mapHooks: RpgMapHooks = {
|
|
551
|
+
* onJoin(player: RpgPlayer, map: RpgMap) {
|
|
552
|
+
* console.log(`${player.name} joined map ${map.id}`)
|
|
553
|
+
* // Perform global actions when player joins any map
|
|
554
|
+
* }
|
|
555
|
+
* }
|
|
556
|
+
* ```
|
|
557
|
+
*/
|
|
558
|
+
onJoin?: (player: RpgPlayer, map: RpgMap) => any
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Called when a player leaves any map
|
|
562
|
+
*
|
|
563
|
+
* This hook is executed each time a player leaves any map in the game.
|
|
564
|
+
* It applies globally to all maps. Use this to perform cleanup or actions
|
|
565
|
+
* that should happen whenever a player exits any map.
|
|
566
|
+
*
|
|
567
|
+
* @param {RpgPlayer} player - The player leaving the map
|
|
568
|
+
* @param {RpgMap} map - The map instance the player left
|
|
569
|
+
* @returns {any}
|
|
570
|
+
* @memberof RpgMapHooks
|
|
571
|
+
* @example
|
|
572
|
+
* ```ts
|
|
573
|
+
* const mapHooks: RpgMapHooks = {
|
|
574
|
+
* onLeave(player: RpgPlayer, map: RpgMap) {
|
|
575
|
+
* console.log(`${player.name} left map ${map.id}`)
|
|
576
|
+
* // Perform global cleanup when player leaves any map
|
|
577
|
+
* }
|
|
578
|
+
* }
|
|
579
|
+
* ```
|
|
580
|
+
*/
|
|
581
|
+
onLeave?: (player: RpgPlayer, map: RpgMap) => any
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Called when the map physics world is initialized.
|
|
585
|
+
*
|
|
586
|
+
* This hook runs each time `loadPhysic()` prepares the physics world, after static
|
|
587
|
+
* map hitboxes are created and before dynamic player/event bodies are hydrated.
|
|
588
|
+
*
|
|
589
|
+
* @param {RpgMap} map - The map instance
|
|
590
|
+
* @param {MapPhysicsInitContext} context - Physics initialization context
|
|
591
|
+
* @returns {any}
|
|
592
|
+
* @memberof RpgMapHooks
|
|
593
|
+
*/
|
|
594
|
+
onPhysicsInit?: (map: RpgMap, context: MapPhysicsInitContext) => any
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Called when a dynamic character physics body is added to the map.
|
|
598
|
+
*
|
|
599
|
+
* @param {RpgMap} map - The map instance
|
|
600
|
+
* @param {MapPhysicsEntityContext} context - Added entity context
|
|
601
|
+
* @returns {any}
|
|
602
|
+
* @memberof RpgMapHooks
|
|
603
|
+
*/
|
|
604
|
+
onPhysicsEntityAdd?: (map: RpgMap, context: MapPhysicsEntityContext) => any
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Called when a dynamic character physics body is removed from the map.
|
|
608
|
+
*
|
|
609
|
+
* @param {RpgMap} map - The map instance
|
|
610
|
+
* @param {MapPhysicsEntityContext} context - Removed entity context
|
|
611
|
+
* @returns {any}
|
|
612
|
+
* @memberof RpgMapHooks
|
|
613
|
+
*/
|
|
614
|
+
onPhysicsEntityRemove?: (map: RpgMap, context: MapPhysicsEntityContext) => any
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Called when the map physics world is reset (before reload).
|
|
618
|
+
*
|
|
619
|
+
* @param {RpgMap} map - The map instance
|
|
620
|
+
* @returns {any}
|
|
621
|
+
* @memberof RpgMapHooks
|
|
622
|
+
*/
|
|
623
|
+
onPhysicsReset?: (map: RpgMap) => any
|
|
475
624
|
}
|
|
476
625
|
|
|
477
626
|
export interface RpgServer {
|
|
@@ -485,14 +634,14 @@ export interface RpgServer {
|
|
|
485
634
|
* @example
|
|
486
635
|
*
|
|
487
636
|
* ```ts
|
|
488
|
-
* import { RpgServer
|
|
637
|
+
* import { RpgServer } from '@rpgjs/server'
|
|
638
|
+
* import { defineModule } from '@rpgjs/common'
|
|
489
639
|
*
|
|
490
|
-
*
|
|
640
|
+
* export default defineModule<RpgServer>({
|
|
491
641
|
* hooks: {
|
|
492
642
|
* player: ['onAuth']
|
|
493
643
|
* }
|
|
494
644
|
* })
|
|
495
|
-
* class RpgServerEngine { }
|
|
496
645
|
* ```
|
|
497
646
|
*
|
|
498
647
|
* Emit the hook:
|
|
@@ -532,18 +681,18 @@ export interface RpgServer {
|
|
|
532
681
|
* Object containing the hooks concerning the engine
|
|
533
682
|
*
|
|
534
683
|
* ```ts
|
|
535
|
-
* import { RpgServerEngine, RpgServerEngineHooks,
|
|
684
|
+
* import { RpgServerEngine, RpgServerEngineHooks, RpgServer } from '@rpgjs/server'
|
|
685
|
+
* import { defineModule } from '@rpgjs/common'
|
|
536
686
|
*
|
|
537
|
-
* const engine:
|
|
687
|
+
* const engine: RpgServerEngineHooks = {
|
|
538
688
|
* onStart(server: RpgServerEngine) {
|
|
539
689
|
* console.log('server is started')
|
|
540
690
|
* }
|
|
541
691
|
* }
|
|
542
692
|
*
|
|
543
|
-
*
|
|
693
|
+
* export default defineModule<RpgServer>({
|
|
544
694
|
* engine
|
|
545
695
|
* })
|
|
546
|
-
* class RpgServerModule {}
|
|
547
696
|
* ```
|
|
548
697
|
*
|
|
549
698
|
* @prop {RpgServerEngineHooks} [engine]
|
|
@@ -555,7 +704,8 @@ export interface RpgServer {
|
|
|
555
704
|
* Give the `player` object hooks. Each time a player connects, an instance of `RpgPlayer` is created.
|
|
556
705
|
*
|
|
557
706
|
* ```ts
|
|
558
|
-
* import { RpgPlayer, RpgServer, RpgPlayerHooks
|
|
707
|
+
* import { RpgPlayer, RpgServer, RpgPlayerHooks } from '@rpgjs/server'
|
|
708
|
+
* import { defineModule } from '@rpgjs/common'
|
|
559
709
|
*
|
|
560
710
|
* const player: RpgPlayerHooks = {
|
|
561
711
|
* onConnected(player: RpgPlayer) {
|
|
@@ -563,10 +713,9 @@ export interface RpgServer {
|
|
|
563
713
|
* }
|
|
564
714
|
* }
|
|
565
715
|
*
|
|
566
|
-
*
|
|
716
|
+
* export default defineModule<RpgServer>({
|
|
567
717
|
* player
|
|
568
718
|
* })
|
|
569
|
-
* class RpgServerEngine { }
|
|
570
719
|
* ```
|
|
571
720
|
*
|
|
572
721
|
* @prop {RpgClassPlayer<RpgPlayer>} [player]
|
|
@@ -578,28 +727,30 @@ export interface RpgServer {
|
|
|
578
727
|
* References all data in the server. it is mainly used to retrieve data according to their identifier
|
|
579
728
|
*
|
|
580
729
|
* ```ts
|
|
581
|
-
* import { RpgServer
|
|
730
|
+
* import { RpgServer } from '@rpgjs/server'
|
|
731
|
+
* import { defineModule } from '@rpgjs/common'
|
|
582
732
|
* import { Potion } from 'my-database/items/potion'
|
|
583
733
|
*
|
|
584
|
-
*
|
|
734
|
+
* export default defineModule<RpgServer>({
|
|
585
735
|
* database: {
|
|
586
736
|
* Potion
|
|
587
737
|
* }
|
|
588
738
|
* })
|
|
589
|
-
* class RpgServerEngine { }
|
|
590
739
|
* ```
|
|
591
740
|
*
|
|
592
|
-
* @prop { { [dataName]: data } } [database]
|
|
741
|
+
* @prop { { [dataName]: data } | (engine: RpgMap) => { [dataName]: data } | Promise<{ [dataName]: data }> } [database]
|
|
593
742
|
* @memberof RpgServer
|
|
594
743
|
* */
|
|
595
|
-
database?: object | any[],
|
|
744
|
+
database?: object | any[] | ((engine: RpgMap) => object | any[] | Promise<object | any[]>),
|
|
596
745
|
|
|
597
746
|
/**
|
|
598
|
-
* Array of all maps. Each element
|
|
747
|
+
* Array of all maps. Each element can be either a class (decorated with `@MapData` or not) or a `MapOptions` object
|
|
599
748
|
*
|
|
600
749
|
* ```ts
|
|
601
|
-
* import { RpgMap, MapData, RpgServer
|
|
750
|
+
* import { RpgMap, MapData, RpgServer } from '@rpgjs/server'
|
|
751
|
+
* import { defineModule } from '@rpgjs/common'
|
|
602
752
|
*
|
|
753
|
+
* // Class that extends RpgMap (optional)
|
|
603
754
|
* @MapData({
|
|
604
755
|
* id: 'town',
|
|
605
756
|
* file: require('./tmx/mymap.tmx'),
|
|
@@ -607,18 +758,29 @@ export interface RpgServer {
|
|
|
607
758
|
* })
|
|
608
759
|
* class TownMap extends RpgMap { }
|
|
609
760
|
*
|
|
610
|
-
*
|
|
761
|
+
* // Or a simple class without extending RpgMap
|
|
762
|
+
* @MapData({
|
|
763
|
+
* id: 'map',
|
|
764
|
+
* file: '',
|
|
765
|
+
* events: [{ x: 100, y: 150, event: Event() }]
|
|
766
|
+
* })
|
|
767
|
+
* class SimpleMap {}
|
|
768
|
+
*
|
|
769
|
+
* export default defineModule<RpgServer>({
|
|
611
770
|
* maps: [
|
|
612
|
-
* TownMap
|
|
771
|
+
* TownMap,
|
|
772
|
+
* SimpleMap
|
|
613
773
|
* ]
|
|
614
774
|
* })
|
|
615
|
-
* class RpgServerEngine { }
|
|
616
775
|
* ```
|
|
617
776
|
*
|
|
618
777
|
* It is possible to just give the object as well
|
|
619
778
|
*
|
|
620
779
|
* ```ts
|
|
621
|
-
* @
|
|
780
|
+
* import { RpgServer } from '@rpgjs/server'
|
|
781
|
+
* import { defineModule } from '@rpgjs/common'
|
|
782
|
+
*
|
|
783
|
+
* export default defineModule<RpgServer>({
|
|
622
784
|
* maps: [
|
|
623
785
|
* {
|
|
624
786
|
* id: 'town',
|
|
@@ -627,25 +789,65 @@ export interface RpgServer {
|
|
|
627
789
|
* }
|
|
628
790
|
* ]
|
|
629
791
|
* })
|
|
630
|
-
* class RpgServerEngine { }
|
|
631
792
|
* ```
|
|
632
793
|
*
|
|
633
794
|
* 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
|
|
634
795
|
*
|
|
635
796
|
* ```ts
|
|
636
|
-
* @
|
|
797
|
+
* import { RpgServer } from '@rpgjs/server'
|
|
798
|
+
* import { defineModule } from '@rpgjs/common'
|
|
799
|
+
*
|
|
800
|
+
* export default defineModule<RpgServer>({
|
|
637
801
|
* maps: [
|
|
638
802
|
* require('./tmx/mymap.tmx') // id is "mymap"
|
|
639
803
|
* ]
|
|
640
804
|
* })
|
|
641
|
-
* class RpgServerEngine { }
|
|
642
805
|
* ```
|
|
643
806
|
*
|
|
644
|
-
* @prop {
|
|
807
|
+
* @prop {(new () => any) | MapOptions)[]} [maps]
|
|
645
808
|
* @memberof RpgServer
|
|
646
809
|
* */
|
|
647
|
-
maps?:
|
|
810
|
+
maps?: ((new () => any) | MapOptions)[],
|
|
648
811
|
|
|
812
|
+
/**
|
|
813
|
+
* Global map hooks that apply to all maps in the game
|
|
814
|
+
*
|
|
815
|
+
* These hooks are executed for every map instance and allow you to define
|
|
816
|
+
* global behavior that should happen for all maps. They are different from
|
|
817
|
+
* map-specific hooks defined in `@MapData` which only apply to a specific map class.
|
|
818
|
+
*
|
|
819
|
+
* ```ts
|
|
820
|
+
* import { RpgServer, RpgMapHooks, RpgMap, RpgPlayer } from '@rpgjs/server'
|
|
821
|
+
* import { defineModule } from '@rpgjs/common'
|
|
822
|
+
*
|
|
823
|
+
* const mapHooks: RpgMapHooks = {
|
|
824
|
+
* onLoad(map: RpgMap) {
|
|
825
|
+
* console.log(`Map ${map.id} loaded`)
|
|
826
|
+
* // Initialize global map properties
|
|
827
|
+
* },
|
|
828
|
+
* onJoin(player: RpgPlayer, map: RpgMap) {
|
|
829
|
+
* console.log(`${player.name} joined map ${map.id}`)
|
|
830
|
+
* // Perform global actions when player joins any map
|
|
831
|
+
* },
|
|
832
|
+
* onLeave(player: RpgPlayer, map: RpgMap) {
|
|
833
|
+
* console.log(`${player.name} left map ${map.id}`)
|
|
834
|
+
* // Perform global cleanup when player leaves any map
|
|
835
|
+
* },
|
|
836
|
+
* onBeforeUpdate(mapData, map) {
|
|
837
|
+
* // Modify map data before update
|
|
838
|
+
* return map
|
|
839
|
+
* }
|
|
840
|
+
* }
|
|
841
|
+
*
|
|
842
|
+
* export default defineModule<RpgServer>({
|
|
843
|
+
* map: mapHooks
|
|
844
|
+
* })
|
|
845
|
+
* ```
|
|
846
|
+
*
|
|
847
|
+
* @prop {RpgMapHooks} [map]
|
|
848
|
+
* @memberof RpgServer
|
|
849
|
+
* @since 4.0.0
|
|
850
|
+
* */
|
|
649
851
|
map?: RpgMapHooks
|
|
650
852
|
|
|
651
853
|
event?: RpgEventHooks
|
|
@@ -661,41 +863,62 @@ export interface RpgServer {
|
|
|
661
863
|
events?: RpgClassEvent<RpgEvent>[]
|
|
662
864
|
|
|
663
865
|
/**
|
|
664
|
-
*
|
|
866
|
+
* Array of world map configurations
|
|
665
867
|
*
|
|
666
|
-
*
|
|
868
|
+
* Loads the content of a `.world` file from Tiled Map Editor into the map scene.
|
|
869
|
+
* Each world contains multiple maps with their spatial relationships.
|
|
667
870
|
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
*
|
|
671
|
-
* {
|
|
672
|
-
* id?: string
|
|
673
|
-
* maps: {
|
|
674
|
-
* id?: string
|
|
675
|
-
* properties?: object
|
|
676
|
-
* fileName: string;
|
|
677
|
-
height: number;
|
|
678
|
-
width: number;
|
|
679
|
-
x: number;
|
|
680
|
-
y: number;
|
|
681
|
-
* }[],
|
|
682
|
-
onlyShowAdjacentMaps: boolean, // only for Tiled Map Editor
|
|
683
|
-
type: 'world' // only for Tiled Map Editor
|
|
684
|
-
* }
|
|
685
|
-
* ```
|
|
871
|
+
* > Note: If a map already exists (i.e. you have already defined an RpgMap),
|
|
872
|
+
* > the world will retrieve the already existing map. Otherwise it will create a new map.
|
|
873
|
+
*
|
|
874
|
+
* @prop {WorldMap[]} [worldMaps]
|
|
686
875
|
* @since 3.0.0-beta.8
|
|
876
|
+
* @memberof RpgServer
|
|
687
877
|
* @example
|
|
688
878
|
* ```ts
|
|
879
|
+
* import { RpgServer } from '@rpgjs/server'
|
|
880
|
+
* import { defineModule } from '@rpgjs/common'
|
|
689
881
|
* import myworld from 'myworld.world'
|
|
690
882
|
*
|
|
691
|
-
*
|
|
692
|
-
*
|
|
693
|
-
*
|
|
694
|
-
*
|
|
883
|
+
* export default defineModule<RpgServer>({
|
|
884
|
+
* worldMaps: [
|
|
885
|
+
* myworld
|
|
886
|
+
* ]
|
|
887
|
+
* })
|
|
888
|
+
* ```
|
|
889
|
+
*
|
|
890
|
+
* @example
|
|
891
|
+
* ```ts
|
|
892
|
+
* import { RpgServer } from '@rpgjs/server'
|
|
893
|
+
* import { defineModule } from '@rpgjs/common'
|
|
894
|
+
*
|
|
895
|
+
* // Manual world configuration
|
|
896
|
+
* export default defineModule<RpgServer>({
|
|
897
|
+
* worldMaps: [
|
|
898
|
+
* {
|
|
899
|
+
* id: 'my-world',
|
|
900
|
+
* maps: [
|
|
901
|
+
* {
|
|
902
|
+
* id: 'map1',
|
|
903
|
+
* worldX: 0,
|
|
904
|
+
* worldY: 0,
|
|
905
|
+
* width: 800,
|
|
906
|
+
* height: 600,
|
|
907
|
+
* tileWidth: 32,
|
|
908
|
+
* tileHeight: 32
|
|
909
|
+
* },
|
|
910
|
+
* {
|
|
911
|
+
* id: 'map2',
|
|
912
|
+
* worldX: 800,
|
|
913
|
+
* worldY: 0,
|
|
914
|
+
* width: 800,
|
|
915
|
+
* height: 600
|
|
916
|
+
* }
|
|
917
|
+
* ]
|
|
918
|
+
* }
|
|
919
|
+
* ]
|
|
695
920
|
* })
|
|
696
|
-
* class RpgServerEngine { }
|
|
697
921
|
* ```
|
|
698
|
-
* @memberof RpgServer
|
|
699
922
|
*/
|
|
700
923
|
worldMaps?: WorldMap[]
|
|
701
924
|
|
|
@@ -720,11 +943,12 @@ export interface RpgServer {
|
|
|
720
943
|
* Example:
|
|
721
944
|
*
|
|
722
945
|
* ```ts
|
|
723
|
-
* import {
|
|
946
|
+
* import { RpgServer, Presets } from '@rpgjs/server'
|
|
947
|
+
* import { defineModule } from '@rpgjs/common'
|
|
724
948
|
*
|
|
725
949
|
* const { ATK, PDEF } = Presets
|
|
726
950
|
*
|
|
727
|
-
*
|
|
951
|
+
* export default defineModule<RpgServer>({
|
|
728
952
|
* damageFormulas: {
|
|
729
953
|
* damagePhysic(a, b) {
|
|
730
954
|
* let damage = a[ATK] - b[PDEF]
|
|
@@ -733,7 +957,6 @@ export interface RpgServer {
|
|
|
733
957
|
* }
|
|
734
958
|
* }
|
|
735
959
|
* })
|
|
736
|
-
* class RpgServerEngine { }
|
|
737
960
|
* ```
|
|
738
961
|
* @prop {object} damageFormulas
|
|
739
962
|
* @memberof RpgServer
|
|
@@ -745,6 +968,10 @@ export interface RpgServer {
|
|
|
745
968
|
coefficientElements?: (a, b, bDef) => number
|
|
746
969
|
}
|
|
747
970
|
|
|
971
|
+
/*
|
|
972
|
+
* Scalability configuration for the server
|
|
973
|
+
* @deprecated
|
|
974
|
+
*/
|
|
748
975
|
scalability?: {
|
|
749
976
|
matchMaker: MatchMakerOption,
|
|
750
977
|
stateStore: IStoreState
|
|
@@ -753,4 +980,8 @@ export interface RpgServer {
|
|
|
753
980
|
doChangeServer(store: IStoreState, matchMaker: RpgMatchMaker, player: RpgPlayer): Promise<boolean> | boolean
|
|
754
981
|
}
|
|
755
982
|
}
|
|
983
|
+
|
|
984
|
+
throttleSync?: number
|
|
985
|
+
throttleStorage?: number
|
|
986
|
+
sessionExpiryTime?: number
|
|
756
987
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export enum EventMode {
|
|
2
|
+
Shared = 'shared',
|
|
3
|
+
Scenario = 'scenario'
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface EventOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The mode of the event, shared evening or scenario
|
|
9
|
+
*
|
|
10
|
+
* 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.
|
|
11
|
+
*
|
|
12
|
+
* `shared` mode by default
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { RpgEvent, EventData, RpgPlayer, EventMode } from '@rpgjs/server'
|
|
16
|
+
* @EventData({
|
|
17
|
+
* name: 'EV-1',
|
|
18
|
+
* mode: EventMode.Scenario // or EventMode.Shared
|
|
19
|
+
* })
|
|
20
|
+
* export class CharaEvent extends RpgEvent { }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @prop {string} [mode] Either "shared" or "scenario".
|
|
24
|
+
* @memberof EventData
|
|
25
|
+
* */
|
|
26
|
+
mode?: EventMode,
|
|
27
|
+
|
|
28
|
+
width?: number,
|
|
29
|
+
height?: number,
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The hitbox of the event. By default, this is the size of the tile of the map
|
|
33
|
+
*
|
|
34
|
+
* @prop { { width: number, height: number }} [hitbox]
|
|
35
|
+
* @memberof EventData
|
|
36
|
+
* */
|
|
37
|
+
hitbox?: {
|
|
38
|
+
width?: number,
|
|
39
|
+
height?: number
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Name of the event. This is its identifier. it allows you to retrieve an event and place it on the map
|
|
44
|
+
*
|
|
45
|
+
* @prop {string} name
|
|
46
|
+
* @memberof EventData
|
|
47
|
+
* */
|
|
48
|
+
name: string
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function EventData(options: EventOptions) {
|
|
52
|
+
return (target) => {
|
|
53
|
+
target.mode = options.mode || EventMode.Shared
|
|
54
|
+
target.width = options.width
|
|
55
|
+
target.height = options.height
|
|
56
|
+
target.hitbox = options.hitbox
|
|
57
|
+
target._name = options.name
|
|
58
|
+
target.prototype._name = options.name
|
|
59
|
+
target.prototype.mode = target.mode
|
|
60
|
+
}
|
|
61
|
+
}
|