mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 17:46:46 +00:00
500b5fcfde
## Description: * Merged similar fields so they can be reused (eg warshipTarget => targetUnit) * simplified isCooldown api * added "touch" method to send update to UI layer * standardized on "undefined" ## Please complete the following: - [ ] I have added screenshots for all UI updates - [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: <DISCORD USERNAME> evan <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Unified and simplified how unit targets and cooldowns are managed across all unit types, resulting in more consistent in-game behavior for nukes, warships, trade ships, and SAM launchers. - Updated naming and logic for unit targeting and cooldowns, improving clarity in status displays and interactions. - Reorganized unit interface and streamlined cooldown handling for smoother gameplay experience. - **Bug Fixes** - Corrected visual indicators for nukes and warships to accurately reflect their targets. - **Tests** - Updated automated tests to align with the new cooldown and targeting logic. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
92 lines
2.6 KiB
TypeScript
92 lines
2.6 KiB
TypeScript
import { NukeExecution } from "../src/core/execution/NukeExecution";
|
|
import { SpawnExecution } from "../src/core/execution/SpawnExecution";
|
|
import {
|
|
Game,
|
|
Player,
|
|
PlayerInfo,
|
|
PlayerType,
|
|
UnitType,
|
|
} from "../src/core/game/Game";
|
|
import { TileRef } from "../src/core/game/GameMap";
|
|
import { setup } from "./util/Setup";
|
|
import { constructionExecution } from "./util/utils";
|
|
|
|
let game: Game;
|
|
let attacker: Player;
|
|
|
|
function attackerBuildsNuke(
|
|
source: TileRef | null,
|
|
target: TileRef,
|
|
initialize = true,
|
|
) {
|
|
game.addExecution(
|
|
new NukeExecution(UnitType.AtomBomb, attacker.id(), target, source),
|
|
);
|
|
if (initialize) {
|
|
game.executeNextTick();
|
|
game.executeNextTick();
|
|
}
|
|
}
|
|
|
|
describe("MissileSilo", () => {
|
|
beforeEach(async () => {
|
|
game = await setup("Plains", { infiniteGold: true, instantBuild: true });
|
|
const attacker_info = new PlayerInfo(
|
|
"fr",
|
|
"attacker_id",
|
|
PlayerType.Human,
|
|
null,
|
|
"attacker_id",
|
|
);
|
|
game.addPlayer(attacker_info);
|
|
|
|
game.addExecution(
|
|
new SpawnExecution(game.player(attacker_info.id).info(), game.ref(1, 1)),
|
|
);
|
|
|
|
while (game.inSpawnPhase()) {
|
|
game.executeNextTick();
|
|
}
|
|
|
|
attacker = game.player("attacker_id");
|
|
|
|
constructionExecution(game, attacker.id(), 1, 1, UnitType.MissileSilo);
|
|
});
|
|
|
|
test("missilesilo should launch nuke", async () => {
|
|
attackerBuildsNuke(null, game.ref(7, 7));
|
|
expect(attacker.units(UnitType.AtomBomb)).toHaveLength(1);
|
|
expect(attacker.units(UnitType.AtomBomb)[0].tile()).not.toBe(
|
|
game.map().ref(7, 7),
|
|
);
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
game.executeNextTick();
|
|
}
|
|
expect(attacker.units(UnitType.AtomBomb)).toHaveLength(0);
|
|
});
|
|
|
|
test("missilesilo should only launch one nuke at a time", async () => {
|
|
attackerBuildsNuke(null, game.ref(7, 7));
|
|
attackerBuildsNuke(null, game.ref(7, 7));
|
|
expect(attacker.units(UnitType.AtomBomb)).toHaveLength(1);
|
|
});
|
|
|
|
test("missilesilo should cooldown as long as configured", async () => {
|
|
expect(attacker.units(UnitType.MissileSilo)[0].isInCooldown()).toBeFalsy();
|
|
// send the nuke far enough away so it doesnt destroy the silo
|
|
attackerBuildsNuke(null, game.ref(50, 50));
|
|
expect(attacker.units(UnitType.AtomBomb)).toHaveLength(1);
|
|
|
|
for (let i = 0; i < game.config().SiloCooldown() - 2; i++) {
|
|
game.executeNextTick();
|
|
expect(
|
|
attacker.units(UnitType.MissileSilo)[0].isInCooldown(),
|
|
).toBeTruthy();
|
|
}
|
|
|
|
game.executeNextTick();
|
|
expect(attacker.units(UnitType.MissileSilo)[0].isInCooldown()).toBeFalsy();
|
|
});
|
|
});
|