mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-10 15:04:36 +00:00
43d07ca85f
Tighten the package model around the determinism invariant: everything the
engine imports must itself be deterministic.
- Rename core-public -> engine-public (package, dir, `engine-public/*` alias,
all 118 import sites). It is the deterministic public surface the engine
depends on and that client/server also use.
- Move the pure formatting helpers (renderNumber/renderTroops) from shared
into engine-public/format — the engine uses them and they're deterministic.
- Drop the now-empty shared package (and its alias). `shared` was intended for
client/server-shared, engine-forbidden code; there is none yet, so it is
removed and can be re-added when such code appears.
Final graph: engine-public (leaf) <- engine <- {client, server};
client/server also -> engine-public.
Verified: tsc clean; 1364 + 65 tests pass; prod build succeeds; engine-public
is a leaf; engine has no client/server imports. Lockfile regenerated.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
101 lines
3.2 KiB
TypeScript
101 lines
3.2 KiB
TypeScript
import { SpawnExecution } from "engine/execution/SpawnExecution";
|
|
import { Game, Player, PlayerInfo, PlayerType } from "engine/game/Game";
|
|
import { GameID } from "engine-public/Schemas";
|
|
import { setup } from "./util/Setup";
|
|
|
|
const gameID: GameID = "test_game";
|
|
|
|
function addPlayerWithGold(
|
|
game: Game,
|
|
id: string,
|
|
type: PlayerType,
|
|
gold: bigint,
|
|
): Player {
|
|
game.addPlayer(new PlayerInfo(id, type, null, id));
|
|
const player = game.player(id);
|
|
player.addGold(gold);
|
|
return player;
|
|
}
|
|
|
|
describe("DefaultConfig.conquerGoldAmount", () => {
|
|
let game: Game;
|
|
|
|
beforeEach(async () => {
|
|
game = await setup("ocean_and_land");
|
|
});
|
|
|
|
test("returns full gold for Bot", () => {
|
|
const bot = addPlayerWithGold(game, "bot", PlayerType.Bot, 1000n);
|
|
expect(game.config().conquerGoldAmount(bot)).toBe(1000n);
|
|
});
|
|
|
|
test("returns full gold for Nation", () => {
|
|
const nation = addPlayerWithGold(game, "nation", PlayerType.Nation, 2000n);
|
|
expect(game.config().conquerGoldAmount(nation)).toBe(2000n);
|
|
});
|
|
|
|
test("returns half gold for Human", () => {
|
|
const human = addPlayerWithGold(game, "human", PlayerType.Human, 1000n);
|
|
expect(game.config().conquerGoldAmount(human)).toBe(500n);
|
|
});
|
|
});
|
|
|
|
describe("Conquest gold transfer", () => {
|
|
let game: Game;
|
|
let conqueror: Player;
|
|
|
|
beforeEach(async () => {
|
|
game = await setup("ocean_and_land");
|
|
const conquerorInfo = new PlayerInfo(
|
|
"conqueror",
|
|
PlayerType.Human,
|
|
null,
|
|
"conqueror",
|
|
);
|
|
game.addPlayer(conquerorInfo);
|
|
game.addExecution(
|
|
new SpawnExecution(gameID, conquerorInfo, game.ref(0, 10)),
|
|
);
|
|
conqueror = game.player(conquerorInfo.id);
|
|
});
|
|
|
|
test("conqueror receives 100% of gold when conquering a Bot", () => {
|
|
const bot = addPlayerWithGold(game, "bot", PlayerType.Bot, 1000n);
|
|
const goldBefore = conqueror.gold();
|
|
game.conquerPlayer(conqueror, bot);
|
|
expect(conqueror.gold()).toBe(goldBefore + 1000n);
|
|
expect(bot.gold()).toBe(0n);
|
|
});
|
|
|
|
test("conqueror receives 100% of gold when conquering a Nation", () => {
|
|
const nation = addPlayerWithGold(game, "nation", PlayerType.Nation, 800n);
|
|
const goldBefore = conqueror.gold();
|
|
game.conquerPlayer(conqueror, nation);
|
|
expect(conqueror.gold()).toBe(goldBefore + 800n);
|
|
expect(nation.gold()).toBe(0n);
|
|
});
|
|
|
|
test("conqueror receives 50% of gold when conquering a Human who has attacked", () => {
|
|
// clientID must be non-null for stats tracking to work
|
|
game.addPlayer(
|
|
new PlayerInfo("victim", PlayerType.Human, "victim_client", "victim"),
|
|
);
|
|
const victim = game.player("victim");
|
|
victim.addGold(1000n);
|
|
// Record an attack so the gold transfer is not skipped
|
|
game.stats().attack(victim, game.terraNullius(), 100);
|
|
const goldBefore = conqueror.gold();
|
|
game.conquerPlayer(conqueror, victim);
|
|
expect(conqueror.gold()).toBe(goldBefore + 500n);
|
|
expect(victim.gold()).toBe(0n);
|
|
});
|
|
|
|
test("conqueror receives no gold when conquering a Human who never attacked", () => {
|
|
const victim = addPlayerWithGold(game, "afk", PlayerType.Human, 1000n);
|
|
const goldBefore = conqueror.gold();
|
|
game.conquerPlayer(conqueror, victim);
|
|
expect(conqueror.gold()).toBe(goldBefore);
|
|
expect(victim.gold()).toBe(1000n);
|
|
});
|
|
});
|