@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.
- 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 +100 -7
- 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 +233 -5
- 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 -29866
- 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 +401 -37
- 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 +284 -149
- 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/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, 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
|
-
|
|
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]
|
|
@@ -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
|
|
599
|
+
* import { RpgServer } from '@rpgjs/server'
|
|
600
|
+
* import { defineModule } from '@rpgjs/common'
|
|
462
601
|
*
|
|
463
|
-
*
|
|
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,
|
|
645
|
+
* import { RpgServerEngine, RpgServerEngineHooks, RpgServer } from '@rpgjs/server'
|
|
646
|
+
* import { defineModule } from '@rpgjs/common'
|
|
508
647
|
*
|
|
509
|
-
* const engine:
|
|
648
|
+
* const engine: RpgServerEngineHooks = {
|
|
510
649
|
* onStart(server: RpgServerEngine) {
|
|
511
650
|
* console.log('server is started')
|
|
512
651
|
* }
|
|
513
652
|
* }
|
|
514
653
|
*
|
|
515
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
|
689
|
+
* import { RpgServer } from '@rpgjs/server'
|
|
690
|
+
* import { defineModule } from '@rpgjs/common'
|
|
552
691
|
* import { Potion } from 'my-database/items/potion'
|
|
553
692
|
*
|
|
554
|
-
*
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
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
|
-
* @
|
|
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 {
|
|
765
|
+
* @prop {(new () => any) | MapOptions)[]} [maps]
|
|
614
766
|
* @memberof RpgServer
|
|
615
767
|
* */
|
|
616
|
-
maps?:
|
|
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
|
-
*
|
|
820
|
+
* Array of world map configurations
|
|
630
821
|
*
|
|
631
|
-
*
|
|
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
|
-
*
|
|
634
|
-
*
|
|
635
|
-
*
|
|
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
|
-
*
|
|
657
|
-
*
|
|
658
|
-
*
|
|
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 {
|
|
898
|
+
* import { RpgServer, Presets } from '@rpgjs/server'
|
|
899
|
+
* import { defineModule } from '@rpgjs/common'
|
|
687
900
|
*
|
|
688
901
|
* const { ATK, PDEF } = Presets
|
|
689
902
|
*
|
|
690
|
-
*
|
|
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 {};
|
|
@@ -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;
|