import { describe, expect, it } from "vitest"; import { emptyTiers, gainExp, highestOpen, noCarry, runExp, startAbilities, toNext, unlockOf, withOriginRules, type CareerState } from "../src/game/rogue/careerRules.ts"; const base = { eloquence: 1, organization: 1, media: 1, finance: 1, integrity: 1 }; const fresh = (over: Partial = {}): CareerState => ({ id: "c", character: { id: "x", name: "林小美", party: "民主進步黨", background: "基層里長", points: { eloquence: 1, organization: 1, media: 1, finance: 1, integrity: 1 }, avatar: {} as never }, county: { code: "64000", name: "高雄市" }, village: null, villageTown: null, district: null, level: 1, exp: 0, skillPoints: 0, abilities: base, base, tiers: emptyTiers(), skipped: [], carry: noCarry(), history: [], pending: null, ...over, }); describe("政治生涯的練等規則", () => { it("一開始只能選里長;議員要先選上里長、而且 Lv 3", () => { const c = fresh(); expect(highestOpen(c)).toBe(1); expect(unlockOf(c, 2)).toEqual({ open: false, why: "先選上里長・要 Lv 3" }); const won = fresh({ tiers: { ...emptyTiers(), 1: { runs: 1, wins: 1, best: "B", topExtra: 0 } } }); expect(unlockOf(won, 2).why).toBe("要 Lv 3"); expect(unlockOf({ ...won, level: 3 }, 2).open).toBe(true); }); it("經驗:當選全額、落選四成、逆風越高越多、回去選低的關打六折", () => { const c = fresh(); expect(runExp(c, 1, true, "B", 0).exp).toBe(40); expect(runExp(c, 1, false, "C", 0).exp).toBe(16); expect(runExp(c, 1, true, "S", 2).exp).toBe(Math.round(40 * 1.3 * 1.5)); const higher = fresh({ level: 3, tiers: { ...emptyTiers(), 1: { runs: 1, wins: 1, best: "B", topExtra: 0 } } }); expect(runExp(higher, 1, true, "B", 0).exp).toBe(24); }); it("升級:經驗滿了升級,每級 +1 技能點,一次可以連升", () => { expect(toNext(1)).toBe(40); expect(toNext(2)).toBe(70); const { next, levels } = gainExp(fresh({ exp: 30 }), 90); expect(levels).toBe(2); expect(next.level).toBe(3); expect(next.exp).toBe(30 + 90 - 40 - 70); expect(next.skillPoints).toBe(2); }); it("選上總統要很多場:大約十幾到二十場才到 Lv 12", () => { let total = 0; for (let lv = 1; lv < 12; lv++) total += toNext(lv); expect(total).toBeGreaterThan(2000); }); }); describe("出身與黨的資源(18 第 53 項)", () => { it("小黨、無黨籍經驗 ×1.2", () => { const c = fresh(); const minor = { ...c, character: { ...c.character, party: null } }; expect(runExp(minor, 1, true, "B", 0).exp).toBe(Math.round(runExp(c, 1, true, "B", 0).exp * 1.2)); expect(runExp(minor, 1, true, "B", 0).why).toContain("無黨籍 ×1.2"); }); it("開局能力:捏人物配的點+出身 +1+黨的資源 +1;舊存檔換新規則時保留升等加的點", () => { const c = fresh(); // 基層里長:組織 +1;民進黨(大黨):組織 +1;每項自己配 1 點 expect(startAbilities(c.character)).toEqual({ eloquence: 1, organization: 3, media: 1, finance: 1, integrity: 1 }); // 第 2 版規則的存檔:角色還是舊版的點數(每項 5 點 → 清廉 0 級),升等在口才加了 2 點 const legacy = { ...c.character, points: undefined, stats: { fame: 5, eloquence: 5, strategy: 5, wealth: 5, network: 5 } } as unknown as CareerState["character"]; const old = { ...c, character: legacy, originRules: 2, base: { eloquence: 1, organization: 3, media: 1, finance: 1, integrity: 0 }, abilities: { eloquence: 3, organization: 3, media: 1, finance: 1, integrity: 0 } }; const next = withOriginRules(old); expect(next.character.points).toEqual({ eloquence: 1, organization: 1, media: 1, finance: 1, integrity: 1 }); expect("stats" in next.character).toBe(false); expect(next.base).toEqual(startAbilities(c.character)); expect(next.abilities).toEqual({ eloquence: 3, organization: 3, media: 1, finance: 1, integrity: 1 }); expect(withOriginRules(next)).toBe(next); }); });