mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 18:56:45 +00:00
f367ea1940
## Description: Conquests are currently mixing all player types. This is not ideal as people wonders why a 50 player game can lead to hundred of kills. Having separate records can also help with achievements and better balancing. This PR splits the conquests record into 3 categories: human, nations and bots. It is linked to this infra PR: https://github.com/openfrontio/infra/pull/246 <img width="895" height="497" alt="image" src="https://github.com/user-attachments/assets/66e49100-8114-4406-84ab-d9627355956d" /> While the recorded data make a distinction between bots/nations, it's only displayed here as a single "bot" category. ## 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: IngloriousTom
244 lines
5.3 KiB
TypeScript
244 lines
5.3 KiB
TypeScript
import {
|
|
Game,
|
|
Player,
|
|
PlayerInfo,
|
|
PlayerType,
|
|
UnitType,
|
|
} from "../src/core/game/Game";
|
|
import { Stats } from "../src/core/game/Stats";
|
|
import { StatsImpl } from "../src/core/game/StatsImpl";
|
|
import { replacer } from "../src/core/Util";
|
|
import { setup } from "./util/Setup";
|
|
|
|
let stats: Stats;
|
|
let game: Game;
|
|
let player1: Player;
|
|
let player2: Player;
|
|
|
|
describe("Stats", () => {
|
|
beforeEach(async () => {
|
|
stats = new StatsImpl();
|
|
game = await setup("half_land_half_ocean", {}, [
|
|
new PlayerInfo("boat dude", PlayerType.Human, "client1", "player_1_id"),
|
|
new PlayerInfo("boat dude", PlayerType.Human, "client2", "player_2_id"),
|
|
]);
|
|
|
|
while (game.inSpawnPhase()) {
|
|
game.executeNextTick();
|
|
}
|
|
|
|
player1 = game.player("player_1_id");
|
|
player2 = game.player("player_2_id");
|
|
});
|
|
|
|
test("attack", () => {
|
|
stats.attack(player1, player2, 1);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
attacks: [1n],
|
|
},
|
|
client2: {
|
|
attacks: [0n, 1n],
|
|
},
|
|
});
|
|
});
|
|
|
|
test("attackCancel", () => {
|
|
stats.attackCancel(player1, player2, 1);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
attacks: [-1n, 0n, 1n],
|
|
},
|
|
client2: {
|
|
attacks: [0n, -1n],
|
|
},
|
|
});
|
|
});
|
|
|
|
test("betray", () => {
|
|
stats.betray(player1);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
betrayals: 1n,
|
|
},
|
|
});
|
|
});
|
|
|
|
test("boatSendTrade", () => {
|
|
stats.boatSendTrade(player1, player2);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
boats: {
|
|
trade: [1n],
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
test("boatArriveTrade", () => {
|
|
stats.boatArriveTrade(player1, player2, 1);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
boats: { trade: [0n, 1n] },
|
|
gold: [0n, 0n, 1n],
|
|
},
|
|
client2: {
|
|
gold: [0n, 0n, 1n],
|
|
},
|
|
});
|
|
});
|
|
|
|
test("boatCapturedTrade", () => {
|
|
stats.boatCapturedTrade(player1, player2, 1);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
boats: { trade: [0n, 0n, 1n] },
|
|
gold: [0n, 0n, 0n, 1n],
|
|
},
|
|
});
|
|
});
|
|
|
|
test("boatDestroyTrade", () => {
|
|
stats.boatDestroyTrade(player1, player2);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
boats: { trade: [0n, 0n, 0n, 1n] },
|
|
},
|
|
});
|
|
});
|
|
|
|
test("boatSendTroops", () => {
|
|
stats.boatSendTroops(player1, player2, 1);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
boats: {
|
|
trans: [1n],
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
test("boatArriveTroops", () => {
|
|
stats.boatArriveTroops(player1, player2, 1);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
boats: { trans: [0n, 1n] },
|
|
},
|
|
});
|
|
});
|
|
|
|
test("boatDestroyTroops", () => {
|
|
stats.boatDestroyTroops(player1, player2, 1);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
boats: { trans: [0n, 0n, 0n, 1n] },
|
|
},
|
|
});
|
|
});
|
|
|
|
test("bombLaunch", () => {
|
|
stats.bombLaunch(player1, player2, UnitType.AtomBomb);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: { bombs: { abomb: [1n] } },
|
|
});
|
|
});
|
|
|
|
test("bombLand", () => {
|
|
stats.bombLand(player1, player2, UnitType.HydrogenBomb);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: { bombs: { hbomb: [0n, 1n] } },
|
|
});
|
|
});
|
|
|
|
test("bombIntercept", () => {
|
|
stats.bombIntercept(player1, UnitType.MIRVWarhead, 1);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: { bombs: { mirvw: [0n, 0n, 1n] } },
|
|
});
|
|
});
|
|
|
|
test("goldWar", () => {
|
|
stats.goldWar(player1, player2, 1);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
gold: [0n, 1n],
|
|
conquests: [1n],
|
|
},
|
|
});
|
|
stats.goldWar(player1, player2, 1);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
gold: [0n, 2n],
|
|
conquests: [2n],
|
|
},
|
|
});
|
|
});
|
|
|
|
test("goldWork", () => {
|
|
stats.goldWork(player1, 1);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: { gold: [1n] },
|
|
});
|
|
});
|
|
|
|
test("unitBuild", () => {
|
|
stats.unitBuild(player1, UnitType.City);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: { units: { city: [1n] } },
|
|
});
|
|
});
|
|
|
|
test("unitCapture", () => {
|
|
stats.unitCapture(player1, UnitType.DefensePost);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
units: {
|
|
defp: [0n, 0n, 1n],
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
test("unitDestroy", () => {
|
|
stats.unitDestroy(player1, UnitType.MissileSilo);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
units: {
|
|
silo: [0n, 1n],
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
test("unitLose", () => {
|
|
stats.unitLose(player1, UnitType.Port);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
units: {
|
|
port: [0n, 0n, 0n, 1n],
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
test("playerKilled", () => {
|
|
stats.playerKilled(player1, 10);
|
|
stats.playerKilled(player2, 40);
|
|
expect(stats.stats()).toStrictEqual({
|
|
client1: {
|
|
killedAt: 10n,
|
|
},
|
|
client2: {
|
|
killedAt: 40n,
|
|
},
|
|
});
|
|
});
|
|
|
|
test("stringify", () => {
|
|
stats.unitLose(player1, UnitType.Port);
|
|
expect(JSON.stringify(stats.stats(), replacer)).toBe(
|
|
'{"client1":{"units":{"port":["0","0","0","1"]}}}',
|
|
);
|
|
});
|
|
});
|