mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 23:21:58 +00:00
f161c94ff4
## Description: Adds a max timer setting The timer starts at max timer and goes down, becoming red if reaching < 1 min The player with the biggest territory wins at the end of the timer  ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: Vivacious Box --------- Co-authored-by: Loymdayddaud <145969603+TheGiraffe3@users.noreply.github.com>
85 lines
2.7 KiB
TypeScript
85 lines
2.7 KiB
TypeScript
import { WinCheckExecution } from "../../../src/core/execution/WinCheckExecution";
|
|
import { GameMode } from "../../../src/core/game/Game";
|
|
import { setup } from "../../util/Setup";
|
|
|
|
describe("WinCheckExecution", () => {
|
|
let mg: any;
|
|
let winCheck: WinCheckExecution;
|
|
|
|
beforeEach(async () => {
|
|
mg = await setup("big_plains", {
|
|
infiniteGold: true,
|
|
gameMode: GameMode.FFA,
|
|
maxTimerValue: 5,
|
|
instantBuild: true,
|
|
});
|
|
mg.setWinner = jest.fn();
|
|
winCheck = new WinCheckExecution();
|
|
winCheck.init(mg, 0);
|
|
});
|
|
|
|
it("should call checkWinnerFFA in FFA mode", () => {
|
|
const spy = jest.spyOn(winCheck as any, "checkWinnerFFA");
|
|
winCheck.tick(10);
|
|
expect(spy).toHaveBeenCalled();
|
|
});
|
|
|
|
it("should call checkWinnerTeam in non-FFA mode", () => {
|
|
mg.config = jest.fn(() => ({
|
|
gameConfig: jest.fn(() => ({
|
|
maxTimerValue: 5,
|
|
gameMode: GameMode.Team,
|
|
})),
|
|
percentageTilesOwnedToWin: jest.fn(() => 50),
|
|
}));
|
|
winCheck.init(mg, 0);
|
|
const spy = jest.spyOn(winCheck as any, "checkWinnerTeam");
|
|
winCheck.tick(10);
|
|
expect(spy).toHaveBeenCalled();
|
|
});
|
|
|
|
it("should set winner in FFA if percentage is reached", () => {
|
|
const player = {
|
|
numTilesOwned: jest.fn(() => 81),
|
|
name: jest.fn(() => "P1"),
|
|
};
|
|
mg.players = jest.fn(() => [player]);
|
|
mg.numLandTiles = jest.fn(() => 100);
|
|
mg.numTilesWithFallout = jest.fn(() => 0);
|
|
winCheck.checkWinnerFFA();
|
|
expect(mg.setWinner).toHaveBeenCalledWith(player, expect.anything());
|
|
});
|
|
|
|
it("should set winner in FFA if timer is 0", () => {
|
|
const player = {
|
|
numTilesOwned: jest.fn(() => 10),
|
|
name: jest.fn(() => "P1"),
|
|
};
|
|
mg.players = jest.fn(() => [player]);
|
|
mg.numLandTiles = jest.fn(() => 100);
|
|
mg.numTilesWithFallout = jest.fn(() => 0);
|
|
mg.stats = jest.fn(() => ({ stats: () => ({ mocked: true }) }));
|
|
// Advance ticks until timeElapsed (in seconds) >= maxTimerValue * 60
|
|
// timeElapsed = (ticks - numSpawnPhaseTurns) / 10 =>
|
|
// ticks >= numSpawnPhaseTurns + maxTimerValue * 600
|
|
const threshold =
|
|
mg.config().numSpawnPhaseTurns() +
|
|
(mg.config().gameConfig().maxTimerValue ?? 0) * 600;
|
|
while (mg.ticks() < threshold) {
|
|
mg.executeNextTick();
|
|
}
|
|
winCheck.checkWinnerFFA();
|
|
expect(mg.setWinner).toHaveBeenCalledWith(player, expect.any(Object));
|
|
});
|
|
|
|
it("should not set winner if no players", () => {
|
|
mg.players = jest.fn(() => []);
|
|
winCheck.checkWinnerFFA();
|
|
expect(mg.setWinner).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("should return false for activeDuringSpawnPhase", () => {
|
|
expect(winCheck.activeDuringSpawnPhase()).toBe(false);
|
|
});
|
|
});
|