diff --git a/src/core/execution/WinCheckExecution.ts b/src/core/execution/WinCheckExecution.ts index 8ea4a001ab..3ae2b40664 100644 --- a/src/core/execution/WinCheckExecution.ts +++ b/src/core/execution/WinCheckExecution.ts @@ -68,6 +68,11 @@ export class WinCheckExecution implements Execution { (this.mg.ticks() - this.mg.config().numSpawnPhaseTurns()) / 10; const numTilesWithoutFallout = this.mg.numLandTiles() - this.mg.numTilesWithFallout(); + + if (numTilesWithoutFallout === 0) { + return; + } + if ( (max.numTilesOwned() / numTilesWithoutFallout) * 100 > this.mg.config().percentageTilesOwnedToWin() || @@ -104,9 +109,14 @@ export class WinCheckExecution implements Execution { (this.mg.ticks() - this.mg.config().numSpawnPhaseTurns()) / 10; const numTilesWithoutFallout = this.mg.numLandTiles() - this.mg.numTilesWithFallout(); - const percentage = (max[1] / numTilesWithoutFallout) * 100; + + if (numTilesWithoutFallout === 0) { + return; + } + if ( - percentage > this.mg.config().percentageTilesOwnedToWin() || + (max[1] / numTilesWithoutFallout) * 100 > + this.mg.config().percentageTilesOwnedToWin() || (this.mg.config().gameConfig().maxTimerValue !== undefined && timeElapsed - this.mg.config().gameConfig().maxTimerValue! * 60 >= 0) || timeElapsed >= WinCheckExecution.HARD_TIME_LIMIT_SECONDS diff --git a/tests/core/executions/WinCheckExecution.test.ts b/tests/core/executions/WinCheckExecution.test.ts index 6b5b07d09e..dfe0b8abe8 100644 --- a/tests/core/executions/WinCheckExecution.test.ts +++ b/tests/core/executions/WinCheckExecution.test.ts @@ -87,6 +87,53 @@ describe("WinCheckExecution", () => { it("should return false for activeDuringSpawnPhase", () => { expect(winCheck.activeDuringSpawnPhase()).toBe(false); }); + + it("should not set winner via tile percentage when all land tiles have fallout (FFA)", () => { + const player = { + numTilesOwned: vi.fn(() => 100), + name: vi.fn(() => "P1"), + }; + mg.players = vi.fn(() => [player]); + mg.numLandTiles = vi.fn(() => 100); + mg.numTilesWithFallout = vi.fn(() => 100); + mg.config = vi.fn(() => ({ + gameConfig: vi.fn(() => ({ + gameMode: GameMode.FFA, + maxTimerValue: undefined, + })), + percentageTilesOwnedToWin: vi.fn(() => 80), + numSpawnPhaseTurns: vi.fn(() => 0), + })); + mg.ticks = vi.fn(() => 0); + mg.stats = vi.fn(() => ({ stats: () => ({}) })); + winCheck.init(mg, 0); + winCheck.checkWinnerFFA(); + expect(mg.setWinner).not.toHaveBeenCalled(); + }); + + it("should not set winner via tile percentage when all land tiles have fallout (Team)", () => { + const player = { + numTilesOwned: vi.fn(() => 100), + name: vi.fn(() => "P1"), + team: vi.fn(() => "Red"), + }; + mg.players = vi.fn(() => [player]); + mg.numLandTiles = vi.fn(() => 100); + mg.numTilesWithFallout = vi.fn(() => 100); + mg.config = vi.fn(() => ({ + gameConfig: vi.fn(() => ({ + gameMode: GameMode.Team, + maxTimerValue: undefined, + })), + percentageTilesOwnedToWin: vi.fn(() => 80), + numSpawnPhaseTurns: vi.fn(() => 0), + })); + mg.ticks = vi.fn(() => 0); + mg.stats = vi.fn(() => ({ stats: () => ({}) })); + winCheck.init(mg, 0); + winCheck.checkWinnerTeam(); + expect(mg.setWinner).not.toHaveBeenCalled(); + }); }); describe("WinCheckExecution - Nation Winners", () => {