Skip to content

Commit

Permalink
refactor freemod mod check logic
Browse files Browse the repository at this point in the history
  • Loading branch information
VINXIS committed Oct 5, 2024
1 parent 2e336e3 commit 87edbdb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BanchoLobby, BanchoMods } from "bancho.js";
import { BanchoLobby } from "bancho.js";
import { MappoolSlot } from "../../../../Models/tournaments/mappools/mappoolSlot";
import getMappoolSlotMods from "./getMappoolSlotMods";

Expand All @@ -7,20 +7,19 @@ export default function doAllPlayersHaveCorrectMods (mpLobby: BanchoLobby, slotM
return true;

const allowedMods = getMappoolSlotMods(slotMod.allowedMods);
if (
( // 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;
if (allowedMods.length === 0)
// Any slot that exists and doesn't have NoFail is invalid
return !mpLobby.slots.some(slot =>
slot &&
!slot.mods.some(mod => mod.enumValue === 1)
);

return true;
return !mpLobby.slots.some(slot =>
slot &&
(
!slot.mods.some(mod => mod.enumValue === 1) ||
slot.mods.some(mod => !allowedMods.some(allowedMod => allowedMod.enumValue === mod.enumValue)) ||
allowedMods.filter(mod => mod.enumValue !== 1).every(allowedMod => !slot.mods.some(mod => mod.enumValue === allowedMod.enumValue))
)
);
}
2 changes: 1 addition & 1 deletion BanchoBot/functions/tournaments/matchup/runMatchup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ async function runMatchupListeners (matchup: Matchup, mpLobby: BanchoLobby, mpCh
return;
}
if (!doAllPlayersHaveCorrectMods(mpLobby, slotMod)) {
await mpChannel.sendMessage(`someone has the wrong mods on for this slot (Allowed mods are ${getMappoolSlotMods(slotMod.allowedMods).map(m => `${m.longMod} (${m.shortMod})`).join(", ")})`);
await mpChannel.sendMessage(`someone has the wrong mods on for this slot (Allowed mods are ${typeof slotMod.allowedMods === "number" ? getMappoolSlotMods(slotMod.allowedMods ?? 1).map(m => `${m.longMod.toUpperCase()} (${m.shortMod})`).join(", ") : "NF (NoFail) with any desired mods"})`);
return;
}

Expand Down

0 comments on commit 87edbdb

Please sign in to comment.