@rpgjs/server 5.0.0-alpha.3 → 5.0.0-alpha.30

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 (99) 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 +24 -3
  8. package/dist/Gui/TitleGui.d.ts +23 -0
  9. package/dist/Gui/index.d.ts +10 -1
  10. package/dist/Player/BattleManager.d.ts +34 -12
  11. package/dist/Player/ClassManager.d.ts +46 -13
  12. package/dist/Player/ComponentManager.d.ts +123 -0
  13. package/dist/Player/Components.d.ts +345 -0
  14. package/dist/Player/EffectManager.d.ts +86 -0
  15. package/dist/Player/ElementManager.d.ts +104 -0
  16. package/dist/Player/GoldManager.d.ts +22 -0
  17. package/dist/Player/GuiManager.d.ts +259 -0
  18. package/dist/Player/ItemFixture.d.ts +6 -0
  19. package/dist/Player/ItemManager.d.ts +451 -9
  20. package/dist/Player/MoveManager.d.ts +324 -69
  21. package/dist/Player/ParameterManager.d.ts +343 -14
  22. package/dist/Player/Player.d.ts +458 -8
  23. package/dist/Player/SkillManager.d.ts +197 -15
  24. package/dist/Player/StateManager.d.ts +89 -25
  25. package/dist/Player/VariableManager.d.ts +74 -0
  26. package/dist/RpgServer.d.ts +462 -62
  27. package/dist/RpgServerEngine.d.ts +2 -1
  28. package/dist/decorators/event.d.ts +46 -0
  29. package/dist/decorators/map.d.ts +265 -0
  30. package/dist/index.d.ts +10 -0
  31. package/dist/index.js +21000 -20723
  32. package/dist/index.js.map +1 -1
  33. package/dist/module.d.ts +43 -1
  34. package/dist/presets/index.d.ts +0 -9
  35. package/dist/rooms/BaseRoom.d.ts +132 -0
  36. package/dist/rooms/lobby.d.ts +10 -2
  37. package/dist/rooms/map.d.ts +1163 -14
  38. package/dist/services/save.d.ts +43 -0
  39. package/dist/storage/index.d.ts +1 -0
  40. package/dist/storage/localStorage.d.ts +23 -0
  41. package/package.json +19 -15
  42. package/src/Gui/DialogGui.ts +19 -4
  43. package/src/Gui/GameoverGui.ts +39 -0
  44. package/src/Gui/Gui.ts +23 -1
  45. package/src/Gui/MenuGui.ts +155 -6
  46. package/src/Gui/NotificationGui.ts +1 -2
  47. package/src/Gui/SaveLoadGui.ts +60 -0
  48. package/src/Gui/ShopGui.ts +145 -16
  49. package/src/Gui/TitleGui.ts +39 -0
  50. package/src/Gui/index.ts +15 -2
  51. package/src/Player/BattleManager.ts +91 -49
  52. package/src/Player/ClassManager.ts +113 -48
  53. package/src/Player/ComponentManager.ts +425 -19
  54. package/src/Player/Components.ts +380 -0
  55. package/src/Player/EffectManager.ts +81 -44
  56. package/src/Player/ElementManager.ts +109 -86
  57. package/src/Player/GoldManager.ts +32 -35
  58. package/src/Player/GuiManager.ts +308 -150
  59. package/src/Player/ItemFixture.ts +4 -5
  60. package/src/Player/ItemManager.ts +768 -352
  61. package/src/Player/MoveManager.ts +1478 -772
  62. package/src/Player/ParameterManager.ts +503 -98
  63. package/src/Player/Player.ts +1121 -88
  64. package/src/Player/SkillManager.ts +520 -195
  65. package/src/Player/StateManager.ts +170 -182
  66. package/src/Player/VariableManager.ts +101 -63
  67. package/src/RpgServer.ts +481 -61
  68. package/src/core/context.ts +1 -0
  69. package/src/decorators/event.ts +61 -0
  70. package/src/decorators/map.ts +302 -0
  71. package/src/index.ts +11 -1
  72. package/src/module.ts +118 -2
  73. package/src/presets/index.ts +1 -10
  74. package/src/rooms/BaseRoom.ts +232 -0
  75. package/src/rooms/lobby.ts +24 -7
  76. package/src/rooms/map.ts +1848 -73
  77. package/src/services/save.ts +147 -0
  78. package/src/storage/index.ts +1 -0
  79. package/src/storage/localStorage.ts +76 -0
  80. package/tests/battle.spec.ts +375 -0
  81. package/tests/change-map.spec.ts +72 -0
  82. package/tests/class.spec.ts +274 -0
  83. package/tests/effect.spec.ts +219 -0
  84. package/tests/element.spec.ts +221 -0
  85. package/tests/event.spec.ts +80 -0
  86. package/tests/gold.spec.ts +99 -0
  87. package/tests/item.spec.ts +591 -0
  88. package/tests/module.spec.ts +38 -0
  89. package/tests/move.spec.ts +601 -0
  90. package/tests/player-param.spec.ts +28 -0
  91. package/tests/random-move.spec.ts +65 -0
  92. package/tests/skill.spec.ts +658 -0
  93. package/tests/state.spec.ts +467 -0
  94. package/tests/variable.spec.ts +185 -0
  95. package/tests/world-maps.spec.ts +814 -0
  96. package/vite.config.ts +16 -0
  97. package/CHANGELOG.md +0 -9
  98. package/dist/Player/Event.d.ts +0 -0
  99. package/src/Player/Event.ts +0 -0
@@ -17,6 +17,11 @@ export interface DialogOptions {
17
17
  tranparent?: boolean;
18
18
  typewriterEffect?: boolean;
19
19
  talkWith?: RpgPlayer;
20
+ speaker?: string;
21
+ face?: {
22
+ id: string;
23
+ expression: string;
24
+ };
20
25
  }
21
26
  export declare class DialogGui extends Gui {
22
27
  constructor(player: RpgPlayer);
@@ -0,0 +1,23 @@
1
+ import { Gui } from './Gui';
2
+ import { RpgPlayer } from '../Player/Player';
3
+ export interface GameoverEntry {
4
+ id: string;
5
+ label: string;
6
+ disabled?: boolean;
7
+ }
8
+ export interface GameoverGuiOptions {
9
+ entries?: GameoverEntry[];
10
+ title?: string;
11
+ subtitle?: string;
12
+ saveLoad?: Record<string, any>;
13
+ localActions?: boolean;
14
+ }
15
+ export interface GameoverGuiSelection {
16
+ id?: string;
17
+ index?: number;
18
+ entry?: GameoverEntry;
19
+ }
20
+ export declare class GameoverGui extends Gui {
21
+ constructor(player: RpgPlayer);
22
+ open(options?: GameoverGuiOptions): Promise<GameoverGuiSelection | null>;
23
+ }
package/dist/Gui/Gui.d.ts CHANGED
@@ -4,10 +4,16 @@ export declare class Gui {
4
4
  protected player: RpgPlayer;
5
5
  private _close;
6
6
  private _blockPlayerInput;
7
+ private _events;
7
8
  constructor(id: string, player: RpgPlayer);
8
9
  open(data?: any, { waitingAction, blockPlayerInput }?: {
9
10
  waitingAction?: boolean | undefined;
10
11
  blockPlayerInput?: boolean | undefined;
11
12
  }): Promise<any>;
13
+ on(event: string, callback: (data: any) => void): void;
14
+ emit(event: string, data: any): Promise<any>;
12
15
  close(data?: any): void;
16
+ update(data?: any, { clientActionId }?: {
17
+ clientActionId?: string;
18
+ }): void;
13
19
  }
@@ -1,7 +1,26 @@
1
1
  import { Gui } from './Gui';
2
2
  import { RpgPlayer } from '../Player/Player';
3
- import { IGui } from '../Interfaces/Gui';
4
- export declare class MenuGui extends Gui implements IGui {
3
+ import { SaveSlot } from './SaveLoadGui';
4
+ export type MenuEntryId = 'items' | 'skills' | 'equip' | 'options' | 'save' | 'exit';
5
+ export interface MenuEntry {
6
+ id: MenuEntryId;
7
+ label: string;
8
+ disabled?: boolean;
9
+ }
10
+ export interface MenuGuiOptions {
11
+ menus?: MenuEntry[];
12
+ disabled?: MenuEntryId[];
13
+ saveSlots?: SaveSlot[];
14
+ saveMaxSlots?: number;
15
+ saveShowAutoSlot?: boolean;
16
+ saveAutoSlotIndex?: number;
17
+ saveAutoSlotLabel?: string;
18
+ }
19
+ export declare class MenuGui extends Gui {
20
+ private menuOptions;
5
21
  constructor(player: RpgPlayer);
6
- open(): Promise<any>;
22
+ private buildSaveLoad;
23
+ private buildMenuData;
24
+ private refreshMenu;
25
+ open(options?: MenuGuiOptions): Promise<any>;
7
26
  }
@@ -1,6 +1,5 @@
1
1
  import { Gui } from './Gui';
2
2
  import { RpgPlayer } from '../Player/Player';
3
- import { IGui } from '../Interfaces/Gui';
4
- export declare class NotificationGui extends Gui implements IGui {
3
+ export declare class NotificationGui extends Gui {
5
4
  constructor(player: RpgPlayer);
6
5
  }
@@ -0,0 +1,13 @@
1
+ import { SaveSlot } from '../../../common/src';
2
+ import { Gui } from './Gui';
3
+ import { RpgPlayer } from '../Player/Player';
4
+ export type SaveLoadMode = 'save' | 'load';
5
+ export type { SaveSlot } from '../../../common/src';
6
+ export interface SaveLoadOptions {
7
+ mode?: SaveLoadMode;
8
+ maxSlots?: number;
9
+ }
10
+ export declare class SaveLoadGui extends Gui {
11
+ constructor(player: RpgPlayer);
12
+ open(slots?: SaveSlot[], options?: SaveLoadOptions): Promise<number | null>;
13
+ }
@@ -1,7 +1,28 @@
1
1
  import { Gui } from './Gui';
2
2
  import { RpgPlayer } from '../Player/Player';
3
- import { IGui } from '../Interfaces/Gui';
4
- export declare class ShopGui extends Gui implements IGui {
3
+ export type ShopSellList = Record<string, number> | Array<{
4
+ id: string;
5
+ multiplier: number;
6
+ }>;
7
+ export interface ShopGuiOptions {
8
+ items: any[];
9
+ sell?: ShopSellList;
10
+ sellMultiplier?: number;
11
+ message?: string;
12
+ face?: {
13
+ id: string;
14
+ expression?: string;
15
+ };
16
+ }
17
+ export declare class ShopGui extends Gui {
18
+ private itemsInput;
19
+ private sellMultipliers;
20
+ private baseSellMultiplier;
21
+ private messageInput?;
22
+ private faceInput?;
5
23
  constructor(player: RpgPlayer);
6
- open(items: any[]): Promise<any>;
24
+ private normalizeSellMultipliers;
25
+ private buildShopData;
26
+ private refreshShop;
27
+ open(itemsOrOptions: any[] | ShopGuiOptions): Promise<any>;
7
28
  }
@@ -0,0 +1,23 @@
1
+ import { Gui } from './Gui';
2
+ import { RpgPlayer } from '../Player/Player';
3
+ export interface TitleEntry {
4
+ id: string;
5
+ label: string;
6
+ disabled?: boolean;
7
+ }
8
+ export interface TitleGuiOptions {
9
+ entries?: TitleEntry[];
10
+ title?: string;
11
+ subtitle?: string;
12
+ version?: string;
13
+ showPressStart?: boolean;
14
+ }
15
+ export interface TitleGuiSelection {
16
+ id?: string;
17
+ index?: number;
18
+ entry?: TitleEntry;
19
+ }
20
+ export declare class TitleGui extends Gui {
21
+ constructor(player: RpgPlayer);
22
+ open(options?: TitleGuiOptions): Promise<TitleGuiSelection | null>;
23
+ }
@@ -3,4 +3,13 @@ import { DialogGui } from './DialogGui';
3
3
  import { MenuGui } from './MenuGui';
4
4
  import { ShopGui } from './ShopGui';
5
5
  import { NotificationGui } from './NotificationGui';
6
- export { Gui, DialogGui, MenuGui, ShopGui, NotificationGui };
6
+ import { SaveLoadGui } from './SaveLoadGui';
7
+ import { TitleGui } from './TitleGui';
8
+ import { GameoverGui } from './GameoverGui';
9
+ export { Gui, DialogGui, MenuGui, ShopGui, NotificationGui, SaveLoadGui, TitleGui, GameoverGui };
10
+ export { DialogPosition } from './DialogGui';
11
+ export type { SaveLoadMode, SaveLoadOptions, SaveSlot } from './SaveLoadGui';
12
+ export type { MenuEntryId, MenuEntry, MenuGuiOptions } from './MenuGui';
13
+ export type { ShopGuiOptions, ShopSellList } from './ShopGui';
14
+ export type { TitleEntry, TitleGuiOptions, TitleGuiSelection } from './TitleGui';
15
+ export type { GameoverEntry, GameoverGuiOptions, GameoverGuiSelection } from './GameoverGui';
@@ -1,15 +1,38 @@
1
- import { Constructor, RpgCommonPlayer } from '@rpgjs/common';
1
+ import { PlayerCtor } from '../../../common/src';
2
2
  import { RpgPlayer } from './Player';
3
- interface PlayerWithMixins extends RpgCommonPlayer {
4
- parameters: any[];
5
- getFormulas(name: string): any;
6
- hasEffect(effect: string): boolean;
7
- coefficientElements(attackerPlayer: RpgPlayer): number;
8
- hp: number;
9
- getFormulas(name: string): any;
10
- hasEffect(effect: string): boolean;
11
- }
12
3
  export interface IBattleManager {
4
+ /**
5
+ * Apply damage. Player will lose HP. the `attackerPlayer` parameter is the other player, the one who attacks.
6
+ *
7
+ * If you don't set the skill parameter, it will be a physical attack.
8
+ * The attack formula is already defined but you can customize it in the server options.
9
+ * This method handles all aspects of damage calculation including critical hits,
10
+ * elemental vulnerabilities, guard effects, and applies the final damage to HP.
11
+ *
12
+ * @param attackerPlayer - The attacking player who deals the damage
13
+ * @param skill - Optional skill object for magical attacks, if not provided uses physical attack
14
+ * @returns Object containing damage details and special effects that occurred
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * // Physical attack
19
+ * const result = player.applyDamage(attackerPlayer);
20
+ * console.log(`Physical damage: ${result.damage}, Critical: ${result.critical}`);
21
+ *
22
+ * // Magical attack with skill
23
+ * const fireSkill = { id: 'fire', power: 50, element: 'fire' };
24
+ * const magicResult = player.applyDamage(attackerPlayer, fireSkill);
25
+ * console.log(`Magic damage: ${magicResult.damage}, Vulnerable: ${magicResult.elementVulnerable}`);
26
+ *
27
+ * // Check for guard effects
28
+ * if (result.guard) {
29
+ * console.log('Attack was partially blocked!');
30
+ * }
31
+ * if (result.superGuard) {
32
+ * console.log('Attack was heavily reduced by super guard!');
33
+ * }
34
+ * ```
35
+ */
13
36
  applyDamage(attackerPlayer: RpgPlayer, skill?: any): {
14
37
  damage: number;
15
38
  critical: boolean;
@@ -18,5 +41,4 @@ export interface IBattleManager {
18
41
  superGuard: boolean;
19
42
  };
20
43
  }
21
- export declare function WithBattleManager<TBase extends Constructor<PlayerWithMixins>>(Base: TBase): Constructor<IBattleManager> & TBase;
22
- export {};
44
+ export declare function WithBattleManager<TBase extends PlayerCtor>(Base: TBase): new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> & IBattleManager;
@@ -1,18 +1,51 @@
1
- import { Constructor, RpgCommonPlayer } from '@rpgjs/common';
1
+ import { PlayerCtor } from '../../../common/src';
2
2
  type ClassClass = any;
3
3
  type ActorClass = any;
4
- interface PlayerWithMixins extends RpgCommonPlayer {
5
- databaseById(id: string): any;
6
- addParameter(name: string, { start, end }: {
7
- start: number;
8
- end: number;
9
- }): void;
10
- addItem(item: any): void;
11
- equip(item: any, equip: boolean): void;
12
- }
4
+ /**
5
+ * Class Manager Mixin
6
+ *
7
+ * Provides class and actor management capabilities to any class. This mixin handles
8
+ * character class assignment and actor setup, including automatic parameter configuration,
9
+ * starting equipment, and skill progression based on class definitions.
10
+ *
11
+ * @param Base - The base class to extend with class management
12
+ * @returns Extended class with class management methods
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * class MyPlayer extends WithClassManager(BasePlayer) {
17
+ * constructor() {
18
+ * super();
19
+ * // Class system is automatically initialized
20
+ * }
21
+ * }
22
+ *
23
+ * const player = new MyPlayer();
24
+ * player.setClass(Fighter);
25
+ * player.setActor(Hero);
26
+ * ```
27
+ */
28
+ export declare function WithClassManager<TBase extends PlayerCtor>(Base: TBase): TBase;
29
+ /**
30
+ * Interface for Class Manager functionality
31
+ *
32
+ * Provides class and actor management capabilities including character class assignment
33
+ * and actor setup. This interface defines the public API of the ClassManager mixin.
34
+ */
13
35
  export interface IClassManager {
14
- setClass(_class: ClassClass | string): ClassClass;
15
- setActor(actorClass: ActorClass | string): ActorClass;
36
+ /**
37
+ * Assign a class to the player
38
+ *
39
+ * @param _class - The class constructor or class ID to assign to the player
40
+ * @returns The instantiated class object
41
+ */
42
+ setClass(_class: ClassClass | string): any;
43
+ /**
44
+ * Set up the player as a specific actor archetype
45
+ *
46
+ * @param actorClass - The actor constructor or actor ID to assign to the player
47
+ * @returns The instantiated actor object
48
+ */
49
+ setActor(actorClass: ActorClass | string): any;
16
50
  }
17
- export declare function WithClassManager<TBase extends Constructor<PlayerWithMixins>>(Base: TBase): Constructor<IClassManager> & TBase;
18
51
  export {};
@@ -0,0 +1,123 @@
1
+ import { Constructor, RpgCommonPlayer } from '../../../common/src';
2
+ import { ComponentInput, ComponentLayout } from './Components';
3
+ type ComponentPosition = 'top' | 'center' | 'bottom' | 'left' | 'right';
4
+ /**
5
+ * Component Manager Mixin
6
+ *
7
+ * Provides graphic and component management capabilities to any class. This mixin allows
8
+ * setting single or multiple graphics for player representation, enabling
9
+ * dynamic visual changes and animation sequences. It also provides methods to
10
+ * display UI components around the player graphic (top, bottom, center, left, right).
11
+ *
12
+ * Components are stored as JSON strings for efficient synchronization.
13
+ *
14
+ * @param Base - The base class to extend with component management
15
+ * @returns Extended class with component management methods
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * class MyPlayer extends WithComponentManager(BasePlayer) {
20
+ * constructor() {
21
+ * super();
22
+ * this.setGraphic("hero");
23
+ * }
24
+ * }
25
+ *
26
+ * const player = new MyPlayer();
27
+ * player.setGraphic(["hero_idle", "hero_walk"]);
28
+ * player.setComponentsTop(Components.text('{name}'));
29
+ * ```
30
+ */
31
+ export declare function WithComponentManager<TBase extends Constructor<RpgCommonPlayer>>(Base: TBase): new (...args: ConstructorParameters<TBase>) => InstanceType<TBase> & IComponentManager;
32
+ /**
33
+ * Interface for component management capabilities
34
+ * Defines the method signatures that will be available on the player
35
+ */
36
+ export interface IComponentManager {
37
+ /**
38
+ * Set the graphic(s) for this player
39
+ *
40
+ * Allows setting either a single graphic or multiple graphics for the player.
41
+ * When multiple graphics are provided, they are used for animation sequences.
42
+ * The graphics system provides flexible visual representation that can be
43
+ * dynamically changed during gameplay for different states, equipment, or animations.
44
+ *
45
+ * @param graphic - Single graphic name or array of graphic names for animation sequences
46
+ * @returns void
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * // Set a single graphic for static representation
51
+ * player.setGraphic("hero");
52
+ *
53
+ * // Set multiple graphics for animation sequences
54
+ * player.setGraphic(["hero_idle", "hero_walk", "hero_run"]);
55
+ *
56
+ * // Dynamic graphic changes based on equipment
57
+ * if (player.hasArmor('platemail')) {
58
+ * player.setGraphic("hero_armored");
59
+ * }
60
+ *
61
+ * // Animation sequences for different actions
62
+ * player.setGraphic(["mage_cast_1", "mage_cast_2", "mage_cast_3"]);
63
+ * ```
64
+ */
65
+ setGraphic(graphic: string | string[]): void;
66
+ /**
67
+ * Set components to display above the player graphic
68
+ *
69
+ * @param layout - Component(s) to display, can be single, array, or 2D array
70
+ * @param options - Optional layout options for positioning and sizing
71
+ * @returns void
72
+ */
73
+ setComponentsTop(layout: ComponentInput, options?: ComponentLayout): void;
74
+ /**
75
+ * Set components to display below the player graphic
76
+ *
77
+ * @param layout - Component(s) to display, can be single, array, or 2D array
78
+ * @param options - Optional layout options for positioning and sizing
79
+ * @returns void
80
+ */
81
+ setComponentsBottom(layout: ComponentInput, options?: ComponentLayout): void;
82
+ /**
83
+ * Set components to display at the center of the player graphic
84
+ *
85
+ * @param layout - Component(s) to display, can be single, array, or 2D array
86
+ * @param options - Optional layout options for positioning and sizing
87
+ * @returns void
88
+ */
89
+ setComponentsCenter(layout: ComponentInput, options?: ComponentLayout): void;
90
+ /**
91
+ * Set components to display to the left of the player graphic
92
+ *
93
+ * @param layout - Component(s) to display, can be single, array, or 2D array
94
+ * @param options - Optional layout options for positioning and sizing
95
+ * @returns void
96
+ */
97
+ setComponentsLeft(layout: ComponentInput, options?: ComponentLayout): void;
98
+ /**
99
+ * Set components to display to the right of the player graphic
100
+ *
101
+ * @param layout - Component(s) to display, can be single, array, or 2D array
102
+ * @param options - Optional layout options for positioning and sizing
103
+ * @returns void
104
+ */
105
+ setComponentsRight(layout: ComponentInput, options?: ComponentLayout): void;
106
+ /**
107
+ * Remove components from a specific position
108
+ *
109
+ * @param position - Position of the components: 'top', 'center', 'bottom', 'left', or 'right'
110
+ * @returns void
111
+ */
112
+ removeComponents(position: ComponentPosition): void;
113
+ /**
114
+ * Merge components with existing components at a specific position
115
+ *
116
+ * @param position - Position of the components: 'top', 'center', 'bottom', 'left', or 'right'
117
+ * @param layout - Component(s) to merge, can be single, array, or 2D array
118
+ * @param options - Optional layout options for positioning and sizing
119
+ * @returns void
120
+ */
121
+ mergeComponents(position: ComponentPosition, layout: ComponentInput, options?: ComponentLayout): void;
122
+ }
123
+ export {};