@rpgjs/server 4.3.0 → 5.0.0-alpha.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 (219) hide show
  1. package/{lib → dist}/Gui/DialogGui.d.ts +1 -2
  2. package/{lib → dist}/Gui/Gui.d.ts +1 -2
  3. package/dist/Player/BattleManager.d.ts +22 -0
  4. package/dist/Player/ClassManager.d.ts +18 -0
  5. package/dist/Player/Event.d.ts +0 -0
  6. package/dist/Player/ItemManager.d.ts +17 -0
  7. package/dist/Player/MoveManager.d.ts +177 -0
  8. package/dist/Player/ParameterManager.d.ts +42 -0
  9. package/dist/Player/Player.d.ts +73 -0
  10. package/dist/Player/SkillManager.d.ts +23 -0
  11. package/dist/Player/StateManager.d.ts +39 -0
  12. package/{lib → dist}/RpgServer.d.ts +32 -15
  13. package/dist/RpgServerEngine.d.ts +5 -0
  14. package/dist/core/context.d.ts +2 -0
  15. package/dist/core/inject.d.ts +5 -0
  16. package/dist/core/setup.d.ts +6 -0
  17. package/dist/index.d.ts +9 -0
  18. package/dist/index.js +29673 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/module.d.ts +2 -0
  21. package/dist/rooms/lobby.d.ts +6 -0
  22. package/dist/rooms/map.d.ts +110 -0
  23. package/package.json +15 -37
  24. package/src/Gui/DialogGui.ts +3 -4
  25. package/src/Gui/Gui.ts +4 -6
  26. package/src/Player/BattleManager.ts +108 -99
  27. package/src/Player/ClassManager.ts +47 -46
  28. package/src/Player/ComponentManager.ts +26 -535
  29. package/src/Player/EffectManager.ts +44 -59
  30. package/src/Player/ElementManager.ts +70 -72
  31. package/src/Player/Event.ts +0 -0
  32. package/src/Player/GoldManager.ts +24 -6
  33. package/src/Player/GuiManager.ts +106 -97
  34. package/src/Player/ItemFixture.ts +22 -17
  35. package/src/Player/ItemManager.ts +234 -225
  36. package/src/Player/MoveManager.ts +1047 -457
  37. package/src/Player/ParameterManager.ts +59 -37
  38. package/src/Player/Player.ts +272 -1058
  39. package/src/Player/SkillManager.ts +146 -137
  40. package/src/Player/StateManager.ts +124 -98
  41. package/src/Player/VariableManager.ts +23 -3
  42. package/src/RpgServer.ts +36 -12
  43. package/src/RpgServerEngine.ts +7 -0
  44. package/src/core/context.ts +3 -0
  45. package/src/core/inject.ts +17 -0
  46. package/src/core/setup.ts +20 -0
  47. package/src/index.ts +9 -31
  48. package/src/module.ts +32 -0
  49. package/src/presets/index.ts +1 -3
  50. package/src/rooms/lobby.ts +24 -0
  51. package/src/rooms/map.ts +311 -0
  52. package/tsconfig.json +26 -23
  53. package/vite.config.ts +21 -0
  54. package/CHANGELOG.md +0 -174
  55. package/LICENSE +0 -19
  56. package/browser/manifest.json +0 -7
  57. package/browser/rpg.server.js +0 -22379
  58. package/browser/rpg.server.umd.cjs +0 -22410
  59. package/lib/Game/EventManager.d.ts +0 -54
  60. package/lib/Game/EventManager.js +0 -107
  61. package/lib/Game/EventManager.js.map +0 -1
  62. package/lib/Game/Map.d.ts +0 -191
  63. package/lib/Game/Map.js +0 -419
  64. package/lib/Game/Map.js.map +0 -1
  65. package/lib/Game/WorldMaps.d.ts +0 -17
  66. package/lib/Game/WorldMaps.js +0 -28
  67. package/lib/Game/WorldMaps.js.map +0 -1
  68. package/lib/Gui/DialogGui.js +0 -57
  69. package/lib/Gui/DialogGui.js.map +0 -1
  70. package/lib/Gui/Gui.js +0 -37
  71. package/lib/Gui/Gui.js.map +0 -1
  72. package/lib/Gui/MenuGui.js +0 -23
  73. package/lib/Gui/MenuGui.js.map +0 -1
  74. package/lib/Gui/NotificationGui.js +0 -8
  75. package/lib/Gui/NotificationGui.js.map +0 -1
  76. package/lib/Gui/ShopGui.js +0 -40
  77. package/lib/Gui/ShopGui.js.map +0 -1
  78. package/lib/Gui/index.js +0 -7
  79. package/lib/Gui/index.js.map +0 -1
  80. package/lib/Interfaces/Gui.d.ts +0 -4
  81. package/lib/Interfaces/Gui.js +0 -2
  82. package/lib/Interfaces/Gui.js.map +0 -1
  83. package/lib/Interfaces/StateStore.d.ts +0 -5
  84. package/lib/Interfaces/StateStore.js +0 -2
  85. package/lib/Interfaces/StateStore.js.map +0 -1
  86. package/lib/MatchMaker.d.ts +0 -24
  87. package/lib/MatchMaker.js +0 -42
  88. package/lib/MatchMaker.js.map +0 -1
  89. package/lib/Monitor/index.d.ts +0 -17
  90. package/lib/Monitor/index.js +0 -72
  91. package/lib/Monitor/index.js.map +0 -1
  92. package/lib/Player/BattleManager.d.ts +0 -36
  93. package/lib/Player/BattleManager.js +0 -101
  94. package/lib/Player/BattleManager.js.map +0 -1
  95. package/lib/Player/ClassManager.d.ts +0 -47
  96. package/lib/Player/ClassManager.js +0 -65
  97. package/lib/Player/ClassManager.js.map +0 -1
  98. package/lib/Player/ComponentManager.d.ts +0 -397
  99. package/lib/Player/ComponentManager.js +0 -505
  100. package/lib/Player/ComponentManager.js.map +0 -1
  101. package/lib/Player/EffectManager.d.ts +0 -46
  102. package/lib/Player/EffectManager.js +0 -75
  103. package/lib/Player/EffectManager.js.map +0 -1
  104. package/lib/Player/ElementManager.d.ts +0 -108
  105. package/lib/Player/ElementManager.js +0 -120
  106. package/lib/Player/ElementManager.js.map +0 -1
  107. package/lib/Player/GoldManager.d.ts +0 -17
  108. package/lib/Player/GoldManager.js +0 -27
  109. package/lib/Player/GoldManager.js.map +0 -1
  110. package/lib/Player/GuiManager.d.ts +0 -247
  111. package/lib/Player/GuiManager.js +0 -291
  112. package/lib/Player/GuiManager.js.map +0 -1
  113. package/lib/Player/ItemFixture.d.ts +0 -7
  114. package/lib/Player/ItemFixture.js +0 -19
  115. package/lib/Player/ItemFixture.js.map +0 -1
  116. package/lib/Player/ItemManager.d.ts +0 -331
  117. package/lib/Player/ItemManager.js +0 -475
  118. package/lib/Player/ItemManager.js.map +0 -1
  119. package/lib/Player/MoveManager.d.ts +0 -333
  120. package/lib/Player/MoveManager.js +0 -450
  121. package/lib/Player/MoveManager.js.map +0 -1
  122. package/lib/Player/ParameterManager.d.ts +0 -316
  123. package/lib/Player/ParameterManager.js +0 -408
  124. package/lib/Player/ParameterManager.js.map +0 -1
  125. package/lib/Player/Player.d.ts +0 -828
  126. package/lib/Player/Player.js +0 -927
  127. package/lib/Player/Player.js.map +0 -1
  128. package/lib/Player/SkillManager.d.ts +0 -163
  129. package/lib/Player/SkillManager.js +0 -223
  130. package/lib/Player/SkillManager.js.map +0 -1
  131. package/lib/Player/StateManager.d.ts +0 -185
  132. package/lib/Player/StateManager.js +0 -228
  133. package/lib/Player/StateManager.js.map +0 -1
  134. package/lib/Player/VariableManager.d.ts +0 -46
  135. package/lib/Player/VariableManager.js +0 -52
  136. package/lib/Player/VariableManager.js.map +0 -1
  137. package/lib/Query.d.ts +0 -127
  138. package/lib/Query.js +0 -159
  139. package/lib/Query.js.map +0 -1
  140. package/lib/RpgServer.js +0 -2
  141. package/lib/RpgServer.js.map +0 -1
  142. package/lib/Scenes/Map.d.ts +0 -136
  143. package/lib/Scenes/Map.js +0 -273
  144. package/lib/Scenes/Map.js.map +0 -1
  145. package/lib/decorators/event.d.ts +0 -43
  146. package/lib/decorators/event.js +0 -13
  147. package/lib/decorators/event.js.map +0 -1
  148. package/lib/decorators/map.d.ts +0 -178
  149. package/lib/decorators/map.js +0 -43
  150. package/lib/decorators/map.js.map +0 -1
  151. package/lib/entry-point.d.ts +0 -34
  152. package/lib/entry-point.js +0 -70
  153. package/lib/entry-point.js.map +0 -1
  154. package/lib/express/api.d.ts +0 -3
  155. package/lib/express/api.js +0 -105
  156. package/lib/express/api.js.map +0 -1
  157. package/lib/express/errors/NotAuthorized.d.ts +0 -4
  158. package/lib/express/errors/NotAuthorized.js +0 -7
  159. package/lib/express/errors/NotAuthorized.js.map +0 -1
  160. package/lib/express/errors/NotFound.d.ts +0 -4
  161. package/lib/express/errors/NotFound.js +0 -7
  162. package/lib/express/errors/NotFound.js.map +0 -1
  163. package/lib/express/server.d.ts +0 -18
  164. package/lib/express/server.js +0 -70
  165. package/lib/express/server.js.map +0 -1
  166. package/lib/index.d.ts +0 -20
  167. package/lib/index.js +0 -19
  168. package/lib/index.js.map +0 -1
  169. package/lib/inject.d.ts +0 -22
  170. package/lib/inject.js +0 -29
  171. package/lib/inject.js.map +0 -1
  172. package/lib/logs/index.js +0 -6
  173. package/lib/logs/index.js.map +0 -1
  174. package/lib/logs/item.js +0 -34
  175. package/lib/logs/item.js.map +0 -1
  176. package/lib/logs/log.js +0 -7
  177. package/lib/logs/log.js.map +0 -1
  178. package/lib/logs/skill.js +0 -19
  179. package/lib/logs/skill.js.map +0 -1
  180. package/lib/logs/state.js +0 -13
  181. package/lib/logs/state.js.map +0 -1
  182. package/lib/models/Item.d.ts +0 -10
  183. package/lib/models/Item.js +0 -2
  184. package/lib/models/Item.js.map +0 -1
  185. package/lib/presets/index.js +0 -65
  186. package/lib/presets/index.js.map +0 -1
  187. package/lib/server.d.ts +0 -137
  188. package/lib/server.js +0 -443
  189. package/lib/server.js.map +0 -1
  190. package/rpg.toml +0 -14
  191. package/src/Game/EventManager.ts +0 -125
  192. package/src/Game/Map.ts +0 -500
  193. package/src/Game/WorldMaps.ts +0 -45
  194. package/src/Interfaces/Gui.ts +0 -4
  195. package/src/Interfaces/StateStore.ts +0 -5
  196. package/src/MatchMaker.ts +0 -65
  197. package/src/Monitor/index.ts +0 -78
  198. package/src/Query.ts +0 -172
  199. package/src/Scenes/Map.ts +0 -310
  200. package/src/decorators/event.ts +0 -58
  201. package/src/decorators/map.ts +0 -226
  202. package/src/entry-point.ts +0 -111
  203. package/src/express/api.ts +0 -118
  204. package/src/express/errors/NotAuthorized.ts +0 -6
  205. package/src/express/errors/NotFound.ts +0 -6
  206. package/src/express/server.ts +0 -94
  207. package/src/inject.ts +0 -33
  208. package/src/models/Item.ts +0 -11
  209. package/src/server.ts +0 -459
  210. /package/{lib → dist}/Gui/MenuGui.d.ts +0 -0
  211. /package/{lib → dist}/Gui/NotificationGui.d.ts +0 -0
  212. /package/{lib → dist}/Gui/ShopGui.d.ts +0 -0
  213. /package/{lib → dist}/Gui/index.d.ts +0 -0
  214. /package/{lib → dist}/logs/index.d.ts +0 -0
  215. /package/{lib → dist}/logs/item.d.ts +0 -0
  216. /package/{lib → dist}/logs/log.d.ts +0 -0
  217. /package/{lib → dist}/logs/skill.d.ts +0 -0
  218. /package/{lib → dist}/logs/state.d.ts +0 -0
  219. /package/{lib → dist}/presets/index.d.ts +0 -0
@@ -1,538 +1,29 @@
1
- import { Utils } from '@rpgjs/common'
2
- import { BarComponentObject, ComponentObject, LayoutObject, LayoutOptions, TextComponentObject, LayoutPositionEnum, ShapeComponentObject, ImageComponentObject, TileComponentObject, DebugComponentObject, TextComponentStyleObject } from '@rpgjs/types'
3
-
4
- const defaultStyle = (style: any) => ({
5
- borderColor: '#000000',
6
- borderWidth: 2,
7
- bgColor: '#000000',
8
- borderRadius: 5,
9
- ...style
10
- })
11
-
12
- const bar = (current: string, max: string, style?: BarComponentObject['value']['style'], text?: string | null): BarComponentObject => {
13
- return {
14
- id: 'bar',
15
- value: {
16
- current,
17
- max,
18
- text: text === null ? '' : text || '{$current}/{$max}',
19
- style
20
- }
21
- }
1
+ import { type Constructor } from "@rpgjs/common";
2
+ import { RpgCommonPlayer } from "@rpgjs/common";
3
+
4
+ /**
5
+ * Interface defining what ComponentManager adds to a class
6
+ */
7
+ export interface IComponentManager {
8
+ setGraphic(graphic: string | string[]): void;
22
9
  }
23
10
 
24
- export const Components = {
25
- /**
26
- * Displays a bar
27
- *
28
- * Example:
29
- *
30
- * ```ts
31
- * import { Components } from '@rpgjs/server'
32
- * Components.bar('hp', 'param.maxHp', {
33
- * bgColor: '#ab0606'
34
- * })
35
- * ```
36
- *
37
- * For text, you can use the following variables:
38
- * - {$current} current value
39
- * - {$max} maximum value
40
- * - {$percent} percentage
41
- *
42
- * Example:
43
- *
44
- * ```ts
45
- * import { Components } from '@rpgjs/server'
46
- * Components.bar('hp', 'param.maxHp', {
47
- * bgColor: '#ab0606'
48
- * }, 'HP: {$current}/{$max}')
49
- * ```
50
- *
51
- * and you can also use the variables of player:
52
- *
53
- * ```ts
54
- * import { Components } from '@rpgjs/server'
55
- * Components.bar('hp', 'param.maxHp', {
56
- * bgColor: '#ab0606'
57
- * }, 'HP: {$current}/{$max} - {name}') // HP: 100/100 - John
58
- * ```
59
- *
60
- * @title Bar Component
61
- * @param {string} current Parameter that corresponds to the current value
62
- * @param {string} max Parameter that corresponds to the maximum value
63
- * @param {object} [style] style
64
- * @param {string} [style.bgColor] background color. Hexadecimal format.
65
- * @param {string} [style.fillColor] fill color. Hexadecimal format.
66
- * @param {string} [style.borderColor] border color. Hexadecimal format.
67
- * @param {number} [style.borderWidth] border width
68
- * @param {number} [style.height] height
69
- * @param {number} [style.width] width
70
- * @param {number} [style.borderRadius] border radius
71
- * @param {number} [style.opacity] opacity
72
- * @param {string | null} [text] text above bar. if null, no text will be displayed. You can use the variables
73
- * @returns {BarComponentObject}
74
- * @memberof Components
75
- * @since 3.3.0
76
- */
77
- bar,
78
-
79
- /**
80
- * Displays a life bar
81
- *
82
- * @title HP Bar Component
83
- * @param {object} [style] style. See bar style (Components.bar())
84
- * @param {string | null} [text] test above bar (Components.bar())
85
- * @returns {BarComponentObject}
86
- * @memberof Components
87
- * @since 3.3.0
88
- */
89
- hpBar(style?: BarComponentObject['value']['style'], text?: string | null): BarComponentObject {
90
- return bar('hp', 'param.maxHp', {
91
- ...defaultStyle({
92
- fillColor: '#ab0606'
93
- }),
94
- ...((style as any) || {})
95
- }, text)
96
- },
97
-
98
- /**
99
- * Displays a SP bar
100
- *
101
- * @title SP Bar Component
102
- * @param {object} [style] style. See bar style (Components.bar())
103
- * @param {string | null} [text] test above bar (Components.bar())
104
- * @returns {BarComponentObject}
105
- * @memberof Components
106
- * @since 3.3.0
107
- */
108
- spBar(style?: BarComponentObject['value']['style'], text?: string | null): BarComponentObject {
109
- return bar('sp', 'param.maxSp', {
110
- ...defaultStyle({
111
- fillColor: '#0fa38c'
112
- }),
113
- ...((style as any) || {}),
114
- }, text)
115
- },
116
-
117
- /**
118
- * Put on the text. You can read the content of a variable with {} format (see example below)
119
- *
120
- * Example:
121
- *
122
- * ```ts
123
- * import { Components } from '@rpgjs/server'
124
- * Components.text('Hello World')
125
- * ```
126
- *
127
- * Example with variable:
128
- *
129
- * ```ts
130
- * import { Components } from '@rpgjs/server'
131
- * Components.text('{name}')
132
- * ```
133
- *
134
- * Other example with position:
135
- *
136
- * ```ts
137
- * import { Components } from '@rpgjs/server'
138
- * Components.text('X: {position.x} Y: {position.y}')
139
- * ```
140
- *
141
- * With style:
142
- *
143
- * ```ts
144
- * import { Components } from '@rpgjs/server'
145
- * Components.text('Hello World', {
146
- * fill: '#ffffff',
147
- * fontSize: 20,
148
- * fontFamily: 'Arial',
149
- * stroke: '#000000',
150
- * fontStyle: 'italic',
151
- * fontWeight: 'bold'
152
- * })
153
- * ```
154
- *
155
- * @title Text Component
156
- * @param {string} value source
157
- * @param {object} [style] style
158
- * @param {string} [style.fill] color. Hexadecimal format.
159
- * @param {number} [style.fontSize] font size
160
- * @param {string} [style.fontFamily] font family
161
- * @param {string} [style.stroke] stroke color. Hexadecimal format.
162
- * @param {'normal' | 'italic' | 'oblique'} [style.fontStyle] font style
163
- * @param {'normal' | 'bold' | 'bolder' | 'lighter' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'} [style.fontWeight] font weight
164
- * @param {number} [style.opacity] opacity. Between 0 and 1
165
- * @param {boolean} [style.wordWrap] word wrap
166
- * @param {'left' | 'center' | 'right' | 'justify'} [style.align] align
167
- * @returns {TextComponentObject}
168
- * @memberof Components
169
- * @since 3.3.0
170
- */
171
- text(value: string, style?: TextComponentStyleObject): TextComponentObject {
172
- return {
173
- id: 'text',
174
- value: {
175
- text: value,
176
- style: {
177
- fill: '#ffffff',
178
- fontSize: 15,
179
- ...((style as any) || {})
180
- }
181
- }
182
- }
183
- },
184
-
185
- /**
186
- * Add a shape
187
- *
188
- * Example:
189
- *
190
- * ```ts
191
- * import { Components } from '@rpgjs/server'
192
- * Components.shape({
193
- * fill: '#ffffff',
194
- * type: 'circle',
195
- * radius: 10
196
- * })
197
- * ```
198
- *
199
- * You can use parameters:
200
- *
201
- * ```ts
202
- * import { Components } from '@rpgjs/server'
203
- * Components.shape({
204
- * fill: '#ffffff',
205
- * type: 'circle',
206
- * radius: 'hp'
207
- * })
208
- * ```
209
- *
210
- * Here, the radius will be the same as the hp value
211
- *
212
- * @title Shape Component
213
- * @param {object} value
214
- * @param {string} value.fill color. Hexadecimal format.
215
- * @param {number | string} [value.opacity] opacity. Between 0 and 1
216
- * @param {string} value.type type of shape. Can be 'circle' or 'rectangle', 'ellipse' or 'polygon', 'line' or 'rounded-rectangle'
217
- * @param {number | string} [value.radius] if type is circle, radius of the circle
218
- * @param {number | string} [value.width] if type is rectangle or ellipse, width of the rectangle
219
- * @param {number | string} [value.height] if type is rectangle or ellipse, height of the rectangle
220
- * @param {number | string} [value.x1] if type is line, x1 position of the line
221
- * @param {number | string} [value.y1] if type is line, y1 position of the line
222
- * @param {number | string} [value.x2] if type is line, x2 position of the line
223
- * @param {number | string} [value.y2] if type is line, y2 position of the line
224
- * @param {number[]} [value.points] if type is polygon, points of the polygon
225
- * @param {object} [value.line] border style
226
- * @param {string} [value.line.color] border color. Hexadecimal format.
227
- * @param {number} [value.line.width] border width
228
- * @param {number} [value.line.alpha] border opacity. Between 0 and 1
229
- * @returns {ShapeComponentObject}
230
- * @memberof Components
231
- * @since 3.3.0
232
- */
233
- shape(value: ShapeComponentObject['value']): ShapeComponentObject {
234
- return {
235
- id: 'shape',
236
- value
237
- }
238
- },
239
-
240
- /**
241
- * Put the link to an image or the identifier of an image (if the spritesheet exists)
242
- *
243
- * Example:
244
- *
245
- * ```ts
246
- * import { Components } from '@rpgjs/server'
247
- * Components.image('mygraphic.png')
248
- * ```
249
- *
250
- * @title Image Component
251
- * @param {string} value source
252
- * @returns {ImageComponentObject}
253
- * @memberof Components
254
- * @since 3.3.0
255
- */
256
- image(value: string): ImageComponentObject {
257
- return {
258
- id: 'image',
259
- value
260
- }
261
- },
262
-
263
- /**
264
- * Indicates the tile ID
265
- *
266
- * Example:
267
- *
268
- * ```ts
269
- * import { Components } from '@rpgjs/server'
270
- * Components.tile(3)
271
- * ```
272
- *
273
- * @title Tile Component
274
- * @param {number} value tile ID
275
- * @returns {TileComponentObject}
276
- * @memberof Components
277
- * @since 3.3.0
278
- */
279
- tile(value: number): TileComponentObject {
280
- return {
281
- id: 'tile',
282
- value
283
- }
284
- },
285
- debug(): DebugComponentObject {
286
- return {
287
- id: 'debug',
288
- value: ''
289
- }
290
- }
11
+ /**
12
+ * Component Manager mixin
13
+ *
14
+ * Adds methods to manage player graphics
15
+ *
16
+ * @param Base - The base class to extend
17
+ * @returns A new class with component management capabilities
18
+ */
19
+ export function WithComponentManager<TBase extends Constructor<RpgCommonPlayer>>(Base: TBase) {
20
+ return class extends Base implements IComponentManager {
21
+ setGraphic(graphic: string | string[]) {
22
+ if (Array.isArray(graphic)) {
23
+ this.graphics.set(graphic);
24
+ } else {
25
+ this.graphics.set([graphic]);
26
+ }
27
+ }
28
+ };
291
29
  }
292
-
293
- export class ComponentManager {
294
- layout: LayoutObject<any>
295
-
296
- /**
297
- * Give the spritesheet identifier
298
- *
299
- * Since version 3.0.0-rc, you can define several graphic elements. If you put a number, it represents the tile ID in the tileset
300
- *
301
- * Example 1:
302
- * ```ts
303
- * player.setGraphic(['body', 'shield'])
304
- * ```
305
- *
306
- * Example 2:
307
- * ```ts
308
- * player.setGraphic(3) // Use tile #3
309
- * ```
310
- *
311
- * > You must, on the client side, create the spritesheet in question. Guide: [Create Sprite](/guide/create-sprite.html)
312
- *
313
- * @title Set Graphic
314
- * @method player.setGraphic(graphic)
315
- * @param {string | number | (string | number)[]} graphic
316
- * @returns {void}
317
- * @memberof ComponentManager
318
- */
319
- setGraphic(graphic: string | number | (string | number)[]) {
320
- const components = (Utils.isArray(graphic) ? graphic : [graphic]) as string[]
321
- const col = [...components.map(value => ({ id: Utils.isString(value) ? 'graphic' : 'tile', value }))]
322
- this.removeComponentById('center', 'graphic')
323
- this.mergeComponent('center', col)
324
- }
325
-
326
- /**
327
- * Delete components
328
- *
329
- * @title Remove Components
330
- * @param {string} position Position of the components. Can be: `top`, `center`, `bottom`, `left`, `right`
331
- * @memberof ComponentManager
332
- * @since 3.3.0
333
- */
334
- removeComponents(position: LayoutPositionEnum) {
335
- (this.layout[position] as any).lines = []
336
- }
337
-
338
- /**
339
- * Delete components by id.
340
- *
341
- * @title Remove Component By Id
342
- * @param {string} position Position of the components. Can be: `top`, `center`, `bottom`, `left`, `right`
343
- * @param {string} id Id of the component
344
- * @since 3.3.0
345
- */
346
- removeComponentById(
347
- position: LayoutPositionEnum,
348
- id: string
349
- ) {
350
- let lines = this.layout[position]?.lines || []
351
- lines = lines.map(line => {
352
- line.col = line.col.filter(c => c.id !== id)
353
- return line
354
- });
355
- lines = lines.filter(line => line.col.length > 0);
356
- (this.layout[position] as any).lines = lines
357
- }
358
-
359
- /**
360
- * Merges components with existing components
361
- *
362
- * For use layout and options, see [setComponentsTop](/api/player.html#setcomponentstop)
363
- *
364
- * @title Merge Components
365
- * @param {string} position Position of the components. Can be: `top`, `center`, `bottom`, `left`, `right`
366
- * @param {Object} layout
367
- * @param {Object} options
368
- * @memberof ComponentManager
369
- * @since 3.3.0
370
- */
371
- mergeComponent<T = any>(
372
- position: LayoutPositionEnum,
373
- layout: ComponentObject<T>[][] | ComponentObject<T>[] | ComponentObject<T>,
374
- options: LayoutOptions = {}
375
- ) {
376
- if (!(layout instanceof Array)) {
377
- layout = [layout]
378
- }
379
-
380
- this.layout[position] = {
381
- lines: [
382
- ...(this.layout[position]?.lines || []),
383
- ...layout.map(col => {
384
- if (!Utils.isArray(col)) {
385
- col = [col]
386
- }
387
- return { col }
388
- })
389
- ],
390
- ...options
391
- }
392
- }
393
-
394
- private setComponents<P extends LayoutPositionEnum, T = any>(
395
- position: P,
396
- layout: ComponentObject<T>[][] | ComponentObject<T>[] | ComponentObject<T>,
397
- options: LayoutOptions = {}
398
- ) {
399
- (this.layout[position] as any).lines = []
400
- this.mergeComponent(position, layout, options)
401
- }
402
-
403
- /**
404
- * Add components to the center of the graphic.
405
- *
406
- * View [setComponentsTop](/api/player.html#setcomponentstop) for more information
407
- *
408
- * > Be careful, because if you assign, it deletes the graphics and if the lines are superimposed (unlike the other locations)
409
- *
410
- * @title Set Components Center
411
- * @method player.setComponentsCenter(layout,options)
412
- * @param {Object} layout
413
- * @param {Object} options
414
- * @memberof ComponentManager
415
- * @since 3.3.0
416
- */
417
- setComponentsCenter<T = any>(layout: ComponentObject<T>[][] | ComponentObject<T>[] | ComponentObject<T>, options: LayoutOptions = {}) {
418
- this.setComponents<'center', T>('center', layout, options)
419
- }
420
-
421
- /**
422
- * Add components to the top of the graphic. e.g. text, life bar etc. The block will be centred
423
- * The first array corresponds to the rows, and the nested table to the array in the row
424
- *
425
- * Example:
426
- *
427
- * ```ts
428
- * import { Components } from '@rpgjs/server'
429
- *
430
- * player.setComponentsTop([
431
- * [Components.text('Hello World')],
432
- * [Components.hpBar()]
433
- * ]) // 2 lines with 1 component each
434
- * ```
435
- *
436
- * or
437
- *
438
- * ```ts
439
- * import { Components } from '@rpgjs/server'
440
- *
441
- * player.setComponentsTop([
442
- * [Components.text('Hello World'), Components.hpBar()]
443
- * ]) // 1 line with 2 components
444
- * ```
445
- *
446
- * You can be faster if you only have lines
447
- *
448
- * ```ts
449
- * player.setComponentsTop([
450
- * Components.text('Hello World'),
451
- * Components.hpBar()
452
- * ]) // 2 lines with 1 component each
453
- * ```
454
- *
455
- * or one component:
456
- *
457
- * ```ts
458
- * player.setComponentsTop(Components.text('Hello World')) // 1 line with 1 component
459
- * ```
460
- *
461
- * You can add options to manage the style
462
- *
463
- * ```ts
464
- * player.setComponentsTop([
465
- * Components.text('Hello World'),
466
- * Components.hpBar()
467
- * ], {
468
- * width: 100,
469
- * height: 20,
470
- * marginTop: 10,
471
- * })
472
- * ```
473
- *
474
- * @title Set Components Top
475
- * @method player.setComponentsTop(layout,options)
476
- * @param {ComponentObject[][] | ComponentObject[] | ComponentObject} layout Components
477
- * @param {Object} [options = {}] Options
478
- * @param {number} [options.width] Width of the block
479
- * @param {number} [options.height = 20] Height of the block
480
- * @param {number} [options.marginTop] Margin top
481
- * @param {number} [options.marginBottom] Margin bottom
482
- * @param {number} [options.marginLeft] Margin left
483
- * @param {number} [options.marginRight] Margin right
484
- * @memberof ComponentManager
485
- * @since 3.3.0
486
- */
487
- setComponentsTop<T = any>(layout: ComponentObject<T>[][] | ComponentObject<T>[] | ComponentObject<T>, options: LayoutOptions = {}) {
488
- this.setComponents<'top', T>('top', layout, options)
489
- }
490
-
491
- /**
492
- * Add components to the bottom of the graphic.
493
- *
494
- * View [setComponentsTop](/api/player.html#setcomponentstop) for more information
495
- *
496
- * @title Set Components Bottom
497
- * @method player.setComponentsBottom(layout,options)
498
- * @param {Object} layout
499
- * @param {Object} options
500
- * @memberof ComponentManager
501
- * @since 3.3.0
502
- */
503
- setComponentsBottom<T = any>(layout: ComponentObject<T>[][] | ComponentObject<T>[] | ComponentObject<T>, options: LayoutOptions = {}) {
504
- this.setComponents<'bottom', T>('bottom', layout, options)
505
- }
506
-
507
- /**
508
- * Add components to the left of the graphic.
509
- *
510
- * View [setComponentsTop](/api/player.html#setcomponentstop) for more information
511
- *
512
- * @title Set Components Left
513
- * @method player.setComponentsLeft(layout,options)
514
- * @param {Object} layout
515
- * @param {Object} options
516
- * @memberof ComponentManager
517
- * @since 3.3.0
518
- */
519
- setComponentsLeft<T = any>(layout: ComponentObject<T>[][] | ComponentObject<T>[] | ComponentObject<T>, options: LayoutOptions = {}) {
520
- this.setComponents<'left', T>('left', layout, options)
521
- }
522
-
523
- /**
524
- * Add components to the right of the graphic.
525
- *
526
- * View [setComponentsTop](/api/player.html#setcomponentstop) for more information
527
- *
528
- * @title Set Components Right
529
- * @method player.setComponentsRight(layout,options)
530
- * @param {Object} layout
531
- * @param {Object} options
532
- * @memberof ComponentManager
533
- * @since 3.3.0
534
- */
535
- setComponentsRight<T = any>(layout: ComponentObject<T>[][] | ComponentObject<T>[] | ComponentObject<T>, options: LayoutOptions = {}) {
536
- this.setComponents<'right', T>('right', layout, options)
537
- }
538
- }
@@ -1,95 +1,80 @@
1
- import { Utils } from '@rpgjs/common'
2
- import { Effect } from '@rpgjs/database'
3
- import { ParameterManager } from './ParameterManager'
4
-
5
1
  import {
6
- MAXHP,
7
- MAXSP
8
- } from '../presets'
9
-
10
- const {
11
- arrayUniq,
12
- arrayFlat,
13
- applyMixins
14
- } = Utils
2
+ arrayFlat,
3
+ arrayUniq,
4
+ Constructor,
5
+ RpgCommonPlayer,
6
+ } from "@rpgjs/common";
15
7
 
16
- export class EffectManager {
17
-
18
- _effects: Effect[]
8
+ export interface IWithEffectManager {
9
+ effects: any[];
10
+ }
19
11
 
20
- // TODO
21
- applyEffect(item) {
22
- if (item.hpValue) {
23
- this.hp += item.hpValue
24
- }
25
- if (item.hpRate) {
26
- this.hp += this.param[MAXHP] * item.hpRate
27
- }
28
- if (item.spValue) {
29
- this.sp += item.spValue
30
- }
31
- if (item.spRate) {
32
- this.sp += this.param[MAXSP] * item.spRate
33
- }
34
- }
12
+ export enum Effect {
13
+ CAN_NOT_SKILL = 'CAN_NOT_SKILL',
14
+ CAN_NOT_ITEM = 'CAN_NOT_ITEM',
15
+ CAN_NOT_STATE = 'CAN_NOT_STATE',
16
+ CAN_NOT_EQUIPMENT = 'CAN_NOT_EQUIPMENT',
17
+ HALF_SP_COST = 'HALF_SP_COST',
18
+ GUARD = 'GUARD',
19
+ SUPER_GUARD = 'SUPER_GUARD'
20
+ }
35
21
 
36
- /**
22
+ export function WithEffectManager<TBase extends Constructor<RpgCommonPlayer>>(
23
+ Base: TBase
24
+ ) {
25
+ return class extends Base implements IWithEffectManager {
26
+ /**
37
27
  * ```ts
38
28
  * import { Effect } from '@rpgjs/database'
39
- *
29
+ *
40
30
  * const bool = player.hasEffect(Effect.CAN_NOT_SKILL)
41
31
  * ```
42
- *
32
+ *
43
33
  * @title Has Effect
44
34
  * @method player.hasEffect(effect)
45
- * @param {Effect} effect
35
+ * @param {string} effect
46
36
  * @returns {boolean}
47
37
  * @memberof EffectManager
48
38
  * */
49
- hasEffect(effect: Effect): boolean {
50
- return this.effects.includes(effect)
39
+ hasEffect(effect: string): boolean {
40
+ return this.effects.includes(effect);
51
41
  }
52
42
 
53
- /**
43
+ /**
54
44
  * Retrieves a array of effects assigned to the player, state effects and effects of weapons and armors equipped with the player's own weapons.
55
- *
45
+ *
56
46
  * ```ts
57
47
  * console.log(player.effects)
58
- * ```
48
+ * ```
59
49
  * @title Get Effects
60
50
  * @prop {Array<Effect>} player.effects
61
51
  * @memberof EffectManager
62
52
  * */
63
53
  get effects(): any[] {
64
- const getEffects = (prop) => {
65
- return arrayFlat(this[prop]
66
- .map(el => el.effects || []))
67
- }
68
- return arrayUniq([
69
- ...this._effects,
70
- ...getEffects('states'),
71
- ...getEffects('equipments')
72
- ])
54
+ const getEffects = (prop) => {
55
+ return arrayFlat(this[prop]().map((el) => el.effects || []));
56
+ };
57
+ return arrayUniq([
58
+ ...this._effects(),
59
+ ...getEffects("states"),
60
+ ...getEffects("equipments"),
61
+ ]);
73
62
  }
74
63
 
75
- /**
64
+ /**
76
65
  * Assigns effects to the player. If you give a array, it does not change the effects of the player's states and armor/weapons equipped.
77
- *
66
+ *
78
67
  * ```ts
79
68
  * import { Effect } from '@rpgjs/database'
80
- *
69
+ *
81
70
  * player.effects = [Effect.CAN_NOT_SKILL]
82
- * ```
71
+ * ```
83
72
  * @title Set Effects
84
73
  * @prop {Array<Effect>} player.effects
85
74
  * @memberof EffectManager
86
75
  * */
87
76
  set effects(val) {
88
- this._effects = val
77
+ this._effects.set(val);
89
78
  }
79
+ };
90
80
  }
91
-
92
- applyMixins(EffectManager, [ParameterManager])
93
-
94
- export interface EffectManager extends ParameterManager { }
95
-