Skip to content

Commit

Permalink
refactoring for mod checks in freemod slots with no defined list of m…
Browse files Browse the repository at this point in the history
…ods allowed
  • Loading branch information
VINXIS committed Oct 3, 2024
1 parent c514efc commit 94ba597
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BanchoLobby } from "bancho.js";
import { BanchoLobby, BanchoMods } from "bancho.js";
import { MappoolSlot } from "../../../../Models/tournaments/mappools/mappoolSlot";
import getMappoolSlotMods from "./getMappoolSlotMods";

Expand All @@ -8,11 +8,19 @@ export default function doAllPlayersHaveCorrectMods (mpLobby: BanchoLobby, slotM

const allowedMods = getMappoolSlotMods(slotMod.allowedMods);
if (
mpLobby.slots.some(slot =>
slot?.mods.some(mod =>
!allowedMods.some(allowedMod => allowedMod.enumValue === mod.enumValue)
( // If any mods were defined
allowedMods.length > 0 &&
mpLobby.slots.some(slot =>
slot?.mods.some(mod =>
!allowedMods.some(allowedMod => allowedMod.enumValue === mod.enumValue)
)
)
) || // If no mods were defined for the slot, then check if anyone is missing NoFail
mpLobby.slots.some(slot =>
slot?.mods.some(mod => (mod.enumValue & BanchoMods.NoFail.enumValue) === 0)
)
)
return false;

return true;
}
6 changes: 4 additions & 2 deletions BanchoBot/functions/tournaments/matchup/getMappoolSlotMods.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { BanchoMod, BanchoMods } from "bancho.js";

export default function getMappoolSlotMods (allowedModsEnum: number | null | undefined): BanchoMod[] {
const modParse = BanchoMods.parseBitFlags(allowedModsEnum ?? 0, true).concat(BanchoMods.NoFail); // Default NoFail requirements

if (typeof allowedModsEnum !== "number")
return [];

const modParse = BanchoMods.parseBitFlags(allowedModsEnum, true).concat(BanchoMods.NoFail); // Default NoFail requirements
return modParse.filter((v, i, a) => a.findIndex(m => m.enumValue === v.enumValue) === i); // If a mappool slot's allowedMods has NoFail already, then it will filter it out.
}

0 comments on commit 94ba597

Please sign in to comment.