mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 16:30:16 +00:00
f1d162825e
Resolves #1041 ## Description: Remove the singleplayer spawn countdown so the game starts when the player spawns, spawn nations immediately after player spawn, and align game timer/max-timer timing with the new start point. Added a singleplayer regression test for spawn-immunity timing (GameImpl.test.ts) and updated spawn-phase loop tests to use gameType: GameType.Public where singleplayer behavior is not under test (e.g. MIRV/AI/Spawn/WinCheck-related suites), eliminating inSpawnPhase() timeout hangs after the new singleplayer start logic. https://github.com/user-attachments/assets/c07a585f-1153-490e-88ca-a91fc7ae5756 ## 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 ## Please put your Discord username so you can be contacted if a bug or regression is found: aotumuri
173 lines
5.2 KiB
TypeScript
173 lines
5.2 KiB
TypeScript
import { GameID } from "../../../src/core/Schemas";
|
|
import { AttackExecution } from "../../../src/core/execution/AttackExecution";
|
|
import { SpawnExecution } from "../../../src/core/execution/SpawnExecution";
|
|
//import { TransportShipExecution } from "../../../src/core/execution/TransportShipExecution";
|
|
import { AllianceRequestExecution } from "../../../src/core/execution/alliance/AllianceRequestExecution";
|
|
import {
|
|
Game,
|
|
GameType,
|
|
Player,
|
|
PlayerInfo,
|
|
PlayerType,
|
|
} from "../../../src/core/game/Game";
|
|
import { TileRef } from "../../../src/core/game/GameMap";
|
|
import { GameUpdateType } from "../../../src/core/game/GameUpdates";
|
|
import { setup } from "../../util/Setup";
|
|
|
|
const gameID: GameID = "game_id";
|
|
let game: Game;
|
|
let attacker: Player;
|
|
let defender: Player;
|
|
let defenderSpawn: TileRef;
|
|
let attackerSpawn: TileRef;
|
|
|
|
describe("GameImpl", () => {
|
|
beforeEach(async () => {
|
|
game = await setup("ocean_and_land", {
|
|
infiniteGold: true,
|
|
instantBuild: true,
|
|
infiniteTroops: true,
|
|
});
|
|
const attackerInfo = new PlayerInfo(
|
|
"attacker dude",
|
|
PlayerType.Human,
|
|
null,
|
|
"attacker_id",
|
|
);
|
|
game.addPlayer(attackerInfo);
|
|
const defenderInfo = new PlayerInfo(
|
|
"defender dude",
|
|
PlayerType.Human,
|
|
null,
|
|
"defender_id",
|
|
);
|
|
game.addPlayer(defenderInfo);
|
|
|
|
defenderSpawn = game.ref(0, 15);
|
|
attackerSpawn = game.ref(0, 14);
|
|
|
|
game.addExecution(
|
|
new SpawnExecution(
|
|
gameID,
|
|
game.player(attackerInfo.id).info(),
|
|
attackerSpawn,
|
|
),
|
|
new SpawnExecution(
|
|
gameID,
|
|
game.player(defenderInfo.id).info(),
|
|
defenderSpawn,
|
|
),
|
|
);
|
|
|
|
attacker = game.player(attackerInfo.id);
|
|
defender = game.player(defenderInfo.id);
|
|
});
|
|
|
|
test("Don't become traitor when betraying inactive player", async () => {
|
|
vi.spyOn(attacker, "canSendAllianceRequest").mockReturnValue(true);
|
|
vi.spyOn(defender, "canSendAllianceRequest").mockReturnValue(true);
|
|
game.addExecution(new AllianceRequestExecution(attacker, defender.id()));
|
|
game.executeNextTick();
|
|
|
|
game.addExecution(new AllianceRequestExecution(defender, attacker.id()));
|
|
game.executeNextTick();
|
|
|
|
expect(attacker.allianceWith(defender)).toBeTruthy();
|
|
expect(defender.allianceWith(attacker)).toBeTruthy();
|
|
|
|
//Defender is marked disconnected
|
|
defender.markDisconnected(true);
|
|
|
|
game.executeNextTick();
|
|
game.executeNextTick();
|
|
|
|
// STEP 1: First betray (manually break alliance)
|
|
const alliance = attacker.allianceWith(defender);
|
|
expect(alliance).toBeTruthy();
|
|
attacker.breakAlliance(alliance!);
|
|
|
|
// STEP 2: Then attack after betrayal
|
|
game.addExecution(new AttackExecution(100, attacker, defender.id()));
|
|
|
|
do {
|
|
game.executeNextTick();
|
|
} while (attacker.outgoingAttacks().length > 0);
|
|
|
|
expect(attacker.isTraitor()).toBe(false);
|
|
expect(attacker.allianceWith(defender)).toBeFalsy();
|
|
});
|
|
|
|
test("Do become traitor when betraying active player", async () => {
|
|
vi.spyOn(attacker, "canSendAllianceRequest").mockReturnValue(true);
|
|
vi.spyOn(defender, "canSendAllianceRequest").mockReturnValue(true);
|
|
game.addExecution(new AllianceRequestExecution(attacker, defender.id()));
|
|
game.executeNextTick();
|
|
|
|
game.addExecution(new AllianceRequestExecution(defender, attacker.id()));
|
|
game.executeNextTick();
|
|
|
|
expect(attacker.allianceWith(defender)).toBeTruthy();
|
|
expect(defender.allianceWith(attacker)).toBeTruthy();
|
|
|
|
//Defender is NOT marked disconnected
|
|
|
|
game.executeNextTick();
|
|
game.executeNextTick();
|
|
|
|
// First betray (manually break alliance)
|
|
const alliance = attacker.allianceWith(defender);
|
|
expect(alliance).toBeTruthy();
|
|
attacker.breakAlliance(alliance!);
|
|
|
|
game.executeNextTick();
|
|
|
|
game.addExecution(new AttackExecution(100, attacker, defender.id()));
|
|
|
|
do {
|
|
game.executeNextTick();
|
|
} while (attacker.outgoingAttacks().length > 0);
|
|
|
|
expect(attacker.isTraitor()).toBe(true);
|
|
expect(attacker.allianceWith(defender)).toBeFalsy();
|
|
});
|
|
|
|
test("Singleplayer late human spawn gets spawn immunity", async () => {
|
|
const singleplayerGame = await setup(
|
|
"plains",
|
|
{
|
|
gameType: GameType.Singleplayer,
|
|
},
|
|
[],
|
|
undefined,
|
|
undefined,
|
|
false,
|
|
);
|
|
(singleplayerGame.config() as any).setSpawnImmunityDuration(100);
|
|
|
|
const pastSpawnCountdown =
|
|
singleplayerGame.config().numSpawnPhaseTurns() + 20;
|
|
for (let i = 0; i < pastSpawnCountdown; i++) {
|
|
singleplayerGame.executeNextTick();
|
|
}
|
|
|
|
const lateHumanInfo = new PlayerInfo(
|
|
"late human",
|
|
PlayerType.Human,
|
|
"late_client_id",
|
|
"late_player_id",
|
|
);
|
|
|
|
singleplayerGame.addExecution(
|
|
new SpawnExecution(gameID, lateHumanInfo, singleplayerGame.ref(5, 5)),
|
|
);
|
|
|
|
// First tick initializes the execution, second tick applies the spawn.
|
|
singleplayerGame.executeNextTick();
|
|
const spawnUpdates = singleplayerGame.executeNextTick();
|
|
|
|
expect(singleplayerGame.player(lateHumanInfo.id).hasSpawned()).toBe(true);
|
|
expect(spawnUpdates[GameUpdateType.SpawnPhaseEnd]).toHaveLength(1);
|
|
expect(singleplayerGame.isSpawnImmunityActive()).toBe(true);
|
|
});
|
|
});
|