@rpgjs/server 5.0.0-alpha.0 → 5.0.0-alpha.10

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 (40) hide show
  1. package/dist/Player/BattleManager.d.ts +32 -22
  2. package/dist/Player/ClassManager.d.ts +31 -18
  3. package/dist/Player/ComponentManager.d.ts +60 -0
  4. package/dist/Player/EffectManager.d.ts +40 -0
  5. package/dist/Player/ElementManager.d.ts +31 -0
  6. package/dist/Player/GoldManager.d.ts +22 -0
  7. package/dist/Player/GuiManager.d.ts +176 -0
  8. package/dist/Player/ItemFixture.d.ts +6 -0
  9. package/dist/Player/ItemManager.d.ts +27 -13
  10. package/dist/Player/MoveManager.d.ts +31 -43
  11. package/dist/Player/ParameterManager.d.ts +27 -19
  12. package/dist/Player/Player.d.ts +123 -8
  13. package/dist/Player/SkillManager.d.ts +27 -19
  14. package/dist/Player/StateManager.d.ts +28 -35
  15. package/dist/Player/VariableManager.d.ts +30 -0
  16. package/dist/RpgServer.d.ts +224 -1
  17. package/dist/index.js +1097 -636
  18. package/dist/index.js.map +1 -1
  19. package/dist/rooms/map.d.ts +70 -1
  20. package/package.json +8 -8
  21. package/src/Player/BattleManager.ts +97 -38
  22. package/src/Player/ClassManager.ts +95 -35
  23. package/src/Player/ComponentManager.ts +64 -20
  24. package/src/Player/EffectManager.ts +110 -27
  25. package/src/Player/ElementManager.ts +126 -25
  26. package/src/Player/GoldManager.ts +32 -35
  27. package/src/Player/GuiManager.ts +187 -140
  28. package/src/Player/ItemFixture.ts +4 -5
  29. package/src/Player/ItemManager.ts +39 -26
  30. package/src/Player/MoveManager.ts +40 -31
  31. package/src/Player/ParameterManager.ts +35 -25
  32. package/src/Player/Player.ts +184 -39
  33. package/src/Player/SkillManager.ts +44 -23
  34. package/src/Player/StateManager.ts +210 -95
  35. package/src/Player/VariableManager.ts +180 -48
  36. package/src/RpgServer.ts +232 -1
  37. package/src/core/context.ts +1 -0
  38. package/src/rooms/map.ts +76 -8
  39. package/dist/Player/Event.d.ts +0 -0
  40. package/src/Player/Event.ts +0 -0
package/src/RpgServer.ts CHANGED
@@ -227,20 +227,251 @@ export interface RpgPlayerHooks {
227
227
  canChangeMap?: (player: RpgPlayer, nextMap: RpgClassMap<RpgMap>) => boolean | Promise<boolean>
228
228
  }
229
229
 
230
+ /**
231
+ * Event hooks interface for handling various event lifecycle methods
232
+ *
233
+ * @interface RpgEventHooks
234
+ * @since 4.0.0
235
+ */
230
236
  export interface RpgEventHooks {
237
+ /**
238
+ * Called as soon as the event is created on the map
239
+ *
240
+ * @param {RpgEvent} event - The event instance being initialized
241
+ * @returns {any}
242
+ * @memberof RpgEventHooks
243
+ * @example
244
+ * ```ts
245
+ * const eventHooks: RpgEventHooks = {
246
+ * onInit(event) {
247
+ * console.log(`Event ${event.name} initialized`)
248
+ * event.graphic('default-sprite')
249
+ * }
250
+ * }
251
+ * ```
252
+ */
231
253
  onInit?: (event: RpgEvent) => any,
254
+
255
+ /**
256
+ * Called when the event collides with a player and the player presses the action key
257
+ *
258
+ * @param {RpgEvent} event - The event being interacted with
259
+ * @param {RpgPlayer} player - The player performing the action
260
+ * @returns {any}
261
+ * @memberof RpgEventHooks
262
+ * @example
263
+ * ```ts
264
+ * const eventHooks: RpgEventHooks = {
265
+ * onAction(event, player) {
266
+ * player.showText('You activated the chest!')
267
+ * player.addItem('POTION', 1)
268
+ * }
269
+ * }
270
+ * ```
271
+ */
232
272
  onAction?: (event: RpgEvent, player: RpgPlayer) => any
273
+
274
+ /**
275
+ * Called before an event object is created and added to the map
276
+ * Allows modification of event properties before instantiation
277
+ *
278
+ * @param {any} object - The event object data before creation
279
+ * @param {RpgMap} map - The map where the event will be created
280
+ * @returns {any}
281
+ * @memberof RpgEventHooks
282
+ * @example
283
+ * ```ts
284
+ * const eventHooks: RpgEventHooks = {
285
+ * onBeforeCreated(object, map) {
286
+ * // Modify event properties based on map conditions
287
+ * if (map.id === 'dungeon') {
288
+ * object.graphic = 'monster-sprite'
289
+ * }
290
+ * }
291
+ * }
292
+ * ```
293
+ */
233
294
  onBeforeCreated?: (object: any, map: RpgMap) => any
295
+
296
+ /**
297
+ * Called when a player or another event enters a shape attached to this event
298
+ *
299
+ * @param {RpgEvent} event - The event with the attached shape
300
+ * @param {RpgPlayer} player - The player entering the shape
301
+ * @param {RpgShape} shape - The shape being entered
302
+ * @returns {any}
303
+ * @since 4.1.0
304
+ * @memberof RpgEventHooks
305
+ * @example
306
+ * ```ts
307
+ * const eventHooks: RpgEventHooks = {
308
+ * onDetectInShape(event, player, shape) {
309
+ * console.log(`Player ${player.name} entered detection zone`)
310
+ * player.showText('You are being watched...')
311
+ * }
312
+ * }
313
+ * ```
314
+ */
234
315
  onDetectInShape?: (event: RpgEvent, player: RpgPlayer, shape: RpgShape) => any
316
+
317
+ /**
318
+ * Called when a player or another event leaves a shape attached to this event
319
+ *
320
+ * @param {RpgEvent} event - The event with the attached shape
321
+ * @param {RpgPlayer} player - The player leaving the shape
322
+ * @param {RpgShape} shape - The shape being left
323
+ * @returns {any}
324
+ * @since 4.1.0
325
+ * @memberof RpgEventHooks
326
+ * @example
327
+ * ```ts
328
+ * const eventHooks: RpgEventHooks = {
329
+ * onDetectOutShape(event, player, shape) {
330
+ * console.log(`Player ${player.name} left detection zone`)
331
+ * player.showText('You escaped the watch...')
332
+ * }
333
+ * }
334
+ * ```
335
+ */
235
336
  onDetectOutShape?: (event: RpgEvent, player: RpgPlayer, shape: RpgShape) => any
337
+
338
+ /**
339
+ * Called when the event enters a shape on the map
340
+ *
341
+ * @param {RpgEvent} event - The event entering the shape
342
+ * @param {RpgShape} shape - The shape being entered
343
+ * @returns {any}
344
+ * @memberof RpgEventHooks
345
+ * @example
346
+ * ```ts
347
+ * const eventHooks: RpgEventHooks = {
348
+ * onInShape(event, shape) {
349
+ * console.log(`Event entered shape: ${shape.id}`)
350
+ * event.speed = 1 // Slow down in this area
351
+ * }
352
+ * }
353
+ * ```
354
+ */
236
355
  onInShape?: (event: RpgEvent, shape: RpgShape) => any
356
+
357
+ /**
358
+ * Called when the event leaves a shape on the map
359
+ *
360
+ * @param {RpgEvent} event - The event leaving the shape
361
+ * @param {RpgShape} shape - The shape being left
362
+ * @returns {any}
363
+ * @memberof RpgEventHooks
364
+ * @example
365
+ * ```ts
366
+ * const eventHooks: RpgEventHooks = {
367
+ * onOutShape(event, shape) {
368
+ * console.log(`Event left shape: ${shape.id}`)
369
+ * event.speed = 3 // Resume normal speed
370
+ * }
371
+ * }
372
+ * ```
373
+ */
237
374
  onOutShape?: (event: RpgEvent, shape: RpgShape) => any
375
+
376
+ /**
377
+ * Called when the event collides with a player (without requiring action key press)
378
+ *
379
+ * @param {RpgEvent} event - The event touching the player
380
+ * @param {RpgPlayer} player - The player being touched
381
+ * @returns {any}
382
+ * @memberof RpgEventHooks
383
+ * @example
384
+ * ```ts
385
+ * const eventHooks: RpgEventHooks = {
386
+ * onPlayerTouch(event, player) {
387
+ * player.hp -= 10 // Damage on touch
388
+ * player.showText('Ouch! You touched a spike!')
389
+ * }
390
+ * }
391
+ * ```
392
+ */
238
393
  onPlayerTouch?: (event: RpgEvent, player: RpgPlayer) => any
394
+
395
+ /**
396
+ * Called whenever any event on the map (including itself) is executed or changes state
397
+ * Useful for creating reactive events that respond to map state changes
398
+ *
399
+ * @param {RpgEvent} event - The event listening for changes
400
+ * @param {RpgPlayer} player - The player involved in the change
401
+ * @returns {any}
402
+ * @memberof RpgEventHooks
403
+ * @example
404
+ * ```ts
405
+ * const eventHooks: RpgEventHooks = {
406
+ * onChanges(event, player) {
407
+ * // Change chest graphic based on game state
408
+ * if (player.getVariable('BATTLE_END')) {
409
+ * event.graphic('chest-open')
410
+ * } else {
411
+ * event.graphic('chest-close')
412
+ * }
413
+ * }
414
+ * }
415
+ * ```
416
+ */
239
417
  onChanges?: (event: RpgEvent, player: RpgPlayer) => any
240
418
  }
241
419
 
420
+ /**
421
+ * Map hooks interface for handling map lifecycle events
422
+ *
423
+ * @interface RpgMapHooks
424
+ * @since 4.0.0
425
+ */
242
426
  export interface RpgMapHooks {
243
- onBeforeUpdate<T = RpgMap>(mapData: any, map: T): T
427
+ /**
428
+ * Called before a map is updated with new data
429
+ * Allows modification of map data before the update is applied
430
+ *
431
+ * The `mapData` parameter contains the loaded map data (retrieved from request body)
432
+ * You can modify the map before the update is processed
433
+ *
434
+ * @template T - Type of the incoming map data
435
+ * @template U - Type of the map instance (defaults to RpgMap)
436
+ * @param {T} mapData - The map data loaded from external source (e.g., request body)
437
+ * @param {U} map - The current map instance being updated
438
+ * @returns {U | Promise<U>} The modified map instance or a promise resolving to it
439
+ * @memberof RpgMapHooks
440
+ * @example
441
+ * ```ts
442
+ * const mapHooks: RpgMapHooks = {
443
+ * onBeforeUpdate(mapData, map) {
444
+ * // Modify map properties based on incoming data
445
+ * if (mapData.weather === 'rain') {
446
+ * map.setWeatherEffect('rain')
447
+ * }
448
+ *
449
+ * // Add custom properties from external data
450
+ * map.customProperty = mapData.customValue
451
+ *
452
+ * return map
453
+ * }
454
+ * }
455
+ * ```
456
+ *
457
+ * @example
458
+ * ```ts
459
+ * // Async example with database operations
460
+ * const mapHooks: RpgMapHooks = {
461
+ * async onBeforeUpdate(mapData, map) {
462
+ * // Load additional data from database
463
+ * const additionalData = await database.getMapExtras(map.id)
464
+ *
465
+ * // Apply modifications
466
+ * map.events = [...map.events, ...additionalData.events]
467
+ * map.npcs = additionalData.npcs
468
+ *
469
+ * return map
470
+ * }
471
+ * }
472
+ * ```
473
+ */
474
+ onBeforeUpdate<T, U = RpgMap>(mapData: T, map: U): U | Promise<U>
244
475
  }
245
476
 
246
477
  export interface RpgServer {
@@ -1,3 +1,4 @@
1
1
  import { Context } from "@signe/di";
2
2
 
3
3
  export const context = new Context();
4
+ context['side'] = 'server'
package/src/rooms/map.ts CHANGED
@@ -220,6 +220,7 @@ export class RpgMap extends RpgCommonMap<RpgPlayer> implements RoomOnJoin {
220
220
  })
221
221
 
222
222
  const { x, y, event } = eventObj;
223
+
223
224
  let id = eventObj.id || generateShortUUID()
224
225
  let eventInstance: RpgPlayer;
225
226
 
@@ -291,16 +292,83 @@ export class RpgMap extends RpgCommonMap<RpgPlayer> implements RoomOnJoin {
291
292
  delete this.events()[eventId]
292
293
  }
293
294
 
294
- showAnimation(animationName: string, object: RpgPlayer) {
295
+ /**
296
+ * Display a component animation at a specific position on the map
297
+ *
298
+ * This method broadcasts a component animation to all clients connected to the map,
299
+ * allowing temporary visual effects to be displayed at any location on the map.
300
+ * Component animations are custom Canvas Engine components that can display
301
+ * complex effects with custom logic and parameters.
302
+ *
303
+ * @param id - The ID of the component animation to display
304
+ * @param position - The x, y coordinates where to display the animation
305
+ * @param params - Parameters to pass to the component animation
306
+ *
307
+ * @example
308
+ * ```ts
309
+ * // Show explosion at specific coordinates
310
+ * map.showComponentAnimation("explosion", { x: 300, y: 400 }, {
311
+ * intensity: 2.5,
312
+ * duration: 1500
313
+ * });
314
+ *
315
+ * // Show area damage effect
316
+ * map.showComponentAnimation("area-damage", { x: player.x, y: player.y }, {
317
+ * radius: 100,
318
+ * color: "red",
319
+ * damage: 50
320
+ * });
321
+ *
322
+ * // Show treasure spawn effect
323
+ * map.showComponentAnimation("treasure-spawn", { x: 150, y: 200 }, {
324
+ * sparkle: true,
325
+ * sound: "treasure-appear"
326
+ * });
327
+ * ```
328
+ */
329
+ showComponentAnimation(id: string, position: { x: number, y: number }, params: any) {
295
330
  this.$broadcast({
296
- type: 'showEffect',
331
+ type: "showComponentAnimation",
297
332
  value: {
298
- id: 'animation',
299
- params: {
300
- name: animationName
301
- },
302
- object: object.id
303
- }
333
+ id,
334
+ params,
335
+ position,
336
+ },
337
+ });
338
+ }
339
+
340
+ /**
341
+ * Display a spritesheet animation at a specific position on the map
342
+ *
343
+ * This method displays a temporary visual animation using a spritesheet at any
344
+ * location on the map. It's a convenience method that internally uses showComponentAnimation
345
+ * with the built-in 'animation' component. This is useful for spell effects, environmental
346
+ * animations, or any visual feedback that uses predefined spritesheets.
347
+ *
348
+ * @param position - The x, y coordinates where to display the animation
349
+ * @param graphic - The ID of the spritesheet to use for the animation
350
+ * @param animationName - The name of the animation within the spritesheet (default: 'default')
351
+ *
352
+ * @example
353
+ * ```ts
354
+ * // Show explosion at specific coordinates
355
+ * map.showAnimation({ x: 100, y: 200 }, "explosion");
356
+ *
357
+ * // Show spell effect at player position
358
+ * const playerPos = { x: player.x, y: player.y };
359
+ * map.showAnimation(playerPos, "spell-effects", "lightning");
360
+ *
361
+ * // Show environmental effect
362
+ * map.showAnimation({ x: 300, y: 150 }, "nature-effects", "wind-gust");
363
+ *
364
+ * // Show portal opening animation
365
+ * map.showAnimation({ x: 500, y: 400 }, "portals", "opening");
366
+ * ```
367
+ */
368
+ showAnimation(position: { x: number, y: number }, graphic: string, animationName: string = 'default') {
369
+ this.showComponentAnimation('animation', position, {
370
+ graphic,
371
+ animationName,
304
372
  })
305
373
  }
306
374
  }
File without changes
File without changes