diff --git a/src/commands/general.ts b/src/commands/general.ts index 695f05dc..55b77238 100644 --- a/src/commands/general.ts +++ b/src/commands/general.ts @@ -14,7 +14,7 @@ import { FishEvents, fishPlugin, fishState, ipPortPattern, recentWhispers, tileH import { FMap, PartialMapRun } from "/maps"; import { FishPlayer } from "/players"; import { Rank, RoleFlag } from "/ranks"; -import { formatTime, formatTimeRelative, getColor, logAction, nearbyEnemyTile, neutralGameover, skipWaves, teleportPlayer } from "/utils"; +import { formatTime, formatTimeRelative, getColor, logAction, nearbyEnemyTile, neutralGameover, skipWaves, teleportPlayer, vnwCondition } from "/utils"; import { VoteManager } from "/votes"; export const commands = commandList({ @@ -787,7 +787,8 @@ Please stop attacking and [lime]build defenses[] first!` }), requirements: [Req.cooldown(3000), Req.integerRange("waves", 1, 15), Req.mode("survival", "testsrv"), Req.gameRunning], async handler({sender, args: {waves}, data:{manager}}){ - + + if (!vnwCondition.check()) fail("You can only do that when all units from previous waves are dead."); //Disable narrowing, this is async if(!manager.session as boolean){ waves ??= await Menu.menu( diff --git a/src/frameworks/commands/requirements.ts b/src/frameworks/commands/requirements.ts index 5dd718d2..87dafab6 100644 --- a/src/frameworks/commands/requirements.ts +++ b/src/frameworks/commands/requirements.ts @@ -53,4 +53,5 @@ export const Req = { Req.integer(argName)({args}) && (args[argName] == undefined || args[argName] > 0 || fail(`${argName} must be positive`)), + }; diff --git a/src/index.ts b/src/index.ts index 2a932ae9..30ecf439 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,7 +14,7 @@ import { PartialMapRun } from "/maps"; import { loadPacketHandlers } from "/packetHandlers"; import { FishPlayer } from "/players"; import * as timers from "/timers"; -import { addToTileHistory, fishCommandsRootDirPath, formatTimeRelative, matchFilter, processChat, restartNow, serverRestartLoop } from "/utils"; +import { addToTileHistory, fishCommandsRootDirPath, formatTimeRelative, matchFilter, processChat, restartNow, serverRestartLoop, vnwCondition } from "/utils"; const { Menu } = menus; @@ -326,6 +326,10 @@ Events.on(EventType.PlayEvent, () => { fishState.startTime = Date.now(); }); +Events.on(EventType.WaveEvent, () => { + if (Vars.state.rules.mode().name() === "survival") vnwCondition.onWaveStart(); +}); + Events.on(EventType.AdminRequestEvent, e => { if(e.action == Packets.AdminAction.wave){ const fishP = FishPlayer.get(e.player); diff --git a/src/utils.ts b/src/utils.ts index bc9220ab..c1097757 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -475,6 +475,19 @@ export function skipWaves(requestedWaves: number, runIntermediateWaves: boolean) } } +export const vnwCondition = { + waveUnits: [] as Unit[], + onWaveStart(){ + let units = Groups.unit.copy(new Seq()); + let enemyTeam = getEnemyTeam(); + this.waveUnits = units.select(u => u.team === enemyTeam).toArray(); + }, + check(){ + if (this.waveUnits.some(u => !u.dead)) return false; + return true; + } +}; + export function logHTrip(player:FishPlayer, name:string, message?:string){ Log.warn(`&yPlayer &b"${player.cleanedName}"&y (&b${player.uuid}&y/&b${player.ip()}&y) tripped &c${name}&y` + (message ? `: ${message}` : ""));