199 lines
6.6 KiB
JavaScript
199 lines
6.6 KiB
JavaScript
|
"use strict";
|
||
|
|
||
|
const mod = require("./package.json");
|
||
|
const config = require("./config.json");
|
||
|
|
||
|
class ModMain {
|
||
|
constructor() {
|
||
|
this.modName = `${mod.author.toLowerCase()}-${mod.name.toLowerCase()}`;
|
||
|
|
||
|
Logger.info(`Loading: ${this.modName} : ${mod.version}`);
|
||
|
|
||
|
const response = {};
|
||
|
response[`${this.modName}`] = (url, info, sessionID, output) => HttpResponse.noBody(config.game);
|
||
|
|
||
|
HttpRouter.onStaticRoute[`/mods/${this.modName}/config`] = response;
|
||
|
this.clientLocationsHandler = HttpRouter.onStaticRoute["/client/locations"];
|
||
|
HttpRouter.onStaticRoute["/client/locations"] = { "aki": (url, info, sessionID, output) => {
|
||
|
for (const handlerId in this.clientLocationsHandler) {
|
||
|
const handler = this.clientLocationsHandler[handlerId];
|
||
|
output = handler(url, info, sessionID, output);
|
||
|
}
|
||
|
const response = JsonUtil.deserialize(output);
|
||
|
this.updateLocations(response.data.locations);
|
||
|
return HttpResponse.getBody(response.data);
|
||
|
}};
|
||
|
|
||
|
ModLoader.onLoad[this.modname] = this.load.bind(this);
|
||
|
}
|
||
|
|
||
|
debug_message(message) {
|
||
|
if (config.server.DEBUG)
|
||
|
Logger.log(`[DEBUG] ${mod.name}: ${message}`, "green", "black");
|
||
|
}
|
||
|
|
||
|
info_message(message) {
|
||
|
Logger.info(`${mod.name}: ${message}`);
|
||
|
}
|
||
|
|
||
|
error_messsage(message) {
|
||
|
Logger.error(`${mod.name}: ${message}`);
|
||
|
}
|
||
|
|
||
|
load() {
|
||
|
const db = DatabaseServer.tables;
|
||
|
|
||
|
for (const coef in config.server.ChangeWaveCoefs) {
|
||
|
const value = config.server.ChangeWaveCoefs[coef];
|
||
|
db.globals.config[coef] = value;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
addIgnoreMaxBots(location) {
|
||
|
if (!location.BossLocationSpawn)
|
||
|
return false;
|
||
|
|
||
|
let isAdded = false;
|
||
|
for (const bossWave of location.BossLocationSpawn) {
|
||
|
bossWave["IgnoreMaxBots"] = true;
|
||
|
isAdded = true;
|
||
|
}
|
||
|
|
||
|
return isAdded;
|
||
|
}
|
||
|
|
||
|
replaceScavWaves(location, waveTemplate, difficultyArray) {
|
||
|
const waves = [];
|
||
|
const spawnPoints = [];
|
||
|
const escapeTimeLimitMin = location.escape_time_limit;
|
||
|
|
||
|
let waveNumber = 1;
|
||
|
let hasBots = false;
|
||
|
for (const wave of location.waves) {
|
||
|
if (wave.WildSpawnType == "marksman")
|
||
|
{
|
||
|
wave.number = waveNumber++;
|
||
|
waves.push(wave);
|
||
|
}
|
||
|
if (wave.WildSpawnType != "marksman" && wave.SpawnPoints.length > 0)
|
||
|
spawnPoints.push(wave.SpawnPoints);
|
||
|
if (wave.slots_min > 0 || wave.slots_max > 0)
|
||
|
hasBots = true;
|
||
|
}
|
||
|
|
||
|
if (!hasBots) {
|
||
|
this.debug_message(`No bots found on '${location.Id}'`);
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if (spawnPoints.length == 0)
|
||
|
{
|
||
|
this.debug_message(`No spawn points found on '${location.Id}'`);
|
||
|
spawnPoints.push("");
|
||
|
}
|
||
|
|
||
|
let instaWaveCount = config.server.ScavInstaWaveCount;
|
||
|
|
||
|
for (let i = 0; i < config.server.ScavWaveCount; i++) {
|
||
|
const wave = JsonUtil.clone(waveTemplate);
|
||
|
wave.number = waveNumber++;
|
||
|
wave.BotPreset = RandomUtil.getArrayValue(difficultyArray);
|
||
|
wave.SpawnPoints = RandomUtil.getArrayValue(spawnPoints);
|
||
|
wave.time_min = instaWaveCount > 0
|
||
|
? 0
|
||
|
: Math.round((i - config.server.ScavInstaWaveCount + 1) * 60 * ((escapeTimeLimitMin * 0.75) / config.server.ScavWaveCount));
|
||
|
wave.time_max = instaWaveCount > 0
|
||
|
? 1
|
||
|
: Math.round((i - config.server.ScavInstaWaveCount + 1) * 60 * ((escapeTimeLimitMin * 0.75) / config.server.ScavWaveCount)) + 1;
|
||
|
|
||
|
if (instaWaveCount > 0)
|
||
|
instaWaveCount--;
|
||
|
|
||
|
waves.push(wave);
|
||
|
}
|
||
|
|
||
|
location.waves = waves;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
showScavWaves(location) {
|
||
|
let waveNumber = 1;
|
||
|
|
||
|
this.info_message(`Location = ${location.Id}`);
|
||
|
for (const wave of location.waves) {
|
||
|
this.info_message(`[${waveNumber}] [${wave.time_min}-${wave.time_max}s] ${wave.slots_min}-${wave.slots_max} [${wave.WildSpawnType}][${wave.BotPreset}] @ [${wave.SpawnPoints}]`);
|
||
|
waveNumber++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
updateLocations(locations) {
|
||
|
for (const locationId in locations) {
|
||
|
const location = locations[locationId];
|
||
|
|
||
|
if (!location || location.Id == "hideout")
|
||
|
continue;
|
||
|
|
||
|
if (config.server.Add_IgnoreMaxBots_ToBossWaves) {
|
||
|
let replaceMessage = `[${location.Id}] Adding 'IgnoreMaxBots' to boss waves...`;
|
||
|
try {
|
||
|
const result = this.addIgnoreMaxBots(location);
|
||
|
replaceMessage += result
|
||
|
? "done"
|
||
|
: "skipped";
|
||
|
} catch (error) {
|
||
|
replaceMessage += "error!";
|
||
|
this.error_message(error);
|
||
|
} finally {
|
||
|
this.info_message(replaceMessage);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (config.server.ReplaceLocationsWaves)
|
||
|
{
|
||
|
const waveTemplate = {
|
||
|
"number": 0,
|
||
|
"time_min": 0,
|
||
|
"time_max": 1,
|
||
|
"slots_min": 1,
|
||
|
"slots_max": 1,
|
||
|
"SpawnPoints": "BotZone",
|
||
|
"BotSide": "Savage",
|
||
|
"BotPreset": "easy",
|
||
|
"WildSpawnType": "assault",
|
||
|
"isPlayers": false
|
||
|
};
|
||
|
|
||
|
const difficultyArray = this.getWeightArray(config.server.ScavDifficultyWeight);
|
||
|
|
||
|
let replaceMessage = `[${location.Id}] Replacing scav waves...`;
|
||
|
try {
|
||
|
const result = this.replaceScavWaves(location, waveTemplate, difficultyArray);
|
||
|
replaceMessage += result
|
||
|
? "done"
|
||
|
: "skipped";
|
||
|
} catch (error) {
|
||
|
replaceMessage += "error!";
|
||
|
this.error_message(error);
|
||
|
} finally {
|
||
|
this.info_message(replaceMessage);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (config.server.ShowGeneratedWaves)
|
||
|
this.showScavWaves(location);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
getWeightArray(entity) {
|
||
|
const result = [];
|
||
|
for (const property in entity) {
|
||
|
const value = entity[property];
|
||
|
for (let i = 0; i < value; i++) {
|
||
|
result.push(property);
|
||
|
}
|
||
|
}
|
||
|
return result;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = new ModMain();
|