@rpgjs/server 5.0.0-alpha.7 → 5.0.0-alpha.8

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.
@@ -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
- onBeforeUpdate<T = RpgMap>(mapData: any, map: T): T;
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
  /**
package/dist/index.js CHANGED
@@ -29791,6 +29791,7 @@ class RpgEvent extends RpgPlayer {
29791
29791
  }
29792
29792
 
29793
29793
  const context$1 = new Context();
29794
+ context$1["side"] = "server";
29794
29795
 
29795
29796
  var __defProp$1 = Object.defineProperty;
29796
29797
  var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;