mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 18:40:53 +00:00
8f53785a80
## Description: - Removed the temporary UnitType.Construction and embedded construction state into real units via isUnderConstruction(). - Centralized non-structure spawning to perform a single validation right before unit creation/launch. - Updated UI layers to render construction state without relying on the removed enum. - Adjusted and created tests to match the new flow and to cover the no-refundscenarios. # Tests updated - tests/economy/ConstructionGold.test.ts: covers structure cost deduction and income, tolerant of passive income; ensures no refunds during construction. - tests/nukes/HydrogenAndMirv.test.ts: accounts for single-check launch flow; MIRV test targets a player-owned tile; ensures launch after payment. - tests/client/graphics/UILayer.test.ts: mocks now provide isUnderConstruction and real type strings; ## 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: CrackeRR1 --------- Co-authored-by: Evan <evanpelle@gmail.com>
108 lines
3.0 KiB
TypeScript
108 lines
3.0 KiB
TypeScript
import { PortExecution } from "../src/core/execution/PortExecution";
|
|
import {
|
|
Game,
|
|
Player,
|
|
PlayerInfo,
|
|
PlayerType,
|
|
UnitType,
|
|
} from "../src/core/game/Game";
|
|
import { setup } from "./util/Setup";
|
|
|
|
let game: Game;
|
|
let player: Player;
|
|
let other: Player;
|
|
|
|
describe("PortExecution", () => {
|
|
beforeEach(async () => {
|
|
game = await setup(
|
|
"half_land_half_ocean",
|
|
{
|
|
instantBuild: true,
|
|
},
|
|
[
|
|
new PlayerInfo("player", PlayerType.Human, null, "player_id"),
|
|
new PlayerInfo("other", PlayerType.Human, null, "other_id"),
|
|
],
|
|
);
|
|
|
|
while (game.inSpawnPhase()) {
|
|
game.executeNextTick();
|
|
}
|
|
|
|
player = game.player("player_id");
|
|
player.addGold(BigInt(1000000));
|
|
other = game.player("other_id");
|
|
|
|
game.config().structureMinDist = () => 10;
|
|
});
|
|
|
|
test("Destination ports chances scale with level", () => {
|
|
game.config().proximityBonusPortsNb = () => 0;
|
|
game.config().tradeShipShortRangeDebuff = () => 0;
|
|
|
|
player.conquer(game.ref(7, 10));
|
|
const spawn = player.canBuild(UnitType.Port, game.ref(7, 10));
|
|
if (spawn === false) {
|
|
throw new Error("Unable to build port for test");
|
|
}
|
|
const port = player.buildUnit(UnitType.Port, spawn, {});
|
|
const execution = new PortExecution(port);
|
|
execution.init(game, 0);
|
|
execution.tick(0);
|
|
|
|
other.conquer(game.ref(0, 0));
|
|
const otherPort = other.buildUnit(UnitType.Port, game.ref(0, 0), {});
|
|
otherPort.increaseLevel();
|
|
otherPort.increaseLevel();
|
|
|
|
const ports = execution.tradingPorts();
|
|
|
|
expect(ports.length).toBe(3);
|
|
});
|
|
|
|
test("Trade ship proximity bonus", () => {
|
|
game.config().proximityBonusPortsNb = () => 10;
|
|
game.config().tradeShipShortRangeDebuff = () => 0;
|
|
|
|
player.conquer(game.ref(7, 10));
|
|
const spawn = player.canBuild(UnitType.Port, game.ref(7, 10));
|
|
if (spawn === false) {
|
|
throw new Error("Unable to build port for test");
|
|
}
|
|
const port = player.buildUnit(UnitType.Port, spawn, {});
|
|
const execution = new PortExecution(port);
|
|
execution.init(game, 0);
|
|
execution.tick(0);
|
|
|
|
other.conquer(game.ref(0, 0));
|
|
other.buildUnit(UnitType.Port, game.ref(0, 0), {});
|
|
|
|
const ports = execution.tradingPorts();
|
|
|
|
expect(ports.length).toBe(2);
|
|
});
|
|
|
|
test("Trade ship short range debuff", () => {
|
|
game.config().proximityBonusPortsNb = () => 10;
|
|
// Short range debuff cancels out the proximity bonus.
|
|
game.config().tradeShipShortRangeDebuff = () => 100;
|
|
|
|
player.conquer(game.ref(7, 10));
|
|
const spawn = player.canBuild(UnitType.Port, game.ref(7, 10));
|
|
if (spawn === false) {
|
|
throw new Error("Unable to build port for test");
|
|
}
|
|
const port = player.buildUnit(UnitType.Port, spawn, {});
|
|
const execution = new PortExecution(port);
|
|
execution.init(game, 0);
|
|
execution.tick(0);
|
|
|
|
other.conquer(game.ref(0, 0));
|
|
other.buildUnit(UnitType.Port, game.ref(0, 0), {});
|
|
|
|
const ports = execution.tradingPorts();
|
|
|
|
expect(ports.length).toBe(1);
|
|
});
|
|
});
|