@@ -74,7 +74,7 @@ module.exports = { | |||||
for (let i = 0; i < itemCount; i++) { | for (let i = 0; i < itemCount; i++) { | ||||
let minLevel = blueprint.items.minLevel || Math.max(1, list.level * 0.75); | let minLevel = blueprint.items.minLevel || Math.max(1, list.level * 0.75); | ||||
let maxLevel = blueprint.items.maxLevel || (list.level * 1.25); | let maxLevel = blueprint.items.maxLevel || (list.level * 1.25); | ||||
let level = Math.min(20, ~~(minLevel + (Math.random() * (maxLevel - minLevel)))); | |||||
let level = Math.min(consts.maxLevel, ~~(minLevel + (Math.random() * (maxLevel - minLevel)))); | |||||
let item = generator.generate({ | let item = generator.generate({ | ||||
noSpell: true, | noSpell: true, | ||||
@@ -1,3 +1,7 @@ | |||||
//Imports | |||||
const eventEmitter = require('../misc/events'); | |||||
//Module | |||||
module.exports = { | module.exports = { | ||||
//At which interval does each zone tick in ms | //At which interval does each zone tick in ms | ||||
tickTime: 350, | tickTime: 350, | ||||
@@ -15,5 +19,25 @@ module.exports = { | |||||
viewDistanceX: 25, | viewDistanceX: 25, | ||||
//How far a player can see objects vertically | //How far a player can see objects vertically | ||||
viewDistanceY: 14 | |||||
viewDistanceY: 14, | |||||
init: function (threadArgs) { | |||||
const emBeforeGetConsts = { | |||||
threadArgs, | |||||
constValues: {} | |||||
}; | |||||
Object.entries(this).forEach(([k, v]) => { | |||||
if (typeof(v) === 'function') | |||||
return; | |||||
emBeforeGetConsts.constValues[k] = v; | |||||
}); | |||||
eventEmitter.emit('beforeGetConsts', emBeforeGetConsts); | |||||
Object.entries(emBeforeGetConsts.constValues).forEach(([k, v]) => { | |||||
this[k] = v; | |||||
}); | |||||
} | |||||
}; | }; |
@@ -3,7 +3,7 @@ | |||||
module.exports = { | module.exports = { | ||||
version: '0.11.0', | version: '0.11.0', | ||||
port: 4000, | port: 4000, | ||||
startupMessage: 'Server: ready', | |||||
startupMessage: 'Ready: Server', | |||||
nodeEnv: process.env.NODE_ENV, | nodeEnv: process.env.NODE_ENV, | ||||
@@ -48,6 +48,8 @@ module.exports = { | |||||
currencyChance = 0; | currencyChance = 0; | ||||
else if (blueprint.level < 14) | else if (blueprint.level < 14) | ||||
currencyChance *= (blueprint.level - 4) / 11; | currencyChance *= (blueprint.level - 4) / 11; | ||||
else if (blueprint.level > consts.maxLevel) | |||||
blueprint.level = consts.maxLevel; | |||||
//If you kill a mob that's too low of a level, idols are much more rare | //If you kill a mob that's too low of a level, idols are much more rare | ||||
if ( | if ( | ||||
@@ -590,7 +590,7 @@ module.exports = { | |||||
if (!value) { | if (!value) { | ||||
if (statBlueprint.generator) { | if (statBlueprint.generator) { | ||||
let level = Math.min(20, item.originalLevel || item.level); | |||||
let level = Math.min(consts.maxLevel, item.originalLevel || item.level); | |||||
value = Math.ceil(this.generators[statBlueprint.generator](item, level, blueprint, blueprint.perfection, null, statBlueprint)); | value = Math.ceil(this.generators[statBlueprint.generator](item, level, blueprint, blueprint.perfection, null, statBlueprint)); | ||||
} else if (!blueprint.perfection) | } else if (!blueprint.perfection) | ||||
value = Math.ceil(random.norm(statBlueprint.min, statBlueprint.max)); | value = Math.ceil(random.norm(statBlueprint.min, statBlueprint.max)); | ||||
@@ -675,7 +675,7 @@ module.exports = { | |||||
} | } | ||||
}; | }; | ||||
const itemLevel = Math.min(20, item.level); | |||||
const itemLevel = Math.min(consts.maxLevel, item.level); | |||||
stat.value = Math.ceil(generator(item, itemLevel, blueprint)); | stat.value = Math.ceil(generator(item, itemLevel, blueprint)); | ||||
} else | } else | ||||
stat.value = Math.ceil(random.norm(statBlueprint.min, statBlueprint.max) * i.valueMult); | stat.value = Math.ceil(random.norm(statBlueprint.min, statBlueprint.max) * i.valueMult); | ||||
@@ -93,8 +93,11 @@ module.exports = { | |||||
keys.forEach(function (k) { | keys.forEach(function (k) { | ||||
let val = player[k]; | let val = player[k]; | ||||
if (val && val.type) { | if (val && val.type) { | ||||
if (['player', 'auth', 'syncer'].indexOf(val.type) === -1) | |||||
if (['player', 'auth', 'syncer'].indexOf(val.type) === -1) { | |||||
delete player[k]; | delete player[k]; | ||||
player.components.spliceWhere(c => c.type === val.type); | |||||
} | |||||
} | } | ||||
}); | }); | ||||
@@ -111,11 +114,13 @@ module.exports = { | |||||
//If we don't do this, the atlas will try to remove it from the thread | //If we don't do this, the atlas will try to remove it from the thread | ||||
delete player.zoneName; | delete player.zoneName; | ||||
delete player.name; | delete player.name; | ||||
delete player.zoneId; | |||||
//A hack to allow us to actually call methods again (like retrieve the player list) | //A hack to allow us to actually call methods again (like retrieve the player list) | ||||
player.dead = false; | player.dead = false; | ||||
player.permadead = false; | player.permadead = false; | ||||
delete player.auth.charname; | delete player.auth.charname; | ||||
player.id = objects.getNextId(); | |||||
this.modifyPlayerCount(-1); | this.modifyPlayerCount(-1); | ||||
@@ -12,7 +12,7 @@ const rest = require('../security/rest'); | |||||
const { | const { | ||||
port = 4000, | port = 4000, | ||||
startupMessage = 'Server: Ready', | |||||
startupMessage = 'Ready: Server', | |||||
nodeEnv | nodeEnv | ||||
} = require('../config/serverConfig'); | } = require('../config/serverConfig'); | ||||
@@ -26,6 +26,9 @@ module.exports = { | |||||
lastTime: 0, | lastTime: 0, | ||||
mapName: null, | |||||
threadArgs: null, | |||||
init: function (args) { | init: function (args) { | ||||
const { zoneId, zoneName } = args; | const { zoneId, zoneName } = args; | ||||
@@ -65,7 +68,7 @@ module.exports = { | |||||
map.randomMap.init(fakeInstance); | map.randomMap.init(fakeInstance); | ||||
this.startRegen(); | this.startRegen(); | ||||
} else | } else | ||||
_.log('(M ' + map.name + '): Ready'); | |||||
_.log(`Ready: ${JSON.stringify(this.threadArgs, null, '\t')}`); | |||||
map.clientMap.zoneId = this.zoneId; | map.clientMap.zoneId = this.zoneId; | ||||
@@ -164,7 +167,7 @@ module.exports = { | |||||
this.addQueue = []; | this.addQueue = []; | ||||
_.log('(M ' + map.name + '): Ready'); | |||||
_.log(`Ready: ${JSON.stringify(this.threadArgs, null, '\t')}`); | |||||
}, | }, | ||||
tick: function () { | tick: function () { | ||||
@@ -166,32 +166,20 @@ const onMessage = (thread, message) => { | |||||
messageHandlers[message.method](thread, message); | messageHandlers[message.method](thread, message); | ||||
}; | }; | ||||
const spawnThread = async ({ name, path, instanced, destroyWhenEmptyForMs = -1 }, obj) => { | |||||
const spawnThread = async ({ map: { name, path, instanced, destroyWhenEmptyForMs = -1 }, obj }) => { | |||||
let cbOnInitialized; | let cbOnInitialized; | ||||
const promise = new Promise(resolveOnReady => { | const promise = new Promise(resolveOnReady => { | ||||
cbOnInitialized = resolveOnReady; | cbOnInitialized = resolveOnReady; | ||||
}); | }); | ||||
const worker = childProcess.fork('./world/worker', [name]); | |||||
let 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, | ||||
name, | name, | ||||
instanced, | instanced, | ||||
path, | path, | ||||
worker, | |||||
worker: null, | |||||
isReady: false, | isReady: false, | ||||
promise, | promise, | ||||
cbOnInitialized, | cbOnInitialized, | ||||
@@ -199,10 +187,25 @@ const spawnThread = async ({ name, path, instanced, destroyWhenEmptyForMs = -1 } | |||||
playersCurrent: [], | playersCurrent: [], | ||||
birthEpoch: +new Date(), | birthEpoch: +new Date(), | ||||
destroyWhenEmptyForMs, | destroyWhenEmptyForMs, | ||||
emptySinceEpoch: null | |||||
emptySinceEpoch: null, | |||||
sendArgsToWorker: ['name', 'id'] | |||||
}; | }; | ||||
worker.on('message', onMessage.bind(null, thread)); | |||||
const emBeforeSpawnThread = { | |||||
thread, | |||||
spawnForObject: obj | |||||
}; | |||||
events.emit('beforeSpawnThread', emBeforeSpawnThread); | |||||
const workerArgs = JSON.stringify( | |||||
Object.fromEntries( | |||||
thread.sendArgsToWorker.map(a => [a, thread[a]]) | |||||
) | |||||
); | |||||
thread.worker = childProcess.fork('./world/worker', [workerArgs]); | |||||
thread.worker.on('message', onMessage.bind(null, thread)); | |||||
threads.push(thread); | threads.push(thread); | ||||
@@ -221,16 +224,19 @@ const getThread = async ({ zoneName, zoneId, obj }) => { | |||||
map = mapList.find(m => m.name === clientConfig.config.defaultZone); | map = mapList.find(m => m.name === clientConfig.config.defaultZone); | ||||
let thread = threads.find(t => t.id === zoneId && t.name === zoneName); | let thread = threads.find(t => t.id === zoneId && t.name === zoneName); | ||||
//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(obj.id)); | 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, obj); | |||||
thread = await spawnThread({ | |||||
map, | |||||
obj | |||||
}); | |||||
} | } | ||||
if (!thread.isReady) | if (!thread.isReady) | ||||
@@ -26,7 +26,9 @@ const profanities = require('../misc/profanities'); | |||||
const eventEmitter = require('../misc/events'); | const eventEmitter = require('../misc/events'); | ||||
//Worker | //Worker | ||||
instancer.mapName = process.argv[2]; | |||||
const threadArgs = JSON.parse(process.argv[2]); | |||||
instancer.mapName = threadArgs.name; | |||||
instancer.threadArgs = threadArgs; | |||||
const onCpnsReady = async function () { | const onCpnsReady = async function () { | ||||
factions.init(); | factions.init(); | ||||
@@ -51,6 +53,7 @@ const onCpnsReady = async function () { | |||||
}; | }; | ||||
const onModsReady = function () { | const onModsReady = function () { | ||||
consts.init(threadArgs); | |||||
components.init(onCpnsReady); | components.init(onCpnsReady); | ||||
}; | }; | ||||