@rpgjs/server 5.0.0-alpha.2 → 5.0.0-alpha.21
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 +4 -0
- package/dist/Gui/index.d.ts +1 -0
- package/dist/Player/BattleManager.d.ts +32 -22
- package/dist/Player/ClassManager.d.ts +31 -18
- package/dist/Player/ComponentManager.d.ts +123 -0
- package/dist/Player/Components.d.ts +345 -0
- package/dist/Player/EffectManager.d.ts +40 -0
- package/dist/Player/ElementManager.d.ts +31 -0
- package/dist/Player/GoldManager.d.ts +22 -0
- package/dist/Player/GuiManager.d.ts +176 -0
- package/dist/Player/ItemFixture.d.ts +6 -0
- package/dist/Player/ItemManager.d.ts +164 -10
- package/dist/Player/MoveManager.d.ts +32 -44
- package/dist/Player/ParameterManager.d.ts +343 -14
- package/dist/Player/Player.d.ts +266 -8
- package/dist/Player/SkillManager.d.ts +27 -19
- package/dist/Player/StateManager.d.ts +28 -35
- package/dist/Player/VariableManager.d.ts +30 -0
- package/dist/RpgServer.d.ts +227 -1
- package/dist/decorators/event.d.ts +46 -0
- package/dist/decorators/map.d.ts +177 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +17472 -18167
- package/dist/index.js.map +1 -1
- package/dist/rooms/map.d.ts +486 -8
- package/package.json +17 -15
- package/src/Gui/DialogGui.ts +7 -2
- package/src/Gui/index.ts +3 -1
- package/src/Player/BattleManager.ts +97 -38
- package/src/Player/ClassManager.ts +95 -35
- package/src/Player/ComponentManager.ts +425 -19
- package/src/Player/Components.ts +380 -0
- package/src/Player/EffectManager.ts +110 -27
- package/src/Player/ElementManager.ts +126 -25
- package/src/Player/GoldManager.ts +32 -35
- package/src/Player/GuiManager.ts +187 -140
- package/src/Player/ItemFixture.ts +4 -5
- package/src/Player/ItemManager.ts +363 -48
- package/src/Player/MoveManager.ts +323 -308
- package/src/Player/ParameterManager.ts +499 -99
- package/src/Player/Player.ts +719 -80
- package/src/Player/SkillManager.ts +44 -23
- package/src/Player/StateManager.ts +210 -95
- package/src/Player/VariableManager.ts +180 -48
- package/src/RpgServer.ts +236 -1
- package/src/core/context.ts +1 -0
- package/src/decorators/event.ts +61 -0
- package/src/decorators/map.ts +198 -0
- package/src/index.ts +7 -1
- package/src/module.ts +24 -0
- package/src/rooms/map.ts +1054 -54
- package/dist/Player/Event.d.ts +0 -0
- package/src/Player/Event.ts +0 -0
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { RpgPlayer } from './Player';
|
|
1
|
+
import { PlayerCtor } from '@rpgjs/common';
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
3
|
+
* Skill Manager Mixin
|
|
4
|
+
*
|
|
5
|
+
* Provides skill management capabilities to any class. This mixin handles
|
|
6
|
+
* learning, forgetting, and using skills, including SP cost management,
|
|
7
|
+
* hit rate calculations, and skill effects application.
|
|
8
|
+
*
|
|
9
|
+
* @param Base - The base class to extend with skill management
|
|
10
|
+
* @returns Extended class with skill management methods
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* class MyPlayer extends WithSkillManager(BasePlayer) {
|
|
15
|
+
* constructor() {
|
|
16
|
+
* super();
|
|
17
|
+
* // Skill system is automatically initialized
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* const player = new MyPlayer();
|
|
22
|
+
* player.learnSkill(Fire);
|
|
23
|
+
* player.useSkill(Fire, targetPlayer);
|
|
24
|
+
* ```
|
|
5
25
|
*/
|
|
6
|
-
|
|
7
|
-
sp: number;
|
|
8
|
-
skills(): any[];
|
|
9
|
-
hasEffect(effect: string): boolean;
|
|
10
|
-
databaseById(id: string): any;
|
|
11
|
-
applyStates(player: RpgPlayer, skill: any): void;
|
|
12
|
-
}
|
|
26
|
+
export declare function WithSkillManager<TBase extends PlayerCtor>(Base: TBase): TBase;
|
|
13
27
|
/**
|
|
14
|
-
*
|
|
28
|
+
* Type helper to extract the interface from the WithSkillManager mixin
|
|
29
|
+
* This provides the type without duplicating method signatures
|
|
15
30
|
*/
|
|
16
|
-
export
|
|
17
|
-
getSkill(skillClass: any | string): any;
|
|
18
|
-
learnSkill(skillId: any | string): any;
|
|
19
|
-
forgetSkill(skillId: any | string): any;
|
|
20
|
-
useSkill(skillId: any | string, otherPlayer?: RpgPlayer | RpgPlayer[]): any;
|
|
21
|
-
}
|
|
22
|
-
export declare function WithSkillManager<TBase extends Constructor<RpgCommonPlayer & SkillManagerDependencies>>(Base: TBase): Constructor<IWithSkillManager> & TBase;
|
|
23
|
-
export {};
|
|
31
|
+
export type ISkillManager = InstanceType<ReturnType<typeof WithSkillManager>>;
|
|
@@ -1,39 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { WritableArraySignal } from '@signe/reactive';
|
|
3
|
-
import { RpgPlayer } from './Player';
|
|
4
|
-
interface StateManagerDependencies {
|
|
5
|
-
equipments(): any[];
|
|
6
|
-
databaseById(id: string | StateClass): any;
|
|
7
|
-
addState(stateClass: StateClass | string, chance?: number): object | null;
|
|
8
|
-
removeState(stateClass: StateClass | string, chance?: number): void;
|
|
9
|
-
}
|
|
1
|
+
import { PlayerCtor } from '@rpgjs/common';
|
|
10
2
|
/**
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}[];
|
|
18
|
-
statesEfficiency: WritableArraySignal<any[]>;
|
|
19
|
-
applyStates(player: RpgPlayer, states: {
|
|
20
|
-
addStates?: any[];
|
|
21
|
-
removeStates?: any[];
|
|
22
|
-
}): void;
|
|
23
|
-
getState(stateClass: StateClass | string): any;
|
|
24
|
-
addState(stateClass: StateClass | string, chance?: number): object | null;
|
|
25
|
-
removeState(stateClass: StateClass | string, chance?: number): void;
|
|
26
|
-
}
|
|
27
|
-
type StateClass = {
|
|
28
|
-
new (...args: any[]): any;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Move Manager mixin
|
|
3
|
+
* State Manager Mixin
|
|
4
|
+
*
|
|
5
|
+
* Provides state management capabilities to any class. This mixin handles
|
|
6
|
+
* player states (buffs/debuffs), state defense from equipment, and state
|
|
7
|
+
* efficiency modifiers. It manages the complete state system including
|
|
8
|
+
* application, removal, and resistance mechanics.
|
|
32
9
|
*
|
|
33
|
-
*
|
|
10
|
+
* @param Base - The base class to extend with state management
|
|
11
|
+
* @returns Extended class with state management methods
|
|
34
12
|
*
|
|
35
|
-
* @
|
|
36
|
-
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* class MyPlayer extends WithStateManager(BasePlayer) {
|
|
16
|
+
* constructor() {
|
|
17
|
+
* super();
|
|
18
|
+
* // State system is automatically initialized
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* const player = new MyPlayer();
|
|
23
|
+
* player.addState(Paralyze);
|
|
24
|
+
* console.log(player.getState(Paralyze));
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function WithStateManager<TBase extends PlayerCtor>(Base: TBase): TBase;
|
|
28
|
+
/**
|
|
29
|
+
* Type helper to extract the interface from the WithStateManager mixin
|
|
30
|
+
* This provides the type without duplicating method signatures
|
|
37
31
|
*/
|
|
38
|
-
export
|
|
39
|
-
export {};
|
|
32
|
+
export type IStateManager = InstanceType<ReturnType<typeof WithStateManager>>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { PlayerCtor } from '@rpgjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* Variable Manager Mixin
|
|
4
|
+
*
|
|
5
|
+
* Provides variable management capabilities to any class. Variables are key-value
|
|
6
|
+
* pairs that can store any type of data associated with the player, such as
|
|
7
|
+
* quest progress, game flags, inventory state, and custom game data.
|
|
8
|
+
*
|
|
9
|
+
* @param Base - The base class to extend with variable management
|
|
10
|
+
* @returns Extended class with variable management methods
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* class MyPlayer extends WithVariableManager(BasePlayer) {
|
|
15
|
+
* constructor() {
|
|
16
|
+
* super();
|
|
17
|
+
* // Variables are automatically initialized
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* const player = new MyPlayer();
|
|
22
|
+
* player.setVariable('questCompleted', true);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function WithVariableManager<TBase extends PlayerCtor>(Base: TBase): TBase;
|
|
26
|
+
/**
|
|
27
|
+
* Type helper to extract the interface from the WithVariableManager mixin
|
|
28
|
+
* This provides the type without duplicating method signatures
|
|
29
|
+
*/
|
|
30
|
+
export type IVariableManager = InstanceType<ReturnType<typeof WithVariableManager>>;
|
package/dist/RpgServer.d.ts
CHANGED
|
@@ -210,19 +210,242 @@ export interface RpgPlayerHooks {
|
|
|
210
210
|
*/
|
|
211
211
|
canChangeMap?: (player: RpgPlayer, nextMap: RpgClassMap<RpgMap>) => boolean | Promise<boolean>;
|
|
212
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Event hooks interface for handling various event lifecycle methods
|
|
215
|
+
*
|
|
216
|
+
* @interface RpgEventHooks
|
|
217
|
+
* @since 4.0.0
|
|
218
|
+
*/
|
|
213
219
|
export interface RpgEventHooks {
|
|
220
|
+
/**
|
|
221
|
+
* Called as soon as the event is created on the map
|
|
222
|
+
*
|
|
223
|
+
* @param {RpgEvent} event - The event instance being initialized
|
|
224
|
+
* @returns {any}
|
|
225
|
+
* @memberof RpgEventHooks
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* const eventHooks: RpgEventHooks = {
|
|
229
|
+
* onInit(event) {
|
|
230
|
+
* console.log(`Event ${event.name} initialized`)
|
|
231
|
+
* event.graphic('default-sprite')
|
|
232
|
+
* }
|
|
233
|
+
* }
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
214
236
|
onInit?: (event: RpgEvent) => any;
|
|
237
|
+
/**
|
|
238
|
+
* Called when the event collides with a player and the player presses the action key
|
|
239
|
+
*
|
|
240
|
+
* @param {RpgEvent} event - The event being interacted with
|
|
241
|
+
* @param {RpgPlayer} player - The player performing the action
|
|
242
|
+
* @returns {any}
|
|
243
|
+
* @memberof RpgEventHooks
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* const eventHooks: RpgEventHooks = {
|
|
247
|
+
* onAction(event, player) {
|
|
248
|
+
* player.showText('You activated the chest!')
|
|
249
|
+
* player.addItem('POTION', 1)
|
|
250
|
+
* }
|
|
251
|
+
* }
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
215
254
|
onAction?: (event: RpgEvent, player: RpgPlayer) => any;
|
|
255
|
+
/**
|
|
256
|
+
* Called before an event object is created and added to the map
|
|
257
|
+
* Allows modification of event properties before instantiation
|
|
258
|
+
*
|
|
259
|
+
* @param {any} object - The event object data before creation
|
|
260
|
+
* @param {RpgMap} map - The map where the event will be created
|
|
261
|
+
* @returns {any}
|
|
262
|
+
* @memberof RpgEventHooks
|
|
263
|
+
* @example
|
|
264
|
+
* ```ts
|
|
265
|
+
* const eventHooks: RpgEventHooks = {
|
|
266
|
+
* onBeforeCreated(object, map) {
|
|
267
|
+
* // Modify event properties based on map conditions
|
|
268
|
+
* if (map.id === 'dungeon') {
|
|
269
|
+
* object.graphic = 'monster-sprite'
|
|
270
|
+
* }
|
|
271
|
+
* }
|
|
272
|
+
* }
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
216
275
|
onBeforeCreated?: (object: any, map: RpgMap) => any;
|
|
276
|
+
/**
|
|
277
|
+
* Called when a player or another event enters a shape attached to this event
|
|
278
|
+
*
|
|
279
|
+
* @param {RpgEvent} event - The event with the attached shape
|
|
280
|
+
* @param {RpgPlayer} player - The player entering the shape
|
|
281
|
+
* @param {RpgShape} shape - The shape being entered
|
|
282
|
+
* @returns {any}
|
|
283
|
+
* @since 4.1.0
|
|
284
|
+
* @memberof RpgEventHooks
|
|
285
|
+
* @example
|
|
286
|
+
* ```ts
|
|
287
|
+
* const eventHooks: RpgEventHooks = {
|
|
288
|
+
* onDetectInShape(event, player, shape) {
|
|
289
|
+
* console.log(`Player ${player.name} entered detection zone`)
|
|
290
|
+
* player.showText('You are being watched...')
|
|
291
|
+
* }
|
|
292
|
+
* }
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
217
295
|
onDetectInShape?: (event: RpgEvent, player: RpgPlayer, shape: RpgShape) => any;
|
|
296
|
+
/**
|
|
297
|
+
* Called when a player or another event leaves a shape attached to this event
|
|
298
|
+
*
|
|
299
|
+
* @param {RpgEvent} event - The event with the attached shape
|
|
300
|
+
* @param {RpgPlayer} player - The player leaving the shape
|
|
301
|
+
* @param {RpgShape} shape - The shape being left
|
|
302
|
+
* @returns {any}
|
|
303
|
+
* @since 4.1.0
|
|
304
|
+
* @memberof RpgEventHooks
|
|
305
|
+
* @example
|
|
306
|
+
* ```ts
|
|
307
|
+
* const eventHooks: RpgEventHooks = {
|
|
308
|
+
* onDetectOutShape(event, player, shape) {
|
|
309
|
+
* console.log(`Player ${player.name} left detection zone`)
|
|
310
|
+
* player.showText('You escaped the watch...')
|
|
311
|
+
* }
|
|
312
|
+
* }
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
218
315
|
onDetectOutShape?: (event: RpgEvent, player: RpgPlayer, shape: RpgShape) => any;
|
|
316
|
+
/**
|
|
317
|
+
* Called when the event enters a shape on the map
|
|
318
|
+
*
|
|
319
|
+
* @param {RpgEvent} event - The event entering the shape
|
|
320
|
+
* @param {RpgShape} shape - The shape being entered
|
|
321
|
+
* @returns {any}
|
|
322
|
+
* @memberof RpgEventHooks
|
|
323
|
+
* @example
|
|
324
|
+
* ```ts
|
|
325
|
+
* const eventHooks: RpgEventHooks = {
|
|
326
|
+
* onInShape(event, shape) {
|
|
327
|
+
* console.log(`Event entered shape: ${shape.id}`)
|
|
328
|
+
* event.speed = 1 // Slow down in this area
|
|
329
|
+
* }
|
|
330
|
+
* }
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
219
333
|
onInShape?: (event: RpgEvent, shape: RpgShape) => any;
|
|
334
|
+
/**
|
|
335
|
+
* Called when the event leaves a shape on the map
|
|
336
|
+
*
|
|
337
|
+
* @param {RpgEvent} event - The event leaving the shape
|
|
338
|
+
* @param {RpgShape} shape - The shape being left
|
|
339
|
+
* @returns {any}
|
|
340
|
+
* @memberof RpgEventHooks
|
|
341
|
+
* @example
|
|
342
|
+
* ```ts
|
|
343
|
+
* const eventHooks: RpgEventHooks = {
|
|
344
|
+
* onOutShape(event, shape) {
|
|
345
|
+
* console.log(`Event left shape: ${shape.id}`)
|
|
346
|
+
* event.speed = 3 // Resume normal speed
|
|
347
|
+
* }
|
|
348
|
+
* }
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
220
351
|
onOutShape?: (event: RpgEvent, shape: RpgShape) => any;
|
|
352
|
+
/**
|
|
353
|
+
* Called when the event collides with a player (without requiring action key press)
|
|
354
|
+
*
|
|
355
|
+
* @param {RpgEvent} event - The event touching the player
|
|
356
|
+
* @param {RpgPlayer} player - The player being touched
|
|
357
|
+
* @returns {any}
|
|
358
|
+
* @memberof RpgEventHooks
|
|
359
|
+
* @example
|
|
360
|
+
* ```ts
|
|
361
|
+
* const eventHooks: RpgEventHooks = {
|
|
362
|
+
* onPlayerTouch(event, player) {
|
|
363
|
+
* player.hp -= 10 // Damage on touch
|
|
364
|
+
* player.showText('Ouch! You touched a spike!')
|
|
365
|
+
* }
|
|
366
|
+
* }
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
221
369
|
onPlayerTouch?: (event: RpgEvent, player: RpgPlayer) => any;
|
|
370
|
+
/**
|
|
371
|
+
* Called whenever any event on the map (including itself) is executed or changes state
|
|
372
|
+
* Useful for creating reactive events that respond to map state changes
|
|
373
|
+
*
|
|
374
|
+
* @param {RpgEvent} event - The event listening for changes
|
|
375
|
+
* @param {RpgPlayer} player - The player involved in the change
|
|
376
|
+
* @returns {any}
|
|
377
|
+
* @memberof RpgEventHooks
|
|
378
|
+
* @example
|
|
379
|
+
* ```ts
|
|
380
|
+
* const eventHooks: RpgEventHooks = {
|
|
381
|
+
* onChanges(event, player) {
|
|
382
|
+
* // Change chest graphic based on game state
|
|
383
|
+
* if (player.getVariable('BATTLE_END')) {
|
|
384
|
+
* event.graphic('chest-open')
|
|
385
|
+
* } else {
|
|
386
|
+
* event.graphic('chest-close')
|
|
387
|
+
* }
|
|
388
|
+
* }
|
|
389
|
+
* }
|
|
390
|
+
* ```
|
|
391
|
+
*/
|
|
222
392
|
onChanges?: (event: RpgEvent, player: RpgPlayer) => any;
|
|
223
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* Map hooks interface for handling map lifecycle events
|
|
396
|
+
*
|
|
397
|
+
* @interface RpgMapHooks
|
|
398
|
+
* @since 4.0.0
|
|
399
|
+
*/
|
|
224
400
|
export interface RpgMapHooks {
|
|
225
|
-
|
|
401
|
+
/**
|
|
402
|
+
* Called before a map is updated with new data
|
|
403
|
+
* Allows modification of map data before the update is applied
|
|
404
|
+
*
|
|
405
|
+
* The `mapData` parameter contains the loaded map data (retrieved from request body)
|
|
406
|
+
* You can modify the map before the update is processed
|
|
407
|
+
*
|
|
408
|
+
* @template T - Type of the incoming map data
|
|
409
|
+
* @template U - Type of the map instance (defaults to RpgMap)
|
|
410
|
+
* @param {T} mapData - The map data loaded from external source (e.g., request body)
|
|
411
|
+
* @param {U} map - The current map instance being updated
|
|
412
|
+
* @returns {U | Promise<U>} The modified map instance or a promise resolving to it
|
|
413
|
+
* @memberof RpgMapHooks
|
|
414
|
+
* @example
|
|
415
|
+
* ```ts
|
|
416
|
+
* const mapHooks: RpgMapHooks = {
|
|
417
|
+
* onBeforeUpdate(mapData, map) {
|
|
418
|
+
* // Modify map properties based on incoming data
|
|
419
|
+
* if (mapData.weather === 'rain') {
|
|
420
|
+
* map.setWeatherEffect('rain')
|
|
421
|
+
* }
|
|
422
|
+
*
|
|
423
|
+
* // Add custom properties from external data
|
|
424
|
+
* map.customProperty = mapData.customValue
|
|
425
|
+
*
|
|
426
|
+
* return map
|
|
427
|
+
* }
|
|
428
|
+
* }
|
|
429
|
+
* ```
|
|
430
|
+
*
|
|
431
|
+
* @example
|
|
432
|
+
* ```ts
|
|
433
|
+
* // Async example with database operations
|
|
434
|
+
* const mapHooks: RpgMapHooks = {
|
|
435
|
+
* async onBeforeUpdate(mapData, map) {
|
|
436
|
+
* // Load additional data from database
|
|
437
|
+
* const additionalData = await database.getMapExtras(map.id)
|
|
438
|
+
*
|
|
439
|
+
* // Apply modifications
|
|
440
|
+
* map.events = [...map.events, ...additionalData.events]
|
|
441
|
+
* map.npcs = additionalData.npcs
|
|
442
|
+
*
|
|
443
|
+
* return map
|
|
444
|
+
* }
|
|
445
|
+
* }
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
onBeforeUpdate<T, U = RpgMap>(mapData: T, map: U): U | Promise<U>;
|
|
226
449
|
}
|
|
227
450
|
export interface RpgServer {
|
|
228
451
|
/**
|
|
@@ -492,5 +715,8 @@ export interface RpgServer {
|
|
|
492
715
|
doChangeServer(store: IStoreState, matchMaker: RpgMatchMaker, player: RpgPlayer): Promise<boolean> | boolean;
|
|
493
716
|
};
|
|
494
717
|
};
|
|
718
|
+
throttleSync?: number;
|
|
719
|
+
throttleStorage?: number;
|
|
720
|
+
sessionExpiryTime?: number;
|
|
495
721
|
}
|
|
496
722
|
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;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
export interface MapOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Map identifier. Allows to go to the map (for example with player.changeMap())
|
|
4
|
+
*
|
|
5
|
+
* @prop {string} [id]
|
|
6
|
+
* @memberof MapData
|
|
7
|
+
* */
|
|
8
|
+
id?: string;
|
|
9
|
+
/**
|
|
10
|
+
* the path to the .tmx file (Tiled Map Editor)
|
|
11
|
+
*
|
|
12
|
+
* Remember to use `require()` function
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { MapData, RpgMap } from '@rpgjs/server'
|
|
16
|
+
*
|
|
17
|
+
* @MapData({
|
|
18
|
+
* id: 'town',
|
|
19
|
+
* file: require('./tmx/town.tmx')
|
|
20
|
+
* })
|
|
21
|
+
* class TownMap extends RpgMap { }
|
|
22
|
+
* ```
|
|
23
|
+
* @prop {string} file
|
|
24
|
+
* @memberof MapData
|
|
25
|
+
* */
|
|
26
|
+
file: any;
|
|
27
|
+
/**
|
|
28
|
+
* The name of the map.
|
|
29
|
+
* @prop {string} [name]
|
|
30
|
+
* @memberof MapData
|
|
31
|
+
* */
|
|
32
|
+
name?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Map events. This is an array containing `RpgEvent` classes.
|
|
35
|
+
* You can also give an object that will indicate the positions of the event on the map.
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { MapData, RpgMap, EventData, RpgEvent } from '@rpgjs/server'
|
|
39
|
+
*
|
|
40
|
+
* @EventData({
|
|
41
|
+
* name: 'Ev-1'
|
|
42
|
+
* })
|
|
43
|
+
* class NpcEvent extends RpgEvent { }
|
|
44
|
+
*
|
|
45
|
+
* @MapData({
|
|
46
|
+
* id: 'medieval',
|
|
47
|
+
* file: require('./tmx/town.tmx'),
|
|
48
|
+
* events: [NpcEvent]
|
|
49
|
+
* })
|
|
50
|
+
* class TownMap extends RpgMap {}
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* If the positions are not defined, the event will be placed on a Tiled Map Editor shape ([/guide/create-event.html#position-the-event-on-the-map](Guide)). Otherwise, it will be placed at `{x:0, y:0 }`
|
|
54
|
+
*
|
|
55
|
+
* You can give positions:
|
|
56
|
+
*
|
|
57
|
+
* ```ts
|
|
58
|
+
* events: [{ event: NpcEvent, x: 10, y: 30 }]
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @prop {Class of RpgEvent[] | { event: Class RpgEvent, x: number, y: number }} [events]
|
|
62
|
+
* @memberof MapData
|
|
63
|
+
* */
|
|
64
|
+
events?: {
|
|
65
|
+
event: any;
|
|
66
|
+
x: number;
|
|
67
|
+
y: number;
|
|
68
|
+
}[] | any[];
|
|
69
|
+
/**
|
|
70
|
+
* The sounds that will be played when the map is open. Sounds must be defined on the client side. Then, put the name of the sound identifier
|
|
71
|
+
*
|
|
72
|
+
* So, it is possible to play several sounds (in loop or not) on the card. You can put a background music (BGM) and a background noise (BGS) for example
|
|
73
|
+
*
|
|
74
|
+
* ```ts
|
|
75
|
+
* sounds: ['my-bgm', 'my-bgs']
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* And client side:
|
|
79
|
+
*
|
|
80
|
+
* ```ts
|
|
81
|
+
* import { Sound } from '@rpgjs/client'
|
|
82
|
+
*
|
|
83
|
+
* @Sound({
|
|
84
|
+
* sounds: {
|
|
85
|
+
* 'my-bgm': require('./assets/bgm.ogg'),
|
|
86
|
+
* 'my-bgs': require('./assets/bgs.ogg')
|
|
87
|
+
* },
|
|
88
|
+
* loop: true
|
|
89
|
+
* })
|
|
90
|
+
* export class Sounds {}
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* See [https://docs.rpgjs.dev/classes/sound.html#properties](RpgSound Decorator)
|
|
94
|
+
*
|
|
95
|
+
* @prop {Array<string>} [sounds]
|
|
96
|
+
* @memberof MapData
|
|
97
|
+
* */
|
|
98
|
+
sounds?: string[];
|
|
99
|
+
/**
|
|
100
|
+
* Specify which properties will be synchronized with the client. On the client side, you can retrieve the values synchronized with the valueChanges property on the scene
|
|
101
|
+
*
|
|
102
|
+
* You must create the schema:
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { MapData, RpgMap } from '@rpgjs/server'
|
|
106
|
+
*
|
|
107
|
+
* @MapData({
|
|
108
|
+
* id: 'medieval',
|
|
109
|
+
* file: require('./tmx/town.tmx'),
|
|
110
|
+
* syncSchema: {
|
|
111
|
+
* count: Number
|
|
112
|
+
* }
|
|
113
|
+
* })
|
|
114
|
+
* export class TownMap extends RpgMap {
|
|
115
|
+
* count: number = 0
|
|
116
|
+
*
|
|
117
|
+
* onLoad() {}
|
|
118
|
+
*
|
|
119
|
+
* onJoin() {
|
|
120
|
+
* this.count++
|
|
121
|
+
* }
|
|
122
|
+
*
|
|
123
|
+
* onLeave(player) {
|
|
124
|
+
* super.onLeave(player)
|
|
125
|
+
* this.count--
|
|
126
|
+
* }
|
|
127
|
+
* }
|
|
128
|
+
*
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* If you want to change the scheme of players and events, consider overwriting the existing scheme
|
|
132
|
+
*
|
|
133
|
+
* ```ts
|
|
134
|
+
* import { MapData, RpgMap, RpgPlayer } from '@rpgjs/server'
|
|
135
|
+
*
|
|
136
|
+
*
|
|
137
|
+
* declare module '@rpgjs/server' {
|
|
138
|
+
* export interface RpgPlayer {
|
|
139
|
+
* customProp: string
|
|
140
|
+
* }
|
|
141
|
+
* }
|
|
142
|
+
*
|
|
143
|
+
* @MapData({
|
|
144
|
+
* id: 'medieval',
|
|
145
|
+
* file: require('./tmx/town.tmx'),
|
|
146
|
+
* syncSchema: {
|
|
147
|
+
* users: [
|
|
148
|
+
* {
|
|
149
|
+
* customProp: String,
|
|
150
|
+
* ...RpgPlayer.schemas
|
|
151
|
+
* }
|
|
152
|
+
* ]
|
|
153
|
+
* }
|
|
154
|
+
* })
|
|
155
|
+
* export class TownMap extends RpgMap {}
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* The properties are called `users` and `events`. Their scheme is identical and defined in `RpgPlayer.schemas`. To write schematics, refer to the [documentation of the simple-room](https://github.com/RSamaium/simple-room) module
|
|
159
|
+
*
|
|
160
|
+
* @prop {object} [syncSchema]
|
|
161
|
+
* @memberof MapData
|
|
162
|
+
* */
|
|
163
|
+
syncSchema?: any;
|
|
164
|
+
/**
|
|
165
|
+
* Decreases the RAM of the map. In this case, some instructions will be different.
|
|
166
|
+
*
|
|
167
|
+
* `map.getTileByIndex()` will not return all tiles of an index but only the tile of the highest layer
|
|
168
|
+
*
|
|
169
|
+
* > You can also use the `low-memory` property in Tiled maps
|
|
170
|
+
*
|
|
171
|
+
* @prop {boolean} [lowMemory=false]
|
|
172
|
+
* @since 3.1.0
|
|
173
|
+
* @memberof MapData
|
|
174
|
+
* */
|
|
175
|
+
lowMemory?: boolean;
|
|
176
|
+
}
|
|
177
|
+
export declare function MapData(options: MapOptions): (target: any) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,12 @@ export * from './RpgServer';
|
|
|
4
4
|
export * from './core/setup';
|
|
5
5
|
export * from './core/inject';
|
|
6
6
|
export * from './Player/Player';
|
|
7
|
+
export * from './Player/Components';
|
|
7
8
|
export * from './module';
|
|
8
9
|
export * from './rooms/map';
|
|
9
10
|
export * from './presets';
|
|
11
|
+
export * from '@signe/reactive';
|
|
12
|
+
export * from './Gui';
|
|
13
|
+
export { RpgShape, RpgModule } from '@rpgjs/common';
|
|
14
|
+
export * from './decorators/event';
|
|
15
|
+
export * from './decorators/map';
|