@@ -37,26 +37,28 @@ define([ | |||||
events.clearQueue(); | events.clearQueue(); | ||||
await Promise.all( | await Promise.all( | ||||
globals.clientConfig.uiList.map(u => { | |||||
const uiType = u.path ? u.path.split('/').pop() : u; | |||||
globals.clientConfig.uiList | |||||
.filter(u => u.autoLoadOnPlay !== false) | |||||
.map(u => { | |||||
const uiType = u.path ? u.path.split('/').pop() : u; | |||||
return new Promise(res => { | |||||
const doneCheck = () => { | |||||
const isDone = this.uis.some(ui => ui.type === uiType); | |||||
if (isDone) { | |||||
res(); | |||||
return new Promise(res => { | |||||
const doneCheck = () => { | |||||
const isDone = this.uis.some(ui => ui.type === uiType); | |||||
if (isDone) { | |||||
res(); | |||||
return; | |||||
} | |||||
return; | |||||
} | |||||
setTimeout(doneCheck, 100); | |||||
}; | |||||
setTimeout(doneCheck, 100); | |||||
}; | |||||
this.build(uiType, { path: u.path }); | |||||
this.build(uiType, { path: u.path }); | |||||
doneCheck(); | |||||
}); | |||||
}) | |||||
doneCheck(); | |||||
}); | |||||
}) | |||||
); | ); | ||||
this.ingameUisBuilt = true; | this.ingameUisBuilt = true; | ||||
@@ -426,8 +426,8 @@ module.exports = { | |||||
}, | }, | ||||
createCharacter: async function (msg) { | createCharacter: async function (msg) { | ||||
let data = msg.data; | |||||
let name = data.name; | |||||
const data = msg.data; | |||||
const name = data.name; | |||||
let error = null; | let error = null; | ||||
@@ -460,7 +460,7 @@ module.exports = { | |||||
const releaseCreateLock = await getCreateLock(); | const releaseCreateLock = await getCreateLock(); | ||||
let exists = await io.getAsync({ | |||||
const exists = await io.getAsync({ | |||||
key: name, | key: name, | ||||
ignoreCase: true, | ignoreCase: true, | ||||
table: 'character', | table: 'character', | ||||
@@ -474,23 +474,19 @@ module.exports = { | |||||
return; | return; | ||||
} | } | ||||
let obj = this.obj; | |||||
const simple = this.obj.getSimple(true); | |||||
extend(obj, { | |||||
name: name, | |||||
skinId: data.skinId, | |||||
Object.assign(simple, { | |||||
name, | |||||
class: data.class, | class: data.class, | ||||
skinId: data.skinId, | |||||
cell: skins.getCell(data.skinId), | cell: skins.getCell(data.skinId), | ||||
sheetName: skins.getSpritesheet(data.skinId), | |||||
x: null, | |||||
y: null | |||||
sheetName: skins.getSpritesheet(data.skinId) | |||||
}); | }); | ||||
let simple = this.obj.getSimple(true); | |||||
await this.verifySkin(simple); | await this.verifySkin(simple); | ||||
let prophecies = (data.prophecies || []).filter(p => p); | |||||
const prophecies = (data.prophecies ?? []).filter(p => p); | |||||
simple.components.push({ | simple.components.push({ | ||||
type: 'prophecies', | type: 'prophecies', | ||||
@@ -500,6 +496,13 @@ module.exports = { | |||||
customChannels: this.customChannels | customChannels: this.customChannels | ||||
}); | }); | ||||
const emBeforeCreateCharacter = { | |||||
obj: simple, | |||||
createData: data | |||||
}; | |||||
await eventEmitter.emit('beforeCreateCharacter', emBeforeCreateCharacter); | |||||
await io.setAsync({ | await io.setAsync({ | ||||
key: name, | key: name, | ||||
table: 'character', | table: 'character', | ||||
@@ -2,7 +2,7 @@ | |||||
const objects = require('../objects/objects'); | const objects = require('../objects/objects'); | ||||
const events = require('../misc/events'); | const events = require('../misc/events'); | ||||
const { | const { | ||||
getThread, killThread, sendMessageToThread, getThreadFromId, returnWhenThreadsIdle, gePlayerCountInThread, addPlayerToThread, removePlayerFromThread | |||||
getThread, sendMessageToThread, getThreadFromId, returnWhenThreadsIdle, addPlayerToThread, removePlayerFromThread | |||||
} = require('./threadManager'); | } = require('./threadManager'); | ||||
const { registerCallback, removeCallback } = require('./atlas/registerCallback'); | const { registerCallback, removeCallback } = require('./atlas/registerCallback'); | ||||
@@ -15,7 +15,7 @@ module.exports = { | |||||
if (!serverObj) | if (!serverObj) | ||||
return; | return; | ||||
events.emit('onBeforePlayerEnterWorld', obj); | |||||
await events.emit('onBeforePlayerEnterWorld', { obj }); | |||||
let { zoneName, zoneId } = obj; | let { zoneName, zoneId } = obj; | ||||
@@ -30,7 +30,7 @@ module.exports = { | |||||
const { thread, resetObjPosition } = await getThread({ | const { thread, resetObjPosition } = await getThread({ | ||||
zoneName, | zoneName, | ||||
zoneId, | zoneId, | ||||
playerId: obj.id | |||||
obj | |||||
}); | }); | ||||
if (resetObjPosition) { | if (resetObjPosition) { | ||||
@@ -16,6 +16,7 @@ const mapList = [ | |||||
//Helpers | //Helpers | ||||
const init = () => { | const init = () => { | ||||
events.emit('onBeforeGetMapList', mapList); | events.emit('onBeforeGetMapList', mapList); | ||||
events.emit('onBeforeFinalizeMapList', mapList); | |||||
}; | }; | ||||
//Exports | //Exports | ||||
@@ -26,6 +26,7 @@ const objects = require('../objects/objects'); | |||||
const connections = require('../security/connections'); | const connections = require('../security/connections'); | ||||
const { mapList } = require('./mapManager'); | const { mapList } = require('./mapManager'); | ||||
const { registerCallback } = require('./atlas/registerCallback'); | const { registerCallback } = require('./atlas/registerCallback'); | ||||
const events = require('../misc/events'); | |||||
//Internals | //Internals | ||||
const threads = []; | const threads = []; | ||||
@@ -165,7 +166,7 @@ const onMessage = (thread, message) => { | |||||
messageHandlers[message.method](thread, message); | messageHandlers[message.method](thread, message); | ||||
}; | }; | ||||
const spawnThread = async ({ name, path, instanced, destroyWhenEmptyForMs = -1 }) => { | |||||
const spawnThread = async ({ name, path, instanced, destroyWhenEmptyForMs = -1 }, obj) => { | |||||
let cbOnInitialized; | let cbOnInitialized; | ||||
const promise = new Promise(resolveOnReady => { | const promise = new Promise(resolveOnReady => { | ||||
@@ -174,7 +175,16 @@ const spawnThread = async ({ name, path, instanced, destroyWhenEmptyForMs = -1 } | |||||
const worker = childProcess.fork('./world/worker', [name]); | const worker = childProcess.fork('./world/worker', [name]); | ||||
const id = instanced ? _.getGuid() : name; | |||||
let id = instanced ? _.getGuid() : name; | |||||
const emBeforeGetThreadId = { | |||||
id, | |||||
obj, | |||||
name, | |||||
instanced | |||||
}; | |||||
events.emit('beforeGetThreadId', emBeforeGetThreadId); | |||||
id = emBeforeGetThreadId.id; | |||||
const thread = { | const thread = { | ||||
id, | id, | ||||
@@ -199,7 +209,7 @@ const spawnThread = async ({ name, path, instanced, destroyWhenEmptyForMs = -1 } | |||||
return promise; | return promise; | ||||
}; | }; | ||||
const getThread = async ({ zoneName, zoneId, playerId }) => { | |||||
const getThread = async ({ zoneName, zoneId, obj }) => { | |||||
const result = { | const result = { | ||||
resetObjPosition: false, | resetObjPosition: false, | ||||
thread: null | thread: null | ||||
@@ -214,15 +224,13 @@ const getThread = async ({ zoneName, zoneId, playerId }) => { | |||||
//Maybe this player has been in a thread for this map before | //Maybe this player has been in a thread for this map before | ||||
if (!thread) | if (!thread) | ||||
thread = threads.find(t => t.name === zoneName && t.players.includes(playerId)); | |||||
thread = threads.find(t => t.name === zoneName && t.players.includes(obj.id)); | |||||
if (!thread) { | if (!thread) { | ||||
if (map.instanced) { | |||||
if (map.instanced) | |||||
result.resetObjPosition = true; | result.resetObjPosition = true; | ||||
thread = await spawnThread(map); | |||||
} else | |||||
thread = getThreadFromName(map.name); | |||||
thread = await spawnThread(map, obj); | |||||
} | } | ||||
if (!thread.isReady) | if (!thread.isReady) | ||||
@@ -274,7 +282,7 @@ const returnWhenThreadsIdle = async () => { | |||||
const spawnMapThreads = async () => { | const spawnMapThreads = async () => { | ||||
const promises = mapList | const promises = mapList | ||||
.filter(m => !m.disabled && !m.instanced) | |||||
.filter(m => !m.disabled && !m.instanced && m.autoSpawn !== false) | |||||
.map(m => spawnThread(m)); | .map(m => spawnThread(m)); | ||||
await Promise.all(promises); | await Promise.all(promises); | ||||