election-game/backend/packages/rogue/test/overtime.test.ts

84 lines
3.5 KiB
TypeScript
Raw Normal View History

選戰卡牌第五版:趕場、政見支票、資源瘦身、新主畫面圖示、修 Bug 資源與載入(docs/27 第 1 節):首頁下載 8.7 → 1.6 MB、載入畫面 4.4 → 1.5 秒,進一局 5.0 → 1.3 MB - 中文字型切成 unicode-range 小片,照畫面出現的頻率排(art/fonts/split-webfonts.py),拿掉 Google Fonts; canvas 上的字(3D 看板、名牌、分享圖)字型片載好再畫一次(ui/canvasFont.ts) - 3D 模型 meshopt 壓縮、只留用到的動作(art/optimize-3d.mjs、game/gltf.ts),5.5 → 1.0 MB - 卡圖 320 px 小圖+srcset(art/cards-small.sh);木紋貼圖縮小;背景音樂改 Opus 96 kbps(art/music-opus.sh) - 新增 GET /api/scenarios/list 只回大廳用到的欄位(1.52 → 0.44 MB);伺服器沒有這條路由時前端改抓舊的清單 玩法(docs/27 第 2–4 節,研究桌遊機制後挑兩個做): - 趕場(推運氣):每週可以翻牌庫頂的牌免費打,越翻越容易翻車(POST /api/rogue/runs/:id/overtime) - 政見支票(藏起來的長期目標):第 1 週開跑記者會三選一或不開,開票時兌現全市加票、跳票掉票 新主畫面圖示:重畫投票箱(art/icon/icon.svg、render-icons.sh),apple-touch 滿版不透明,加 Android maskable 修 Bug: - 舊版伺服器沒有新路由時,首頁、政治生涯的紅色「Not Found」改成照樣能用;版本對不上時寫中文說明 - 捏人物「存起來,去政治生涯」直接選好剛捏的角色、跳到選家鄉 - 政見支票:開票畫面的兌現與否和開票結果一致(照投票日的票數判定);跳過=不開;模擬玩家都不開 - 趕場翻到的免費牌只免費一次 - 劇本清單算錯一次後不會一直回錯誤 - 分享圖的標語、減少動態效果時的 3D 看板,字型晚到後重畫 - Safari 解不開 OGG 時改放 MP3 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 09:04:19 +00:00
import { describe, expect, it } from "vitest";
import { cardCost } from "../src/cards.ts";
import { cardDef } from "../src/data.ts";
import { OVERTIME_FATIGUE, isSlip, overtime, overtimeBlocked, overtimeRisk } from "../src/overtime.ts";
import { createRun, playCard } from "../src/rules.ts";
import type { RunState } from "../src/state.ts";
import { tutorialSetup } from "../src/tutorial.ts";
import { toView } from "../src/view.ts";
import { SETUP, advance, must, toPlan } from "./fixtures.ts";
/** docs/27:趕場(推運氣) */
/** 體力用完、牌庫頂是指定的牌 */
function tired(top: string, seed = 3): RunState {
const s = structuredClone(toPlan(createRun(SETUP, "r", seed))) as RunState;
s.energy = 0;
s.draw.unshift({ uid: "top", id: top });
return s;
}
describe("趕場", () => {
it("體力用完才能趕場;新手教學不能", () => {
const s = toPlan(createRun(SETUP, "r", 3));
expect(s.energy).toBeGreaterThan(0);
expect(overtimeBlocked(s)).toBe("體力用完才能趕場");
const t = toPlan(createRun(tutorialSetup(), "t", 1, { tutorial: true }));
expect(overtimeBlocked({ ...t, energy: 0 })).toBe("新手教學不能趕場");
expect(toView(t).overtime).toBeNull();
});
it("翻到的牌這週不花體力,牌庫多兩張疲勞", () => {
const s = tired("walk");
const size = s.draw.length;
const r = must(overtime(s));
expect(r.hand.some((c) => c.uid === "top")).toBe(true);
expect(cardCost(r, cardDef("walk")!, "top").energy).toBe(0);
expect(r.draw.length).toBe(size - 1 + OVERTIME_FATIGUE);
expect(r.draw.filter((c) => c.id === "tired")).toHaveLength(OVERTIME_FATIGUE);
expect(toView(r).hand.find((c) => c.uid === "top")).toMatchObject({ cost: 0, overtime: true, blocked: null });
const played = playCard(r, "top", r.towns[0]!.code);
expect("error" in played).toBe(false);
// 只免費這一次:同一週洗回手上要照付體力
if (!("error" in played)) {
expect(played.state.overtime?.free).not.toContain("top");
expect(cardCost(played.state, cardDef("walk")!, "top").energy).toBe(cardDef("walk")!.cost);
}
});
it("翻到負面狀態牌就翻車:下週體力 −1、聲勢 −1、這週不能再趕", () => {
const s = tired("favor");
s.momentum = 2;
const r = must(overtime(s));
expect(r.momentum).toBe(1);
expect(r.energyNext).toBe(s.energyNext - 1);
expect(r.overtime?.done).toBe(true);
expect(overtimeBlocked(r)).toBe("這週翻車了,明天再趕");
expect(r.stats.busts).toBe(1);
// 下一週重新開始:可以再趕場,體力少 1
const next = advance(r, 2);
expect(next.overtime).toBeNull();
expect(next.energy).toBe(next.energyMax - 1);
});
it("好的狀態牌(黨部動員掃街)不算翻車", () => {
expect(isSlip("walkx")).toBe(false);
expect(isSlip("tired")).toBe(true);
expect(isSlip("reporter")).toBe(true);
const r = must(overtime(tired("walkx")));
expect(r.overtime?.done).toBe(false);
});
it("風險=下一疊牌裡的負面狀態牌;抽牌堆空了看棄牌堆", () => {
const s = tired("walk");
s.draw = [{ uid: "a", id: "walk" }, { uid: "b", id: "tired" }];
expect(overtimeRisk(s)).toEqual({ bad: 1, total: 2 });
s.draw = [];
s.discard = [{ uid: "c", id: "favor" }, { uid: "d", id: "walk" }, { uid: "e", id: "tv" }];
expect(overtimeRisk(s)).toEqual({ bad: 1, total: 3 });
const r = must(overtime(s));
expect(r.discard).toHaveLength(0);
expect(r.overtime!.flips).toBe(1);
});
});