@rpgjs/server 4.0.0-beta.9 → 4.0.0-rc.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.
- package/CHANGELOG.md +32 -0
- package/lib/Game/EventManager.d.ts +53 -0
- package/lib/Game/EventManager.js +93 -0
- package/lib/Game/EventManager.js.map +1 -0
- package/lib/Game/Map.d.ts +6 -30
- package/lib/Game/Map.js +26 -61
- package/lib/Game/Map.js.map +1 -1
- package/lib/Gui/MenuGui.js +2 -2
- package/lib/Gui/MenuGui.js.map +1 -1
- package/lib/Player/BattleManager.d.ts +5 -5
- package/lib/Player/BattleManager.js +8 -7
- package/lib/Player/BattleManager.js.map +1 -1
- package/lib/Player/ClassManager.d.ts +11 -4
- package/lib/Player/ClassManager.js +7 -3
- package/lib/Player/ClassManager.js.map +1 -1
- package/lib/Player/EffectManager.d.ts +2 -2
- package/lib/Player/EffectManager.js +6 -6
- package/lib/Player/EffectManager.js.map +1 -1
- package/lib/Player/ElementManager.d.ts +4 -1
- package/lib/Player/ElementManager.js.map +1 -1
- package/lib/Player/ItemManager.d.ts +21 -0
- package/lib/Player/ItemManager.js +22 -1
- package/lib/Player/ItemManager.js.map +1 -1
- package/lib/Player/MoveManager.js +27 -14
- package/lib/Player/MoveManager.js.map +1 -1
- package/lib/Player/ParameterManager.d.ts +2 -1
- package/lib/Player/ParameterManager.js +15 -4
- package/lib/Player/ParameterManager.js.map +1 -1
- package/lib/Player/Player.d.ts +150 -54
- package/lib/Player/Player.js +142 -58
- package/lib/Player/Player.js.map +1 -1
- package/lib/Player/SkillManager.d.ts +13 -8
- package/lib/Player/SkillManager.js +14 -12
- package/lib/Player/SkillManager.js.map +1 -1
- package/lib/Player/StateManager.d.ts +11 -6
- package/lib/Player/StateManager.js +21 -6
- package/lib/Player/StateManager.js.map +1 -1
- package/lib/RpgServer.d.ts +42 -2
- package/lib/Scenes/Map.d.ts +3 -0
- package/lib/Scenes/Map.js +4 -0
- package/lib/Scenes/Map.js.map +1 -1
- package/lib/decorators/event.d.ts +1 -1
- package/lib/decorators/event.js +2 -1
- package/lib/decorators/event.js.map +1 -1
- package/lib/decorators/map.d.ts +5 -2
- package/lib/decorators/map.js.map +1 -1
- package/lib/express/server.js +5 -1
- package/lib/express/server.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/models/Item.d.ts +1 -1
- package/lib/server.d.ts +3 -6
- package/lib/server.js +9 -8
- package/lib/server.js.map +1 -1
- package/package.json +8 -7
- package/src/Game/EventManager.ts +110 -0
- package/src/Game/Map.ts +37 -69
- package/src/Gui/MenuGui.ts +3 -3
- package/src/Player/BattleManager.ts +10 -9
- package/src/Player/ClassManager.ts +13 -7
- package/src/Player/EffectManager.ts +6 -5
- package/src/Player/ElementManager.ts +4 -1
- package/src/Player/ItemManager.ts +47 -26
- package/src/Player/MoveManager.ts +35 -15
- package/src/Player/ParameterManager.ts +19 -8
- package/src/Player/Player.ts +170 -57
- package/src/Player/SkillManager.ts +23 -21
- package/src/Player/StateManager.ts +30 -11
- package/src/RpgServer.ts +42 -2
- package/src/Scenes/Map.ts +4 -0
- package/src/decorators/event.ts +2 -1
- package/src/decorators/map.ts +5 -2
- package/src/express/server.ts +9 -3
- package/src/index.ts +10 -8
- package/src/models/Item.ts +1 -1
- package/src/server.ts +11 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Direction, LiteralDirection, RpgShape, Vector2d } from '@rpgjs/common'
|
|
2
2
|
import { Utils } from '@rpgjs/common'
|
|
3
3
|
import { Behavior, ClientMode, MoveMode, MoveTo, PositionXY, SocketEvents, SocketMethods, Tick } from '@rpgjs/types'
|
|
4
|
-
import { Observable, Subscription, takeUntil, Subject } from 'rxjs'
|
|
4
|
+
import { Observable, Subscription, takeUntil, Subject, tap, switchMap, of, from, debounceTime } from 'rxjs'
|
|
5
5
|
import { RpgServerEngine } from '../server'
|
|
6
6
|
import { RpgEvent, RpgPlayer } from './Player'
|
|
7
7
|
|
|
@@ -444,20 +444,28 @@ export class MoveManager {
|
|
|
444
444
|
this._finishRoute = resolve
|
|
445
445
|
routes = routes.map((route: any) => {
|
|
446
446
|
if (isFunction(route)) {
|
|
447
|
-
|
|
447
|
+
const map = this.getCurrentMap()
|
|
448
|
+
if (!map) {
|
|
449
|
+
return undefined
|
|
450
|
+
}
|
|
451
|
+
return route.apply(route, [this, map])
|
|
448
452
|
}
|
|
449
453
|
return route
|
|
450
454
|
})
|
|
451
455
|
routes = arrayFlat(routes)
|
|
452
|
-
const move = () => {
|
|
456
|
+
const move = (): Observable<any> => {
|
|
453
457
|
// If movement continues while the player no longer exists or is no longer on the map
|
|
454
458
|
if (!this) {
|
|
455
|
-
return
|
|
459
|
+
return of(null)
|
|
460
|
+
}
|
|
461
|
+
// if map not exists
|
|
462
|
+
if (!this.getCurrentMap()) {
|
|
463
|
+
return of(null)
|
|
456
464
|
}
|
|
457
465
|
if (count >= this['nbPixelInTile']) {
|
|
458
466
|
if (frequence < this.frequency) {
|
|
459
467
|
frequence++
|
|
460
|
-
return
|
|
468
|
+
return of(null)
|
|
461
469
|
}
|
|
462
470
|
}
|
|
463
471
|
|
|
@@ -468,37 +476,49 @@ export class MoveManager {
|
|
|
468
476
|
|
|
469
477
|
if (route === undefined) {
|
|
470
478
|
this.breakRoutes()
|
|
471
|
-
return
|
|
479
|
+
return of(null)
|
|
472
480
|
}
|
|
473
481
|
|
|
482
|
+
let ob$ = new Observable()
|
|
483
|
+
|
|
474
484
|
switch (route) {
|
|
475
485
|
case Direction.Left:
|
|
476
486
|
case Direction.Down:
|
|
477
487
|
case Direction.Right:
|
|
478
488
|
case Direction.Up:
|
|
479
|
-
this.moveByDirection(route, 1)
|
|
489
|
+
ob$ = from(this.moveByDirection(route, 1))
|
|
480
490
|
break
|
|
481
491
|
case 'turn-' + Direction.Left:
|
|
482
|
-
this.changeDirection(Direction.Left)
|
|
492
|
+
ob$ = of(this.changeDirection(Direction.Left))
|
|
483
493
|
break
|
|
484
494
|
case 'turn-' + Direction.Right:
|
|
485
|
-
this.changeDirection(Direction.Right)
|
|
495
|
+
ob$ = of(this.changeDirection(Direction.Right))
|
|
486
496
|
break
|
|
487
497
|
case 'turn-' + Direction.Up:
|
|
488
|
-
this.changeDirection(Direction.Up)
|
|
498
|
+
ob$ = of(this.changeDirection(Direction.Up))
|
|
489
499
|
break
|
|
490
500
|
case 'turn-' + Direction.Down:
|
|
491
|
-
this.changeDirection(Direction.Down)
|
|
501
|
+
ob$ = of(this.changeDirection(Direction.Down))
|
|
492
502
|
break
|
|
493
503
|
}
|
|
494
504
|
|
|
495
|
-
|
|
505
|
+
return ob$.pipe(
|
|
506
|
+
tap(() => {
|
|
507
|
+
routes.shift()
|
|
508
|
+
})
|
|
509
|
+
)
|
|
496
510
|
}
|
|
497
511
|
this.movingSubscription = this.server.tick
|
|
498
512
|
.pipe(
|
|
499
|
-
takeUntil(
|
|
513
|
+
takeUntil(
|
|
514
|
+
this._destroy$.pipe(
|
|
515
|
+
tap(() => {
|
|
516
|
+
this.breakRoutes(true)
|
|
517
|
+
})
|
|
518
|
+
)),
|
|
519
|
+
switchMap(move)
|
|
500
520
|
)
|
|
501
|
-
.subscribe(
|
|
521
|
+
.subscribe()
|
|
502
522
|
})
|
|
503
523
|
}
|
|
504
524
|
|
|
@@ -550,7 +570,7 @@ export class MoveManager {
|
|
|
550
570
|
*/
|
|
551
571
|
breakRoutes(force: boolean = false): void {
|
|
552
572
|
if (this._finishRoute) {
|
|
553
|
-
this.movingSubscription
|
|
573
|
+
this.movingSubscription?.unsubscribe()
|
|
554
574
|
this._finishRoute(force)
|
|
555
575
|
}
|
|
556
576
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { Utils } from '@rpgjs/common'
|
|
2
|
-
import { RpgPlayer } from './Player'
|
|
3
|
-
|
|
4
2
|
import {
|
|
5
3
|
MAXHP,
|
|
6
4
|
MAXSP,
|
|
@@ -97,8 +95,8 @@ export class ParameterManager {
|
|
|
97
95
|
if (val > this.param[MAXHP]) {
|
|
98
96
|
val = this.param[MAXHP]
|
|
99
97
|
}
|
|
100
|
-
else if (val <= 0) {
|
|
101
|
-
this['
|
|
98
|
+
else if (val <= 0) {
|
|
99
|
+
this['execMethod']('onDead')
|
|
102
100
|
val = 0
|
|
103
101
|
}
|
|
104
102
|
this._hp = val
|
|
@@ -187,7 +185,7 @@ export class ParameterManager {
|
|
|
187
185
|
* */
|
|
188
186
|
set level(val: number) {
|
|
189
187
|
const lastLevel = this._level
|
|
190
|
-
if (this.finalLevel &&
|
|
188
|
+
if (this.finalLevel && val > this.finalLevel) {
|
|
191
189
|
val = this.finalLevel
|
|
192
190
|
}
|
|
193
191
|
if (this._class) {
|
|
@@ -200,7 +198,9 @@ export class ParameterManager {
|
|
|
200
198
|
}
|
|
201
199
|
}
|
|
202
200
|
const hasNewLevel = val - lastLevel
|
|
203
|
-
if (hasNewLevel > 0)
|
|
201
|
+
if (hasNewLevel > 0) {
|
|
202
|
+
this['execMethod']('onLevelUp', <any>[hasNewLevel])
|
|
203
|
+
}
|
|
204
204
|
this._level = val
|
|
205
205
|
}
|
|
206
206
|
|
|
@@ -342,6 +342,7 @@ export class ParameterManager {
|
|
|
342
342
|
}
|
|
343
343
|
}) {
|
|
344
344
|
this._paramsModifier = val
|
|
345
|
+
this.changeRoomState('param')
|
|
345
346
|
}
|
|
346
347
|
|
|
347
348
|
get parameters() {
|
|
@@ -370,7 +371,7 @@ export class ParameterManager {
|
|
|
370
371
|
return features
|
|
371
372
|
}
|
|
372
373
|
|
|
373
|
-
getParamValue(name: string): number {
|
|
374
|
+
getParamValue(name: string): number | never {
|
|
374
375
|
const features = this.getParam(name)
|
|
375
376
|
let curveVal = Math.floor((features.end - features.start) * ((this.level-1) / (this.finalLevel - this.initialLevel))) + features.start
|
|
376
377
|
const modifier = this.paramsModifier[name]
|
|
@@ -410,6 +411,15 @@ export class ParameterManager {
|
|
|
410
411
|
start,
|
|
411
412
|
end
|
|
412
413
|
})
|
|
414
|
+
const maxHp = this.param[MAXHP]
|
|
415
|
+
const maxSp = this.param[MAXSP]
|
|
416
|
+
if (name == MAXHP && this.hp > maxHp) {
|
|
417
|
+
this.hp = maxHp // forcing hp not to exceed maxp
|
|
418
|
+
}
|
|
419
|
+
else if (name == MAXSP && this.sp > maxSp) {
|
|
420
|
+
this.sp = maxSp
|
|
421
|
+
}
|
|
422
|
+
this.changeRoomState('param.' + name)
|
|
413
423
|
}
|
|
414
424
|
|
|
415
425
|
/**
|
|
@@ -464,5 +474,6 @@ export class ParameterManager {
|
|
|
464
474
|
|
|
465
475
|
export interface ParameterManager {
|
|
466
476
|
_class,
|
|
467
|
-
$schema
|
|
477
|
+
$schema,
|
|
478
|
+
changeRoomState(key: string): void
|
|
468
479
|
}
|
package/src/Player/Player.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RpgCommonPlayer, Utils, RpgPlugin, RpgCommonGame, RpgCommonMap, Direction } from '@rpgjs/common'
|
|
2
|
-
import { Room } from 'simple-room'
|
|
2
|
+
import { Room, WorldClass } from 'simple-room'
|
|
3
3
|
import { RpgMap, EventPosOption } from '../Game/Map'
|
|
4
4
|
import { Query } from '../Query'
|
|
5
5
|
import merge from 'lodash.merge'
|
|
@@ -36,6 +36,7 @@ import { RpgTiledWorldMap } from '../Game/WorldMaps'
|
|
|
36
36
|
import { CameraOptions, PositionXY_OptionalZ, SocketEvents, SocketMethods, LayoutObject } from '@rpgjs/types'
|
|
37
37
|
import { ComponentManager } from './ComponentManager'
|
|
38
38
|
import { Subject } from 'rxjs'
|
|
39
|
+
import { EventManager, EventMode } from '../Game/EventManager'
|
|
39
40
|
|
|
40
41
|
const {
|
|
41
42
|
isPromise,
|
|
@@ -45,14 +46,26 @@ const {
|
|
|
45
46
|
|
|
46
47
|
export interface Position { x: number, y: number, z: number }
|
|
47
48
|
|
|
48
|
-
const
|
|
49
|
-
name:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
const commonSchemaFeature = {
|
|
50
|
+
name: {
|
|
51
|
+
$permanent: false
|
|
52
|
+
},
|
|
53
|
+
description: {
|
|
54
|
+
$permanent: false
|
|
55
|
+
},
|
|
53
56
|
id: String
|
|
54
57
|
}
|
|
55
58
|
|
|
59
|
+
const itemSchemas = {
|
|
60
|
+
price: {
|
|
61
|
+
$permanent: false
|
|
62
|
+
},
|
|
63
|
+
consumable: {
|
|
64
|
+
$permanent: false
|
|
65
|
+
},
|
|
66
|
+
...commonSchemaFeature
|
|
67
|
+
}
|
|
68
|
+
|
|
56
69
|
export const componentSchema = { id: String, value: String }
|
|
57
70
|
export const layoutSchema = {
|
|
58
71
|
width: Number,
|
|
@@ -73,22 +86,39 @@ const playerSchemas = {
|
|
|
73
86
|
z: Number
|
|
74
87
|
},
|
|
75
88
|
direction: Number,
|
|
89
|
+
|
|
76
90
|
teleported: {
|
|
77
91
|
$permanent: false
|
|
78
92
|
},
|
|
93
|
+
|
|
94
|
+
deleted: {
|
|
95
|
+
$permanent: false
|
|
96
|
+
},
|
|
97
|
+
|
|
79
98
|
param: Object,
|
|
80
99
|
hp: Number,
|
|
81
100
|
sp: Number,
|
|
82
101
|
gold: Number,
|
|
83
|
-
level:
|
|
102
|
+
level: {
|
|
103
|
+
$effects: ['$this.expForNextlevel']
|
|
104
|
+
},
|
|
105
|
+
expForNextlevel: {
|
|
106
|
+
$permanent: false
|
|
107
|
+
},
|
|
84
108
|
exp: Number,
|
|
85
109
|
name: String,
|
|
86
|
-
expForNextlevel: Number,
|
|
87
110
|
items: [{ nb: Number, item: itemSchemas }],
|
|
88
|
-
_class:
|
|
111
|
+
_class: commonSchemaFeature,
|
|
89
112
|
equipments: [itemSchemas],
|
|
90
|
-
skills: [
|
|
91
|
-
|
|
113
|
+
skills: [
|
|
114
|
+
{
|
|
115
|
+
spCost: {
|
|
116
|
+
$permanent: false
|
|
117
|
+
},
|
|
118
|
+
...commonSchemaFeature
|
|
119
|
+
}
|
|
120
|
+
],
|
|
121
|
+
states: [commonSchemaFeature],
|
|
92
122
|
effects: [String],
|
|
93
123
|
|
|
94
124
|
layout: {
|
|
@@ -159,14 +189,26 @@ export class RpgPlayer extends RpgCommonPlayer {
|
|
|
159
189
|
public _rooms = []
|
|
160
190
|
public session: string | null = null
|
|
161
191
|
public prevMap: string = ''
|
|
162
|
-
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* ```ts
|
|
195
|
+
* retreive the server instance
|
|
196
|
+
* ```
|
|
197
|
+
* @title Server Instance
|
|
198
|
+
* @prop {RpgServerEngine} player.server
|
|
199
|
+
* @memberof Player
|
|
200
|
+
* */
|
|
163
201
|
public server: RpgServerEngine
|
|
164
202
|
private touchSide: boolean = false
|
|
203
|
+
|
|
165
204
|
/** @internal */
|
|
166
205
|
public tmpPositions: Position | string | null = null
|
|
167
206
|
public otherPossessedPlayer: RpgPlayer | RpgEvent | null = null
|
|
168
207
|
public following: RpgPlayer | RpgEvent | null = null
|
|
169
208
|
|
|
209
|
+
// Indicates whether to load data with load(). In this case, hooks are not triggered.
|
|
210
|
+
private _dataLoading: boolean = false
|
|
211
|
+
|
|
170
212
|
_lastFramePositions: {
|
|
171
213
|
frame: number
|
|
172
214
|
position: Position
|
|
@@ -182,9 +224,16 @@ export class RpgPlayer extends RpgCommonPlayer {
|
|
|
182
224
|
return super.otherPlayersCollision as RpgPlayer[]
|
|
183
225
|
}
|
|
184
226
|
|
|
227
|
+
get world(): WorldClass | undefined {
|
|
228
|
+
return this.server?.world
|
|
229
|
+
}
|
|
230
|
+
|
|
185
231
|
// As soon as a teleport has been made, the value is changed to force the client to change the positions on the map without making a move.
|
|
186
232
|
teleported: number = 0
|
|
187
233
|
|
|
234
|
+
// a flag that lets the client know if the event is suppressed. The client can, for example, end animations before completely deleting the object (client side).
|
|
235
|
+
deleted: boolean = false
|
|
236
|
+
|
|
188
237
|
/** @internal */
|
|
189
238
|
initialize() {
|
|
190
239
|
this.expCurve = {
|
|
@@ -391,6 +440,7 @@ export class RpgPlayer extends RpgCommonPlayer {
|
|
|
391
440
|
let ret = {}
|
|
392
441
|
for (let key in events) {
|
|
393
442
|
this.events[key] = events[key]
|
|
443
|
+
this.events[key].playerRelated = this
|
|
394
444
|
this.events[key].execMethod('onInit', [this])
|
|
395
445
|
// force to get Proxy object to sync with client
|
|
396
446
|
ret = { ...ret, [key]: this.events[key] }
|
|
@@ -398,21 +448,6 @@ export class RpgPlayer extends RpgCommonPlayer {
|
|
|
398
448
|
return ret
|
|
399
449
|
}
|
|
400
450
|
|
|
401
|
-
/**
|
|
402
|
-
* Removes an event from the map (Scenario Mode). Returns false if the event is not found
|
|
403
|
-
* @title Remove Event
|
|
404
|
-
* @since 3.0.0-beta.4
|
|
405
|
-
* @method player.removeEvent(eventId)
|
|
406
|
-
* @param {string} eventId Event Name
|
|
407
|
-
* @returns {boolean}
|
|
408
|
-
* @memberof Player
|
|
409
|
-
*/
|
|
410
|
-
removeEvent(eventId: string): boolean {
|
|
411
|
-
if (!this.events[eventId]) return false
|
|
412
|
-
delete this.events[eventId]
|
|
413
|
-
return true
|
|
414
|
-
}
|
|
415
|
-
|
|
416
451
|
/**
|
|
417
452
|
* Allows to change the positions of the player on the current map.
|
|
418
453
|
* You can put the X and Y positions or the name of the created shape on Tiled Map Editor.
|
|
@@ -465,10 +500,12 @@ export class RpgPlayer extends RpgCommonPlayer {
|
|
|
465
500
|
* @title Load progress
|
|
466
501
|
* @method player.load(json)
|
|
467
502
|
* @param {string} json The JSON sent by the method save()
|
|
468
|
-
* @returns {
|
|
503
|
+
* @returns {Promise<boolean | RpgMap | null>}
|
|
469
504
|
* @memberof Player
|
|
470
505
|
*/
|
|
471
|
-
load(json: any) {
|
|
506
|
+
async load(json: any): Promise<boolean | RpgMap | null> {
|
|
507
|
+
this._dataLoading = true
|
|
508
|
+
|
|
472
509
|
if (isString(json)) json = JSON.parse(json)
|
|
473
510
|
|
|
474
511
|
const getData = (id) => new (this.databaseById(id))()
|
|
@@ -487,10 +524,12 @@ export class RpgPlayer extends RpgCommonPlayer {
|
|
|
487
524
|
items[it.item.id] = getData(it.item.id)
|
|
488
525
|
}
|
|
489
526
|
json.items = json.items.map(it => ({ nb: it.nb, item: items[it.item.id] }))
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
527
|
+
if (Array.isArray(json.equipments)) {
|
|
528
|
+
json.equipments = json.equipments.map(it => {
|
|
529
|
+
items[it.id].equipped = true
|
|
530
|
+
return items[it.id]
|
|
531
|
+
})
|
|
532
|
+
}
|
|
494
533
|
}
|
|
495
534
|
if (json.states) json.states = json.states.map(state => getData(state.id))
|
|
496
535
|
if (json.skills) json.skills = json.skills.map(skill => getData(skill.id))
|
|
@@ -499,10 +538,17 @@ export class RpgPlayer extends RpgCommonPlayer {
|
|
|
499
538
|
merge(this, json)
|
|
500
539
|
|
|
501
540
|
this.position = json.position
|
|
541
|
+
|
|
502
542
|
if (json.map) {
|
|
503
543
|
this.map = ''
|
|
504
|
-
this.changeMap(json.map, json.tmpPositions || json.position)
|
|
544
|
+
const map = await this.changeMap(json.map, json.tmpPositions || json.position)
|
|
545
|
+
this._dataLoading = false
|
|
546
|
+
return map
|
|
505
547
|
}
|
|
548
|
+
|
|
549
|
+
this._dataLoading = false
|
|
550
|
+
|
|
551
|
+
return null
|
|
506
552
|
}
|
|
507
553
|
|
|
508
554
|
/**
|
|
@@ -659,6 +705,7 @@ export class RpgPlayer extends RpgCommonPlayer {
|
|
|
659
705
|
* This is useful, if for example, you want to make an animated character (sword stroke when pressing a key)
|
|
660
706
|
* When the animation is finished, the original graphic is displayed again
|
|
661
707
|
*
|
|
708
|
+
*
|
|
662
709
|
* ```ts
|
|
663
710
|
* player.showAnimation('sword_stroke', 'default', true)
|
|
664
711
|
* ```
|
|
@@ -669,6 +716,10 @@ export class RpgPlayer extends RpgCommonPlayer {
|
|
|
669
716
|
* player.showAnimation(['body', 'sword_stroke'], 'default', true)
|
|
670
717
|
* ```
|
|
671
718
|
*
|
|
719
|
+
* ::: tip
|
|
720
|
+
* For this to work, the animations must have been previously defined in `setGraphic`.
|
|
721
|
+
* :::
|
|
722
|
+
*
|
|
672
723
|
* @title Show Animation
|
|
673
724
|
* @method player.showAnimation(graphic,animationName,replaceGraphic=false)
|
|
674
725
|
* @param {string | string[]} graphic spritesheet identifier
|
|
@@ -679,7 +730,6 @@ export class RpgPlayer extends RpgCommonPlayer {
|
|
|
679
730
|
*/
|
|
680
731
|
showAnimation(graphic: string | string[], animationName: string, replaceGraphic: boolean = false) {
|
|
681
732
|
this.emitToMap('callMethod', {
|
|
682
|
-
objectId: this.playerId,
|
|
683
733
|
name: SocketMethods.ShowAnimation,
|
|
684
734
|
params: [graphic, animationName, replaceGraphic]
|
|
685
735
|
})
|
|
@@ -784,12 +834,30 @@ export class RpgPlayer extends RpgCommonPlayer {
|
|
|
784
834
|
if (this._socket) this._socket.removeAllListeners(key)
|
|
785
835
|
}
|
|
786
836
|
|
|
837
|
+
disconnect() {
|
|
838
|
+
if (this._socket) this._socket.disconnect()
|
|
839
|
+
}
|
|
840
|
+
|
|
787
841
|
emitToMap(key: string, value: any) {
|
|
788
|
-
|
|
842
|
+
const map = this.getCurrentMap()
|
|
843
|
+
if (map) {
|
|
844
|
+
map.$setCurrentState(`users.${this.id}.${key}`, value)
|
|
845
|
+
}
|
|
789
846
|
}
|
|
790
847
|
|
|
791
|
-
async execMethod(methodName: string, methodData = []) {
|
|
792
|
-
const
|
|
848
|
+
async execMethod(methodName: string, methodData = [], target?: any) {
|
|
849
|
+
const ignoreIfDataLoading = ['onLevelUp', 'onDead']
|
|
850
|
+
if (ignoreIfDataLoading.includes(methodName) && this._dataLoading) {
|
|
851
|
+
return
|
|
852
|
+
}
|
|
853
|
+
let ret
|
|
854
|
+
if (target && target[methodName]) {
|
|
855
|
+
ret = target[methodName](...methodData)
|
|
856
|
+
if (isPromise(ret)) await ret
|
|
857
|
+
}
|
|
858
|
+
else {
|
|
859
|
+
ret = await RpgPlugin.emit(`Server.${methodName}`, [this, ...methodData], true)
|
|
860
|
+
}
|
|
793
861
|
this.syncChanges()
|
|
794
862
|
return ret
|
|
795
863
|
}
|
|
@@ -799,6 +867,21 @@ export class RpgPlayer extends RpgCommonPlayer {
|
|
|
799
867
|
this.emit('Player.' + name, val)
|
|
800
868
|
}
|
|
801
869
|
|
|
870
|
+
// @internal
|
|
871
|
+
/**
|
|
872
|
+
* Allows you to manually update a status in the rooms that will then be sent to the customer.
|
|
873
|
+
* @param path
|
|
874
|
+
* @example
|
|
875
|
+
* ```ts
|
|
876
|
+
* player.changeRoomState('hp')
|
|
877
|
+
* ```
|
|
878
|
+
*/
|
|
879
|
+
changeRoomState(path: string) {
|
|
880
|
+
this.world?.forEachUserRooms(this.id, (room) => {
|
|
881
|
+
(room as any).$setCurrentState(`users.${this.id}.${path}`)
|
|
882
|
+
})
|
|
883
|
+
}
|
|
884
|
+
|
|
802
885
|
private _eventChanges() {
|
|
803
886
|
if (!this._getMap(this.map)) return
|
|
804
887
|
const {
|
|
@@ -839,18 +922,18 @@ export class RpgPlayer extends RpgCommonPlayer {
|
|
|
839
922
|
* @title Play Sound
|
|
840
923
|
* @method player.playSound(soundId,allMap=false)
|
|
841
924
|
* @param {string} soundId Sound identifier, defined on the client side
|
|
842
|
-
* @param {boolean} [
|
|
925
|
+
* @param {boolean} [forEveryone=false] Indicate if the sound is heard by the players on the map
|
|
843
926
|
* @since 3.0.0-alpha.9
|
|
844
927
|
* @returns {void}
|
|
845
928
|
* @memberof Player
|
|
846
929
|
*/
|
|
847
|
-
playSound(soundId: string,
|
|
930
|
+
playSound(soundId: string, forEveryone: boolean = false) {
|
|
848
931
|
const obj = {
|
|
849
932
|
objectId: this.playerId,
|
|
850
933
|
name: SocketMethods.PlaySound,
|
|
851
934
|
params: [soundId]
|
|
852
935
|
}
|
|
853
|
-
if (!
|
|
936
|
+
if (!forEveryone) {
|
|
854
937
|
this.emit(SocketEvents.CallMethod, obj)
|
|
855
938
|
return
|
|
856
939
|
}
|
|
@@ -860,6 +943,7 @@ export class RpgPlayer extends RpgCommonPlayer {
|
|
|
860
943
|
}
|
|
861
944
|
|
|
862
945
|
export interface RpgPlayer extends
|
|
946
|
+
EventManager,
|
|
863
947
|
ItemManager,
|
|
864
948
|
GoldManager,
|
|
865
949
|
StateManager,
|
|
@@ -879,6 +963,7 @@ export interface RpgPlayer extends
|
|
|
879
963
|
}
|
|
880
964
|
|
|
881
965
|
applyMixins(RpgPlayer, [
|
|
966
|
+
EventManager,
|
|
882
967
|
ItemManager,
|
|
883
968
|
GoldManager,
|
|
884
969
|
StateManager,
|
|
@@ -894,11 +979,6 @@ applyMixins(RpgPlayer, [
|
|
|
894
979
|
ComponentManager
|
|
895
980
|
])
|
|
896
981
|
|
|
897
|
-
export enum EventMode {
|
|
898
|
-
Shared = 'shared',
|
|
899
|
-
Scenario = 'scenario'
|
|
900
|
-
}
|
|
901
|
-
|
|
902
982
|
export interface RpgClassEvent<T> {
|
|
903
983
|
_name: string
|
|
904
984
|
new(): T,
|
|
@@ -908,24 +988,57 @@ export class RpgEvent extends RpgPlayer {
|
|
|
908
988
|
|
|
909
989
|
public readonly type: string = 'event'
|
|
910
990
|
properties: any = {}
|
|
991
|
+
mode: EventMode
|
|
992
|
+
playerRelated: RpgPlayer | null = null
|
|
993
|
+
|
|
994
|
+
constructor(gameEngine: RpgCommonGame, playerId: string) {
|
|
995
|
+
super(gameEngine, playerId)
|
|
996
|
+
}
|
|
911
997
|
|
|
912
998
|
async execMethod(methodName: string, methodData = []) {
|
|
913
999
|
if (!this[methodName]) {
|
|
914
1000
|
return
|
|
915
1001
|
}
|
|
916
1002
|
const ret = this[methodName](...methodData)
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
1003
|
+
return ret
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
changeRoomState(path: string) {
|
|
1007
|
+
const room = this.getCurrentMap()
|
|
1008
|
+
if (room) {
|
|
1009
|
+
(room as any).$setCurrentState(`events.${this.id}.${path}`)
|
|
922
1010
|
}
|
|
923
|
-
|
|
924
|
-
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* Deletes the event from the map (in shared or scenario mode)
|
|
1015
|
+
*
|
|
1016
|
+
* @title Remove
|
|
1017
|
+
* @since 4.0.0
|
|
1018
|
+
* @method event.remove()
|
|
1019
|
+
* @returns {boolean} true if the event has been removed. If false, the event is not on the map
|
|
1020
|
+
* @memberof RpgEvent
|
|
1021
|
+
*/
|
|
1022
|
+
remove(): boolean {
|
|
1023
|
+
let bool = false
|
|
1024
|
+
if (this.playerRelated) bool = this.playerRelated.removeEvent(this.id)
|
|
1025
|
+
const map = this.getCurrentMap()
|
|
1026
|
+
if (map) {
|
|
1027
|
+
bool = map.removeEvent(this.id)
|
|
925
1028
|
}
|
|
926
|
-
|
|
927
|
-
|
|
1029
|
+
return bool
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
override emitToMap(key: string, value: any) {
|
|
1033
|
+
const map = this.getCurrentMap()
|
|
1034
|
+
if (map) {
|
|
1035
|
+
const eventPath = `events.${this.id}.${key}`
|
|
1036
|
+
if (this.playerRelated) {
|
|
1037
|
+
map.$setCurrentState(`users.${this.playerRelated.id}.${eventPath}`, value)
|
|
1038
|
+
}
|
|
1039
|
+
else {
|
|
1040
|
+
map.$setCurrentState(eventPath, value)
|
|
1041
|
+
}
|
|
928
1042
|
}
|
|
929
|
-
return ret
|
|
930
1043
|
}
|
|
931
|
-
}
|
|
1044
|
+
}
|