From 0e24ee6a16e5f703f7f6eb0eb62038e6301ca800 Mon Sep 17 00:00:00 2001 From: daniel wang Date: Wed, 28 Oct 2026 17:45:05 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=B8=E6=88=B0=E5=8D=A1=E7=89=8C=EF=BC=9A?= =?UTF-8?q?=E5=B0=8D=E6=89=8B=E8=A6=8F=E5=89=87=E3=80=81=E9=9A=A8=E6=A9=9F?= =?UTF-8?q?=E8=A1=8C=E4=BA=8B=E6=9B=86=E3=80=81=E6=B5=81=E6=B4=BE=E6=A0=B8?= =?UTF-8?q?=E5=BF=83=E7=89=8C=E3=80=81=E7=B2=BE=E8=8B=B1=E7=AB=99=E3=80=81?= =?UTF-8?q?=E5=B1=80=E4=B8=AD=E5=B0=8F=E5=8B=9D=E5=88=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 每局不一樣(docs/25 第 3、4 節) - 對手規則 7 條(名嘴加持、地方大老、大打空戰、鐵票區、網路謠言、地毯式掃街、形象牌),開局抽 1 條,逆風 5 起 2 條 - 辯論、民調、黑函的週次每局隨機;上方週次標出大場面 - 精英站「地方派系談判」:接下挑戰,下週在指定的區淨增票數,達成拿稀有幕僚 - 下一站畫面看得到下下週的門 流派與小勝利(第 2、5 節) - 9 張流派核心牌、5 位改規則的幕僚 - 翻區抽牌(每週最多 2 張)、民調領先多一張稀有牌、落後下週體力 +1、結果頁標出最關鍵的一區 選人與手感(第 1、7 節) - 選人畫面顯示候選人類型、技能、弱點與這個類型的逆風紀錄(伺服器啟動時先算好,人物查詢改用姓名索引) - 出牌不等伺服器:牌先飛出去、手牌體力先扣,伺服器回來校正 - 設定加「快速模式」:開票夜、週末結算、選情快報快一倍 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Uirha5kfuiGbEBhsk7ijDg --- backend/apps/server/src/app.ts | 28 ++- backend/apps/server/src/main.ts | 2 +- backend/apps/server/src/people-routes.ts | 19 +- backend/docs/25-gameplay-v3.md | 26 ++- backend/docs/README.md | 4 +- backend/packages/protocol/src/common.ts | 4 + backend/packages/protocol/src/game.ts | 4 +- backend/packages/protocol/src/rogue.ts | 14 +- backend/packages/rogue/src/advisors.ts | 6 + backend/packages/rogue/src/bots.ts | 5 + backend/packages/rogue/src/cards.ts | 78 +++++++- backend/packages/rogue/src/data.ts | 33 +++- backend/packages/rogue/src/mechanics.ts | 20 +- backend/packages/rogue/src/rival.ts | 81 +++++++- backend/packages/rogue/src/route.ts | 39 +++- backend/packages/rogue/src/rules.ts | 87 ++++++++- backend/packages/rogue/src/scenes.ts | 48 ++++- backend/packages/rogue/src/state.ts | 25 ++- backend/packages/rogue/src/view.ts | 37 +++- backend/packages/rogue/test/schools.test.ts | 153 +++++++++++++++ backend/packages/rogue/test/variety.test.ts | 206 ++++++++++++++++++++ web/src/game/audio/settings.ts | 7 +- web/src/game/hud/SettingsMenu.tsx | 4 + web/src/game/rogue/RogueScreen.tsx | 16 +- web/src/game/rogue/RogueStart.tsx | 22 ++- web/src/game/rogue/brief.tsx | 8 +- web/src/game/rogue/finale.tsx | 10 +- web/src/game/rogue/flow.tsx | 49 +++-- web/src/game/rogue/overlays.tsx | 2 +- web/src/game/rogue/parts.tsx | 42 +++- web/src/game/rogue/rogue-finale.css | 2 + web/src/game/rogue/rogue-flow.css | 3 + web/src/game/rogue/rogue-start.css | 4 + web/src/game/rogue/rogue.css | 5 + web/src/game/rogue/weekend.tsx | 6 +- 35 files changed, 1003 insertions(+), 96 deletions(-) create mode 100644 backend/packages/rogue/test/schools.test.ts create mode 100644 backend/packages/rogue/test/variety.test.ts diff --git a/backend/apps/server/src/app.ts b/backend/apps/server/src/app.ts index bef4050..96d9add 100644 --- a/backend/apps/server/src/app.ts +++ b/backend/apps/server/src/app.ts @@ -7,12 +7,12 @@ import { CONTENT, candidateStats, personName, withCustomCandidate } from "@elect import { loadScenarioRegistry, type ScenarioRegistry } from "@election2026/scenarios"; import { DEFAULT_PARAMS, buildPackData, type PackData, type PackFiles, type Scenario } from "@election2026/engine"; import { DEFAULT_PACKS_ROOT, loadGenders, loadPackFiles, loadSlogans } from "@election2026/pack-loader"; -import { cleanAvatar, type ApiError, type ScenarioSummary } from "@election2026/protocol"; +import { cleanAvatar, type ApiError, type RogueArchetype, type ScenarioSummary } from "@election2026/protocol"; import Fastify, { type FastifyInstance, type FastifyReply } from "fastify"; import type { z } from "zod"; import type { CouncilDistrict } from "@election2026/rogue/local"; import type { TopologyLike } from "@election2026/rogue/setup"; -import { registerRogue } from "./rogue-routes.ts"; +import { realArchetype, registerRogue } from "./rogue-routes.ts"; import { registerPeople } from "./people-routes.ts"; export interface AppOptions { @@ -28,6 +28,8 @@ export interface AppOptions { rogueSaveDir?: string | null; /** 議員選區檔;沒給就用 data/build/council/2022.json */ councilFile?: string; + /** 啟動後在背景先算好每位候選人的類型(正式啟動用;測試不需要) */ + warmArchetypes?: boolean; } const DEFAULT_COUNCIL_FILE = fileURLToPath(new URL("../../../data/build/council/2022.json", import.meta.url)); @@ -54,7 +56,7 @@ function withSlogans(s: Scenario, slogans: Slogans): Scenario { }; } -function summary(raw: Scenario, genders: Readonly>, slogans: Slogans): ScenarioSummary { +function summary(raw: Scenario, genders: Readonly>, slogans: Slogans, archetypes: ReadonlyMap): ScenarioSummary { const s = withSlogans(raw, slogans); return { id: s.id, @@ -89,6 +91,7 @@ function summary(raw: Scenario, genders: Readonly>, sl slogan: c.slogan ?? null, sloganSource: c.sloganSource ?? null, stats: candidateStats(s, c), + archetype: archetypes.get(`${s.id}|${c.id}`) ?? null, })), notes: [...s.notes], sources: s.sources.map((x) => ({ ...x })), @@ -141,7 +144,24 @@ export async function buildApp(options: AppOptions = {}): Promise ({ ok: true })); - app.get("/api/scenarios", async () => registry.all.map((s) => summary(s, genders, slogans))); + // 每位候選人的類型(docs/25,依中選會選舉紀錄):第一次要劇本清單時算一次(正式啟動時在背景先算),之後用快取 + let archetypes: Promise> | null = null; + const archetypesOf = (): Promise> => + (archetypes ??= (async () => { + const out = new Map(); + for (const s of registry.all) + for (const c of s.candidates) { + const record = await people.abilitiesFor(personName(c.name), s.region.countyCode, s.electionDate); + out.set(`${s.id}|${c.id}`, realArchetype(record, candidateStats(s, c).wealth).archetype); + } + return out; + })()); + app.get("/api/scenarios", async () => { + const types = await archetypesOf(); + return registry.all.map((s) => summary(s, genders, slogans, types)); + }); + // 啟動後馬上在背景算好,首頁第一次要劇本清單就不用等(people 在下面才註冊,所以排到下一輪) + if (options.warmArchetypes) setImmediate(() => void archetypesOf().catch(() => (archetypes = null))); const topologies = new Map>(); let council: Promise | null = null; diff --git a/backend/apps/server/src/main.ts b/backend/apps/server/src/main.ts index c0aa362..c534a62 100644 --- a/backend/apps/server/src/main.ts +++ b/backend/apps/server/src/main.ts @@ -6,5 +6,5 @@ const host = process.env.HOST ?? "127.0.0.1"; /** 選戰卡牌的存檔(每一局一個 JSON 檔),伺服器重開也能繼續玩 */ const rogueSaveDir = process.env.ROGUE_SAVE_DIR ?? fileURLToPath(new URL("../../../data/runs/", import.meta.url)); -const app = await buildApp({ logger: true, rogueSaveDir }); +const app = await buildApp({ logger: true, rogueSaveDir, warmArchetypes: true }); await app.listen({ port, host }); diff --git a/backend/apps/server/src/people-routes.ts b/backend/apps/server/src/people-routes.ts index 54915d0..bf2f0b8 100644 --- a/backend/apps/server/src/people-routes.ts +++ b/backend/apps/server/src/people-routes.ts @@ -94,10 +94,27 @@ const NATIONWIDE = "00000"; * 同名的還有好幾位時,有「這場選舉本身」紀錄的那一位優先(同一天投票、同一個縣市;總統選舉看總統副總統紀錄)。 * 這場選舉本身的紀錄只拿來認人,不算進能力。 */ +/** 依姓名索引(同一份名單只建一次):劇本清單一次要查兩千多位候選人 */ +const byName = new WeakMap>(); +function peopleNamed(people: readonly PersonRecord[], key: string): readonly PersonRecord[] { + let index = byName.get(people); + if (!index) { + index = new Map(); + for (const p of people) { + const k = searchKey(p.name); + const list = index.get(k); + if (list) list.push(p); + else index.set(k, [p]); + } + byName.set(people, index); + } + return index.get(key) ?? []; +} + function findPerson(people: readonly PersonRecord[], name: string, countyCode: string, date: string): PersonRecord | null { const key = searchKey(name); const nationwide = countyCode === NATIONWIDE; - const named = people.filter((p) => searchKey(p.name) === key && p.confidence !== "low" && (nationwide || p.runs.some((r) => r.countyCode === countyCode))); + const named = peopleNamed(people, key).filter((p) => p.confidence !== "low" && (nationwide || p.runs.some((r) => r.countyCode === countyCode))); if (named.length === 1) return named[0]!; const same = named.filter((p) => p.runs.some((r) => r.date === date && (nationwide ? r.office === "president" : r.countyCode === countyCode))); return same.length === 1 ? same[0]! : null; diff --git a/backend/docs/25-gameplay-v3.md b/backend/docs/25-gameplay-v3.md index 693ec5a..3ebabc5 100644 --- a/backend/docs/25-gameplay-v3.md +++ b/backend/docs/25-gameplay-v3.md @@ -9,14 +9,28 @@ | 節 | 狀態 | 實際做法 | |---|---|---| | 1a 本命區 | 完成 | `rogue/src/archetypes.ts` 的 `homeTowns`;雙方都有。你的牌 ×1.2、失守聲勢 −2;攻下對手的本命區聲勢 +2、對手下週少一個行動(`rivalStun`);對手在自己本命區 ×1.2。新牌「回鄉造勢」(`homecoming`,只能打在本命區) | -| 1b 類型與技能 | 完成(數字已依模擬調過) | 六種類型照規格,調整:黑馬型每點聲勢 +12%(規格 +16% 太強)、財務型每週 +150 萬、地面牌 −5%。真實候選人:資歷三項取最高,同級比實際數字超過門檻多少;資歷都是 0 才看經費(多 → 財務型,少 → 黑馬型)。2022 縣市長 42 位主要候選人:組織 20、媒體 9、資深 7、財務 5、黑馬 1。每日一戰也套用。對手的類型還沒做 | +| 1b 類型與技能 | 完成(數字已依模擬調過) | 六種類型照規格,調整:黑馬型每點聲勢 +12%(規格 +16% 太強)、財務型每週 +150 萬、地面牌 −5%。真實候選人:資歷三項取最高,同級比實際數字超過門檻多少;資歷都是 0 才看經費(多 → 財務型,少 → 黑馬型)。2022 縣市長 42 位主要候選人:組織 20、媒體 9、資深 7、財務 5、黑馬 1。每日一戰也套用;選人畫面就看得到類型(`/api/scenarios` 的 `archetype`,伺服器啟動時先算好)。對手的類型還沒做 | | 1c 接上流派 | 完成 | 下一站、物資行裡和類型搭配的牌、幕僚權重 ×1.5,牌面標「適合你的類型」 | -| 7 再來一局 | 部分 | 結果頁:贏了就有「挑戰逆風 N+1 級」(已解鎖就出現,不只剛解鎖那次)、Enter 直接再來、「攻下一塊地盤」(隨機挑還沒打下的縣市開新局)。出牌不等伺服器、快速模式還沒做 | -| 8 跨局進度 | 部分 | 完成度:全台制霸(22 縣市+總統大選)、六種類型、類型逆風挑戰(每種類型 0–10 級)、成就;大廳一條、圖鑑完整面板(`web/src/game/rogue/Completion.tsx`、`progress.ts`)。聲望解鎖新牌還沒做 | -| 2、3、4、5、6 | 還沒做 | 流派核心牌、對手規則與精英站、隨機行事曆、局中小勝利、難度重調 | +| 2 流派與爆分 | 完成 | 9 張核心牌(走透透、挨家挨戶、樁腳網、聲量滾雪球、懶人包、反將一軍、沙盤推演、地毯式廣告、小額募款)+5 位幕僚(鐵腿、派系協調人、懶人包小編、危機變轉機、精算師)。「全面動員令+」沒改。插圖先共用主題相近的 | +| 3 對手規則與精英站 | 完成 | 7 條規則(名嘴加持、地方大老、大打空戰、鐵票區、網路謠言、地毯式掃街、形象牌;後發制人維持原本的風格),逆風 5 起抽 2 條。精英站「地方派系談判」:第 2、4 週結束後可能出現,選了就接下挑戰(不進門),下週結算。下一站畫面灰色顯示下下週的門(到時候不能用的會重抽) | +| 4 隨機行事曆 | 部分 | 8 週的局辯論 3–5、民調 4–5、黑函 5–6 週,5 種排法;上方週次標「辯、民、函、勢、夜」。地方事件週(遶境、義民祭…)還沒做 | +| 5 局中小勝利 | 完成 | 翻區抽牌(每週最多 2 張,黑馬型另外再抽);民調領先多一張稀有牌(偏向你的類型)、落後下週體力 +1;結果頁標「最關鍵的一區」 | +| 6 張力與難度 | 不改基準數字 | 見下面的模擬。預估數字照舊完整顯示(docs/21 的決定:畫面上的數字和打出去一致) | +| 7 再來一局 | 完成 | 結果頁:贏了就有「挑戰逆風 N+1 級」(已解鎖就出現)、Enter 直接再來、「攻下一塊地盤」;出牌不等伺服器(牌先飛出去、手牌體力先扣,伺服器回來校正);設定的「快速模式」讓開票夜、週末結算、選情快報快一倍 | +| 8 跨局進度 | 部分 | 完成度:全台制霸(22 縣市+總統大選)、六種類型、類型逆風挑戰(每種類型 0–10 級)、成就;大廳一條、圖鑑完整面板(`web/src/game/rogue/Completion.tsx`、`progress.ts`);選人畫面顯示這個類型的逆風紀錄。聲望解鎖新牌沒做(新牌直接進獎勵池) | -模擬(`node apps/sim/src/rogue-balance.ts --archetypes all`,桃園 2022 勢均力敵,每種 80 局):「打得好」六種類型都 100% 勝,平均差距 +7.8~+12 個百分點; -標準難度對會打的人太簡單的問題(第 6 節)還在,目前靠「贏了直接挑戰下一級逆風」與類型逆風挑戰讓會打的人往上爬。 +模擬(`node apps/sim/src/rogue-balance.ts`,桃園 2022 勢均力敵,每種 100 局,兩位候選人): + +| 難度 | 打得好(greedy) | 隨手玩(casual) | 只拿地面/空戰/攻防牌 | +|---|---|---|---| +| 標準 | 99–100%(差距 +7.6~+8.0) | 45–46%(加對手規則前是 52–65%) | 差距 +8.0~+8.3/+6.4~+6.6/+6.1 | +| 逆風 6 | 67–74% | 6–10% | — | + +六種類型分開跑(`--archetypes all`):「打得好」都 98–100%,差距 +6.7~+10.7;「隨手玩」30–68%(財務型、資深型最難,黑馬型、組織型最容易)。 + +第 6 節的兩個目標(打得好 75–85%、隨手玩 35–45%)在目前的技術差距下互相衝突:兩種玩家差 8 個百分點, +把會打的人壓到 85% 以下,隨手玩會掉到一成左右。所以標準難度不再加難(隨手玩已經落在目標裡), +會打的人靠「贏了直接挑戰下一級逆風」往上爬(逆風 6 約七成)。流派核心牌讓單一流派接近混打,但還沒有超過混打(規格目標 +5~10),之後可以再加強核心牌的倍率。 ## 0. 現況診斷 diff --git a/backend/docs/README.md b/backend/docs/README.md index 8b71190..ac29196 100644 --- a/backend/docs/README.md +++ b/backend/docs/README.md @@ -57,8 +57,8 @@ backend/packages ──► backend/apps/server(Fastify,REST /api)──► | `rules.ts` | `createRun`、`endWeek`、`choose`、`ultimate`,以及從 `cards.ts` 轉出的 `playCard`:每個動作回傳新的狀態 | | `state.ts` | `RunState`、`TOTAL_WEEKS = 8`、存檔版本 `SAVE_VERSION` 與 `migrateRun` | | `data.ts`、`cards.ts` | 牌的資料與效果 | -| `rival.ts` | 對手每週的意圖與行動 | -| `route.ts`、`scenes.ts`、`content.ts` | 每週結束的「下一站」、辯論/民調/黑函週、堵麥與地方抉擇 | +| `rival.ts` | 對手每週的意圖與行動;每局抽的對手規則(docs/25) | +| `route.ts`、`scenes.ts`、`content.ts` | 每週結束的「下一站」(含地方派系談判、下下週的門)、辯論/民調/黑函週(週次每局隨機)、堵麥與地方抉擇 | | `advisors.ts`、`feats.ts`、`meta.ts`、`ultimate.ts`、`mechanics.ts` | 幕僚、成就、生涯能力與政策、大絕招、逆風等級 | | `view.ts` | 給前端的玩家視角(含每張手牌打在每一區的預估) | | `tutorial.ts`、`bots.ts` | 新手教學;模擬玩家(平衡報告用) | diff --git a/backend/packages/protocol/src/common.ts b/backend/packages/protocol/src/common.ts index 51a103f..ad43e7b 100644 --- a/backend/packages/protocol/src/common.ts +++ b/backend/packages/protocol/src/common.ts @@ -32,3 +32,7 @@ export const SourceList = z.object({ sources: z.array(SourceRef), }); export type SourceList = z.infer; + +/** 候選人類型(docs/25):真實候選人依中選會選舉紀錄、自創角色依出身;決定選戰卡牌的技能與弱點 */ +export const RogueArchetype = z.enum(["media", "organization", "eloquence", "finance", "integrity", "newcomer"]); +export type RogueArchetype = z.infer; diff --git a/backend/packages/protocol/src/game.ts b/backend/packages/protocol/src/game.ts index 2d9cad0..8e2a6d5 100644 --- a/backend/packages/protocol/src/game.ts +++ b/backend/packages/protocol/src/game.ts @@ -1,5 +1,5 @@ import { z } from "zod"; -import { TownCode, VillageCode } from "./common.ts"; +import { RogueArchetype, TownCode, VillageCode } from "./common.ts"; import { PARTY_NAMES } from "./parties.ts"; const PARTY_SET = new Set(PARTY_NAMES); @@ -448,6 +448,8 @@ export const ScenarioSummary = z.object({ stats: CandidateStats.optional(), /** 歷史劇本:真實的政治獻金收支(元) */ realFinance: z.object({ income: z.number().int(), spending: z.number().int() }).nullable(), + /** 選戰卡牌的候選人類型(docs/25,依中選會選舉紀錄);伺服器還沒算好是 null */ + archetype: RogueArchetype.nullable().default(null), }), ), /** 數字的出處,以及哪些是遊戲設定 */ diff --git a/backend/packages/protocol/src/rogue.ts b/backend/packages/protocol/src/rogue.ts index 5a940db..58f40d2 100644 --- a/backend/packages/protocol/src/rogue.ts +++ b/backend/packages/protocol/src/rogue.ts @@ -1,4 +1,5 @@ import { z } from "zod"; +import { RogueArchetype } from "./common.ts"; import { CandidatePublic, CustomCandidate } from "./game.ts"; /** @@ -11,9 +12,6 @@ export type RogueTrait = z.infer; export const RogueOwner = z.enum(["you", "rival"]).nullable(); -/** 候選人類型(docs/25):真實候選人依中選會選舉紀錄、自創角色依出身;決定技能與弱點 */ -export const RogueArchetype = z.enum(["media", "organization", "eloquence", "finance", "integrity", "newcomer"]); -export type RogueArchetype = z.infer; export const RogueTown = z.object({ code: z.string(), @@ -228,7 +226,7 @@ export const IslandBuilding = z.object({ }); export type IslandBuilding = z.infer; -export const RogueStopKind = z.enum(["card", "advisor", "upgrade", "remove", "shop", "encounter", "event", "minigame"]); +export const RogueStopKind = z.enum(["card", "advisor", "upgrade", "remove", "shop", "encounter", "event", "minigame", "elite"]); export type RogueStopKind = z.infer; /** 獎勵、商店上的一個選項(牌或幕僚) */ @@ -366,6 +364,14 @@ export const RogueView = z.object({ others: z.array(CandidatePublic), /** 雙方的代表色(政黨色;同一個顏色或教學關卡用別的顏色區分) */ colors: z.object({ you: z.string(), rival: z.string() }), + /** 這局的行事曆(docs/25):辯論、民調、黑函、對手大型造勢在第幾週;新手教學是 null */ + schedule: z.object({ debate: z.number().int(), poll: z.number().int(), crisis: z.number().int(), bigRally: z.number().int().nullable() }).nullable().default(null), + /** 下下週的門(docs/25:看得到前方):選下一站的時候灰色顯示 */ + nextRoute: z.array(z.object({ kind: RogueStopKind, title: z.string() })).nullable().default(null), + /** 地方派系談判(精英站,docs/25):這週在哪一區淨增多少票;progress 是目前淨增 */ + contract: z.object({ town: z.string(), name: z.string(), goal: z.number().int(), progress: z.number().int() }).nullable().default(null), + /** 這局對手的規則(docs/25):整局有效 */ + rivalRules: z.array(z.object({ id: z.string(), name: z.string(), text: z.string() })).default([]), /** 你的候選人特色(docs/25):類型、技能、弱點與依據;新手教學、舊存檔是 null */ identity: z .object({ diff --git a/backend/packages/rogue/src/advisors.ts b/backend/packages/rogue/src/advisors.ts index 39666ff..1fd182d 100644 --- a/backend/packages/rogue/src/advisors.ts +++ b/backend/packages/rogue/src/advisors.ts @@ -18,6 +18,12 @@ export const ADVISORS: readonly AdvisorDef[] = [ { id: "hakka_director", name: "客家事務主任", art: "visit_associations", text: "打在客家庄的牌 +50%", school: "ground" }, { id: "farm_ally", name: "農會總幹事", art: "homecoming", text: "打在地廣人稀的區的牌 +50%", school: "ground" }, { id: "student_leader", name: "學生會長", art: "forum", text: "打在年輕人多的區的牌 +40%", school: "ground" }, + // 流派的改規則幕僚(docs/25 第 2 節) + { id: "iron_legs", name: "鐵腿", art: "grassroots_walk", text: "一週在 3 個以上不同的區出牌,週末聲勢 +2", school: "ground" }, + { id: "faction_broker", name: "派系協調人", art: "banquet", text: "你的樁腳擋下對手的票,一半變成你的", school: "org" }, + { id: "meme_editor", name: "懶人包小編", art: "influencer_live", text: "爆紅之後,那張牌回到手上(每週一次)", school: "air" }, + { id: "crisis_flip", name: "危機變轉機", art: "crisis_pr", text: "每擋下對手一次批評,週末聲勢 +1", school: "defend" }, + { id: "actuary", name: "精算師", art: "self_fund", text: "週末存款每 100 萬多 5 萬利息(最多 +50 萬)", school: "money" }, { id: "truck_captain", name: "宣傳車隊長", art: "sound_truck", text: "打在某區的地面牌,隔壁每一區也有兩成效果", school: "ground" }, { id: "social_editor", name: "網路小編", art: "online_ad", text: "每週第一張網路牌不花體力", school: "air" }, diff --git a/backend/packages/rogue/src/bots.ts b/backend/packages/rogue/src/bots.ts index faaff55..96f1e7c 100644 --- a/backend/packages/rogue/src/bots.ts +++ b/backend/packages/rogue/src/bots.ts @@ -121,11 +121,13 @@ const CARD_TASTE: Record = { rally: 5, pilgrimage: 5, celebrity: 4.5, door: 4, tv: 4, counter: 4, office: 4, online: 3.5, oath: 3.5, kneel: 4, night: 3, calls: 3, clarify: 3, expose: 2.5, probe: 2.5, live: 3, talk: 2.5, walk: 2.5, small: 2, breakfast: 3.5, park: 3, campus: 3, hakka: 2.5, weddings: 3, truck: 4, banquet: 3.5, endorse: 3.5, billboard: 3, volunteers: 3.5, phonebank: 3.5, mobilize: 3, allnighter: 3, shorts: 3, line: 3.5, radio: 3, flyers: 3, policy: 3.5, whitepaper: 3, mediatraining: 3.5, fieldwork: 3.5, factcheck: 3, contrast: 3, selffund: 2.5, tycoon: 2, elder: 4, + legwork: 3.5, doorstep: 4, network: 3.5, buzz: 3.5, explainer: 3.5, turntable: 3, wargame: 3, carpetads: 3, microdonate: 2.5, }; const ADVISOR_TASTE: Record = { chief: 5, youth_corps: 4.5, scheduler: 4, combo_coach: 4, rally_king: 3.5, temple_master: 3, market_auntie: 3.5, ad_planner: 3, tycoon: 3, old_stake: 2.5, spin_doctor: 3, social_editor: 2.5, muckraker: 2.5, opener: 4, night_owl: 3.5, truck_captain: 3.5, councilors: 3, iron_base: 3, party_org: 3.5, volunteer_lead: 3.5, mascot: 3, pollster: 3, fundraiser: 2.5, cfo: 2.5, lawyer: 2.5, crisis_team: 2.5, debate_coach: 3, influencer: 2.5, speechwriter: 3, hakka_director: 2, farm_ally: 2, student_leader: 2.5, + iron_legs: 3.5, faction_broker: 3, meme_editor: 2.5, crisis_flip: 3, actuary: 2.5, }; const ARCHETYPE_TAGS: Partial> = { ground: ["ground", "rally", "org"], air: ["media", "online", "tv", "press"], attack: ["attack", "intel", "press", "defend"] }; const ARCHETYPE_SCHOOL: Partial> = { ground: ["ground", "org", "any"], air: ["air", "any", "money"], attack: ["defend", "any", "air"] }; @@ -212,6 +214,7 @@ function routeScore(s: RunState, bot: BotName, kind: StopKind): number { encounter: 2.4, event: 2.2, minigame: 2.3, + elite: 2.5, }; if (bot === "attack" && kind === "encounter") return 1; return scores[kind]; @@ -251,6 +254,8 @@ function pickStopFor(s: RunState, bot: BotName, d: Dice): { pick: number | "skip const stop = s.stop!; const randomish = !smart(bot); switch (stop.kind) { + case "elite": + return { pick: "skip", target: null }; case "card": { if (randomish) return { pick: Math.floor(d.next() * stop.options.length), target: null }; const ranked = stop.options.map((id, i) => ({ i, v: cardScore(bot, id) })).sort((a, b) => b.v - a.v); diff --git a/backend/packages/rogue/src/cards.ts b/backend/packages/rogue/src/cards.ts index 2ea949b..d332685 100644 --- a/backend/packages/rogue/src/cards.ts +++ b/backend/packages/rogue/src/cards.ts @@ -2,7 +2,7 @@ import { ADVISOR_BY_ID } from "./advisors.ts"; import { HOME_MULT } from "./archetypes.ts"; import { POWERS, TRAIT_LABELS, cardDef, hasKeyword, type CardDef } from "./data.ts"; import { BUILDING_BY_ID, POLICY_HOME, POLICY_HOME_STEP, policyTargetOf } from "./meta.ts"; -import { addMomentum, addStatus, asc, cityVotes, drawCards, eventMult, eventOf, has, isArch, loseVotes, moveVotes, spread, updateFlags } from "./mechanics.ts"; +import { addMomentum, addRivalMomentum, addStatus, asc, cityVotes, drawCards, eventMult, eventOf, has, isArch, loseVotes, moveVotes, spread, updateFlags } from "./mechanics.ts"; import { addTally, cloneState, newCard, rand, type CardInst, type Intent, type RunState, type TownState } from "./state.ts"; /** 組合拳:同一週同一區打出第 n 種不同的牌,這張牌的加成 */ @@ -21,6 +21,9 @@ export function cardCost(s: RunState, card: CardDef): { energy: number; money: n // 資深型:回應記者追問不花體力;組織型:每週第一張佈樁牌不花體力 if ((card.id === "reporter" || card.id === "storm") && isArch(s, "eloquence")) return { energy: 0, money: 0 }; if (card.effect.kind === "shield" && isArch(s, "organization") && !(s.weekCards ?? []).some((id) => cardDef(id)?.effect.kind === "shield")) return { energy: 0, money: card.money }; + // 沙盤推演(能力):每週第一張擋對手的牌不花體力 + const blocker = (id: string) => ["counter", "clarify", "nullify", "turnaround"].includes(cardDef(id)?.effect.kind ?? ""); + if (s.powers.includes("wargame") && blocker(card.id) && !(s.weekCards ?? []).some(blocker)) return { energy: 0, money: card.money }; const freeOnline = has(s, "social_editor") && card.tags.includes("online") && s.onlinePlayed === 0; const ads = has(s, "ad_planner") && (card.id === "tv" || card.id === "online"); return { energy: freeOnline ? 0 : card.cost, money: Math.round(card.money * (ads ? 0.7 : 1)) }; @@ -82,8 +85,14 @@ export function boost(s: RunState, card: CardDef, town: TownState | null): Boost for (const a of CARD_ADVISORS) if (has(s, a.id) && a.ok(card)) apply(a.m, `${ADVISOR_BY_ID.get(a.id)!.name} ×${a.m}`); for (const p of s.powers) { const power = POWERS[p]; - if (power && card.tags.includes(power.tag)) apply(power.mult, `${power.label} ×${power.mult}`); + if (power?.tag && power.mult && card.tags.includes(power.tag)) apply(power.mult, `${power.label} ×${power.mult}`); } + // 流派核心牌(docs/25 第 2 節) + const ground = s.groundPlayed ?? 0; + if (s.powers.includes("legwork") && card.tags.includes("ground") && ground > 0) apply(1 + 0.08 * ground, `走透透 ×${(1 + 0.08 * ground).toFixed(2)}`); + const buzz = s.buzz ?? 0; + if (s.powers.includes("buzz") && card.tags.includes("media") && buzz > 0) apply(1 + 0.03 * buzz, `聲量 ${buzz} ×${(1 + 0.03 * buzz).toFixed(2)}`); + if (card.id === "explainer" && buzz > 0) apply(1 + 0.05 * buzz, `懶人包・聲量 ${buzz} ×${(1 + 0.05 * buzz).toFixed(2)}`); for (const b of s.buffs) if (card.tags.includes(b.tag)) apply(b.mult, `這週加成 ×${b.mult}`); // 政策島的建築 const perk = (id: string) => s.options.perks?.[id] ?? 0; @@ -133,6 +142,8 @@ function comboOf(s: RunState, card: CardDef, town: TownState): number { interface Played { log: RunState["log"]; notes: string[]; + /** 懶人包小編:這張牌打完回到手上 */ + back?: boolean; } /** 你在某一區加票:先被對手樁腳擋掉一部分。spill 是擴散到隔壁區(不算組合拳) */ @@ -166,8 +177,22 @@ function gainCity(s: RunState, card: CardDef, total: number, weightTrait: string out.log.push({ side: "you", text: `${label}・全市`, town: null, votes: Math.round(net) }); } -/** 對手全市掉票(依對手支持者分布) */ +/** 對手規則(rival.ts 的 RIVAL_RULES);cards 不依賴 rival.ts */ +const rule = (s: RunState, id: string): boolean => (s.rivalRules ?? []).includes(id); + +/** 名嘴加持:你澄清、事實查核的時候,對手聲勢 −1 */ +function punditBacklash(s: RunState, out: Played): void { + if (!rule(s, "pundit") || s.rivalMomentum <= 0) return; + addRivalMomentum(s, -1); + out.notes.push("名嘴被打臉:對手聲勢 −1"); +} + +/** 對手全市掉票(依對手支持者分布);對手規則「形象牌」只剩一半 */ function hurtRival(s: RunState, amount: number, out: Played, text: string): void { + if (rule(s, "image")) { + amount *= 0.5; + out.notes.push("形象牌:效果只剩一半"); + } const parts = spread(s.towns, amount, (t) => t.rival); const hurt = s.towns.reduce((a, t, i) => a + loseVotes(t, parts[i]!, "rival"), 0); out.log.push({ side: "you", text, town: null, votes: Math.round(hurt) }); @@ -225,6 +250,11 @@ function resolve(s: RunState, card: CardDef, town: TownState | null, intent: Int s.viral = { used: true, boost: true }; out.notes.push("媒體型:下一張空戰牌效果加倍"); } + if (hit && e.hit > 1 && has(s, "meme_editor") && !s.memeUsed) { + s.memeUsed = true; + out.back = true; + out.notes.push("懶人包小編:這張牌回到手上"); + } break; } case "counter": { @@ -238,6 +268,7 @@ function resolve(s: RunState, card: CardDef, town: TownState | null, intent: Int case "clarify": { for (const i of s.intents) if (i.kind === "attack") i.cut = Math.min(i.cut, e.cut); if (e.momentum) addMomentum(s, e.momentum); + punditBacklash(s, out); out.notes.push(e.cut === 0 ? "對手這週的批評全部無效" : `對手這週的批評剩 ${Math.round(e.cut * 100)}%`); if (e.base > 0) gainCity(s, card, e.base * boost(s, card, null).mult, undefined, out); else out.log.push({ side: "you", text: card.name, town: null, votes: 0 }); @@ -246,6 +277,7 @@ function resolve(s: RunState, card: CardDef, town: TownState | null, intent: Int case "nullify": { intent!.cut = 0; out.notes.push("這個批評失效"); + punditBacklash(s, out); gainCity(s, card, e.base * boost(s, card, null).mult, undefined, out); break; } @@ -320,6 +352,40 @@ function resolve(s: RunState, card: CardDef, town: TownState | null, intent: Int out.notes.push(`${POWERS[e.power]?.label ?? card.name}:整局有效`); out.log.push({ side: "you", text: `${card.name}:整局有效`, town: null, votes: 0 }); break; + case "breadth": { + // 這週出過牌的區(含這一區) + const towns = Math.min(5, s.towns.filter((t) => t.played.length > 0 && t !== town).length + 1); + out.notes.push(`這週出過牌的區 ${towns} 區 ×${towns}`); + gainAt(s, card, town!, e.base * towns, out); + break; + } + case "turnaround": + for (const i of s.intents) if (i.kind === "attack") i.cut = Math.min(i.cut, e.cut); + s.turnaround = true; + out.notes.push(`對手這週的批評剩 ${Math.round(e.cut * 100)}%,擋下的一半變成你的票`); + out.log.push({ side: "you", text: card.name, town: null, votes: 0 }); + punditBacklash(s, out); + break; + case "spend": { + const hundreds = Math.floor(s.money / 100); + if (hundreds <= 0) { + out.log.push({ side: "you", text: `${card.name}:手上沒有錢`, town: null, votes: 0 }); + break; + } + s.money -= hundreds * 100; + const b = boost(s, card, null); + out.notes.push(...b.notes, `花掉 ${hundreds * 100} 萬`); + gainCity(s, card, e.perHundred * hundreds * b.mult, undefined, out); + break; + } + case "flagMoney": { + const flags = s.towns.filter((t) => t.flag === "you").length; + const amount = Math.round((e.base + e.perFlag * flags) * (has(s, "fundraiser") ? 1.5 : 1)); + s.money += amount; + out.notes.push(`資金 +${amount} 萬(${flags} 面旗)`); + out.log.push({ side: "you", text: `${card.name}:資金 +${amount} 萬`, town: null, votes: 0 }); + break; + } case "kneel": { const b = boost(s, card, null); out.notes.push(...b.notes); @@ -377,6 +443,9 @@ export function playCard(state: RunState, uid: string, target: string | null, ex const boosted = s.viral?.boost === true; resolve(s, card, town, intent, expect, out); if (boosted && card.tags.includes("media") && s.viral) s.viral.boost = false; + // 流派核心牌:這週打過幾張地面牌、聲量(整局累積,最多 15) + if (card.tags.includes("ground")) s.groundPlayed = (s.groundPlayed ?? 0) + 1; + if (card.tags.includes("media")) s.buzz = Math.min(15, (s.buzz ?? 0) + 1); const mark = town ?? (intent?.town ? s.towns.find((t) => t.code === intent!.town)! : null); if (mark && !mark.played.includes(card.id)) { mark.played.push(card.id); @@ -393,7 +462,8 @@ export function playCard(state: RunState, uid: string, target: string | null, ex const lost = cityVotes(s, -card.side.backlash * s.scale); out.log.push({ side: "you", text: `${card.name}:被刪預算的人不高興`, town: null, votes: Math.round(lost) }); } - if (hasKeyword(card, "exhaust")) s.exhausted.push(inst); + if (out.back) s.hand.push(inst); + else if (hasKeyword(card, "exhaust")) s.exhausted.push(inst); else s.discard.push(inst); s.paying = 0; s.weekCards = [...(s.weekCards ?? []), card.id]; diff --git a/backend/packages/rogue/src/data.ts b/backend/packages/rogue/src/data.ts index e99cc29..f270796 100644 --- a/backend/packages/rogue/src/data.ts +++ b/backend/packages/rogue/src/data.ts @@ -47,6 +47,14 @@ export type CardEffect = | { kind: "buff"; tag: string; mult: number; base: number } /** 能力牌:整局有效 */ | { kind: "power"; power: string } + /** 挨家挨戶:該區 base × 這週出過牌的區數(含這區,最多 5 區) */ + | { kind: "breadth"; base: number } + /** 反將一軍:這週對手的批評剩 cut,擋下的一半變成你的全市票 */ + | { kind: "turnaround"; cut: number } + /** 地毯式廣告:花光資金,每 100 萬全市 +perHundred */ + | { kind: "spend"; perHundred: number } + /** 小額募款:資金 +base,你每插一面旗再 +perFlag(萬元) */ + | { kind: "flagMoney"; base: number; perFlag: number } /** 選前之夜下跪:只能在最後一週打,聲勢大增、全市加票 */ | { kind: "kneel"; base: number; momentum: number } /** 狀態牌:回應記者追問(全市一點點) */ @@ -107,6 +115,16 @@ export const CARDS: readonly CardDef[] = [ { id: "temple", name: "宮廟參拜", art: "temple_visit", cost: 1, money: 0, rarity: "basic", tags: ["ground", "temple"], target: "town", effect: { kind: "gain", base: 1260 }, bonus: [{ trait: "temples", mult: 2 }], text: "該區 +{n};宮廟多 ×2" }, { id: "stake", name: "拜託里長佈樁", art: "recruit_machine", cost: 1, money: 0, rarity: "basic", tags: ["org", "defend"], target: "town", effect: { kind: "shield", base: 2880, gain: 580 }, text: "該區樁腳 {n},擋對手這週在這區的行動" }, { id: "dinner", name: "募款餐會", art: "fundraiser_dinner", cost: 1, money: 0, rarity: "basic", tags: ["money"], target: "none", effect: { kind: "money", base: 300, perMomentum: 30 }, text: "資金 +{m} 萬;聲勢越高募越多" }, + // ── 流派核心牌(docs/25 第 2 節):會疊加、組成形會爆分 ── + { id: "legwork", name: "走透透", art: "workout", cost: 1, money: 0, rarity: "rare", tags: ["ground"], target: "none", effect: { kind: "power", power: "legwork" }, text: "能力:這週每打過一張地面牌,之後的地面牌 +8%(週末歸零)" }, + { id: "doorstep", name: "挨家挨戶", art: "door_to_door", cost: 1, money: 0, rarity: "rare", tags: ["ground"], target: "town", effect: { kind: "breadth", base: 900 }, text: "該區 +{n} × 這週出過牌的區數(最多 5 區)" }, + { id: "network", name: "樁腳網", art: "party_elder", cost: 1, money: 0, rarity: "rare", tags: ["org"], target: "none", effect: { kind: "power", power: "network" }, text: "能力:週末每座還沒被用掉的樁腳,兩成變成你在那區的票" }, + { id: "buzz", name: "聲量滾雪球", art: "short_video", cost: 1, money: 0, rarity: "rare", tags: ["media"], target: "none", effect: { kind: "power", power: "buzz" }, text: "能力:每打一張空戰牌聲量 +1(整局累積,最多 15);空戰牌每點聲量 +3%" }, + { id: "explainer", name: "懶人包", art: "line_groups", cost: 1, money: 0, rarity: "rare", tags: ["media", "online"], target: "city", effect: { kind: "city", base: 2300, weight: "young" }, text: "全市 +{n},年輕人多的區分到較多;每點聲量再 +5%" }, + { id: "turntable", name: "反將一軍", art: "press_conference", cost: 1, money: 0, rarity: "rare", tags: ["defend"], target: "none", effect: { kind: "turnaround", cut: 0.5 }, text: "對手這週的批評剩一半;擋下來的一半變成你的全市票" }, + { id: "wargame", name: "沙盤推演", art: "internal_poll", cost: 1, money: 0, rarity: "rare", tags: ["defend", "intel"], target: "none", effect: { kind: "power", power: "wargame" }, text: "能力:每週第一張打對台、澄清、事實查核、反將一軍不花體力" }, + { id: "carpetads", name: "地毯式廣告", art: "eve_online_ad", cost: 1, money: 0, rarity: "rare", tags: ["money"], target: "city", effect: { kind: "spend", perHundred: 900 }, text: "花光手上的資金:每 100 萬全市 +{n}" }, + { id: "microdonate", name: "小額募款", art: "live_pledge", cost: 1, money: 0, rarity: "rare", tags: ["money"], target: "none", effect: { kind: "flagMoney", base: 120, perFlag: 60 }, text: "資金 +{m} 萬;你每插一面旗再 +{p} 萬" }, { id: "homecoming", name: "回鄉造勢", art: "homecoming", cost: 1, money: 0, rarity: "basic", tags: ["ground", "rally"], target: "town", homeOnly: true, effect: { kind: "rally", base: 2600, momentum: 1 }, text: "只能打在你的本命區;該區 +{n},聲勢 +1" }, { id: "rally", name: "造勢晚會", art: "rally", cost: 2, money: 200, rarity: "basic", tags: ["ground", "rally"], target: "town", effect: { kind: "rally", base: 3450, momentum: 2, spill: 0.25 }, plus: { effect: { kind: "rally", base: 4140, momentum: 3, spill: 0.3 } }, text: "該區 +{n}、隔壁區兩成半,聲勢 +2" }, @@ -239,6 +257,14 @@ function scaleEffect(e: CardEffect): CardEffect { return { ...e, energy: e.energy + 1 }; case "buff": return { ...e, base: m(e.base), mult: e.mult + 0.2 }; + case "breadth": + return { ...e, base: m(e.base) }; + case "turnaround": + return { ...e, cut: e.cut * 0.6 }; + case "spend": + return { ...e, perHundred: m(e.perHundred) }; + case "flagMoney": + return { ...e, base: m(e.base), perFlag: m(e.perFlag) }; case "probe": case "power": case "none": @@ -270,9 +296,14 @@ export const upgradable = (id: string, up?: boolean): boolean => !up && (findCar export const hasKeyword = (card: CardDef, k: Keyword): boolean => (card.keywords ?? []).includes(k); /** 能力牌的效果 */ -export const POWERS: Record = { +/** 能力牌:tag、mult 是「某類牌固定加成」;沒寫的是規則裡另外處理的能力(流派核心牌,docs/25) */ +export const POWERS: Record = { media: { tag: "media", mult: 1.25, label: "媒體訓練" }, ground: { tag: "ground", mult: 1.15, label: "蹲點研究" }, + legwork: { label: "走透透" }, + network: { label: "樁腳網" }, + buzz: { label: "聲量滾雪球" }, + wargame: { label: "沙盤推演" }, }; export interface EventDef { diff --git a/backend/packages/rogue/src/mechanics.ts b/backend/packages/rogue/src/mechanics.ts index 63a6142..f7948d7 100644 --- a/backend/packages/rogue/src/mechanics.ts +++ b/backend/packages/rogue/src/mechanics.ts @@ -1,7 +1,7 @@ import type { RogueArchetype } from "@election2026/protocol"; import { HOME_LOST_MOMENTUM, HOME_TAKEN_MOMENTUM } from "./archetypes.ts"; import { EVENT_BY_ID, EVENTS, type EventDef } from "./data.ts"; -import { FLAG_LEAD, HAND_MAX, MOMENTUM_MAX, newCard, shuffle, townLead, type Owner, type RunState, type TownState } from "./state.ts"; +import { ELDER_LEAD, FLAG_LEAD, FLIP_DRAW_MAX, HAND_MAX, MOMENTUM_MAX, newCard, shuffle, townLead, type Owner, type RunState, type TownState } from "./state.ts"; /** 規則與對手 AI 共用的小工具:幕僚、每週事件、逆風難度、搬票、抽牌、插旗 */ export const has = (s: RunState, advisor: string): boolean => s.advisors.includes(advisor); @@ -109,8 +109,11 @@ export const flagOwner = (t: TownState): Owner => { export function updateFlags(s: RunState): { gained: TownState[]; lost: TownState[] } { const gained: TownState[] = []; const lost: TownState[] = []; + // 地方大老(對手規則,rival.ts):對手插旗的區,要領先 ELDER_LEAD 才翻得過來 + const elder = (s.rivalRules ?? []).includes("elder"); for (const t of s.towns) { - const next = flagOwner(t); + let next = flagOwner(t); + if (elder && t.flag === "rival" && next !== "rival" && townLead(t) < ELDER_LEAD) next = "rival"; t.flag = next; if (!next || next === t.was) continue; if (t.was === "rival") gained.push(t); @@ -129,10 +132,15 @@ export function updateFlags(s: RunState): { gained: TownState[]; lost: TownState s.log.push({ side: "you", text: `攻下${s.setup.rival.name}的本命區${t.name}!聲勢 +${HOME_TAKEN_MOMENTUM},對手下週少一個行動`, town: t.code, votes: 0 }); } else s.log.push({ side: "you", text: `翻轉!你在${t.name}插旗,聲勢 +1`, town: t.code, votes: 0 }); } - // 黑馬型:每翻轉一區多抽 1 張(出牌時才抽,週末結算翻的不抽) - if (isArch(s, "newcomer") && s.phase === "plan") { - drawCards(s, gained.length); - s.log.push({ side: "you", text: `黑馬氣勢:抽 ${gained.length} 張牌`, town: null, votes: 0 }); + // 翻區獎勵:每翻轉一區抽 1 張,每週最多 FLIP_DRAW_MAX 張;黑馬型每區再多抽 1 張(出牌時才抽,週末結算翻的不抽) + if (s.phase === "plan") { + const reward = Math.min(gained.length, FLIP_DRAW_MAX - (s.flipDraws ?? 0)); + const extra = isArch(s, "newcomer") ? gained.length : 0; + if (reward > 0) s.flipDraws = (s.flipDraws ?? 0) + reward; + if (reward + extra > 0) { + drawCards(s, reward + extra); + s.log.push({ side: "you", text: `翻區獎勵:抽 ${reward + extra} 張牌${extra ? "(含黑馬氣勢)" : ""}`, town: null, votes: 0 }); + } } } if (lost.length) { diff --git a/backend/packages/rogue/src/rival.ts b/backend/packages/rogue/src/rival.ts index 9eeb800..e932d2c 100644 --- a/backend/packages/rogue/src/rival.ts +++ b/backend/packages/rogue/src/rival.ts @@ -31,6 +31,57 @@ const STYLE_WEIGHTS: Record> = { air: { canvass: 2, rally: 1, tv: 2.5, online: 2, attack: 1.2, smear: 0.6, stake: 0.6 }, }; +/** + * 對手規則(docs/25 第 3 節,參考《小丑牌》的 Boss 盲注):開局抽 1 條(逆風 5 起 2 條),整局有效、畫面上一直看得到。 + * 對手的風格決定比較常抽到哪幾條。規則對所有候選人一樣,只是機制,不描述真人。 + */ +export const RIVAL_RULES: Record }> = { + pundit: { name: "名嘴加持", text: "對手的批評 ×1.5;你澄清、事實查核的時候,對手聲勢 −1", weight: { balanced: 1, ground: 0.6, air: 1.5 } }, + elder: { name: "地方大老", text: "對手插旗的區,你要領先 12 個百分點(一般 8)才翻得過來", weight: { balanced: 1, ground: 1.5, air: 0.6 } }, + airwar: { name: "大打空戰", text: "對手每週多一個電視或網路廣告", weight: { balanced: 1, ground: 0.5, air: 1.5 } }, + stronghold: { name: "鐵票區", text: "對手的本命區每週自動有一座樁腳", weight: { balanced: 1, ground: 1.5, air: 0.8 } }, + rumor: { name: "網路謠言", text: "每週末隨機一區你的支持者被拉走一點;那週打探過對手就沒事", weight: { balanced: 1, ground: 0.8, air: 1.3 } }, + carpet: { name: "地毯式掃街", text: "對手的掃街會擴散到隔壁區兩成", weight: { balanced: 1, ground: 1.5, air: 0.5 } }, + image: { name: "形象牌", text: "你的爆料、比較文宣效果只剩一半;電視辯論贏的回合多 50%", weight: { balanced: 1, ground: 1, air: 1 } }, +}; +/** 網路謠言:每週被拉走的票(以全市 100 萬人為基準) */ +const RUMOR_BASE = 900; + +export const hasRule = (s: RunState, id: string): boolean => (s.rivalRules ?? []).includes(id); + +/** 開局抽對手規則(新手教學沒有) */ +export function drawRivalRules(s: RunState): string[] { + if (s.options.tutorial) return []; + const n = asc(s, 5) ? 2 : 1; + const out: string[] = []; + for (let k = 0; k < n; k++) { + const id = pickWeighted(s, Object.keys(RIVAL_RULES).filter((x) => !out.includes(x)), (x) => RIVAL_RULES[x]!.weight[s.setup.rivalStyle]); + if (id) out.push(id); + } + return out; +} + +/** 每週開始:鐵票區(對手本命區自動有樁腳) */ +export function applyRivalRules(s: RunState): void { + if (!hasRule(s, "stronghold")) return; + for (const t of s.towns.filter((x) => x.home === "rival")) { + t.rivalShield += intentAmount(s, "stake", t); + s.log.push({ side: "rival", text: `鐵票區:${s.setup.rival.name}的本命區${t.name}樁腳到位`, town: t.code, votes: 0 }); + } +} + +/** 週末:網路謠言(那週打探過對手就沒事) */ +export function rumorAtWeekend(s: RunState, probed: boolean): void { + if (!hasRule(s, "rumor")) return; + if (probed) { + s.log.push({ side: "you", text: "網路謠言:你這週打探過對手,謠言沒有擴散", town: null, votes: 0 }); + return; + } + const t = pickWeighted(s, s.towns, (x) => x.you) ?? s.towns[0]!; + const lost = loseVotes(t, RUMOR_BASE * s.scale * t.reach, "you"); + s.log.push({ side: "rival", text: `網路謠言在${t.name}流傳`, town: t.code, votes: -Math.round(lost) }); +} + /** 每週最多幾個同一類的行動 */ const LIMITS: Partial> = { rally: 1, tv: 1, online: 1, attack: 1, smear: 1, stake: 1 }; @@ -73,7 +124,8 @@ function intentAmount(s: RunState, kind: RogueIntentKind, town: TownState | null // 對手在自己的本命區比較強;媒體型被批評損失比較大(docs/25) const home = town?.home === "rival" ? RIVAL_HOME_MULT : 1; const weak = kind === "attack" && isArch(s, "media") ? 1.2 : 1; - return round10(INTENT_BASE[kind] * rivalPower(s) * reach * eventMult(s, INTENT_TAGS[kind]) * styleMult(s, kind) * home * weak); + const pundit = kind === "attack" && hasRule(s, "pundit") ? 1.5 : 1; + return round10(INTENT_BASE[kind] * rivalPower(s) * reach * eventMult(s, INTENT_TAGS[kind]) * styleMult(s, kind) * home * weak * pundit); } export function planIntents(s: RunState): Intent[] { @@ -106,6 +158,11 @@ export function planIntents(s: RunState): Intent[] { if (town) used.add(town.code); out.push({ id: `i${s.week}-${k}`, kind, town: town?.code ?? null, amount: intentAmount(s, kind, town), cut: 1 }); } + // 大打空戰:每週多一個電視或網路廣告(這週還沒排的那一種) + if (hasRule(s, "airwar")) { + const kind = !count.get("tv") ? "tv" : !count.get("online") ? "online" : null; + if (kind) out.push({ id: `i${s.week}-air`, kind, town: null, amount: intentAmount(s, kind, null), cut: 1 }); + } return out; } @@ -149,6 +206,11 @@ export function executeIntent(s: RunState, i: Intent): void { if (prevented >= 1) { const how = i.kind === "attack" ? (i.cut === 0 ? "批評被你完全擋下" : "批評被你擋掉一部分") : "被你打對台"; s.log.push({ side: "you", text: `${name}${label}${how}`, town: i.town, votes: 0, blocked: Math.round(prevented) }); + // 反將一軍:擋下的批評,一半變成你的全市票 + if (i.kind === "attack" && s.turnaround) { + const got = cityVotes(s, prevented * 0.5, "you"); + s.log.push({ side: "you", text: "反將一軍:擋下的批評變成你的票", town: null, votes: Math.round(got) }); + } } if (i.kind === "tv" || i.kind === "online") { const parts = spread(s.towns, amount, (x) => x.voters * (x.traits.includes(i.kind === "tv" ? "old" : "young") ? 1.5 : 1)); @@ -172,6 +234,11 @@ export function executeIntent(s: RunState, i: Intent): void { t.shield -= blocked; const rest = amount - blocked; if (blocked > 0) s.log.push({ side: "you", text: `樁腳擋下${name}在${t.name}的${INTENT_LABELS[i.kind]}`, town: t.code, votes: 0, blocked: Math.round(blocked) }); + // 派系協調人:樁腳擋下的票,一半變成你的 + if (blocked > 0 && has(s, "faction_broker")) { + const got = moveVotes(t, blocked * 0.5, "you"); + if (got >= 1) s.log.push({ side: "you", text: `派系協調人・${t.name}`, town: t.code, votes: Math.round(got) }); + } if (i.kind === "smear") { // 到你的票倉拉票:你的支持者被拉走一部分(變回還沒表態),對手拿到一半 const lost = loseVotes(t, rest, "you"); @@ -182,4 +249,16 @@ export function executeIntent(s: RunState, i: Intent): void { const net = moveVotes(t, rest, "rival"); s.log.push({ side: "rival", text: `${name}${label}`, town: t.code, votes: -Math.round(net) }); if (i.kind === "rally") addRivalMomentum(s, i.big ? 3 : 2); + // 地毯式掃街:擴散到隔壁區兩成(隔壁區的樁腳照樣先擋) + if (i.kind === "canvass" && hasRule(s, "carpet")) { + for (const code of t.neighbors) { + const n = s.towns.find((x) => x.code === code); + if (!n) continue; + const spill = amount * 0.2; + const stop = Math.min(n.shield, spill); + n.shield -= stop; + const got = moveVotes(n, spill - stop, "rival"); + if (got >= 1) s.log.push({ side: "rival", text: `${name}地毯式掃街擴散到${n.name}`, town: n.code, votes: -Math.round(got) }); + } + } } diff --git a/backend/packages/rogue/src/route.ts b/backend/packages/rogue/src/route.ts index d2422a5..603845a 100644 --- a/backend/packages/rogue/src/route.ts +++ b/backend/packages/rogue/src/route.ts @@ -7,7 +7,7 @@ import { REWARD_CARDS, cardDef, upgradable } from "./data.ts"; import { addMomentum, asc, cityVotes, has, isArch, moveVotes } from "./mechanics.ts"; import { applyOutcome, choiceBlocked, rollChoice } from "./scenes.ts"; import type { MiniGameKind } from "@election2026/protocol"; -import { MAX_ADVISORS, gainCard, newCard, pickWeighted, rand, shuffle, type RunState, type ShopItem, type Stop, type StopKind } from "./state.ts"; +import { MAX_ADVISORS, TOTAL_WEEKS, gainCard, newCard, pickWeighted, rand, round10, shuffle, type RunState, type ShopItem, type Stop, type StopKind } from "./state.ts"; /** * 每週結束後的「下一站」(docs/22,像《殺戮尖塔》的地圖):三選一,再進那一站做選擇。 @@ -40,8 +40,12 @@ export const STOP_LABELS: Record = { encounter: { title: "深入基層", text: "親自拜票,連遇三個人" }, event: { title: "地方抉擇", text: "有代價、有風險的選擇" }, minigame: { title: "選戰小遊戲", text: "掃街、造勢或看板卡位,玩得好就加成" }, + elite: { title: "地方派系談判", text: "接下挑戰:下週在指定的區淨增票數,達成拿一位稀有幕僚;沒達成聲勢 −1" }, }; +/** 地方派系談判的目標(以全市 100 萬人為基準,乘上區的大小) */ +export const ELITE_GOAL = 3000; + const deckOf = (s: RunState) => [...s.draw, ...s.discard, ...s.hand]; const optionCount = (s: RunState) => (asc(s, 4) ? 2 : 3); const advisorOpen = (s: RunState) => s.advisors.length < MAX_ADVISORS; @@ -60,6 +64,8 @@ export function makeRoute(s: RunState): StopKind[] { encounter: 1.2, event: STOP_EVENTS.some((e) => !s.seen.includes(e.id)) ? 1.3 : 0, minigame: s.options.tutorial ? 0 : 1.1, + // 精英站:第 2、4 週結束後可能出現(docs/25 第 3 節) + elite: !s.options.tutorial && s.totalWeeks === TOTAL_WEEKS && (s.week === 2 || s.week === 4) ? 1.4 : 0, }; while (out.length < optionCount(s)) { const kinds = (Object.keys(weights) as StopKind[]).filter((k) => !out.includes(k)); @@ -121,6 +127,10 @@ const encounterPool = (): readonly EncounterDef[] => ENCOUNTERS.filter((e) => e. function makeStop(s: RunState, kind: StopKind): Stop { switch (kind) { + case "elite": { + const t = contestedTown(s); + return { kind, town: t.code, goal: round10(ELITE_GOAL * s.scale * t.reach) }; + } case "card": return { kind, options: cardOptions(s, optionCount(s)) }; case "advisor": @@ -155,9 +165,27 @@ function makeStop(s: RunState, kind: StopKind): Stop { } /** 這週結束:排好三扇門,門裡的內容也先備好(畫面直接攤開,一次點選就拿到) */ +/** 先抽好的門到時候還能不能用(幕僚滿了、牌組太小、地方抉擇都看過了、精英站只在第 2、4 週) */ +function stillValid(s: RunState, kinds: readonly StopKind[]): boolean { + return kinds.every((k) => { + if (k === "advisor") return advisorOpen(s); + if (k === "remove") return deckOf(s).length > 8; + if (k === "event") return STOP_EVENTS.some((e) => !s.seen.includes(e.id)); + if (k === "elite") return s.week === 2 || s.week === 4; + return true; + }); +} + export function prepareRoute(s: RunState): void { - s.route = makeRoute(s); + // 上週已經預告的門照用(還能用的話) + s.route = s.nextRoute && stillValid(s, s.nextRoute) ? s.nextRoute : makeRoute(s); s.routeStops = s.route.map((k) => makeStop(s, k)); + // 下下週的門:照下週的狀況先抽好種類,畫面灰色顯示 + if (s.week + 1 < s.totalWeeks) { + s.week += 1; + s.nextRoute = makeRoute(s); + s.week -= 1; + } else s.nextRoute = null; } /** 拜會地方、招募幕僚、地方抉擇:在門上直接選,不用再進門 */ @@ -181,6 +209,13 @@ export function pickRoute(s: RunState, pick: number | "skip", option?: number): const stop = s.routeStops?.[pick] ?? makeStop(s, kind); s.route = null; s.routeStops = null; + // 地方派系談判:選了就接下挑戰,下週結算 + if (stop.kind === "elite") { + s.contract = { town: stop.town, goal: stop.goal, week: s.week + 1 }; + const name = s.towns.find((t) => t.code === stop.town)?.name ?? stop.town; + s.log.push({ side: "system", text: `接下地方派系談判:下週在${name}淨增 ${stop.goal.toLocaleString("en-US")} 票`, town: stop.town, votes: 0 }); + return { done: true }; + } if (stop.kind === "event") s.seen.push(stop.id); s.stop = stop; s.phase = "stop"; diff --git a/backend/packages/rogue/src/rules.ts b/backend/packages/rogue/src/rules.ts index 30be135..0cfdced 100644 --- a/backend/packages/rogue/src/rules.ts +++ b/backend/packages/rogue/src/rules.ts @@ -1,19 +1,20 @@ import type { MiniGameKind, RogueResult } from "@election2026/protocol"; -import { ADVISOR_BY_ID } from "./advisors.ts"; +import { ADVISOR_BY_ID, ADVISORS } from "./advisors.ts"; import { ARCHETYPES, homeBasis, homeTowns } from "./archetypes.ts"; import type { IslandPerk, PolicySpec } from "@election2026/protocol"; import { MINOR_REPORTER_MULT, ORIGINS, PARTY_LEAN_SHIFT, type Background } from "@election2026/protocol"; import { CARD_BY_ID, cardDef, EVENTS, findCard, hasKeyword, REPORTER_PENALTY, STARTER_DECK, upgradable } from "./data.ts"; import { perkLevels, policyCardId, policySlots } from "./meta.ts"; -import { asc, cityVotes, drawCards, eventOf, flagOwner, has, isArch, moveVotes, updateFlags } from "./mechanics.ts"; +import { addMomentum, asc, cityVotes, drawCards, eventOf, flagOwner, has, isArch, moveVotes, updateFlags } from "./mechanics.ts"; import { featsOf } from "./feats.ts"; -import { announceBigRally, applyRivalShields, executeIntent, planIntents } from "./rival.ts"; +import { announceBigRally, applyRivalRules, applyRivalShields, drawRivalRules, executeIntent, planIntents, rumorAtWeekend } from "./rival.ts"; import { pickRoute, pickStop, prepareRoute } from "./route.ts"; import { applyUltimate, chargeUltimate, secondChance } from "./ultimate.ts"; -import { committedShares, resolveScene, sceneFor } from "./scenes.ts"; +import { committedShares, makeSchedule, resolveScene, sceneFor } from "./scenes.ts"; import { BASE_ENERGY, FLAG_INCOME, + MAX_ADVISORS, HAND_SIZE, SAVE_VERSION, TOTAL_WEEKS, @@ -79,6 +80,10 @@ function startWeek(s: RunState): void { s.energy = Math.max(0, s.energyMax + s.energyNext); s.energyNext = 0; s.buffs = []; + s.flipDraws = 0; + s.groundPlayed = 0; + s.turnaround = false; + s.memeUsed = false; if (s.viral) s.viral.used = false; s.playedThisWeek = 0; s.onlinePlayed = 0; @@ -96,6 +101,13 @@ function startWeek(s: RunState): void { announceBigRally(s); s.intents = planIntents(s); applyRivalShields(s); + applyRivalRules(s); + // 地方派系談判:記下這週開始時那區的差距 + const deal = s.contract; + if (deal && deal.week === s.week) { + const t = s.towns.find((x) => x.code === deal.town); + if (t) deal.start = t.you - t.rival; + } // 組織型:本命區每週自動有一座樁腳(和「拜託里長佈樁」一樣大) if (isArch(s, "organization")) { for (const t of s.towns.filter((x) => x.home === "you")) { @@ -261,6 +273,10 @@ export function createRun(setup: RogueSetup, runId: string, seed: number, opts: s.policyNames = { ...s.policyNames, [id]: p.name }; gainCard(s, newCard(s, id)); }); + // 每局不一樣(docs/25):對手規則、辯論/民調/黑函的週次 + s.rivalRules = drawRivalRules(s); + const schedule = makeSchedule(s); + if (schedule) s.schedule = schedule; const start = committedShares(s); s.startGap = (start.you - start.rival) * 100; s.history.push({ week: 0, ...start }); @@ -338,6 +354,58 @@ function cleanupHand(s: RunState): void { s.hand = keep; } +/** 地方派系談判結算(對手週末行動之後):達成拿一位稀有幕僚(滿了就升級兩張牌),沒達成聲勢 −1 */ +function settleContract(s: RunState): void { + const deal = s.contract; + if (!deal || deal.week !== s.week) return; + s.contract = undefined; + const t = s.towns.find((x) => x.code === deal.town); + if (!t) return; + const net = t.you - t.rival - (deal.start ?? 0); + if (net < deal.goal) { + addMomentum(s, -1); + s.log.push({ side: "rival", text: `地方派系談判沒談成:${t.name}只淨增 ${Math.round(Math.max(0, net)).toLocaleString("en-US")} 票,聲勢 −1`, town: t.code, votes: 0 }); + return; + } + if (s.advisors.length < MAX_ADVISORS) { + const pool = ADVISORS.filter((a) => !s.advisors.includes(a.id)); + const arch = s.options.archetype ? ARCHETYPES[s.options.archetype] : null; + const pick = pickWeighted(s, pool, (a) => (arch && arch.school === a.school ? 1.5 : 1)); + if (pick) { + s.advisors.push(pick.id); + s.log.push({ side: "you", text: `地方派系談判成功:${pick.name}加入團隊`, town: t.code, votes: 0 }); + return; + } + } + const ups = shuffle(s, [...s.draw, ...s.discard, ...s.hand].filter((c) => upgradable(c.id, c.up))).slice(0, 2); + for (const c of ups) c.up = true; + s.log.push({ side: "you", text: `地方派系談判成功:升級 ${ups.length} 張牌`, town: t.code, votes: 0 }); +} + +/** 週末的流派效果(docs/25 第 2 節):樁腳網、鐵腿、危機變轉機(在樁腳、出牌紀錄清掉之前) */ +function weekendSchools(s: RunState): void { + if (s.powers.includes("network")) { + for (const t of s.towns.filter((x) => x.shield > 0)) { + const net = moveVotes(t, t.shield * 0.2, "you"); + if (net >= 1) s.log.push({ side: "you", text: `樁腳網・${t.name}`, town: t.code, votes: Math.round(net) }); + } + } + if (has(s, "iron_legs")) { + const towns = s.towns.filter((t) => t.played.length > 0).length; + if (towns >= 3) { + addMomentum(s, 2); + s.log.push({ side: "you", text: `鐵腿:這週跑了 ${towns} 區,聲勢 +2`, town: null, votes: 0 }); + } + } + if (has(s, "crisis_flip")) { + const blocked = s.intents.filter((i) => i.kind === "attack" && i.cut < 1).length; + if (blocked > 0) { + addMomentum(s, blocked); + s.log.push({ side: "you", text: `危機變轉機:擋下 ${blocked} 次批評,聲勢 +${blocked}`, town: null, votes: 0 }); + } + } +} + /** 結束這週:服務處加票、對手照意圖行動、記者追問、聲勢消退、收入,然後選下一站(最後一週直接開票) */ export function endWeek(state: RunState): RunState | { error: string } { if (state.phase !== "plan") return { error: "現在不能結束這週" }; @@ -355,6 +423,9 @@ export function endWeek(state: RunState): RunState | { error: string } { } } for (const intent of s.intents) executeIntent(s, intent); + rumorAtWeekend(s, (s.weekCards ?? []).some((id) => cardDef(id)?.effect.kind === "probe")); + weekendSchools(s); + settleContract(s); const reporters = s.hand.filter((c) => c.id === "reporter" || c.id === "storm").length; if (reporters > 0 && !has(s, "crisis_team")) { const integrity = 1 - 0.15 * (s.options.abilities?.integrity ?? 0); @@ -376,6 +447,14 @@ export function endWeek(state: RunState): RunState | { error: string } { ) * (isArch(s, "integrity") ? 0.8 : 1); s.money += income; s.log.push({ side: "system", text: `本週收入 ${income} 萬${flags ? `(含 ${flags} 面旗的小額捐款)` : ""}`, town: null, votes: 0 }); + // 精算師:存款利息 + if (has(s, "actuary")) { + const interest = Math.min(50, Math.floor(s.money / 100) * 5); + if (interest > 0) { + s.money += interest; + s.log.push({ side: "system", text: `精算師:利息 ${interest} 萬`, town: null, votes: 0 }); + } + } s.lastFocus = s.towns .filter((t) => t.played.length > 0) .sort((a, b) => b.played.length - a.played.length) diff --git a/backend/packages/rogue/src/scenes.ts b/backend/packages/rogue/src/scenes.ts index e17fe3c..a036082 100644 --- a/backend/packages/rogue/src/scenes.ts +++ b/backend/packages/rogue/src/scenes.ts @@ -1,4 +1,5 @@ import { ADVISORS } from "./advisors.ts"; +import { AFFINITY_WEIGHT, ARCHETYPES } from "./archetypes.ts"; import { CRISIS_CHOICES, DEBATE_ARGS, @@ -14,9 +15,9 @@ import { type Outcome, type PressTrigger, } from "./content.ts"; -import { findCard, upgradable } from "./data.ts"; +import { REWARD_CARDS, findCard, upgradable } from "./data.ts"; import { addMomentum, addRivalMomentum, addStatus, asc, cityVotes, has, isArch, loseVotes, spread } from "./mechanics.ts"; -import { MAX_ADVISORS, addTally, gainCard, newCard, pickWeighted, rand, shuffle, totals, type DebateArg, type DebateMove, type RunState, type Scene } from "./state.ts"; +import { MAX_ADVISORS, TOTAL_WEEKS, addTally, gainCard, newCard, pickWeighted, rand, shuffle, totals, type DebateArg, type DebateMove, type RunState, type Scene } from "./state.ts"; /** * 每週開場的劇情(docs/22):記者堵麥、電視辯論(第 3 週)、民調公布(第 4 週)、匿名黑函危機(第 6 週)。 @@ -26,6 +27,24 @@ import { MAX_ADVISORS, addTally, gainCard, newCard, pickWeighted, rand, shuffle, export const DEBATE_WEEK = 3; export const POLL_WEEK = 4; export const CRISIS_WEEK = 6; + +/** 8 週的局,辯論、民調、黑函的週次每局隨機(docs/25 第 4 節):辯論 3–5、民調 4–5、黑函 5–6 週,不重疊 */ +const SCHEDULES = [ + [3, 4, 5], + [3, 4, 6], + [3, 5, 6], + [4, 5, 6], + [5, 4, 6], +] as const; + +export function makeSchedule(s: RunState): RunState["schedule"] { + if (s.options.tutorial || s.totalWeeks !== TOTAL_WEEKS) return undefined; + const [debate, poll, crisis] = SCHEDULES[Math.floor(rand(s) * SCHEDULES.length)]!; + return { debate, poll, crisis }; +} + +/** 這局的行事曆;短局(里長、議員)、舊存檔用固定週次 */ +export const scheduleOf = (s: RunState): { debate: number; poll: number; crisis: number } => s.schedule ?? { debate: DEBATE_WEEK, poll: POLL_WEEK, crisis: CRISIS_WEEK }; /** 辯論贏一回合:全市加票(基準),連續答對 ×1.5、×2;輸一回合:你掉票 */ export const DEBATE_WIN = 1730; export const DEBATE_LOSS = 860; @@ -201,11 +220,21 @@ function publishPoll(s: RunState): void { const lead = you >= rival; s.stats.pollGap = (rival - you) * 100; if (lead) { + // 領先:西瓜效應,還多一張稀有牌(和你的類型搭配的比較常出現) addMomentum(s, 1); - s.log.push({ side: "you", text: "民調領先,西瓜效應:聲勢 +1", town: null, votes: 0 }); + const arch = s.options.archetype ? ARCHETYPES[s.options.archetype] : null; + const rare = pickWeighted( + s, + REWARD_CARDS.filter((c) => c.rarity === "rare" && c.effect.kind !== "kneel"), + (c) => (arch && arch.tags.some((t) => c.tags.includes(t)) ? AFFINITY_WEIGHT : 1), + ); + if (rare) s.hand.push(newCard(s, rare.id)); + s.log.push({ side: "you", text: `民調領先,西瓜效應:聲勢 +1${rare ? `,支持者送來一張「${rare.name}」` : ""}`, town: null, votes: 0 }); } else { + // 落後:悲情催票,下週體力 +1 s.hand.push(newCard(s, "sympathy")); - s.log.push({ side: "you", text: "民調落後,支持者危機意識上升:手上多一張「悲情催票」", town: null, votes: 0 }); + s.energyNext += 1; + s.log.push({ side: "you", text: "民調落後,支持者危機意識上升:手上多一張「悲情催票」,下週體力 +1", town: null, votes: 0 }); } s.poll = { week: s.week, you, rival, lead }; } @@ -219,12 +248,13 @@ function crisisScene(s: RunState): Scene { /** 這週開場的劇情;新手教學沒有 */ export function sceneFor(s: RunState, prev: RunState["lastWeek"]): Scene | null { if (s.options.tutorial || s.week < 2) return null; - if (s.week === DEBATE_WEEK) return debateScene(s); - if (s.week === POLL_WEEK) { + const when = scheduleOf(s); + if (s.week === when.debate) return debateScene(s); + if (s.week === when.poll) { publishPoll(s); return null; } - if (s.week === CRISIS_WEEK) return crisisScene(s); + if (s.week === when.crisis) return crisisScene(s); return pressScene(s, prev); } @@ -272,7 +302,9 @@ function resolveSceneInner(s: RunState, pick: number): string | null { scene.combo += 1; addMomentum(s, 1); const mult = DEBATE_COMBO[Math.min(scene.combo, DEBATE_COMBO.length) - 1]! * (arg.policy ? DEBATE_POLICY_BONUS : 1); - votes = Math.round(cityVotes(s, DEBATE_WIN * mult * s.scale)); + // 對手規則「形象牌」:辯論贏的回合多 50% + const image = (s.rivalRules ?? []).includes("image") ? 1.5 : 1; + votes = Math.round(cityVotes(s, DEBATE_WIN * mult * image * s.scale)); s.log.push({ side: "you", text: `${head},說服了觀眾!${scene.combo > 1 ? `${scene.combo} 連擊 ×${DEBATE_COMBO[Math.min(scene.combo, DEBATE_COMBO.length) - 1]},` : ""}聲勢 +1`, town: null, votes }); } else if (result === "lose") { scene.losses += 1; diff --git a/backend/packages/rogue/src/state.ts b/backend/packages/rogue/src/state.ts index c47b895..aad00d8 100644 --- a/backend/packages/rogue/src/state.ts +++ b/backend/packages/rogue/src/state.ts @@ -157,7 +157,7 @@ export type Scene = | { kind: "crisis"; amount: number } | { kind: "poll"; you: number; rival: number; lead: boolean }; -export type StopKind = "card" | "advisor" | "upgrade" | "remove" | "shop" | "encounter" | "event" | "minigame"; +export type StopKind = "card" | "advisor" | "upgrade" | "remove" | "shop" | "encounter" | "event" | "minigame" | "elite"; export interface ShopItem { kind: "card" | "advisor" | "remove"; @@ -174,7 +174,9 @@ export type Stop = | { kind: "shop"; items: ShopItem[] } | { kind: "encounter"; town: string; encounters: string[]; step: number; score: number; notes: string[] } | { kind: "event"; id: string } - | { kind: "minigame"; game: MiniGameKind; town: string | null; level: number; seed: number }; + | { kind: "minigame"; game: MiniGameKind; town: string | null; level: number; seed: number } + /** 地方派系談判(精英站,docs/25 第 3 節):選了就接下挑戰,不用進門 */ + | { kind: "elite"; town: string; goal: number }; export interface RunStats { played: number; @@ -247,6 +249,8 @@ export interface RunState { route: StopKind[] | null; /** 下一站每扇門裡面的內容(開門前就備好,畫面直接攤開;舊存檔沒有) */ routeStops?: Stop[] | null; + /** 下下週的門(docs/25:看得到前方,好規劃);只先決定種類,到時候不能用的門會重抽 */ + nextRoute?: StopKind[] | null; /** 最近一次民調(第 4 週自動公布;舊存檔沒有) */ poll?: { week: number; you: number; rival: number; lead: boolean } | null; stop: Stop | null; @@ -272,6 +276,19 @@ export interface RunState { viral?: { used: boolean; boost: boolean }; /** 你翻走對手的本命區:對手下週少幾個行動 */ rivalStun?: number; + /** 這局的行事曆(docs/25 第 4 節):辯論、民調、黑函在第幾週;舊存檔、短局沒有,用固定週次 */ + schedule?: { debate: number; poll: number; crisis: number }; + /** 這局對手的規則(docs/25 第 3 節,rival.ts 的 RIVAL_RULES);舊存檔沒有 */ + rivalRules?: string[]; + /** 這週翻區已經抽了幾張(每週最多 FLIP_DRAW_MAX) */ + flipDraws?: number; + /** 地方派系談判:第 week 週在 town 淨增 goal 票(start 是那週開始時的差距) */ + contract?: { town: string; goal: number; week: number; start?: number }; + /** 流派核心牌(docs/25 第 2 節):聲量(整局累積)、這週打過幾張地面牌、反將一軍、懶人包小編用過了 */ + buzz?: number; + groundPlayed?: number; + turnaround?: boolean; + memeUsed?: boolean; stats: RunStats; result: RogueResult | null; } @@ -292,6 +309,10 @@ export const WEEKLY_INCOME = 100; export const FLAG_LEAD = 0.08; /** 每面旗每週的小額捐款(萬元) */ export const FLAG_INCOME = 20; +/** 對手規則「地方大老」:翻對手的旗要領先這麼多 */ +export const ELDER_LEAD = 0.12; +/** 翻區獎勵:每翻轉一區抽 1 張,每週最多幾張(docs/25 第 5 節) */ +export const FLIP_DRAW_MAX = 2; /** 可重現的亂數(mulberry32):回傳 [0, 1) 與新的狀態 */ export function nextRandom(rng: number): [number, number] { diff --git a/backend/packages/rogue/src/view.ts b/backend/packages/rogue/src/view.ts index 88ead1a..9ea3ea8 100644 --- a/backend/packages/rogue/src/view.ts +++ b/backend/packages/rogue/src/view.ts @@ -9,9 +9,9 @@ import { CARD_BY_ID, EVENTS, KEYWORD_LABELS, ORIGIN_CARDS, POWERS, REPORTER_PENA import { FEATS } from "./feats.ts"; import { ABILITY_EFFECTS, ABILITY_LABELS, BUILDINGS, POLICY_HOME } from "./meta.ts"; import { ASCENSION, eventOf, has, momentumMax } from "./mechanics.ts"; -import { BIG_RALLY_WEEK, RIVAL_TRAITS, intentDamp, intentLabel } from "./rival.ts"; +import { BIG_RALLY_WEEK, RIVAL_RULES, RIVAL_TRAITS, intentDamp, intentLabel } from "./rival.ts"; import { encounterById, fillVars, MINIGAME_INFO, pickInDoor, PRICES, SKIP_MONEY, STOP_LABELS } from "./route.ts"; -import { bestArg, choiceBlocked, debateSure } from "./scenes.ts"; +import { bestArg, choiceBlocked, debateSure, scheduleOf } from "./scenes.ts"; import { electionForecast } from "./rules.ts"; import { MAX_ADVISORS, round10, totals, type CardInst, type RunState, type ShopItem, type Stop } from "./state.ts"; @@ -63,6 +63,14 @@ function face(s: RunState | null, card: CardDef): { value: string | null; text: return { value: `×${e.mult}`, text: fill(card.text, { n: fmt(n(e.base)) }).replace("×1.5", `×${e.mult}`) }; case "power": return { value: "能力", text: card.text }; + case "breadth": + return { value: `+${fmt(n(e.base))}×區`, text: fill(card.text, { n: fmt(n(e.base)) }) }; + case "turnaround": + return { value: "反將", text: card.text }; + case "spend": + return { value: "錢換票", text: fill(card.text, { n: fmt(n(e.perHundred)) }) }; + case "flagMoney": + return { value: `+${e.base}萬`, text: fill(card.text, { m: String(e.base), p: String(e.perFlag) }) }; case "answer": return { value: "回應", text: fill(card.text, { n: fmt(n(e.base)), n2: fmt(n(REPORTER_PENALTY)) }) }; case "none": @@ -189,6 +197,9 @@ function stopView(s: RunState): RogueStop | null { function stopViewOf(s: RunState, stop: Stop): RogueStop { switch (stop.kind) { + case "elite": + // 地方派系談判選了就接下挑戰(route.ts pickRoute),不會停在站裡 + throw new Error("地方派系談判沒有站內畫面"); case "card": return { kind: "card", options: stop.options.map((id) => cardOffer(s, id)) }; case "advisor": @@ -270,6 +281,22 @@ function colorsOf(s: RunState): RogueView["colors"] { } +/** 地方派系談判的門:寫出哪一區、要淨增多少 */ +function eliteText(s: RunState, stop: Stop | undefined): { text?: string } { + if (stop?.kind !== "elite") return {}; + const name = s.towns.find((t) => t.code === stop.town)?.name ?? stop.town; + return { text: `下週在${name}淨增 ${fmt(stop.goal)} 票:達成拿一位稀有幕僚(幕僚滿了就升級兩張牌);沒達成聲勢 −1` }; +} + +/** 這週的地方派系談判進度 */ +function contractOf(s: RunState): RogueView["contract"] { + const deal = s.contract; + if (!deal || deal.week !== s.week) return null; + const t = s.towns.find((x) => x.code === deal.town); + if (!t) return null; + return { town: t.code, name: t.name, goal: deal.goal, progress: Math.round(t.you - t.rival - (deal.start ?? 0)) }; +} + /** 你的候選人特色:類型、技能、弱點、本命區(docs/25);新手教學、舊存檔是 null */ function identityOf(s: RunState): RogueView["identity"] { const arch = s.options.archetype; @@ -308,6 +335,8 @@ export function toView(s: RunState): RogueView { others: s.setup.others, colors: colorsOf(s), identity: identityOf(s), + schedule: s.options.tutorial ? null : { ...scheduleOf(s), bigRally: s.totalWeeks >= BIG_RALLY_WEEK ? BIG_RALLY_WEEK : null }, + rivalRules: (s.rivalRules ?? []).flatMap((id) => (RIVAL_RULES[id] ? [{ id, name: RIVAL_RULES[id]!.name, text: RIVAL_RULES[id]!.text }] : [])), rivalTrait: RIVAL_TRAITS[s.setup.rivalStyle], towns: s.towns.map((t) => ({ code: t.code, @@ -343,7 +372,9 @@ export function toView(s: RunState): RogueView { previews: s.phase === "plan" ? previewsFor(s) : {}, scene: sceneView(s), // 門上直接攤開內容(拜會地方的三張牌、幕僚、地方抉擇的選項),一次點選就拿到 - route: s.route ? s.route.map((kind, i) => ({ kind, ...STOP_LABELS[kind], preview: pickInDoor(kind) && s.routeStops?.[i] ? stopViewOf(s, s.routeStops[i]!) : null })) : null, + route: s.route ? s.route.map((kind, i) => ({ kind, ...STOP_LABELS[kind], ...eliteText(s, s.routeStops?.[i]), preview: pickInDoor(kind) && s.routeStops?.[i] ? stopViewOf(s, s.routeStops[i]!) : null })) : null, + contract: contractOf(s), + nextRoute: s.route && s.nextRoute ? s.nextRoute.map((kind) => ({ kind, title: STOP_LABELS[kind].title })) : null, poll: s.poll ?? null, ultimate: s.options.tutorial ? null diff --git a/backend/packages/rogue/test/schools.test.ts b/backend/packages/rogue/test/schools.test.ts new file mode 100644 index 0000000..8d89c8f --- /dev/null +++ b/backend/packages/rogue/test/schools.test.ts @@ -0,0 +1,153 @@ +import { describe, expect, it } from "vitest"; +import { REWARD_CARDS } from "../src/data.ts"; +import { executeIntent } from "../src/rival.ts"; +import { createRun, endWeek, playCard } from "../src/rules.ts"; +import { FLAG_LEAD, type Intent, type RunState, type TownState } from "../src/state.ts"; +import { catalog } from "../src/view.ts"; +import { SETUP, must } from "./fixtures.ts"; + +/** 流派核心牌與改規則的幕僚(docs/25 第 2 節) */ + +const town = (s: RunState, code: string): TownState => s.towns.find((t) => t.code === code)!; + +/** 乾淨的局面:指定手牌、幕僚、能力,清掉意圖、樁腳、本命區、對手規則 */ +function bare(hand: string[], opts: { advisors?: string[]; powers?: string[]; intents?: Intent[] } = {}): RunState { + const s = structuredClone(createRun(SETUP, "r", 1)); + return { + ...s, + phase: "plan", + scene: null, + rivalRules: [], + towns: s.towns.map((t) => ({ ...t, shield: 0, rivalShield: 0, home: null })), + hand: hand.map((id, i) => ({ uid: `t${i}`, id })), + intents: opts.intents ?? [], + advisors: opts.advisors ?? [], + powers: opts.powers ?? [], + energy: 9, + money: 1000, + momentum: 0, + }; +} + +const ok = (r: ReturnType): RunState => { + if ("error" in r) throw new Error(r.error); + return r.state; +}; +const gained = (a: RunState, b: RunState) => b.towns.reduce((x, t, i) => x + t.you - a.towns[i]!.you, 0); + +describe("流派核心牌", () => { + it("十張新牌都在獎勵池、圖鑑裡", () => { + const ids = ["legwork", "doorstep", "network", "buzz", "explainer", "turntable", "wargame", "carpetads", "microdonate"]; + for (const id of ids) expect(REWARD_CARDS.some((c) => c.id === id)).toBe(true); + const listed = new Set(catalog().cards.map((c) => c.id)); + for (const id of ids) expect(listed.has(id)).toBe(true); + for (const a of ["iron_legs", "faction_broker", "meme_editor", "crisis_flip", "actuary"]) expect(catalog().advisors.some((x) => x.id === a)).toBe(true); + }); + + it("走透透:這週每打過一張地面牌,之後的地面牌 +8%", () => { + const s = bare(["canvass", "canvass", "canvass"], { powers: ["legwork"] }); + const plain = bare(["canvass"]); + const one = ok(playCard(s, "t0", "D")); + const two = ok(playCard(one, "t1", "C")); + const three = ok(playCard(two, "t2", "D")); + const base = gained(plain, ok(playCard(plain, "t0", "D"))); + // 第三張打在丁區:前面打過 2 張地面牌 ×1.16,同一區第二種牌不算組合拳(都是掃街) + expect(gained(two, three)).toBeCloseTo(base * 1.16, 0); + }); + + it("挨家挨戶:這週出過牌的區越多越強(最多 5 區)", () => { + const s = bare(["canvass", "canvass", "doorstep"]); + const after2 = ok(playCard(ok(playCard(s, "t0", "A")), "t1", "B")); + const first = bare(["doorstep"]); + const alone = gained(first, ok(playCard(first, "t0", "D"))); + expect(gained(after2, ok(playCard(after2, "t2", "D")))).toBeCloseTo(alone * 3, 0); + }); + + it("樁腳網:週末還沒被用掉的樁腳,兩成變成你在那區的票", () => { + const s = bare([], { powers: ["network"] }); + town(s, "A").shield = 1000; + const after = must(endWeek(s)); + expect(after.log.some((l) => l.text === "樁腳網・甲區" && l.votes === 200)).toBe(true); + }); + + it("聲量滾雪球:空戰牌累積聲量,每點 +3%;懶人包每點再 +5%", () => { + const s = bare(["tv", "tv"], { powers: ["buzz"] }); + const one = ok(playCard(s, "t0", null)); + expect(one.buzz).toBe(1); + const plain = bare(["tv"]); + const base = gained(plain, ok(playCard(plain, "t0", null))); + expect(gained(one, ok(playCard(one, "t1", null)))).toBeCloseTo(base * 1.03, -1); + const ex = { ...bare(["explainer"]), buzz: 4 }; + const exPlain = bare(["explainer"]); + expect(gained(ex, ok(playCard(ex, "t0", null)))).toBeCloseTo(gained(exPlain, ok(playCard(exPlain, "t0", null))) * 1.2, -1); + }); + + it("反將一軍:批評剩一半,擋下的一半變成你的全市票", () => { + const attack: Intent = { id: "a", kind: "attack", town: null, amount: 1000, cut: 1 }; + const s = ok(playCard(bare(["turntable"], { intents: [attack] }), "t0", null)); + expect(s.intents[0]!.cut).toBe(0.5); + const before = s.towns.reduce((a, t) => a + t.you, 0); + executeIntent(s, s.intents[0]!); + const back = s.log.find((l) => l.text === "反將一軍:擋下的批評變成你的票")!; + expect(back.votes).toBe(250); + expect(before).toBeGreaterThan(0); + }); + + it("沙盤推演:每週第一張擋對手的牌不花體力", () => { + const attack: Intent = { id: "a", kind: "attack", town: null, amount: 1000, cut: 1 }; + const s = bare(["clarify", "clarify"], { powers: ["wargame"], intents: [attack] }); + const one = ok(playCard(s, "t0", null)); + expect(one.energy).toBe(9); + expect(ok(playCard(one, "t1", null)).energy).toBe(8); + }); + + it("地毯式廣告:花光資金,每 100 萬全市 +票;小額募款:每面旗多 60 萬", () => { + const s = bare(["carpetads"]); + const after = ok(playCard(s, "t0", null)); + expect(after.money).toBe(0); + expect(gained(s, after)).toBeGreaterThan(0); + const m = bare(["microdonate"]); + for (const code of ["A", "B"]) { + const t = town(m, code); + t.you = t.rival + (t.you + t.rival + t.others) * (FLAG_LEAD + 0.05) * 2; + t.flag = "you"; + } + expect(ok(playCard(m, "t0", null)).money - m.money).toBe(120 + 60 * 2); + }); +}); + +describe("流派幕僚", () => { + it("鐵腿:一週跑 3 區以上,週末聲勢 +2", () => { + let s = bare(["canvass", "canvass", "canvass"], { advisors: ["iron_legs"] }); + for (const [uid, code] of [["t0", "A"], ["t1", "B"], ["t2", "C"]] as const) s = ok(playCard(s, uid, code)); + const before = s.momentum; + expect(must(endWeek(s)).log.some((l) => l.text.startsWith("鐵腿"))).toBe(true); + expect(before).toBeGreaterThanOrEqual(0); + }); + + it("派系協調人:樁腳擋下的票,一半變成你的", () => { + const s = bare([], { advisors: ["faction_broker"] }); + town(s, "A").shield = 1000; + executeIntent(s, { id: "c", kind: "canvass", town: "A", amount: 800, cut: 1 }); + expect(s.log.find((l) => l.text === "派系協調人・甲區")!.votes).toBe(400); + }); + + it("懶人包小編:爆紅之後那張牌回到手上(每週一次)", () => { + // 找一個會爆紅的亂數狀態 + for (let rng = 1; rng < 200; rng++) { + const s = { ...bare(["live"], { advisors: ["meme_editor"] }), rng }; + const after = ok(playCard(s, "t0", null)); + if (!after.memeUsed) continue; + expect(after.hand.map((c) => c.id)).toEqual(["live"]); + return; + } + throw new Error("找不到爆紅的亂數"); + }); + + it("危機變轉機:擋下幾次批評,週末聲勢就 +幾;精算師:存款利息最多 50 萬", () => { + const s = bare(["clarify"], { advisors: ["crisis_flip", "actuary"], intents: [{ id: "a", kind: "attack", town: null, amount: 1000, cut: 1 }] }); + const after = must(endWeek(ok(playCard(s, "t0", null)))); + expect(after.log.some((l) => l.text.startsWith("危機變轉機"))).toBe(true); + expect(after.log.find((l) => l.text.startsWith("精算師"))!.text).toContain("50 萬"); + }); +}); diff --git a/backend/packages/rogue/test/variety.test.ts b/backend/packages/rogue/test/variety.test.ts new file mode 100644 index 0000000..7cc5737 --- /dev/null +++ b/backend/packages/rogue/test/variety.test.ts @@ -0,0 +1,206 @@ +import { describe, expect, it } from "vitest"; +import { cardDef } from "../src/data.ts"; +import { updateFlags } from "../src/mechanics.ts"; +import { applyRivalRules, executeIntent, planIntents, RIVAL_RULES } from "../src/rival.ts"; +import { choose, createRun, endWeek, playCard } from "../src/rules.ts"; +import { sceneFor } from "../src/scenes.ts"; +import { ELDER_LEAD, FLAG_LEAD, FLIP_DRAW_MAX, type RogueSetup, type RunState, type TownState } from "../src/state.ts"; +import { toView } from "../src/view.ts"; +import { SETUP, must, toPlan } from "./fixtures.ts"; + +/** 每局不一樣(docs/25 第 3、4 節)與局中的小勝利(第 5 節) */ + +const LEANED: RogueSetup = { + ...SETUP, + towns: [ + { ...SETUP.towns[0]!, lean: { you: 0.55, rival: 0.35, others: 0.1 } }, + { ...SETUP.towns[1]!, lean: { you: 0.35, rival: 0.55, others: 0.1 } }, + { ...SETUP.towns[2]!, lean: { you: 0.6, rival: 0.3, others: 0.1 } }, + { ...SETUP.towns[3]!, lean: { you: 0.45, rival: 0.45, others: 0.1 } }, + ], +}; + +const town = (s: RunState, code: string): TownState => s.towns.find((t) => t.code === code)!; + +/** 指定手牌與對手規則,清掉意圖與樁腳 */ +function bare(s: RunState, rules: string[], hand: string[] = []): RunState { + const copy = structuredClone(s); + return { ...copy, phase: "plan", scene: null, rivalRules: rules, towns: copy.towns.map((t) => ({ ...t, shield: 0, rivalShield: 0 })), hand: hand.map((id, i) => ({ uid: `t${i}`, id })), intents: [], energy: 9, money: 5000, momentum: 0 }; +} + +const ok = (r: ReturnType): RunState => { + if ("error" in r) throw new Error(r.error); + return r.state; +}; + +function takeLead(t: TownState, side: "you" | "rival", lead: number): void { + const other = side === "you" ? "rival" : "you"; + t.was = other; + t.flag = other; + t[side] = (t[other] + lead * (t[other] + t.others)) / (1 - lead); +} + +describe("行事曆每局不同", () => { + it("8 週的局:辯論 3–5、民調 4–5、黑函 5–6 週,不重疊;同一個種子一樣;換種子會變", () => { + const seen = new Set(); + for (let seed = 1; seed <= 40; seed++) { + const s = createRun(LEANED, "r", seed); + const { debate, poll, crisis } = s.schedule!; + expect([3, 4, 5]).toContain(debate); + expect([4, 5]).toContain(poll); + expect([5, 6]).toContain(crisis); + expect(new Set([debate, poll, crisis]).size).toBe(3); + seen.add(`${debate}${poll}${crisis}`); + } + expect(seen.size).toBeGreaterThan(2); + expect(createRun(LEANED, "r", 9).schedule).toEqual(createRun(LEANED, "r", 9).schedule); + expect(createRun(LEANED, "r", 9, { tutorial: true }).schedule).toBeUndefined(); + expect(createRun(LEANED, "r", 9, { weeks: 5 }).schedule).toBeUndefined(); + }); + + it("辯論照行事曆的週次開場;畫面拿得到行事曆", () => { + const s = createRun(LEANED, "r", 3); + const when = s.schedule!; + expect(sceneFor({ ...structuredClone(s), week: when.debate }, s.lastWeek)?.kind).toBe("debate"); + expect(sceneFor({ ...structuredClone(s), week: when.crisis }, s.lastWeek)?.kind).toBe("crisis"); + expect(toView(s).schedule).toMatchObject({ ...when, bigRally: 7 }); + }); +}); + +describe("對手規則", () => { + it("開局抽 1 條(逆風 5 起 2 條),同一個種子一樣,新手教學沒有;畫面列出名稱與說明", () => { + const s = createRun(LEANED, "r", 5); + expect(s.rivalRules).toHaveLength(1); + expect(createRun(LEANED, "r", 5, { ascension: 5 }).rivalRules).toHaveLength(2); + expect(createRun(LEANED, "r", 5).rivalRules).toEqual(s.rivalRules); + expect(createRun(LEANED, "r", 5, { tutorial: true }).rivalRules).toEqual([]); + const id = s.rivalRules![0]!; + expect(toView(s).rivalRules).toEqual([{ id, name: RIVAL_RULES[id]!.name, text: RIVAL_RULES[id]!.text }]); + }); + + it("名嘴加持:批評 ×1.5;你澄清時對手聲勢 −1", () => { + const base = { ...createRun(LEANED, "r", 1), week: 3, rng: 77 }; + const attack = (rules: string[]) => planIntents({ ...structuredClone(base), rivalRules: rules }).find((i) => i.kind === "attack"); + const a = attack(["pundit"]); + const b = attack([]); + if (a && b) expect(a.amount / b.amount).toBeCloseTo(1.5, 1); + const s = { ...bare(createRun(LEANED, "r", 1), ["pundit"], ["clarify"]), rivalMomentum: 2 }; + expect(ok(playCard(s, "t0", null)).rivalMomentum).toBe(1); + }); + + it("地方大老:對手插旗的區要領先 12 個百分點才翻得過來", () => { + const s = bare(createRun(LEANED, "r", 1), ["elder"]); + takeLead(town(s, "B"), "you", FLAG_LEAD + 0.01); + updateFlags(s); + expect(town(s, "B").flag).toBe("rival"); + takeLead(town(s, "B"), "you", ELDER_LEAD + 0.01); + updateFlags(s); + expect(town(s, "B").flag).toBe("you"); + }); + + it("大打空戰:每週多一個電視或網路廣告", () => { + const base = { ...createRun(LEANED, "r", 1), week: 3, rng: 5 }; + const air = planIntents({ ...structuredClone(base), rivalRules: ["airwar"] }); + const plain = planIntents({ ...structuredClone(base), rivalRules: [] }); + expect(air.length).toBe(plain.length + (plain.some((i) => i.kind === "tv") && plain.some((i) => i.kind === "online") ? 0 : 1)); + }); + + it("鐵票區:對手本命區每週自動有樁腳", () => { + const s = bare(createRun(LEANED, "r", 1), ["stronghold"]); + applyRivalRules(s); + expect(town(s, "B").rivalShield).toBeGreaterThan(0); + expect(town(s, "A").rivalShield).toBe(0); + }); + + it("網路謠言:週末有一區被拉走票;那週打探過就沒事", () => { + const run = (played: string[]) => { + const s = { ...bare(createRun(LEANED, "r", 1), ["rumor"]), weekCards: played }; + const after = must(endWeek(s)); + return after.log.find((l) => l.text.includes("網路謠言"))!; + }; + expect(run([]).votes).toBeLessThan(0); + expect(run(["probe"]).votes).toBe(0); + }); + + it("地毯式掃街:對手掃街擴散到隔壁區兩成", () => { + const s = bare(createRun(LEANED, "r", 1), ["carpet"]); + const before = town(s, "B").rival; + executeIntent(s, { id: "x", kind: "canvass", town: "A", amount: 1000, cut: 1 }); + expect(town(s, "B").rival - before).toBeCloseTo(200, 0); + }); + + it("形象牌:你的比較文宣只剩一半", () => { + const hurt = (rules: string[]) => { + const s = bare(createRun(LEANED, "r", 1), rules, ["contrast"]); + const after = ok(playCard(s, "t0", null)); + return s.towns.reduce((a, t, i) => a + t.rival - after.towns[i]!.rival, 0); + }; + expect(hurt(["image"])).toBeCloseTo(hurt([]) / 2, 0); + }); +}); + +describe("局中的小勝利", () => { + it("翻區:每翻轉一區抽 1 張,每週最多 2 張", () => { + const s = bare(createRun(LEANED, "r", 1), []); + s.draw = Array.from({ length: 6 }, (_, i) => ({ uid: `d${i}`, id: "canvass" })); + for (const code of ["B", "D", "C"]) takeLead(town(s, code), "you", FLAG_LEAD + 0.03); + updateFlags(s); + expect(s.hand).toHaveLength(FLIP_DRAW_MAX); + expect(s.flipDraws).toBe(FLIP_DRAW_MAX); + }); + + it("民調週:領先聲勢 +1、多一張稀有牌;落後多一張悲情催票、下週體力 +1", () => { + const s = createRun(LEANED, "r", 2); + const poll = s.schedule!.poll; + const lead: RunState = { ...structuredClone(s), week: poll, momentum: 0, hand: [] }; + lead.towns = lead.towns.map((t) => ({ ...t, you: t.you * 2 })); + sceneFor(lead, s.lastWeek); + expect(lead.momentum).toBe(1); + expect(lead.hand.map((c) => cardDef(c.id)!.rarity)).toEqual(["rare"]); + const behind: RunState = { ...structuredClone(s), week: poll, momentum: 0, hand: [], energyNext: 0 }; + behind.towns = behind.towns.map((t) => ({ ...t, rival: t.rival * 2 })); + sceneFor(behind, s.lastWeek); + expect(behind.hand.map((c) => c.id)).toEqual(["sympathy"]); + expect(behind.energyNext).toBe(1); + }); +}); + +describe("精英站:地方派系談判", () => { + /** 停在下一站、只有一扇派系談判的門 */ + const atDoor = (): RunState => { + const s = must(endWeek(toPlan(createRun(LEANED, "r", 4)))); + return { ...s, rivalRules: [], route: ["elite"], routeStops: [{ kind: "elite", town: "D", goal: 1000 }] }; + }; + + it("選了就接下挑戰、直接進下一週;畫面看得到進度", () => { + const s = must(choose(atDoor(), 0)); + expect(s.phase === "plan" || s.phase === "scene").toBe(true); + expect(s.contract).toMatchObject({ town: "D", goal: 1000, week: s.week }); + expect(toView(toPlan(s)).contract).toMatchObject({ town: "D", name: "丁區", goal: 1000 }); + }); + + it("達成:拿一位幕僚;沒達成:聲勢 −1", () => { + const won = toPlan(must(choose(atDoor(), 0))); + const d = town(won, "D"); + d.you += 5000; + d.undecided = Math.max(0, d.undecided - 5000); + const after = must(endWeek({ ...won, intents: [], advisors: [] })); + expect(after.advisors).toHaveLength(1); + expect(after.contract).toBeUndefined(); + const lost = toPlan(must(choose(atDoor(), 0))); + const before = { ...lost, intents: [], momentum: 3 }; + expect(must(endWeek(before)).log.some((l) => l.text.startsWith("地方派系談判沒談成"))).toBe(true); + }); +}); + +describe("看得到前方:下下週的門", () => { + it("選下一站時看得到下下週的門;到時候還能用就照預告的出現", () => { + let s = must(endWeek(toPlan(createRun(LEANED, "r", 6)))); + expect(s.nextRoute?.length).toBeGreaterThan(0); + expect(toView(s).nextRoute?.map((d) => d.kind)).toEqual(s.nextRoute); + const promised = s.nextRoute!; + s = must(endWeek(toPlan(must(choose(s, "skip"))))); + // 第 2 週結束時可能被換掉的只有「不能用」的門;三扇都還能用就一模一樣 + if (!promised.includes("elite") && !promised.includes("advisor")) expect(s.route).toEqual(promised); + }); +}); diff --git a/web/src/game/audio/settings.ts b/web/src/game/audio/settings.ts index 5be7cbe..e8f5ac3 100644 --- a/web/src/game/audio/settings.ts +++ b/web/src/game/audio/settings.ts @@ -10,10 +10,12 @@ export interface Settings { shake: boolean; /** 全遊戲的頭像畫風(comic 漫畫、chibi Q 版大頭、pixel 復刻像素、sticker 平面貼紙;docs/24);自創角色可以各自選 */ avatarStyle: string; + /** 快速模式(docs/25):開票夜、週末結算、選情快報的節奏加快一倍 */ + fast: boolean; } const KEY = "tongsuan.settings"; -const DEFAULTS: Settings = { sound: true, music: true, voice: true, shake: true, avatarStyle: "comic" }; +const DEFAULTS: Settings = { sound: true, music: true, voice: true, shake: true, avatarStyle: "comic", fast: false }; const AVATAR_STYLES = ["comic", "chibi", "pixel", "sticker"]; const listeners = new Set<() => void>(); @@ -59,3 +61,6 @@ export function subscribeSettings(fn: () => void): () => void { listeners.add(fn); return () => listeners.delete(fn); } + +/** 動畫、播報的時間:快速模式減半 */ +export const pace = (ms: number): number => (current.fast ? Math.round(ms / 2) : ms); diff --git a/web/src/game/hud/SettingsMenu.tsx b/web/src/game/hud/SettingsMenu.tsx index 096fcae..9d3db0d 100644 --- a/web/src/game/hud/SettingsMenu.tsx +++ b/web/src/game/hud/SettingsMenu.tsx @@ -43,6 +43,10 @@ export function SettingsMenu() { 畫面震動 updateSettings({ shake: e.target.checked })} /> +