@rpgjs/server 4.2.2 → 5.0.0-alpha.0
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/{lib → dist}/Gui/DialogGui.d.ts +1 -2
- package/{lib → dist}/Gui/Gui.d.ts +1 -2
- package/dist/Player/BattleManager.d.ts +22 -0
- package/dist/Player/ClassManager.d.ts +18 -0
- package/dist/Player/Event.d.ts +0 -0
- package/dist/Player/ItemManager.d.ts +17 -0
- package/dist/Player/MoveManager.d.ts +177 -0
- package/dist/Player/ParameterManager.d.ts +42 -0
- package/dist/Player/Player.d.ts +73 -0
- package/dist/Player/SkillManager.d.ts +23 -0
- package/dist/Player/StateManager.d.ts +39 -0
- package/{lib → dist}/RpgServer.d.ts +34 -17
- package/dist/RpgServerEngine.d.ts +5 -0
- package/dist/core/context.d.ts +2 -0
- package/dist/core/inject.d.ts +5 -0
- package/dist/core/setup.d.ts +6 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +29673 -0
- package/dist/index.js.map +1 -0
- package/dist/module.d.ts +2 -0
- package/dist/rooms/lobby.d.ts +6 -0
- package/dist/rooms/map.d.ts +110 -0
- package/package.json +16 -38
- package/src/Gui/DialogGui.ts +3 -4
- package/src/Gui/Gui.ts +4 -6
- package/src/Player/BattleManager.ts +108 -99
- package/src/Player/ClassManager.ts +47 -46
- package/src/Player/ComponentManager.ts +26 -535
- package/src/Player/EffectManager.ts +44 -59
- package/src/Player/ElementManager.ts +70 -72
- package/src/Player/Event.ts +0 -0
- package/src/Player/GoldManager.ts +24 -6
- package/src/Player/GuiManager.ts +106 -97
- package/src/Player/ItemFixture.ts +22 -17
- package/src/Player/ItemManager.ts +234 -225
- package/src/Player/MoveManager.ts +1047 -457
- package/src/Player/ParameterManager.ts +59 -37
- package/src/Player/Player.ts +272 -1058
- package/src/Player/SkillManager.ts +146 -137
- package/src/Player/StateManager.ts +124 -98
- package/src/Player/VariableManager.ts +23 -3
- package/src/RpgServer.ts +38 -14
- package/src/RpgServerEngine.ts +7 -0
- package/src/core/context.ts +3 -0
- package/src/core/inject.ts +17 -0
- package/src/core/setup.ts +20 -0
- package/src/index.ts +9 -31
- package/src/module.ts +32 -0
- package/src/presets/index.ts +1 -3
- package/src/rooms/lobby.ts +24 -0
- package/src/rooms/map.ts +311 -0
- package/tsconfig.json +26 -23
- package/vite.config.ts +21 -0
- package/CHANGELOG.md +0 -163
- package/LICENSE +0 -19
- package/browser/manifest.json +0 -7
- package/browser/rpg.server.js +0 -22372
- package/browser/rpg.server.umd.cjs +0 -22403
- package/lib/Game/EventManager.d.ts +0 -54
- package/lib/Game/EventManager.js +0 -107
- package/lib/Game/EventManager.js.map +0 -1
- package/lib/Game/Map.d.ts +0 -191
- package/lib/Game/Map.js +0 -414
- package/lib/Game/Map.js.map +0 -1
- package/lib/Game/WorldMaps.d.ts +0 -17
- package/lib/Game/WorldMaps.js +0 -28
- package/lib/Game/WorldMaps.js.map +0 -1
- package/lib/Gui/DialogGui.js +0 -57
- package/lib/Gui/DialogGui.js.map +0 -1
- package/lib/Gui/Gui.js +0 -37
- package/lib/Gui/Gui.js.map +0 -1
- package/lib/Gui/MenuGui.js +0 -23
- package/lib/Gui/MenuGui.js.map +0 -1
- package/lib/Gui/NotificationGui.js +0 -8
- package/lib/Gui/NotificationGui.js.map +0 -1
- package/lib/Gui/ShopGui.js +0 -40
- package/lib/Gui/ShopGui.js.map +0 -1
- package/lib/Gui/index.js +0 -7
- package/lib/Gui/index.js.map +0 -1
- package/lib/Interfaces/Gui.d.ts +0 -4
- package/lib/Interfaces/Gui.js +0 -2
- package/lib/Interfaces/Gui.js.map +0 -1
- package/lib/Interfaces/StateStore.d.ts +0 -5
- package/lib/Interfaces/StateStore.js +0 -2
- package/lib/Interfaces/StateStore.js.map +0 -1
- package/lib/MatchMaker.d.ts +0 -24
- package/lib/MatchMaker.js +0 -42
- package/lib/MatchMaker.js.map +0 -1
- package/lib/Monitor/index.d.ts +0 -17
- package/lib/Monitor/index.js +0 -72
- package/lib/Monitor/index.js.map +0 -1
- package/lib/Player/BattleManager.d.ts +0 -36
- package/lib/Player/BattleManager.js +0 -101
- package/lib/Player/BattleManager.js.map +0 -1
- package/lib/Player/ClassManager.d.ts +0 -47
- package/lib/Player/ClassManager.js +0 -65
- package/lib/Player/ClassManager.js.map +0 -1
- package/lib/Player/ComponentManager.d.ts +0 -397
- package/lib/Player/ComponentManager.js +0 -505
- package/lib/Player/ComponentManager.js.map +0 -1
- package/lib/Player/EffectManager.d.ts +0 -46
- package/lib/Player/EffectManager.js +0 -75
- package/lib/Player/EffectManager.js.map +0 -1
- package/lib/Player/ElementManager.d.ts +0 -108
- package/lib/Player/ElementManager.js +0 -120
- package/lib/Player/ElementManager.js.map +0 -1
- package/lib/Player/GoldManager.d.ts +0 -17
- package/lib/Player/GoldManager.js +0 -27
- package/lib/Player/GoldManager.js.map +0 -1
- package/lib/Player/GuiManager.d.ts +0 -247
- package/lib/Player/GuiManager.js +0 -291
- package/lib/Player/GuiManager.js.map +0 -1
- package/lib/Player/ItemFixture.d.ts +0 -7
- package/lib/Player/ItemFixture.js +0 -19
- package/lib/Player/ItemFixture.js.map +0 -1
- package/lib/Player/ItemManager.d.ts +0 -331
- package/lib/Player/ItemManager.js +0 -475
- package/lib/Player/ItemManager.js.map +0 -1
- package/lib/Player/MoveManager.d.ts +0 -333
- package/lib/Player/MoveManager.js +0 -450
- package/lib/Player/MoveManager.js.map +0 -1
- package/lib/Player/ParameterManager.d.ts +0 -316
- package/lib/Player/ParameterManager.js +0 -408
- package/lib/Player/ParameterManager.js.map +0 -1
- package/lib/Player/Player.d.ts +0 -828
- package/lib/Player/Player.js +0 -927
- package/lib/Player/Player.js.map +0 -1
- package/lib/Player/SkillManager.d.ts +0 -163
- package/lib/Player/SkillManager.js +0 -223
- package/lib/Player/SkillManager.js.map +0 -1
- package/lib/Player/StateManager.d.ts +0 -185
- package/lib/Player/StateManager.js +0 -228
- package/lib/Player/StateManager.js.map +0 -1
- package/lib/Player/VariableManager.d.ts +0 -46
- package/lib/Player/VariableManager.js +0 -52
- package/lib/Player/VariableManager.js.map +0 -1
- package/lib/Query.d.ts +0 -127
- package/lib/Query.js +0 -159
- package/lib/Query.js.map +0 -1
- package/lib/RpgServer.js +0 -2
- package/lib/RpgServer.js.map +0 -1
- package/lib/Scenes/Map.d.ts +0 -136
- package/lib/Scenes/Map.js +0 -273
- package/lib/Scenes/Map.js.map +0 -1
- package/lib/decorators/event.d.ts +0 -43
- package/lib/decorators/event.js +0 -13
- package/lib/decorators/event.js.map +0 -1
- package/lib/decorators/map.d.ts +0 -178
- package/lib/decorators/map.js +0 -43
- package/lib/decorators/map.js.map +0 -1
- package/lib/entry-point.d.ts +0 -34
- package/lib/entry-point.js +0 -70
- package/lib/entry-point.js.map +0 -1
- package/lib/express/api.d.ts +0 -3
- package/lib/express/api.js +0 -105
- package/lib/express/api.js.map +0 -1
- package/lib/express/errors/NotAuthorized.d.ts +0 -4
- package/lib/express/errors/NotAuthorized.js +0 -7
- package/lib/express/errors/NotAuthorized.js.map +0 -1
- package/lib/express/errors/NotFound.d.ts +0 -4
- package/lib/express/errors/NotFound.js +0 -7
- package/lib/express/errors/NotFound.js.map +0 -1
- package/lib/express/server.d.ts +0 -16
- package/lib/express/server.js +0 -65
- package/lib/express/server.js.map +0 -1
- package/lib/index.d.ts +0 -20
- package/lib/index.js +0 -19
- package/lib/index.js.map +0 -1
- package/lib/inject.d.ts +0 -22
- package/lib/inject.js +0 -29
- package/lib/inject.js.map +0 -1
- package/lib/logs/index.js +0 -6
- package/lib/logs/index.js.map +0 -1
- package/lib/logs/item.js +0 -34
- package/lib/logs/item.js.map +0 -1
- package/lib/logs/log.js +0 -7
- package/lib/logs/log.js.map +0 -1
- package/lib/logs/skill.js +0 -19
- package/lib/logs/skill.js.map +0 -1
- package/lib/logs/state.js +0 -13
- package/lib/logs/state.js.map +0 -1
- package/lib/models/Item.d.ts +0 -10
- package/lib/models/Item.js +0 -2
- package/lib/models/Item.js.map +0 -1
- package/lib/presets/index.js +0 -65
- package/lib/presets/index.js.map +0 -1
- package/lib/server.d.ts +0 -137
- package/lib/server.js +0 -443
- package/lib/server.js.map +0 -1
- package/rpg.toml +0 -14
- package/src/Game/EventManager.ts +0 -125
- package/src/Game/Map.ts +0 -495
- package/src/Game/WorldMaps.ts +0 -45
- package/src/Interfaces/Gui.ts +0 -4
- package/src/Interfaces/StateStore.ts +0 -5
- package/src/MatchMaker.ts +0 -65
- package/src/Monitor/index.ts +0 -78
- package/src/Query.ts +0 -172
- package/src/Scenes/Map.ts +0 -310
- package/src/decorators/event.ts +0 -58
- package/src/decorators/map.ts +0 -226
- package/src/entry-point.ts +0 -111
- package/src/express/api.ts +0 -118
- package/src/express/errors/NotAuthorized.ts +0 -6
- package/src/express/errors/NotFound.ts +0 -6
- package/src/express/server.ts +0 -87
- package/src/inject.ts +0 -33
- package/src/models/Item.ts +0 -11
- package/src/server.ts +0 -459
- /package/{lib → dist}/Gui/MenuGui.d.ts +0 -0
- /package/{lib → dist}/Gui/NotificationGui.d.ts +0 -0
- /package/{lib → dist}/Gui/ShopGui.d.ts +0 -0
- /package/{lib → dist}/Gui/index.d.ts +0 -0
- /package/{lib → dist}/logs/index.d.ts +0 -0
- /package/{lib → dist}/logs/item.d.ts +0 -0
- /package/{lib → dist}/logs/log.d.ts +0 -0
- /package/{lib → dist}/logs/skill.d.ts +0 -0
- /package/{lib → dist}/logs/state.d.ts +0 -0
- /package/{lib → dist}/presets/index.d.ts +0 -0
package/src/server.ts
DELETED
|
@@ -1,459 +0,0 @@
|
|
|
1
|
-
import { SceneMap } from './Scenes/Map';
|
|
2
|
-
import { RpgPlayer } from './Player/Player'
|
|
3
|
-
import { Query } from './Query'
|
|
4
|
-
import { DAMAGE_SKILL, DAMAGE_PHYSIC, DAMAGE_CRITICAL, COEFFICIENT_ELEMENTS } from './presets'
|
|
5
|
-
import { World, WorldClass, Transport } from 'simple-room'
|
|
6
|
-
import { Utils, RpgPlugin, Scheduler, HookServer, RpgCommonGame, DefaultInput } from '@rpgjs/common'
|
|
7
|
-
import { Observable } from 'rxjs';
|
|
8
|
-
import { Tick } from '@rpgjs/types';
|
|
9
|
-
import { Actor, Armor, Class, DatabaseTypes, Item, Skill, State, Weapon } from '@rpgjs/database';
|
|
10
|
-
import { inject } from './inject';
|
|
11
|
-
|
|
12
|
-
export class RpgServerEngine {
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Express App Instance. If you have assigned this variable before starting the game, you can get the instance of Express
|
|
16
|
-
*
|
|
17
|
-
* @prop {Express App} [app]
|
|
18
|
-
* @memberof RpgServerEngine
|
|
19
|
-
*/
|
|
20
|
-
app
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* List of the data
|
|
24
|
-
*
|
|
25
|
-
* @prop {object} [database]
|
|
26
|
-
* @memberof RpgServerEngine
|
|
27
|
-
*/
|
|
28
|
-
public database: any = {}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* retrieve the global configurations assigned at the entry point
|
|
32
|
-
*
|
|
33
|
-
* @prop {object} [globalConfig]
|
|
34
|
-
* @readonly
|
|
35
|
-
* @memberof RpgServerEngine
|
|
36
|
-
* */
|
|
37
|
-
public globalConfig: any = {}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Combat formulas
|
|
41
|
-
*
|
|
42
|
-
* @prop {object} [damageFormulas]
|
|
43
|
-
* @memberof RpgServerEngine
|
|
44
|
-
*/
|
|
45
|
-
public damageFormulas: any = {}
|
|
46
|
-
|
|
47
|
-
public serverId: string = process.env.SERVER_ID || Utils.generateUID()
|
|
48
|
-
|
|
49
|
-
private scenes: Map<string, any> = new Map()
|
|
50
|
-
protected totalConnected: number = 0
|
|
51
|
-
private scheduler: Scheduler = new Scheduler()
|
|
52
|
-
private playerProps: any
|
|
53
|
-
public gameEngine: RpgCommonGame = inject(RpgCommonGame)
|
|
54
|
-
|
|
55
|
-
world: WorldClass = World
|
|
56
|
-
workers: any
|
|
57
|
-
envs: any = {}
|
|
58
|
-
io: any
|
|
59
|
-
inputOptions: any = {}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Combat formulas
|
|
63
|
-
*
|
|
64
|
-
* @prop {Socket Io Server} [io]
|
|
65
|
-
* @memberof RpgServerEngine
|
|
66
|
-
*/
|
|
67
|
-
initialize(io, inputOptions) {
|
|
68
|
-
this.io = io
|
|
69
|
-
this.inputOptions = inputOptions
|
|
70
|
-
this.envs = inputOptions.envs || {}
|
|
71
|
-
if (this.inputOptions.workers) {
|
|
72
|
-
console.log('workers enabled')
|
|
73
|
-
this.workers = this.gameEngine.createWorkers(this.inputOptions.workers).load()
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
private async _init() {
|
|
78
|
-
this.damageFormulas = this.inputOptions.damageFormulas || {}
|
|
79
|
-
this.damageFormulas = {
|
|
80
|
-
damageSkill: DAMAGE_SKILL,
|
|
81
|
-
damagePhysic: DAMAGE_PHYSIC,
|
|
82
|
-
damageCritical: DAMAGE_CRITICAL,
|
|
83
|
-
coefficientElements: COEFFICIENT_ELEMENTS,
|
|
84
|
-
...this.damageFormulas
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
this.globalConfig = this.inputOptions.globalConfig
|
|
88
|
-
|
|
89
|
-
if (!this.inputOptions.maps) this.inputOptions.maps = []
|
|
90
|
-
if (!this.inputOptions.events) this.inputOptions.events = []
|
|
91
|
-
if (!this.inputOptions.worldMaps) this.inputOptions.worldMaps = []
|
|
92
|
-
this.playerProps = this.inputOptions.playerProps
|
|
93
|
-
|
|
94
|
-
this.inputOptions.maps = [
|
|
95
|
-
...Utils.arrayFlat(await RpgPlugin.emit(HookServer.AddMap, this.inputOptions.maps)) || [],
|
|
96
|
-
...this.inputOptions.maps
|
|
97
|
-
]
|
|
98
|
-
|
|
99
|
-
this.inputOptions.events = [
|
|
100
|
-
...Utils.arrayFlat(await RpgPlugin.emit(HookServer.AddEvent, this.inputOptions.events)) || [],
|
|
101
|
-
...this.inputOptions.events
|
|
102
|
-
]
|
|
103
|
-
|
|
104
|
-
this.inputOptions.worldMaps = [
|
|
105
|
-
...Utils.arrayFlat(await RpgPlugin.emit(HookServer.AddWorldMaps, this.inputOptions.worldMaps)) || [],
|
|
106
|
-
...this.inputOptions.worldMaps
|
|
107
|
-
]
|
|
108
|
-
|
|
109
|
-
this.globalConfig.inputs = {
|
|
110
|
-
...DefaultInput,
|
|
111
|
-
...(this.globalConfig.inputs || {})
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (!this.inputOptions.database) this.inputOptions.database = {}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* data is array with object or array
|
|
118
|
-
*/
|
|
119
|
-
const datas = await RpgPlugin.emit(HookServer.AddDatabase, this.inputOptions.database) || []
|
|
120
|
-
|
|
121
|
-
for (let element of datas) {
|
|
122
|
-
if (Array.isArray(element)) {
|
|
123
|
-
for (let data of element) {
|
|
124
|
-
this.addInDatabase(data.id, data)
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
for (let id in element) {
|
|
129
|
-
this.addInDatabase(element[id].id ?? id, element[id])
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
this.loadScenes()
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Adds data to the server's database (in RAM) for later use
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
* @method server.addInDatabase(id,data)
|
|
142
|
-
* @title Add in database
|
|
143
|
-
* @param {number} id resource id
|
|
144
|
-
* @param {class | object} dataClass A class representing the data. You can just add a object if you specify the type
|
|
145
|
-
* @enum {string} [type] The type of data
|
|
146
|
-
*
|
|
147
|
-
* item
|
|
148
|
-
* weapon
|
|
149
|
-
* armor
|
|
150
|
-
* skill
|
|
151
|
-
* class
|
|
152
|
-
* state
|
|
153
|
-
* actor
|
|
154
|
-
* @since 3.0.0-beta.4
|
|
155
|
-
* @example
|
|
156
|
-
* ```ts
|
|
157
|
-
* @Item({
|
|
158
|
-
* name: 'Potion',
|
|
159
|
-
* description: 'Gives 100 HP',
|
|
160
|
-
* })
|
|
161
|
-
* class MyItem() {}
|
|
162
|
-
*
|
|
163
|
-
* server.addInDatabase('dynamic_item', MyItem)
|
|
164
|
-
* ```
|
|
165
|
-
*
|
|
166
|
-
* or with an object
|
|
167
|
-
*
|
|
168
|
-
* ```ts
|
|
169
|
-
* server.addInDatabase('dynamic_item', {
|
|
170
|
-
* name: 'Potion',
|
|
171
|
-
* description: 'Gives 100 HP',
|
|
172
|
-
* }, 'item')
|
|
173
|
-
* ```
|
|
174
|
-
*
|
|
175
|
-
* @returns {void}
|
|
176
|
-
* @memberof RpgServerEngine
|
|
177
|
-
*/
|
|
178
|
-
addInDatabase(id: string, dataClass: any, type?: DatabaseTypes) {
|
|
179
|
-
if (Utils.isClass(dataClass)) {
|
|
180
|
-
this.database[id] = dataClass
|
|
181
|
-
return
|
|
182
|
-
}
|
|
183
|
-
if (!type) {
|
|
184
|
-
throw new Error(`You must specify a type for the database ${id}`)
|
|
185
|
-
}
|
|
186
|
-
switch (type) {
|
|
187
|
-
case 'item':
|
|
188
|
-
@Item(dataClass) class ItemClass { }
|
|
189
|
-
this.database[id] = ItemClass
|
|
190
|
-
break;
|
|
191
|
-
case 'weapon':
|
|
192
|
-
@Weapon(dataClass) class WeaponClass { }
|
|
193
|
-
this.database[id] = WeaponClass
|
|
194
|
-
break;
|
|
195
|
-
case 'armor':
|
|
196
|
-
@Armor(dataClass) class ArmorClass { }
|
|
197
|
-
this.database[id] = ArmorClass
|
|
198
|
-
break;
|
|
199
|
-
case 'skill':
|
|
200
|
-
@Skill(dataClass) class SkillClass { }
|
|
201
|
-
this.database[id] = SkillClass
|
|
202
|
-
break;
|
|
203
|
-
case 'class':
|
|
204
|
-
@Class(dataClass) class ClassClass { }
|
|
205
|
-
this.database[id] = ClassClass
|
|
206
|
-
break;
|
|
207
|
-
case 'state':
|
|
208
|
-
@State(dataClass) class StateClass { }
|
|
209
|
-
this.database[id] = StateClass
|
|
210
|
-
break;
|
|
211
|
-
case 'actor':
|
|
212
|
-
@Actor(dataClass) class ActorClass { }
|
|
213
|
-
this.database[id] = ActorClass
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Start the RPG server
|
|
220
|
-
*
|
|
221
|
-
* @method server.start()
|
|
222
|
-
* @title Start Server
|
|
223
|
-
* @returns {void}
|
|
224
|
-
* @memberof RpgServerEngine
|
|
225
|
-
*/
|
|
226
|
-
async start(inputOptions?, scheduler = true) {
|
|
227
|
-
if (inputOptions) this.inputOptions = inputOptions
|
|
228
|
-
await this._init()
|
|
229
|
-
this.tick.subscribe(({ timestamp, deltaTime }) => {
|
|
230
|
-
this.step(timestamp, deltaTime)
|
|
231
|
-
})
|
|
232
|
-
if (scheduler) this.scheduler.start({
|
|
233
|
-
fps: inputOptions?.fps || 60
|
|
234
|
-
})
|
|
235
|
-
this.gameEngine.start({
|
|
236
|
-
getObject(id) {
|
|
237
|
-
return Query.getPlayer(id)
|
|
238
|
-
},
|
|
239
|
-
getObjectsOfGroup(groupId: string, player: RpgPlayer) {
|
|
240
|
-
return Query._getObjectsOfMap(groupId, player)
|
|
241
|
-
},
|
|
242
|
-
getShapesOfGroup(map: string) {
|
|
243
|
-
return Query._getShapesOfMap(map)
|
|
244
|
-
}
|
|
245
|
-
})
|
|
246
|
-
//this.io.on('connection', this.onPlayerConnected.bind(this))
|
|
247
|
-
this.transport(this.io)
|
|
248
|
-
await RpgPlugin.emit(HookServer.Start, this)
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
private transport(io): Transport {
|
|
252
|
-
const timeoutDisconnect = this.globalConfig.timeoutDisconnect ?? 0
|
|
253
|
-
const auth = this.globalConfig.disableAuth ? () => Utils.generateUID() :
|
|
254
|
-
async (socket) => {
|
|
255
|
-
const val = await RpgPlugin.emit(HookServer.Auth, [this, socket], true)
|
|
256
|
-
if (val.length == 0) {
|
|
257
|
-
return Utils.generateUID()
|
|
258
|
-
}
|
|
259
|
-
return val[val.length - 1]
|
|
260
|
-
}
|
|
261
|
-
const transport = new Transport(io, {
|
|
262
|
-
timeoutDisconnect,
|
|
263
|
-
auth
|
|
264
|
-
})
|
|
265
|
-
this.world.timeoutDisconnect = timeoutDisconnect
|
|
266
|
-
transport.onConnected(this.onPlayerConnected.bind(this))
|
|
267
|
-
transport.onDisconnected(this.onPlayerDisconnected.bind(this))
|
|
268
|
-
return transport
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
get tick(): Observable<Tick> {
|
|
272
|
-
return this.scheduler.tick as any
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Sends all packages to clients. The sending is done automatically but you can decide to send yourself by calling this method (for example, for unit tests)
|
|
277
|
-
*
|
|
278
|
-
* @method server.send()
|
|
279
|
-
* @title Send All Packets
|
|
280
|
-
* @returns {void}
|
|
281
|
-
* @memberof RpgServerEngine
|
|
282
|
-
*/
|
|
283
|
-
send(): Promise<void> {
|
|
284
|
-
return this.world.send()
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
private async updatePlayersMove(deltaTimeInt: number) {
|
|
288
|
-
const players = this.world.getUsers()
|
|
289
|
-
const obj: any = []
|
|
290
|
-
let p: Promise<RpgPlayer>[] = []
|
|
291
|
-
for (let playerId in players) {
|
|
292
|
-
const playerInstance = players[playerId]['proxy'] as RpgPlayer
|
|
293
|
-
if (!playerInstance) continue
|
|
294
|
-
const player = playerInstance.otherPossessedPlayer ?? playerInstance
|
|
295
|
-
if (player.pendingMove.length > 0) {
|
|
296
|
-
|
|
297
|
-
const lastFrame = player.pendingMove[player.pendingMove.length - 1]
|
|
298
|
-
if (this.inputOptions.workers) obj.push(player.toObject())
|
|
299
|
-
else {
|
|
300
|
-
p.push(this.gameEngine.processInput(player.playerId, this.globalConfig.inputs).then((val) => {
|
|
301
|
-
player.pendingMove = []
|
|
302
|
-
player.moving = false
|
|
303
|
-
player._lastFramePositions = {
|
|
304
|
-
frame: lastFrame.frame,
|
|
305
|
-
position: { ...player.position }
|
|
306
|
-
}
|
|
307
|
-
return player
|
|
308
|
-
}))
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
// TODO
|
|
313
|
-
if (this.inputOptions.workers) {
|
|
314
|
-
this.workers.call('movePlayers', obj).then((players) => {
|
|
315
|
-
for (let playerId in players) {
|
|
316
|
-
const player = this.world.getUser(playerId) as RpgPlayer
|
|
317
|
-
const data = players[playerId]
|
|
318
|
-
if (player) {
|
|
319
|
-
player.position = data.position
|
|
320
|
-
player.direction = data.direction
|
|
321
|
-
}
|
|
322
|
-
RpgPlugin.emit('Server.onInput', [player, {
|
|
323
|
-
input: data.direction,
|
|
324
|
-
moving: true
|
|
325
|
-
}], true)
|
|
326
|
-
}
|
|
327
|
-
})
|
|
328
|
-
}
|
|
329
|
-
return Promise.all(p)
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
nextTick(timestamp: number) {
|
|
333
|
-
this.scheduler.nextTick(timestamp)
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
step(t: number, dt: number) {
|
|
337
|
-
this.updatePlayersMove(1)
|
|
338
|
-
if (this.scheduler.frame % 4 === 0) {
|
|
339
|
-
this.send()
|
|
340
|
-
}
|
|
341
|
-
RpgPlugin.emit(HookServer.Step, this)
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
private loadScenes() {
|
|
345
|
-
this.scenes.set(SceneMap.id, new SceneMap(
|
|
346
|
-
{
|
|
347
|
-
maps: this.inputOptions.maps,
|
|
348
|
-
events: this.inputOptions.events,
|
|
349
|
-
worldMaps: this.inputOptions.worldMaps
|
|
350
|
-
}
|
|
351
|
-
))
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
getScene<T>(name: string): T {
|
|
355
|
-
return this.scenes.get(name)
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Return the scene that manages the maps of the game
|
|
360
|
-
* @prop {SceneMap} [sceneMap]
|
|
361
|
-
* @since 3.0.0-beta.4
|
|
362
|
-
* @memberof RpgServerEngine
|
|
363
|
-
*/
|
|
364
|
-
get sceneMap(): SceneMap {
|
|
365
|
-
return this.getScene<SceneMap>(SceneMap.id)
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
get module() {
|
|
369
|
-
return RpgPlugin
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
get assetsPath(): string {
|
|
373
|
-
return this.envs?.['VITE_ASSETS_PATH'] || 'assets'
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
sendToPlayer(currentPlayer, eventName, data) {
|
|
377
|
-
currentPlayer._socket.emit(eventName, data)
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
private getPlayerBySession(session: string): RpgPlayer | null {
|
|
381
|
-
const users = this.world.getUsers<RpgPlayer>()
|
|
382
|
-
for (let userId in users) {
|
|
383
|
-
const user = users[userId]
|
|
384
|
-
if (user.session === session) {
|
|
385
|
-
return user
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
return null
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
private onPlayerConnected(socket, playerId: string) {
|
|
392
|
-
const existingUser = this.world.getUser<RpgPlayer>(playerId, false)
|
|
393
|
-
|
|
394
|
-
this.world.connectUser(socket, playerId)
|
|
395
|
-
|
|
396
|
-
let player: RpgPlayer
|
|
397
|
-
|
|
398
|
-
if (!existingUser) {
|
|
399
|
-
const { token } = socket.handshake.auth
|
|
400
|
-
player = new RpgPlayer(playerId)
|
|
401
|
-
player.session = token
|
|
402
|
-
|
|
403
|
-
this.world.setUser(player, socket)
|
|
404
|
-
|
|
405
|
-
player._init()
|
|
406
|
-
|
|
407
|
-
if (!token) {
|
|
408
|
-
const newToken = Utils.generateUID() + '-' + Utils.generateUID() + '-' + Utils.generateUID()
|
|
409
|
-
player.session = newToken
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
if (!token) {
|
|
413
|
-
player.execMethod('onConnected')
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
RpgPlugin.emit(HookServer.ScalabilityPlayerConnected, player)
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
else {
|
|
420
|
-
player = existingUser
|
|
421
|
-
if (player.map) {
|
|
422
|
-
player.emit('preLoadScene', {
|
|
423
|
-
reconnect: true,
|
|
424
|
-
id: player.map
|
|
425
|
-
})
|
|
426
|
-
player.emitSceneMap()
|
|
427
|
-
this.world.joinRoom(player.map, playerId)
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
socket.emit('playerJoined', { playerId, session: player.session })
|
|
432
|
-
|
|
433
|
-
socket.on('move', (data: { input: string[], frame: number }) => {
|
|
434
|
-
if (!data?.input) return
|
|
435
|
-
if (!Array.isArray(data.input)) return
|
|
436
|
-
const controlPlayer = player.otherPossessedPlayer ?? player
|
|
437
|
-
if (!controlPlayer.canMove) {
|
|
438
|
-
return
|
|
439
|
-
}
|
|
440
|
-
for (let input of data.input) {
|
|
441
|
-
controlPlayer.pendingMove.push({
|
|
442
|
-
input,
|
|
443
|
-
frame: data.frame
|
|
444
|
-
})
|
|
445
|
-
}
|
|
446
|
-
})
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
private onPlayerDisconnected(playerId: string) {
|
|
451
|
-
const player: RpgPlayer = World.getUser(playerId) as RpgPlayer
|
|
452
|
-
player.execMethod('onDisconnected')
|
|
453
|
-
this.world.disconnectUser(playerId)
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
stop() {
|
|
457
|
-
this.scheduler.stop()
|
|
458
|
-
}
|
|
459
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|