added option for no repeat modes

This commit is contained in:
maskedmonkyman 2022-04-14 02:08:53 -07:00
parent 0981a89bcb
commit 6e33aa7552

View File

@ -64,7 +64,7 @@ export default class MapVote extends BasePlugin
required: false, required: false,
description: 'broadcast interval for vote notification in mils', description: 'broadcast interval for vote notification in mils',
default: 15 default: 15
}, }
}; };
} }
@ -236,13 +236,40 @@ export default class MapVote extends BasePlugin
this.server.rcon.execute(`AdminSetNextLayer ${nextMap}`); this.server.rcon.execute(`AdminSetNextLayer ${nextMap}`);
} }
matchLayers(builtString)
{
return Layers.layers.filter(element => element.layerid.startsWith(builtString));
}
getMode(modes, currentMode)
{
let mode = modes[0];
if (mode === "Any")
modes = this.voteRules.modes;
if (this.voteRules.repeatBlacklist.includes(currentMode))
{
modes = modes.filter(mode => !mode.includes(currentMode));
}
while (modes.length > 0)
{
mode = randomElement(this.modes);
modes = modes.filter(elem => elem !== mode);
if (matchLayers(`${cafPrefix}${mapName}_${mode}`).length > 0)
break;
}
return mode;
}
//TODO: right now if version is set to "Any" no caf layers will be selected //TODO: right now if version is set to "Any" no caf layers will be selected
populateNominations() //gets nomination strings from layer options populateNominations() //gets nomination strings from layer options
{ {
//helpers //helpers
const splitName = name => name.substring(0, name.lastIndexOf("_")); const splitName = name => name.substring(0, name.lastIndexOf("_"));
const removeCAF = name => name.replace("CAF_", ""); const removeCAF = name => name.replace("CAF_", "");
const matchLayers = builtString => Layers.layers.filter((element) => element.layerid.startsWith(builtString));
if (!this.server.currentLayer) if (!this.server.currentLayer)
{ {
@ -271,7 +298,7 @@ export default class MapVote extends BasePlugin
for(const nomination of nominationsList) for(const nomination of nominationsList)
{ {
const mapName = nomination.map; const mapName = nomination.map;
let mode = randomElement(nomination.modes); let mode = getMode(nomination.modes, this.server.currentLayer.gamemode);
let version = randomElement(nomination.versions); let version = randomElement(nomination.versions);
let cafPrefix = ""; let cafPrefix = "";
@ -281,18 +308,6 @@ export default class MapVote extends BasePlugin
version = removeCAF(version); version = removeCAF(version);
} }
if (mode === "Any")
{
let modes = this.voteRules.modes;
while (modes.length > 0)
{
mode = randomElement(this.voteRules.modes);
modes = modes.filter((elem) => elem !== mode);
if (matchLayers(`${cafPrefix}${mapName}_${mode}`).length > 0)
break;
}
}
let builtLayerString = `${cafPrefix}${mapName}_${mode}_${version}`; let builtLayerString = `${cafPrefix}${mapName}_${mode}_${version}`;
if (version === "Any") if (version === "Any")
{ {