diff --git a/art/cards.tsv b/art/cards.tsv index a9bdd92..5814b65 100644 --- a/art/cards.tsv +++ b/art/cards.tsv @@ -85,3 +85,17 @@ street_interview a Taiwanese street corner with arcade shophouses, a small camer grassroots_walk a lone campaigner walking along a quiet Taiwanese rural road past rice paddies and a small temple, wearing a plain sash and carrying a rolled cloth banner, afternoon light facebook_live a small cluttered Taiwanese campaign office at night, a smartphone on a tripod with ring light streaming live, floating heart and comment bubbles shown as abstract shapes, cup of tea on the desk volunteer_calls a cozy Taiwanese apartment living room in the evening, two older volunteers sitting at a table with mobile phones and a handwritten contact notebook, making friendly calls +walk_everywhere a candidate in sneakers walking briskly along a winding path that passes through several different Taiwanese neighborhoods: an alley with arcade shophouses, the edge of a rice field, a night market entrance; a small team follows carrying water bottles +blooming_districts a miniature diorama of a Taiwanese county seen from above, divided into several small districts, each with tiny campaign volunteers greeting residents and small flower blossoms popping up across the neighborhoods +local_network a Taiwanese village diorama where red strings connect small houses, a temple plaza and porches where local community leaders sit; a small campaign team stands at the center of the web shaking hands +snowball_buzz a giant rolling snowball made of blank speech bubbles, heart icons and smartphone notification shapes rolling down a Taiwanese city street, growing bigger, passers-by looking at their phones in amazement +explainer_cards volunteers in a small bright campaign office arranging large colorful infographic cards with simple icons and abstract charts on a table, a smartphone screen showing a swipeable carousel of the same cards +turn_the_tables a press conference podium where a calm candidate holds up a document while reporters' camera flashes bounce back like a mirror; a chess board with a knight piece in the foreground +war_room a campaign war room with a large tabletop sand-table relief map of a Taiwanese county, tiny wooden pieces and arrows on it, staffers leaning over it planning, a whiteboard with abstract diagrams +ad_blitz a Taiwanese city intersection completely covered with plain campaign billboards, bus-side ads, banners on lamp posts and large video screens, all blank and colorful, pedestrians and scooters passing by +donation_box many ordinary people of all ages dropping coins and small bills into a large clear donation box on a street-side folding table, a big piggy bank, volunteers bowing to thank them +iron_legs a tireless campaign aide with sturdy legs and running shoes striding at dawn past several small Taiwanese town gateways, a step-counter watch on the wrist and a folded map in hand +faction_broker a seasoned local mediator seated at a round banquet table between two groups of local elders, tea cups and a lazy susan of dishes, everyone reaching across to shake hands +meme_editor a young social media editor at a laptop with two monitors full of colorful image tiles and emoji-like reaction icons, a coffee cup, stickers on the laptop, a ring light behind +crisis_flip a calm spokesperson standing in the rain under an umbrella as dark clouds break into sunshine and a rainbow, reporters' microphones around, puddles reflecting the light +actuary a meticulous campaign accountant at a desk with an abacus, a calculator, neat stacks of coins growing like a bar chart, ledgers and reading glasses diff --git a/art/generated/actuary.png b/art/generated/actuary.png new file mode 100644 index 0000000..7760cea --- /dev/null +++ b/art/generated/actuary.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ec02aaa750efe7295a0ed5103ddb0fe9df81f0626c6f3057e8e3dc3a818f7eb +size 1037398 diff --git a/art/generated/ad_blitz.png b/art/generated/ad_blitz.png new file mode 100644 index 0000000..cdae9df --- /dev/null +++ b/art/generated/ad_blitz.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a3d5ddd10a4116800dccf4c6278d732700bb60c50b2d8465fe7452dff5e98106 +size 1112862 diff --git a/art/generated/blooming_districts.png b/art/generated/blooming_districts.png new file mode 100644 index 0000000..9ab1acc --- /dev/null +++ b/art/generated/blooming_districts.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:43bedee7dd131ae959290c0af5fad755f45d9e804228f753e67839c5387acea2 +size 1364021 diff --git a/art/generated/crisis_flip.png b/art/generated/crisis_flip.png new file mode 100644 index 0000000..cc99cdb --- /dev/null +++ b/art/generated/crisis_flip.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:18e8a1782bdb63133208b2c02604d8f6d1bfa032e2e05f507ab9b7f2fbf910c6 +size 1251718 diff --git a/art/generated/donation_box.png b/art/generated/donation_box.png new file mode 100644 index 0000000..2773f68 --- /dev/null +++ b/art/generated/donation_box.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:23ce603bc35412e678742b0b20c93101f69503056749489217b0ce8404f21692 +size 1133756 diff --git a/art/generated/explainer_cards.png b/art/generated/explainer_cards.png new file mode 100644 index 0000000..4a67bfa --- /dev/null +++ b/art/generated/explainer_cards.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7874a98288cc3967f2b29cfe4b585774016d27e4b44d21d665d4c5d198a89e0b +size 1019148 diff --git a/art/generated/faction_broker.png b/art/generated/faction_broker.png new file mode 100644 index 0000000..4508832 --- /dev/null +++ b/art/generated/faction_broker.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d81f343e7b7826e5f781df1fc2a60a81d76df00ad12c72a808cdd79c4bdc88e2 +size 1251600 diff --git a/art/generated/iron_legs.png b/art/generated/iron_legs.png new file mode 100644 index 0000000..6711ade --- /dev/null +++ b/art/generated/iron_legs.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c6c0aed6bccd5b190d79a775769be2b212c92ab71a328c057692d79323b2ad1 +size 1017948 diff --git a/art/generated/local_network.png b/art/generated/local_network.png new file mode 100644 index 0000000..009e6ae --- /dev/null +++ b/art/generated/local_network.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ca3798b56546ec3f30dfc8c7070c3c77234bee41336ad476d63b2a886920f251 +size 1370588 diff --git a/art/generated/meme_editor.png b/art/generated/meme_editor.png new file mode 100644 index 0000000..4d351be --- /dev/null +++ b/art/generated/meme_editor.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0aca2c96279090b1c48b8d44dd62c59a27e4755d71f936505700a5fab1d48776 +size 1171920 diff --git a/art/generated/snowball_buzz.png b/art/generated/snowball_buzz.png new file mode 100644 index 0000000..4e40013 --- /dev/null +++ b/art/generated/snowball_buzz.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3749bc50aedeb052295742b2a8d387f2de95bc3defaa187e00a1ee2f10621fc7 +size 1128668 diff --git a/art/generated/turn_the_tables.png b/art/generated/turn_the_tables.png new file mode 100644 index 0000000..b38db26 --- /dev/null +++ b/art/generated/turn_the_tables.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3686d3b1f201c27e568d01378309dfdc87294d0420fc2305430b99ea409c367b +size 994938 diff --git a/art/generated/walk_everywhere.png b/art/generated/walk_everywhere.png new file mode 100644 index 0000000..0761659 --- /dev/null +++ b/art/generated/walk_everywhere.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:802b0408ea80a5f8e42757e0dd7ba7fa1c687ea42c65a5abf3c4b8df69fd4514 +size 1313374 diff --git a/art/generated/war_room.png b/art/generated/war_room.png new file mode 100644 index 0000000..ab12a26 --- /dev/null +++ b/art/generated/war_room.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5ebe1271c7e852257a8fc55393a4ad03295441028e646c5c56c61c9dbed8a78a +size 1066673 diff --git a/backend/apps/server/src/rogue-routes.ts b/backend/apps/server/src/rogue-routes.ts index 59d8d0a..ff0d1ae 100644 --- a/backend/apps/server/src/rogue-routes.ts +++ b/backend/apps/server/src/rogue-routes.ts @@ -102,7 +102,7 @@ export function registerRogue(app: FastifyInstance, ctx: RogueContext): void { app.post("/api/rogue/runs", async (request, reply) => { const parsed = ctx.parse(CreateRogueRequest, request.body); if (!parsed.ok) return ctx.fail(reply, 400, "請求格式不正確", parsed.details); - const { scenarioId, seed, ascension, even, daily, custom, career, carry, abilities, perks, policies, local } = parsed.data; + const { scenarioId, seed, ascension, even, daily, custom, career, carry, abilities, perks, policies, local, reputation } = parsed.data; const candidateId = custom ? CUSTOM_ID : parsed.data.candidateId; const runSeed = seed ?? (daily ? dailySeed(daily) : randomInt(2 ** 31)); let setup: Promise | undefined; @@ -174,6 +174,17 @@ export function registerRogue(app: FastifyInstance, ctx: RogueContext): void { const ability = ORIGINS[custom.background as Background]?.ability; if (ability) identity = { archetype: ability, basis: `出身:${custom.background}` }; } + // 對手的類型(docs/25):劇本裡的真實人物才有,和你一樣依那場選舉之前的選舉紀錄、政治獻金 + let rivalIdentity: { archetype: RogueArchetype; basis: string } | null = null; + if (!local) { + const world = await ctx.world(scenarioId); + const rival = (await setup).rival; + const cand = world?.scenario.candidates.find((c) => c.id === rival.id); + if (world && cand) { + const rec = ctx.realAbilities ? await ctx.realAbilities(rival.name, world.scenario.region.countyCode, world.scenario.electionDate) : null; + rivalIdentity = realArchetype(rec, candidateStats(world.scenario, cand).wealth); + } + } const state = createRun(await setup, randomUUID(), runSeed, { weeks: local ? (local.kind === "village" ? VILLAGE_WEEKS : COUNCIL_WEEKS) : undefined, ascension, @@ -187,6 +198,9 @@ export function registerRogue(app: FastifyInstance, ctx: RogueContext): void { abilitiesBasis: daily ? null : (record?.basis ?? null), archetype: identity?.archetype ?? null, archetypeBasis: identity?.basis ?? null, + rivalArchetype: rivalIdentity?.archetype ?? null, + rivalArchetypeBasis: rivalIdentity?.basis ?? null, + reputation: reputation ?? null, // 自創角色的出身與政黨:專屬起始牌、黨的資源(每日一戰大家條件一樣,不套用) origin: custom && !daily ? { background: custom.background, party: custom.party, kind: partyKind(custom.party) } : null, perks: daily ? [] : perks, diff --git a/backend/apps/sim/src/rogue-balance.ts b/backend/apps/sim/src/rogue-balance.ts index 5aba202..81a3546 100644 --- a/backend/apps/sim/src/rogue-balance.ts +++ b/backend/apps/sim/src/rogue-balance.ts @@ -5,6 +5,7 @@ * - 打得好(greedy)要比亂打(random)、不理對手(naive)多拿好幾個百分點 → 技術有差 * - 只拿某一派牌的玩家(地面、空戰、攻擊)勝率不能差太多 → 沒有一招通吃 * - --archetypes all:每種候選人類型(docs/25)各跑一次,「打得好」的勝率差距要在 ±5 個百分點內 + * - --rivals all:對手的每種類型各跑一次(真實人物的對手都有類型;不指定是沒有類型) */ import { mkdir, readFile, writeFile } from "node:fs/promises"; import { join } from "node:path"; @@ -31,11 +32,12 @@ const mean = (xs: number[]) => xs.reduce((a, b) => a + b, 0) / (xs.length || 1); async function main(): Promise { const { values } = parseArgs({ - options: { scenario: { type: "string", default: "taoyuan-2022-mayor-even" }, seeds: { type: "string", default: "200" }, ascension: { type: "string", default: "0" }, even: { type: "boolean", default: false }, bots: { type: "string" }, archetypes: { type: "string" } }, + options: { scenario: { type: "string", default: "taoyuan-2022-mayor-even" }, seeds: { type: "string", default: "200" }, ascension: { type: "string", default: "0" }, even: { type: "boolean", default: false }, bots: { type: "string" }, archetypes: { type: "string" }, rivals: { type: "string" } }, }); const ascension = Number(values.ascension); // 不指定類型就是舊的玩法(沒有類型);all 是六種都跑 const archetypes: (RogueArchetype | null)[] = !values.archetypes ? [null] : values.archetypes === "all" ? (Object.keys(ARCHETYPES) as RogueArchetype[]) : (values.archetypes.split(",") as RogueArchetype[]); + const rivals: (RogueArchetype | null)[] = !values.rivals ? [null] : values.rivals === "all" ? (Object.keys(ARCHETYPES) as RogueArchetype[]) : (values.rivals.split(",") as RogueArchetype[]); const started = Date.now(); const world = await loadWorld(values.scenario); const topology = JSON.parse(await readFile(join(DEFAULT_PACKS_ROOT, world.scenario.packId, "topology.json"), "utf-8")) as TopologyLike; @@ -50,16 +52,18 @@ async function main(): Promise { const voters = setup.towns.reduce((a, t) => a + t.voters, 0); lines.push(`## 玩 ${setup.you.name}(對手 ${setup.rival.name})`, ""); lines.push(`預計投票 ${Math.round(voters).toLocaleString()} 人;各區特色:${setup.towns.map((t) => `${t.name}${t.traits.length ? `(${t.traits.map((x) => TRAIT_LABELS[x]).join("、")})` : ""}`).join("、")}`, ""); - lines.push("| 類型 | 玩家 | 平均得票率 | 平均差距 | 勝率 |", "|---|---|---:|---:|---:|"); + lines.push("| 類型 | 對手類型 | 玩家 | 平均得票率 | 平均差距 | 勝率 |", "|---|---|---|---:|---:|---:|"); for (const archetype of archetypes) - for (const bot of bots) { - const runs = seeds.map((seed) => runBot(setup, seed, bot.id, { ascension, archetype }).result!); - const share = mean(runs.map((r) => r.youShare)); - const margin = mean(runs.map((r) => r.youShare - r.rivalShare)); - const win = mean(runs.map((r) => (r.won ? 1 : 0))); - lines.push(`| ${archetype ? ARCHETYPES[archetype].name : "(無)"} | ${bot.label} | ${pct(share, 2)} | ${margin >= 0 ? "+" : ""}${(margin * 100).toFixed(2)} | ${pct(win, 0)} |`); - json.push({ candidate: cand.name, archetype, bot: bot.id, ascension, share, margin, win }); - } + for (const rivalArchetype of rivals) + for (const bot of bots) { + const runs = seeds.map((seed) => runBot(setup, seed, bot.id, { ascension, archetype, rivalArchetype }).result!); + const share = mean(runs.map((r) => r.youShare)); + const margin = mean(runs.map((r) => r.youShare - r.rivalShare)); + const win = mean(runs.map((r) => (r.won ? 1 : 0))); + const name = (a: RogueArchetype | null) => (a ? ARCHETYPES[a].name : "(無)"); + lines.push(`| ${name(archetype)} | ${name(rivalArchetype)} | ${bot.label} | ${pct(share, 2)} | ${margin >= 0 ? "+" : ""}${(margin * 100).toFixed(2)} | ${pct(win, 0)} |`); + json.push({ candidate: cand.name, archetype, rivalArchetype, bot: bot.id, ascension, share, margin, win }); + } lines.push(""); console.log(`${cand.name} 完成`); } diff --git a/backend/docs/25-gameplay-v3.md b/backend/docs/25-gameplay-v3.md index 3ebabc5..ccceacf 100644 --- a/backend/docs/25-gameplay-v3.md +++ b/backend/docs/25-gameplay-v3.md @@ -4,33 +4,36 @@ > 搭配某些卡片」;之後又要求「增加遊戲的黏著度以及可完成度,不然好像隨完即丟」。本文件是給實作用的規格:每一節寫現況(附程式位置與數據)、要加什麼、怎麼改、怎麼驗收。 > 所有數字都是起始值,一律用 `apps/sim` 的 `rogue-balance`、`career-balance` 跑過再定案。 -## 實作狀態(2026-10-28) +## 實作狀態(2026-10-29) | 節 | 狀態 | 實際做法 | |---|---|---| | 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。每日一戰也套用;選人畫面就看得到類型(`/api/scenarios` 的 `archetype`,伺服器啟動時先算好)。對手的類型還沒做 | +| 1b 類型與技能 | 完成(數字已依模擬調過) | 六種類型照規格,調整:黑馬型每點聲勢 +12%(規格 +16% 太強)、財務型每週 +150 萬、地面牌 −5%,另外週末依手上的資金自動加票(每 100 萬全市 +150 票,最多算 1,000 萬;隨手玩的人不會花錢,財務型原本最難)。真實候選人:資歷三項取最高,同級比實際數字超過門檻多少;資歷都是 0 才看經費(多 → 財務型,少 → 黑馬型)。2022 縣市長 42 位主要候選人:組織 20、媒體 9、資深 7、財務 5、黑馬 1。每日一戰也套用;選人畫面就看得到類型(`/api/scenarios` 的 `archetype`,伺服器啟動時先算好)。對手也有類型(同樣依選舉紀錄,`rival.ts` 的 `RIVAL_TYPES`):決定出招比例、比較常抽到哪幾條規則,強項和弱點各一個(例如媒體型對手空戰 +10%,但你的比較文宣對他 +20%),畫面上和對手規則並排、第一週的快報也會說。依模擬調過,讓「隨手玩」對上各種類型的勝率不要差太多 | | 1c 接上流派 | 完成 | 下一站、物資行裡和類型搭配的牌、幕僚權重 ×1.5,牌面標「適合你的類型」 | -| 2 流派與爆分 | 完成 | 9 張核心牌(走透透、挨家挨戶、樁腳網、聲量滾雪球、懶人包、反將一軍、沙盤推演、地毯式廣告、小額募款)+5 位幕僚(鐵腿、派系協調人、懶人包小編、危機變轉機、精算師)。「全面動員令+」沒改。插圖先共用主題相近的 | +| 2 流派與爆分 | 完成 | 9 張核心牌(走透透、遍地開花、樁腳網、聲量滾雪球、懶人包、反將一軍、沙盤推演、地毯式廣告、小額募款)+5 位幕僚(鐵腿、派系協調人、懶人包小編、危機變轉機、精算師)。「全面動員令+」沒改。14 張專屬插圖用 `art/cards.tsv` 的題材補上。依模擬加強:聲量每點 +5%、空戰牌花費 −30%;懶人包每點聲量 +6%;樁腳網三成;反將一軍把這週擋下的所有行動一半變成票;沙盤推演每週前兩張;危機變轉機算所有擋下的行動(最多 +2)。**流派傾向**(`route.ts` 的 `schoolPull`):牌組裡某一派的牌越多,那一派的牌、幕僚越常出現;同一派 3 張以上算成形,拜會地方、物資行一定有一張那一派還沒拿的核心牌 | | 3 對手規則與精英站 | 完成 | 7 條規則(名嘴加持、地方大老、大打空戰、鐵票區、網路謠言、地毯式掃街、形象牌;後發制人維持原本的風格),逆風 5 起抽 2 條。精英站「地方派系談判」:第 2、4 週結束後可能出現,選了就接下挑戰(不進門),下週結算。下一站畫面灰色顯示下下週的門(到時候不能用的會重抽) | -| 4 隨機行事曆 | 部分 | 8 週的局辯論 3–5、民調 4–5、黑函 5–6 週,5 種排法;上方週次標「辯、民、函、勢、夜」。地方事件週(遶境、義民祭…)還沒做 | +| 4 隨機行事曆 | 完成 | 8 週的局辯論 3–5、民調 4–5、黑函 5–6 週,5 種排法;上方週次標「辯、民、函、勢、夜」。地方事件週:縣市裡有宮廟多、客家庄、人口密集、長輩多、年輕人多的區,開局就排 1 個(一半的局 2 個)神明遶境、義民祭、捷運通車剪綵、重陽敬老、青年音樂祭,在第 2–6 週沒有大場面的週;只加成有那個特色的區,雙方都算(`data.ts` 的 `EVENTS` 裡有 `local` 的)。週次上標「遶、義、捷、敬、音」 | | 5 局中小勝利 | 完成 | 翻區抽牌(每週最多 2 張,黑馬型另外再抽);民調領先多一張稀有牌(偏向你的類型)、落後下週體力 +1;結果頁標「最關鍵的一區」 | | 6 張力與難度 | 不改基準數字 | 見下面的模擬。預估數字照舊完整顯示(docs/21 的決定:畫面上的數字和打出去一致) | | 7 再來一局 | 完成 | 結果頁:贏了就有「挑戰逆風 N+1 級」(已解鎖就出現)、Enter 直接再來、「攻下一塊地盤」;出牌不等伺服器(牌先飛出去、手牌體力先扣,伺服器回來校正);設定的「快速模式」讓開票夜、週末結算、選情快報快一倍 | -| 8 跨局進度 | 部分 | 完成度:全台制霸(22 縣市+總統大選)、六種類型、類型逆風挑戰(每種類型 0–10 級)、成就;大廳一條、圖鑑完整面板(`web/src/game/rogue/Completion.tsx`、`progress.ts`);選人畫面顯示這個類型的逆風紀錄。聲望解鎖新牌沒做(新牌直接進獎勵池) | +| 8 跨局進度 | 完成 | 完成度:全台制霸(22 縣市+總統大選)、六種類型、類型逆風挑戰(每種類型 0–10 級)、成就;大廳一條、圖鑑完整面板(`web/src/game/rogue/Completion.tsx`、`progress.ts`);選人畫面顯示這個類型的逆風紀錄。聲望解鎖:聲望 = 打完的局數+勝場(輸了 +1、贏了 +2,舊玩家照已有的紀錄算),9 張核心牌和 5 位新幕僚依聲望 1–22 逐一解鎖(`rogue/src/unlocks.ts`),開局帶給伺服器;圖鑑寫解鎖條件、結果頁寫「解鎖了什麼/再幾點解鎖什麼」,完成度多一項「聲望解鎖」。每日一戰、模擬全部解鎖。流派熟練度沒做(和聲望合併) | -模擬(`node apps/sim/src/rogue-balance.ts`,桃園 2022 勢均力敵,每種 100 局,兩位候選人): +模擬(`node apps/sim/src/rogue-balance.ts`,桃園 2022 勢均力敵,每種 100 局,兩位候選人;2026-10-29 加完地方事件週、對手類型、流派傾向之後): -| 難度 | 打得好(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% | — | +| 難度 | 打得好(greedy) | 隨手玩(casual) | +|---|---|---| +| 標準 | 99%(差距 +7.6~+8.4) | 37–46% | +| 逆風 6 | 63–74% | 7–10% | -六種類型分開跑(`--archetypes all`):「打得好」都 98–100%,差距 +6.7~+10.7;「隨手玩」30–68%(財務型、資深型最難,黑馬型、組織型最容易)。 +- **流派**(逆風 6,`--bots greedy,ground,air,attack`;標準難度大家都贏,看不出差別):混打 63–74%;只拿地面牌 69–78%(比混打多 4–6 個百分點,達到規格);只拿攻防牌 53–70%(少 4–10);只拿空戰牌 51–61%(少 12–13)。 + 空戰派卡在錢:電視廣告一張 300 萬,逆風 2、3 級又砍資金和收入;核心牌加強、空戰牌打七折之後還是追不上。之後可以考慮空戰派的錢從哪裡來(例如網路牌回收一點資金)。 +- **你的類型**(`--archetypes all`):「打得好」98–100%(差距 +6.2~+10.8);「隨手玩」資深型 32–46%、清廉型 44–50%、媒體型 44–61%、黑馬型 55%、財務型 49–62%(原本最難,加了「資金自動加票」)、組織型 60–74%。 +- **對手的類型**(`--rivals all`,隨手玩):媒體型 33–46%、組織型 50–58%、資深型 43–55%、財務型 29–45%、清廉型 47–60%、黑馬型 36–47%(沒有類型時 37–46%)。 第 6 節的兩個目標(打得好 75–85%、隨手玩 35–45%)在目前的技術差距下互相衝突:兩種玩家差 8 個百分點, 把會打的人壓到 85% 以下,隨手玩會掉到一成左右。所以標準難度不再加難(隨手玩已經落在目標裡), -會打的人靠「贏了直接挑戰下一級逆風」往上爬(逆風 6 約七成)。流派核心牌讓單一流派接近混打,但還沒有超過混打(規格目標 +5~10),之後可以再加強核心牌的倍率。 +會打的人靠「贏了直接挑戰下一級逆風」往上爬(逆風 6 約七成)。 ## 0. 現況診斷 @@ -76,7 +79,7 @@ |---|---|---|---|---| | 媒體型 | 單次最高得票多 | 空戰牌(media、online、tv)+15%;每週第一次爆紅成功,下一張空戰牌再 ×2 | 對手的批評 +20% | 臉書直播(`live`) | | 組織型 | 當選次數多 | 每週開始,本命區自動有一座樁腳(盾 = 佈樁基礎值);佈樁牌每週第一張不花體力 | 空戰牌 −15% | 志工大隊(`volunteers`) | -| 資深型 | 從政年資長 | 記者會類(press)+20%;辯論多一張論點;「記者追問」不花體力 | 年輕人多的區 −15% | 政策白皮書(`whitepaper`) | +| 資深型 | 從政年資長 | 記者會類(press)+20%;辯論多一張論點;「記者追問」不花體力 | 年輕人多的區 −10%(規格 −15%,依模擬調過) | 政策白皮書(`whitepaper`) | | 財務型 | 政治獻金多 | 每週資金 +100 萬;物資行八折;新牌「地毯式廣告」可以把錢換成票 | 地面牌 −10% | 募款餐會(`dinner`)多一張 | | 清廉型 | 自創角色出身(醫師) | 黑函危機損失減半;「記者追問」不會被塞進牌組 | 每週資金 −20% | 巡迴義診(`origin_clinic`) | | 黑馬型 | 沒有當選紀錄、小黨 | 聲勢每點 +16%(一般 +8%);每翻轉一區多抽 1 張 | 起始資金 −30% | 徒步掃街(`walkx`) | @@ -97,13 +100,13 @@ | 派系 | 核心牌 1 | 核心牌 2 | 幕僚 | |---|---|---|---| -| 地面 | 「走透透」能力:同一週每多打一張地面牌,之後的地面牌 +8%(疊加,週末歸零) | 「挨家挨戶」:這週在幾個不同的區出過牌,就 +幾倍的基礎票 | 「鐵腿」:一週在 3 個以上不同的區出牌,週末聲勢 +2 | +| 地面 | 「走透透」能力:同一週每多打一張地面牌,之後的地面牌 +8%(疊加,週末歸零) | 「遍地開花」(原名挨家挨戶,和一般牌撞名):這週在幾個不同的區出過牌,就 +幾倍的基礎票 | 「鐵腿」:一週在 3 個以上不同的區出牌,週末聲勢 +2 | | 組織 | 「樁腳網」能力:週末每座還在的樁腳,在那區把盾剩下的一成轉成你的票 | 「全面動員令+」改成插旗的區每區 +票(現有 `mobilize` 加強) | 「派系協調人」:樁腳擋下對手的票,一半轉成你的 | | 空戰 | 「聲量滾雪球」能力:每打一張空戰牌,聲量 +1(整局不歸零,上限 15);空戰牌 +4% × 聲量 | 「懶人包」:全市 +票,聲量每點多 5% | 「懶人包小編」:爆紅成功後,那張牌回到手上(每週一次) | | 攻防 | 「反將一軍」:這週擋下的批評,一半變成你的票 | 「沙盤推演」能力:每週多看到對手下週的一個意圖 | 「危機變轉機」:每擋下一次攻擊,聲勢 +1 | | 資金 | 「地毯式廣告」:花掉手上所有錢,每 100 萬換全市 +票 | 「小額募款」:資金 +,你插旗的區越多募越多 | 「精算師」:週末每 100 萬存款 +3%(錢滾錢,上限 1,000 萬) | -- 新牌的插圖:`web/public/cards` 現有的 88 張都已經有牌或幕僚在用。先共用主題相近的(例如挨家挨戶用 `door_to_door`、懶人包用 `line_groups`),再用 `art/cards.tsv` 加題材、`art/regen-grokcli.sh` 補專屬插圖。 +- 新牌的插圖:14 張都用 `art/cards.tsv` 的題材、`art/gen-card-grokcli.sh` 的流程補上專屬插圖(`walk_everywhere`、`snowball_buzz`、`donation_box`…)。 - 新牌、新幕僚加進圖鑑(`view.ts catalog`)。 ## 3. 對手規則與精英站 diff --git a/backend/packages/protocol/src/rogue.ts b/backend/packages/protocol/src/rogue.ts index 58f40d2..5097f09 100644 --- a/backend/packages/protocol/src/rogue.ts +++ b/backend/packages/protocol/src/rogue.ts @@ -108,6 +108,8 @@ export const RogueAdvisor = z.object({ school: z.string(), /** 圖鑑:怎麼拿到 */ how: z.string().optional(), + /** 圖鑑:聲望幾點解鎖(null 是一開始就有) */ + unlock: z.number().int().nullable().optional(), }); export type RogueAdvisor = z.infer; @@ -233,6 +235,8 @@ export type RogueStopKind = z.infer; export const RogueOffer = z.object({ /** 圖鑑:怎麼拿到(只有圖鑑的清單有) */ how: z.string().optional(), + /** 圖鑑:聲望幾點解鎖(null 是一開始就有;只有圖鑑的清單有) */ + unlock: z.number().int().nullable().optional(), kind: z.enum(["card", "advisor", "remove"]), id: z.string(), name: z.string(), @@ -365,7 +369,17 @@ export const RogueView = z.object({ /** 雙方的代表色(政黨色;同一個顏色或教學關卡用別的顏色區分) */ 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), + schedule: z + .object({ + debate: z.number().int(), + poll: z.number().int(), + crisis: z.number().int(), + bigRally: z.number().int().nullable(), + /** 地方事件週(遶境、義民祭…):short 是行事曆上的一個字 */ + local: z.array(z.object({ week: z.number().int(), id: z.string(), title: z.string(), short: z.string() })).default([]), + }) + .nullable() + .default(null), /** 下下週的門(docs/25:看得到前方):選下一站的時候灰色顯示 */ nextRoute: z.array(z.object({ kind: RogueStopKind, title: z.string() })).nullable().default(null), /** 地方派系談判(精英站,docs/25):這週在哪一區淨增多少票;progress 是目前淨增 */ @@ -389,6 +403,8 @@ export const RogueView = z.object({ .default(null), /** 對手性格 */ rivalTrait: z.object({ name: z.string(), text: z.string() }), + /** 對手的類型(docs/25):真實人物才有,依中選會選舉紀錄 */ + rivalType: z.object({ archetype: RogueArchetype, name: z.string(), skill: z.string(), weakness: z.string(), basis: z.string().nullable() }).nullable().default(null), towns: z.array(RogueTown), intents: z.array(RogueIntent), /** 對手預告的大型造勢(第幾週、哪一區、預計多少) */ @@ -479,6 +495,8 @@ export const CreateRogueRequest = z.object({ seed: z.number().int().nonnegative().optional(), /** 逆風難度 0–10 */ ascension: z.number().int().min(0).max(10).default(0), + /** 聲望(打完的局數 + 勝場):決定哪些核心牌、幕僚已經解鎖(docs/25 第 8 節);沒帶是全部解鎖 */ + reputation: z.number().int().min(0).max(1_000_000).optional(), /** 勢均力敵:雙方開局底盤拉平(劇本 id 結尾是 -even 的一定拉平) */ even: z.boolean().default(false), /** 每日一戰的日期(YYYY-MM-DD) */ diff --git a/backend/packages/rogue/src/advisors.ts b/backend/packages/rogue/src/advisors.ts index 1fd182d..23e9472 100644 --- a/backend/packages/rogue/src/advisors.ts +++ b/backend/packages/rogue/src/advisors.ts @@ -19,11 +19,11 @@ export const ADVISORS: readonly AdvisorDef[] = [ { 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: "iron_legs", name: "鐵腿", art: "iron_legs", text: "一週在 3 個以上不同的區出牌,週末聲勢 +2", school: "ground" }, + { id: "faction_broker", name: "派系協調人", art: "faction_broker", text: "你的樁腳擋下對手的票,一半變成你的", school: "org" }, + { id: "meme_editor", name: "懶人包小編", art: "meme_editor", text: "爆紅之後,那張牌回到手上(每週一次)", school: "air" }, + { id: "crisis_flip", name: "危機變轉機", art: "crisis_flip", text: "每擋下對手一個行動(批評、打對台),週末聲勢 +1(最多 +2)", school: "defend" }, + { id: "actuary", name: "精算師", art: "actuary", 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/archetypes.ts b/backend/packages/rogue/src/archetypes.ts index 819a741..c49f9af 100644 --- a/backend/packages/rogue/src/archetypes.ts +++ b/backend/packages/rogue/src/archetypes.ts @@ -42,7 +42,7 @@ export const ARCHETYPES: Record = { eloquence: { name: "資深型", skill: "記者會、座談類的牌 +20%;辯論多一張論點;回應記者追問不花體力", - weakness: "年輕人多的區 −15%", + weakness: "年輕人多的區 −10%", card: "whitepaper", replaces: "canvass", tags: ["press"], @@ -50,7 +50,7 @@ export const ARCHETYPES: Record = { }, finance: { name: "財務型", - skill: "每週資金 +150 萬;競選物資行八折", + skill: "每週資金 +150 萬;競選物資行八折;週末依手上的資金自動加票(最多算 1,000 萬)", weakness: "地面牌 −5%", card: "dinner", replaces: null, diff --git a/backend/packages/rogue/src/bots.ts b/backend/packages/rogue/src/bots.ts index 96f1e7c..f19692c 100644 --- a/backend/packages/rogue/src/bots.ts +++ b/backend/packages/rogue/src/bots.ts @@ -88,6 +88,8 @@ function playCasual(s: RunState): RunState { return s; } +const CORE_POWERS = new Set(["legwork", "network", "buzz", "wargame"]); + /** 每點體力換多少票;錢不夠時募款牌加分,沒有把柄時打探加分 */ function playGreedy(s: RunState): RunState { for (let k = 0; k < 14; k++) { @@ -102,7 +104,8 @@ function playGreedy(s: RunState): RunState { if (kind === "probe") value = s.leverage === 0 ? 2500 * s.scale : 0; if (kind === "draw") value = 2600 * s.scale; if (kind === "rush") value = s.hand.length > 1 ? 3000 * s.scale : 0; - if (kind === "power") value = (s.totalWeeks - s.week + 1) * 900 * s.scale; + // 能力牌整局有效:越早打越值得(流派核心的能力牌效果大,打得好的人一拿到就先打) + if (kind === "power") value = (s.totalWeeks - s.week + 1) * (CORE_POWERS.has(card.id) ? 2200 : 900) * s.scale; if (kind === "answer") value = 3000 * s.scale; const per = value / Math.max(0.5, card.cost); if (per > 0 && (!best || per > best.value)) best = { uid: c.uid, target: p.target === "city" ? null : p.target, value: per }; @@ -132,13 +135,22 @@ const ADVISOR_TASTE: Record = { 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"] }; +/** 只拿某一派牌的玩家:組成形的流派會先拿自己那派的核心牌、幕僚(docs/25 第 2 節) */ +const CORE: Partial> = { + ground: ["legwork", "doorstep", "network", "iron_legs", "faction_broker"], + air: ["buzz", "explainer", "meme_editor", "carpetads"], + attack: ["turntable", "wargame", "crisis_flip"], +}; + const cardScore = (bot: BotName, id: string): number => { + if (CORE[bot]?.includes(id)) return 6; const card = findCard(id)!; const tags = ARCHETYPE_TAGS[bot]; if (tags && !card.tags.some((t) => tags.includes(t))) return 0; return CARD_TASTE[id] ?? 1; }; const advisorScore = (bot: BotName, id: string): number => { + if (CORE[bot]?.includes(id)) return 6; const schools = ARCHETYPE_SCHOOL[bot]; if (schools && !schools.includes(ADVISOR_BY_ID.get(id)?.school ?? "any")) return 0.5; return ADVISOR_TASTE[id] ?? 1; diff --git a/backend/packages/rogue/src/cards.ts b/backend/packages/rogue/src/cards.ts index d332685..b361e43 100644 --- a/backend/packages/rogue/src/cards.ts +++ b/backend/packages/rogue/src/cards.ts @@ -1,8 +1,8 @@ import { ADVISOR_BY_ID } from "./advisors.ts"; -import { HOME_MULT } from "./archetypes.ts"; +import { ARCHETYPES, 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, addRivalMomentum, 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, rivalHurtMult, spread, updateFlags } from "./mechanics.ts"; import { addTally, cloneState, newCard, rand, type CardInst, type Intent, type RunState, type TownState } from "./state.ts"; /** 組合拳:同一週同一區打出第 n 種不同的牌,這張牌的加成 */ @@ -21,12 +21,14 @@ 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 }; + if (s.powers.includes("wargame") && blocker(card.id) && (s.weekCards ?? []).filter(blocker).length < 2) 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)) }; + // 聲量滾雪球(能力):聲量大,廣告好談價,空戰牌的花費 −30% + const buzz = s.powers.includes("buzz") && card.tags.includes("media"); + return { energy: freeOnline ? 0 : card.cost, money: Math.round(card.money * (ads ? 0.7 : 1) * (buzz ? 0.7 : 1)) }; } /** 對手這週可以打對台的行動:打在某一區、還沒被打對台過 */ @@ -61,6 +63,10 @@ const TOWN_ADVISORS = [ { id: "student_leader", trait: "young", m: 1.4 }, ] as const; +/** 聲量滾雪球:每點聲量讓空戰牌 +5%;懶人包每點再 +6%(docs/25 第 2 節,依模擬調過) */ +export const BUZZ_STEP = 0.05; +export const EXPLAINER_STEP = 0.06; + /** 牌類的幕僚 */ const CARD_ADVISORS = [ { id: "temple_master", ok: (c: CardDef) => c.tags.includes("temple"), m: 1.6 }, @@ -91,8 +97,8 @@ export function boost(s: RunState, card: CardDef, town: TownState | null): Boost 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)}`); + if (s.powers.includes("buzz") && card.tags.includes("media") && buzz > 0) apply(1 + BUZZ_STEP * buzz, `聲量 ${buzz} ×${(1 + BUZZ_STEP * buzz).toFixed(2)}`); + if (card.id === "explainer" && buzz > 0) apply(1 + EXPLAINER_STEP * buzz, `懶人包・聲量 ${buzz} ×${(1 + EXPLAINER_STEP * 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; @@ -119,9 +125,9 @@ export function boost(s: RunState, card: CardDef, town: TownState | null): Boost if (isArch(s, "media") && air && s.viral?.boost) apply(2, "爆紅加持 ×2"); if (isArch(s, "organization") && air) apply(0.85, "組織型(空戰)×0.85"); if (isArch(s, "eloquence") && card.tags.includes("press")) apply(1.2, "資深型 ×1.2"); - if (isArch(s, "eloquence") && town?.traits.includes("young")) apply(0.85, "資深型(年輕人多)×0.85"); + if (isArch(s, "eloquence") && town?.traits.includes("young")) apply(0.9, "資深型(年輕人多)×0.9"); if (isArch(s, "finance") && card.tags.includes("ground")) apply(0.95, "財務型(地面)×0.95"); - const ev = eventMult(s, card.tags); + const ev = eventMult(s, card.tags, town); apply(ev, `${eventOf(s).title} ×${ev}`); if (s.week === s.totalWeeks && card.tags.includes("rally")) apply(EVE_RALLY, `選前之夜 ×${EVE_RALLY}`); if (has(s, "opener") && s.playedThisWeek === 0) apply(1.5, "開場哥 ×1.5"); @@ -193,6 +199,11 @@ function hurtRival(s: RunState, amount: number, out: Played, text: string): void amount *= 0.5; out.notes.push("形象牌:效果只剩一半"); } + const type = rivalHurtMult(s); + if (type !== 1) { + amount *= type; + out.notes.push(`對手是${ARCHETYPES[s.options.rivalArchetype!].name} ×${type}`); + } 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) }); @@ -362,7 +373,7 @@ function resolve(s: RunState, card: CardDef, town: TownState | null, intent: Int 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.notes.push(`對手這週的批評剩 ${Math.round(e.cut * 100)}%;這週擋下的行動,一半變成你的票`); out.log.push({ side: "you", text: card.name, town: null, votes: 0 }); punditBacklash(s, out); break; diff --git a/backend/packages/rogue/src/data.ts b/backend/packages/rogue/src/data.ts index f270796..841c4f3 100644 --- a/backend/packages/rogue/src/data.ts +++ b/backend/packages/rogue/src/data.ts @@ -116,15 +116,15 @@ export const CARDS: readonly CardDef[] = [ { 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: "legwork", name: "走透透", art: "walk_everywhere", cost: 1, money: 0, rarity: "rare", tags: ["ground"], target: "none", effect: { kind: "power", power: "legwork" }, text: "能力:這週每打過一張地面牌,之後的地面牌 +8%(週末歸零)" }, + { id: "doorstep", name: "遍地開花", art: "blooming_districts", cost: 1, money: 0, rarity: "rare", tags: ["ground"], target: "town", effect: { kind: "breadth", base: 900 }, text: "該區 +{n} × 這週出過牌的區數(最多 5 區)" }, + { id: "network", name: "樁腳網", art: "local_network", cost: 1, money: 0, rarity: "rare", tags: ["org"], target: "none", effect: { kind: "power", power: "network" }, text: "能力:週末每座還沒被用掉的樁腳,三成變成你在那區的票" }, + { id: "buzz", name: "聲量滾雪球", art: "snowball_buzz", cost: 1, money: 0, rarity: "rare", tags: ["media"], target: "none", effect: { kind: "power", power: "buzz" }, text: "能力:空戰牌的花費 −30%;每打一張空戰牌聲量 +1(整局累積,最多 15),空戰牌每點聲量 +5%" }, + { id: "explainer", name: "懶人包", art: "explainer_cards", cost: 1, money: 0, rarity: "rare", tags: ["media", "online"], target: "city", effect: { kind: "city", base: 2300, weight: "young" }, text: "全市 +{n},年輕人多的區分到較多;每點聲量再 +6%" }, + { id: "turntable", name: "反將一軍", art: "turn_the_tables", cost: 1, money: 0, rarity: "rare", tags: ["defend"], target: "none", effect: { kind: "turnaround", cut: 0.5 }, text: "對手這週的批評剩一半;這週你擋下的對手行動,一半變成你的全市票" }, + { id: "wargame", name: "沙盤推演", art: "war_room", cost: 1, money: 0, rarity: "rare", tags: ["defend", "intel"], target: "none", effect: { kind: "power", power: "wargame" }, text: "能力:每週前兩張打對台、澄清、事實查核、反將一軍不花體力" }, + { id: "carpetads", name: "地毯式廣告", art: "ad_blitz", cost: 1, money: 0, rarity: "rare", tags: ["money"], target: "city", effect: { kind: "spend", perHundred: 900 }, text: "花光手上的資金:每 100 萬全市 +{n}" }, + { id: "microdonate", name: "小額募款", art: "donation_box", 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" }, @@ -311,14 +311,18 @@ export interface EventDef { title: string; text: string; weight: number; - /** 有這個標籤的牌(雙方都算)效果倍率 */ - mods?: { tag: string; mult: number }[]; + /** 有這個標籤的牌(雙方都算)效果倍率;tag "*" 是所有的牌;有 trait 的只算打在有這個特色的區 */ + mods?: { tag: string; mult: number; trait?: RogueTrait }[]; /** 本週收入倍率 */ income?: number; /** 對手所有行動的倍率 */ rival?: number; /** 不好的事(逆風 9 級以上比較常出現) */ bad?: boolean; + /** 地方事件週(docs/25 第 4 節):縣市裡有這個特色的區才排進行事曆,不會隨機抽到 */ + local?: RogueTrait; + /** 行事曆上的一個字 */ + short?: string; } export const EVENTS: readonly EventDef[] = [ @@ -338,6 +342,12 @@ export const EVENTS: readonly EventDef[] = [ { id: "prices", title: "物價上漲", text: "大家荷包變薄:本週收入 −30%。", weight: 0.8, income: 0.7, bad: true }, { id: "outage", title: "社群平台當機", text: "網路牌 −50%(雙方都一樣)。", weight: 0.7, mods: [{ tag: "online", mult: 0.5 }], bad: true }, { id: "fair", title: "地方節慶", text: "各區活動多、人潮多:地面牌 +20%。", weight: 1, mods: [{ tag: "ground", mult: 1.2 }] }, + // 地方事件週:開局就排進行事曆,只影響有這個特色的區(雙方都一樣) + { id: "procession", title: "神明遶境", text: "宮廟多的區:宮廟牌 ×2;造勢被遶境人潮搶走 −30%(雙方都一樣)。", weight: 0, local: "temples", short: "遶", mods: [{ tag: "temple", mult: 2, trait: "temples" }, { tag: "rally", mult: 0.7, trait: "temples" }] }, + { id: "yimin", title: "義民祭", text: "客家庄:地面牌 ×1.5(雙方都一樣)。", weight: 0, local: "hakka", short: "義", mods: [{ tag: "ground", mult: 1.5, trait: "hakka" }] }, + { id: "metro", title: "捷運通車剪綵", text: "人口密集的區:地面牌 ×1.4、造勢 ×1.3(雙方都一樣)。", weight: 0, local: "dense", short: "捷", mods: [{ tag: "ground", mult: 1.4, trait: "dense" }, { tag: "rally", mult: 1.3, trait: "dense" }] }, + { id: "elders", title: "重陽敬老", text: "長輩多的區:所有的牌 ×1.3(雙方都一樣)。", weight: 0, local: "old", short: "敬", mods: [{ tag: "*", mult: 1.3, trait: "old" }] }, + { id: "musicfest", title: "青年音樂祭", text: "年輕人多的區:造勢 ×1.5、地面牌 ×1.2(雙方都一樣)。", weight: 0, local: "young", short: "音", mods: [{ tag: "rally", mult: 1.5, trait: "young" }, { tag: "ground", mult: 1.2, trait: "young" }] }, ]; export const EVENT_BY_ID = new Map(EVENTS.map((e) => [e.id, e])); diff --git a/backend/packages/rogue/src/index.ts b/backend/packages/rogue/src/index.ts index 8cfdf0d..3e90902 100644 --- a/backend/packages/rogue/src/index.ts +++ b/backend/packages/rogue/src/index.ts @@ -6,6 +6,7 @@ export * from "./content.ts"; export * from "./mechanics.ts"; export * from "./rules.ts"; export * from "./rival.ts"; +export * from "./unlocks.ts"; export * from "./route.ts"; export * from "./scenes.ts"; export * from "./feats.ts"; diff --git a/backend/packages/rogue/src/mechanics.ts b/backend/packages/rogue/src/mechanics.ts index f7948d7..f87710f 100644 --- a/backend/packages/rogue/src/mechanics.ts +++ b/backend/packages/rogue/src/mechanics.ts @@ -7,6 +7,8 @@ import { ELDER_LEAD, FLAG_LEAD, FLIP_DRAW_MAX, HAND_MAX, MOMENTUM_MAX, newCard, export const has = (s: RunState, advisor: string): boolean => s.advisors.includes(advisor); /** 你的候選人類型是不是 a(docs/25) */ export const isArch = (s: RunState, a: RogueArchetype): boolean => s.options.archetype === a; +/** 對手類型(rival.ts RIVAL_TYPES):你打對手支持者(比較文宣、爆料)的倍率,媒體型 +20%、清廉型 −20% */ +export const rivalHurtMult = (s: RunState): number => (s.options.rivalArchetype === "media" ? 1.2 : s.options.rivalArchetype === "integrity" ? 0.8 : 1); /** 塞一張狀態牌進棄牌堆(記者追問、人情包袱…);清廉型不會被塞記者追問。回傳有沒有塞 */ export function addStatus(s: RunState, id: string): boolean { @@ -35,9 +37,9 @@ export const ASCENSION: readonly string[] = [ ]; export const MAX_ASCENSION = ASCENSION.length - 1; -/** 每週事件對這些標籤的倍率(雙方都適用) */ -export function eventMult(s: RunState, tags: readonly string[]): number { - return (eventOf(s).mods ?? []).filter((m) => tags.includes(m.tag)).reduce((a, m) => a * m.mult, 1); +/** 每週事件對這些標籤的倍率(雙方都適用);地方事件週只算打在有那個特色的區 */ +export function eventMult(s: RunState, tags: readonly string[], town?: TownState | null): number { + return (eventOf(s).mods ?? []).filter((m) => (m.tag === "*" || tags.includes(m.tag)) && (!m.trait || town?.traits.includes(m.trait))).reduce((a, m) => a * m.mult, 1); } export function addMomentum(s: RunState, n: number): void { diff --git a/backend/packages/rogue/src/rival.ts b/backend/packages/rogue/src/rival.ts index e932d2c..061d392 100644 --- a/backend/packages/rogue/src/rival.ts +++ b/backend/packages/rogue/src/rival.ts @@ -1,4 +1,4 @@ -import type { RogueIntentKind } from "@election2026/protocol"; +import type { RogueArchetype, RogueIntentKind } from "@election2026/protocol"; import { RIVAL_HOME_MULT } from "./archetypes.ts"; import { INTENT_BASE, INTENT_LABELS, INTENT_TAGS } from "./data.ts"; import { addRivalMomentum, addStatus, asc, cityVotes, eventMult, eventOf, has, isArch, loseVotes, moveVotes, spread } from "./mechanics.ts"; @@ -31,9 +31,45 @@ 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):和你一樣只從客觀資料來(中選會選舉紀錄、政治獻金),名稱和弱點都是中性的機制。 + * 決定出招比例、比較常抽到哪幾條規則,強項、弱點各一個;沒有類型(自創的對手、地方選舉、舊存檔)照劇本的風格 + */ +export const RIVAL_TYPES: Record>; rules: readonly string[] }> = { + media: { skill: "電視、網路廣告 +10%", weakness: "你的比較文宣、爆料對他 +20%", moves: { tv: 1.3, online: 1.3 }, rules: ["pundit", "rumor"] }, + organization: { skill: "佈樁的盾 +40%、掃街 +10%", weakness: "電視、網路廣告 −10%", moves: { stake: 1.5, canvass: 1.3 }, rules: ["elder", "stronghold", "carpet"] }, + eloquence: { skill: "批評你的政見 +20%", weakness: "在年輕人多的區行動 −15%", moves: { attack: 1.6 }, rules: ["pundit", "elder", "image"] }, + finance: { skill: "電視廣告、造勢 +5%", weakness: "掃街拜票 −15%", moves: { tv: 1.2, rally: 1.2 }, rules: ["airwar", "carpet"] }, + integrity: { skill: "掃街、造勢 +10%;你的比較文宣、爆料對他 −20%", weakness: "批評你的政見 −20%", moves: { canvass: 1.2 }, rules: ["image", "stronghold"] }, + newcomer: { skill: "每週變強的幅度多一點", weakness: "前 3 週行動 −10%", moves: { online: 1.3, rally: 1.2 }, rules: ["rumor", "carpet"] }, +}; + +const rivalType = (s: RunState) => (s.options.rivalArchetype ? RIVAL_TYPES[s.options.rivalArchetype] : null); + +/** 對手類型的強項與弱點(行動的倍率) */ +function rivalTypeMult(s: RunState, kind: RogueIntentKind, town: TownState | null): number { + const air = kind === "tv" || kind === "online"; + switch (s.options.rivalArchetype) { + case "media": + return air ? 1.1 : 1; + case "organization": + return kind === "stake" ? 1.4 : kind === "canvass" ? 1.1 : air ? 0.9 : 1; + case "eloquence": + return (kind === "attack" ? 1.2 : 1) * (town?.traits.includes("young") ? 0.85 : 1); + case "finance": + return kind === "tv" || kind === "rally" ? 1.05 : kind === "canvass" ? 0.85 : 1; + case "integrity": + return kind === "canvass" || kind === "rally" ? 1.1 : kind === "attack" ? 0.8 : 1; + case "newcomer": + return s.week <= 3 ? 0.9 : 1; + default: + return 1; + } +} + /** * 對手規則(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 } }, @@ -55,7 +91,11 @@ export function drawRivalRules(s: RunState): string[] { 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]); + const id = pickWeighted( + s, + Object.keys(RIVAL_RULES).filter((x) => !out.includes(x)), + (x) => RIVAL_RULES[x]!.weight[s.setup.rivalStyle] * (rivalType(s)?.rules.includes(x) ? 2 : 1), + ); if (id) out.push(id); } return out; @@ -89,7 +129,7 @@ export const intentsThisWeek = (s: RunState): number => (s.week <= 2 ? 2 : s.wee export function rivalPower(s: RunState): number { const style = s.setup.rivalStyle; - const growth = style === "balanced" ? 0.05 : RIVAL_GROWTH; + const growth = (style === "balanced" ? 0.05 : RIVAL_GROWTH) + (s.options.rivalArchetype === "newcomer" ? 0.005 : 0); const start = style === "balanced" ? 0.92 : 1; // 新手教學的老里長比較弱,照提示打就會贏 const tutorial = s.options.tutorial ? 0.4 : 1; @@ -125,11 +165,13 @@ function intentAmount(s: RunState, kind: RogueIntentKind, town: TownState | null const home = town?.home === "rival" ? RIVAL_HOME_MULT : 1; const weak = kind === "attack" && isArch(s, "media") ? 1.2 : 1; 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); + return round10(INTENT_BASE[kind] * rivalPower(s) * reach * eventMult(s, INTENT_TAGS[kind], town) * styleMult(s, kind) * rivalTypeMult(s, kind, town) * home * weak * pundit); } export function planIntents(s: RunState): Intent[] { - const weights = STYLE_WEIGHTS[s.setup.rivalStyle]; + const style = STYLE_WEIGHTS[s.setup.rivalStyle]; + const moves = rivalType(s)?.moves ?? {}; + const weights = (kind: RogueIntentKind) => style[kind] * (moves[kind] ?? 1); const count = new Map(); const used = new Set(); const out: Intent[] = []; @@ -145,13 +187,13 @@ export function planIntents(s: RunState): Intent[] { const n = Math.max(1, intentsThisWeek(s) - (s.rivalStun ?? 0)); s.rivalStun = 0; for (let k = out.length; k < n; k++) { - const kinds = (Object.keys(weights) as RogueIntentKind[]).filter((kind) => { + const kinds = (Object.keys(style) as RogueIntentKind[]).filter((kind) => { if ((count.get(kind) ?? 0) >= (LIMITS[kind] ?? 9)) return false; // 第一週還沒什麼好批評的 if ((kind === "attack" || kind === "smear") && s.week < 2) return false; return true; }); - const kind = pickWeighted(s, kinds, (x) => weights[x])!; + const kind = pickWeighted(s, kinds, weights)!; count.set(kind, (count.get(kind) ?? 0) + 1); const city = kind === "tv" || kind === "online" || kind === "attack"; const town = city ? null : chooseTown(s, kind, used); @@ -206,10 +248,10 @@ 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) { + // 反將一軍:這週擋下的行動(批評、打對台擋下的),一半變成你的全市票 + if (s.turnaround) { const got = cityVotes(s, prevented * 0.5, "you"); - s.log.push({ side: "you", text: "反將一軍:擋下的批評變成你的票", town: null, votes: Math.round(got) }); + s.log.push({ side: "you", text: "反將一軍:擋下的行動變成你的票", town: null, votes: Math.round(got) }); } } if (i.kind === "tv" || i.kind === "online") { diff --git a/backend/packages/rogue/src/route.ts b/backend/packages/rogue/src/route.ts index 603845a..c987785 100644 --- a/backend/packages/rogue/src/route.ts +++ b/backend/packages/rogue/src/route.ts @@ -4,6 +4,7 @@ import { ADVISORS, type AdvisorDef } from "./advisors.ts"; import { AFFINITY_WEIGHT, ARCHETYPES } from "./archetypes.ts"; import { STOP_EVENTS, STOP_EVENT_BY_ID } from "./content.ts"; import { REWARD_CARDS, cardDef, upgradable } from "./data.ts"; +import { isLocked, UNLOCKS } from "./unlocks.ts"; import { addMomentum, asc, cityVotes, has, isArch, moveVotes } from "./mechanics.ts"; import { applyOutcome, choiceBlocked, rollChoice } from "./scenes.ts"; import type { MiniGameKind } from "@election2026/protocol"; @@ -83,13 +84,40 @@ const affinity = (s: RunState, tags: readonly string[]): number => { }; const advisorAffinity = (s: RunState, a: AdvisorDef): number => { const arch = s.options.archetype ? ARCHETYPES[s.options.archetype] : null; - return arch && arch.school === a.school ? AFFINITY_WEIGHT : 1; + return (arch && arch.school === a.school ? AFFINITY_WEIGHT : 1) * schoolPull(deckSchools(s), new Set([a.school]), a.id); }; +/** 牌的標籤屬於哪一派(docs/25 第 2 節;和幕僚的 school 一樣) */ +const SCHOOL_OF: Readonly> = { ground: "ground", rally: "ground", org: "org", media: "air", defend: "defend", attack: "defend", intel: "defend", money: "money" }; +const schoolsOf = (tags: readonly string[]): Set => new Set(tags.flatMap((t) => (SCHOOL_OF[t] ? [SCHOOL_OF[t]!] : []))); + +/** 牌組裡各派有幾張牌(不算開局的基本牌、狀態牌) */ +function deckSchools(s: RunState): Map { + const out = new Map(); + for (const c of deckOf(s)) { + const def = cardDef(c.id); + if (!def || def.rarity === "basic" || def.rarity === "status") continue; + for (const x of schoolsOf(def.tags)) out.set(x, (out.get(x) ?? 0) + 1); + } + return out; +} + +/** + * 流派傾向:牌組裡某一派的牌越多,那一派的牌、幕僚越常出現(每張 +20%,最多 ×3); + * 成形(3 張以上)之後,那一派的核心牌、幕僚再多一倍,拜會地方、物資行一定有一張還沒拿的核心牌。讓「組成一個流派」真的組得起來 + */ +function schoolPull(counts: ReadonlyMap, schools: ReadonlySet, id: string): number { + const n = Math.max(0, ...[...schools].map((x) => counts.get(x) ?? 0)); + return Math.min(3, 1 + 0.2 * n) * (UNLOCKS[id] !== undefined && n >= FORMED ? 2 : 1); +} + +/** 同一派幾張牌算成形 */ +export const FORMED = 3; + /** 幕僚選項:不重複,和類型同一派的比較常出現 */ function advisorOptions(s: RunState, n: number): string[] { const out: string[] = []; - const pool = ADVISORS.filter((a) => !has(s, a.id)); + const pool = ADVISORS.filter((a) => !has(s, a.id) && !isLocked(s, a.id)); while (out.length < n) { const a = pickWeighted( s, @@ -107,19 +135,34 @@ const price = (s: RunState, base: number): number => Math.round(base * (isArch(s function cardOptions(s: RunState, n: number): string[] { const options: string[] = []; - const pool = REWARD_CARDS.filter((c) => c.effect.kind !== "kneel" || s.week >= s.totalWeeks - 3); + const pool = REWARD_CARDS.filter((c) => (c.effect.kind !== "kneel" || s.week >= s.totalWeeks - 3) && !isLocked(s, c.id)); + const counts = deckSchools(s); while (options.length < n) { const c = pickWeighted( s, pool.filter((x) => !options.includes(x.id)), - (x) => (x.rarity === "rare" ? 1 : 3) * affinity(s, x.tags), + (x) => (x.rarity === "rare" ? 1 : 3) * affinity(s, x.tags) * schoolPull(counts, schoolsOf(x.tags), x.id), ); if (!c) break; options.push(c.id); } + // 流派成形(同一派 3 張以上):一定有一張那一派還沒拿的核心牌 + const core = formedCore(s, counts); + if (core && options.length && !options.includes(core)) options[Math.floor(rand(s) * options.length)] = core; return options; } +/** 牌組裡成形的流派(3 張以上,多的優先)還沒拿到、已經解鎖的核心牌 */ +function formedCore(s: RunState, counts: ReadonlyMap): string | null { + const owned = new Set([...deckOf(s), ...s.exhausted].map((c) => c.id).concat(s.powers)); + const formed = [...counts].filter(([, n]) => n >= FORMED).sort((a, b) => b[1] - a[1]); + for (const [school] of formed) { + const c = REWARD_CARDS.find((x) => UNLOCKS[x.id] !== undefined && schoolsOf(x.tags).has(school) && !owned.has(x.id) && !isLocked(s, x.id)); + if (c) return c.id; + } + return null; +} + /** 選情最接近的大區(深入基層、小遊戲去那裡) */ const contestedTown = (s: RunState) => pickWeighted(s, s.towns, (t) => t.voters * (1 - Math.abs(t.you - t.rival) / (t.you + t.rival || 1)) ** 3) ?? s.towns[0]!; diff --git a/backend/packages/rogue/src/rules.ts b/backend/packages/rogue/src/rules.ts index 0cfdced..e53de2b 100644 --- a/backend/packages/rogue/src/rules.ts +++ b/backend/packages/rogue/src/rules.ts @@ -7,6 +7,7 @@ import { CARD_BY_ID, cardDef, EVENTS, findCard, hasKeyword, REPORTER_PENALTY, ST import { perkLevels, policyCardId, policySlots } from "./meta.ts"; import { addMomentum, asc, cityVotes, drawCards, eventOf, flagOwner, has, isArch, moveVotes, updateFlags } from "./mechanics.ts"; import { featsOf } from "./feats.ts"; +import { isLocked } from "./unlocks.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"; @@ -51,10 +52,13 @@ const ASC10_GAP = 0.03; function pickEvent(s: RunState): string { if (s.week === 1 || s.options.tutorial) return "calm"; + // 行事曆上的地方事件週 + const local = s.schedule?.local?.find((l) => l.week === s.week); + if (local) return local.event; const badBoost = asc(s, 9) ? 2 : 1; return pickWeighted( s, - EVENTS.filter((e) => e.id !== s.event), + EVENTS.filter((e) => !e.local && e.id !== s.event), (e) => e.weight * (e.bad ? badBoost : 1), )!.id; } @@ -164,6 +168,9 @@ export function createRun(setup: RogueSetup, runId: string, seed: number, opts: ...(opts.noUltimate ? { noUltimate: true } : {}), archetype: opts.tutorial ? null : (opts.archetype ?? null), archetypeBasis: opts.archetypeBasis ?? null, + rivalArchetype: opts.tutorial ? null : (opts.rivalArchetype ?? null), + reputation: opts.tutorial || opts.daily ? null : (opts.reputation ?? null), + rivalArchetypeBasis: opts.rivalArchetypeBasis ?? null, }; const voters = setup.towns.reduce((a, t) => a + t.voters, 0); const meanVoters = voters / (setup.towns.length || 1); @@ -368,7 +375,7 @@ function settleContract(s: RunState): void { return; } if (s.advisors.length < MAX_ADVISORS) { - const pool = ADVISORS.filter((a) => !s.advisors.includes(a.id)); + const pool = ADVISORS.filter((a) => !s.advisors.includes(a.id) && !isLocked(s, 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) { @@ -382,11 +389,18 @@ function settleContract(s: RunState): void { s.log.push({ side: "you", text: `地方派系談判成功:升級 ${ups.length} 張牌`, town: t.code, votes: 0 }); } +/** 財務型:週末手上每 100 萬資金全市加幾票(最多算 FINANCE_CAP 萬) */ +export const FINANCE_PER_100 = 150; +export const FINANCE_CAP = 1000; + +/** 樁腳網:週末還沒被用掉的樁腳,這麼多變成你的票 */ +export const NETWORK_SHARE = 0.3; + /** 週末的流派效果(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"); + const net = moveVotes(t, t.shield * NETWORK_SHARE, "you"); if (net >= 1) s.log.push({ side: "you", text: `樁腳網・${t.name}`, town: t.code, votes: Math.round(net) }); } } @@ -398,10 +412,10 @@ function weekendSchools(s: RunState): void { } } if (has(s, "crisis_flip")) { - const blocked = s.intents.filter((i) => i.kind === "attack" && i.cut < 1).length; + const blocked = Math.min(2, s.intents.filter((i) => i.kind !== "stake" && i.cut < 1).length); if (blocked > 0) { addMomentum(s, blocked); - s.log.push({ side: "you", text: `危機變轉機:擋下 ${blocked} 次批評,聲勢 +${blocked}`, town: null, votes: 0 }); + s.log.push({ side: "you", text: `危機變轉機:擋下對手的行動,聲勢 +${blocked}`, town: null, votes: 0 }); } } } @@ -447,6 +461,11 @@ 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 (isArch(s, "finance") && s.money >= 100) { + const got = cityVotes(s, (Math.min(s.money, FINANCE_CAP) / 100) * FINANCE_PER_100 * s.scale, "you"); + s.log.push({ side: "you", text: "財務型:手上的資金換成廣告曝光", town: null, votes: Math.round(got) }); + } // 精算師:存款利息 if (has(s, "actuary")) { const interest = Math.min(50, Math.floor(s.money / 100) * 5); diff --git a/backend/packages/rogue/src/scenes.ts b/backend/packages/rogue/src/scenes.ts index a036082..960701c 100644 --- a/backend/packages/rogue/src/scenes.ts +++ b/backend/packages/rogue/src/scenes.ts @@ -15,9 +15,11 @@ import { type Outcome, type PressTrigger, } from "./content.ts"; -import { REWARD_CARDS, findCard, upgradable } from "./data.ts"; +import { EVENTS, REWARD_CARDS, findCard, upgradable } from "./data.ts"; import { addMomentum, addRivalMomentum, addStatus, asc, cityVotes, has, isArch, loseVotes, spread } from "./mechanics.ts"; -import { MAX_ADVISORS, TOTAL_WEEKS, addTally, gainCard, newCard, pickWeighted, rand, shuffle, totals, type DebateArg, type DebateMove, type RunState, type Scene } from "./state.ts"; +import { BIG_RALLY_WEEK } from "./rival.ts"; +import { isLocked } from "./unlocks.ts"; +import { MAX_ADVISORS, TOTAL_WEEKS, addTally, gainCard, newCard, pickWeighted, rand, shuffle, totals, type DebateArg, type DebateMove, type RunState, type Scene, type Schedule } from "./state.ts"; /** * 每週開場的劇情(docs/22):記者堵麥、電視辯論(第 3 週)、民調公布(第 4 週)、匿名黑函危機(第 6 週)。 @@ -37,14 +39,34 @@ const SCHEDULES = [ [5, 4, 6], ] as const; -export function makeSchedule(s: RunState): RunState["schedule"] { +export function makeSchedule(s: RunState): Schedule | undefined { 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 }; + return { debate, poll, crisis, local: localWeeks(s, [debate, poll, crisis]) }; +} + +/** + * 地方事件週(docs/25 第 4 節):縣市裡有宮廟多、客家庄、人口密集、長輩多、年輕人多的區,就可能排進遶境、義民祭… + * 有符合的就排 1 個,一半的局再排第 2 個;排在第 2 週到對手大型造勢的前一週、沒有辯論/民調/黑函的週 + */ +function localWeeks(s: RunState, taken: readonly number[]): { week: number; event: string }[] { + const pool = shuffle( + s, + EVENTS.filter((e) => e.local && s.towns.some((t) => t.traits.includes(e.local!))), + ); + const free = shuffle( + s, + Array.from({ length: BIG_RALLY_WEEK - 2 }, (_, i) => i + 2).filter((w) => !taken.includes(w)), + ); + const n = Math.min(pool.length, free.length, rand(s) < 0.5 ? 2 : 1); + return pool + .slice(0, n) + .map((e, i) => ({ week: free[i]!, event: e.id })) + .sort((a, b) => a.week - b.week); } /** 這局的行事曆;短局(里長、議員)、舊存檔用固定週次 */ -export const scheduleOf = (s: RunState): { debate: number; poll: number; crisis: number } => s.schedule ?? { debate: DEBATE_WEEK, poll: POLL_WEEK, crisis: CRISIS_WEEK }; +export const scheduleOf = (s: RunState): Schedule => s.schedule ?? { debate: DEBATE_WEEK, poll: POLL_WEEK, crisis: CRISIS_WEEK }; /** 辯論贏一回合:全市加票(基準),連續答對 ×1.5、×2;輸一回合:你掉票 */ export const DEBATE_WIN = 1730; export const DEBATE_LOSS = 860; @@ -96,7 +118,7 @@ export function applyOutcome(s: RunState, o: Outcome, when: "now" | "between"): } } if (o.advisor && s.advisors.length < MAX_ADVISORS) { - const pool = ADVISORS.filter((a) => !has(s, a.id)); + const pool = ADVISORS.filter((a) => !has(s, a.id) && !isLocked(s, a.id)); const a = pool[Math.floor(rand(s) * pool.length)]; if (a) { s.advisors.push(a.id); @@ -225,7 +247,7 @@ function publishPoll(s: RunState): void { 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"), + REWARD_CARDS.filter((c) => c.rarity === "rare" && c.effect.kind !== "kneel" && !isLocked(s, c.id)), (c) => (arch && arch.tags.some((t) => c.tags.includes(t)) ? AFFINITY_WEIGHT : 1), ); if (rare) s.hand.push(newCard(s, rare.id)); diff --git a/backend/packages/rogue/src/state.ts b/backend/packages/rogue/src/state.ts index aad00d8..9d1ff88 100644 --- a/backend/packages/rogue/src/state.ts +++ b/backend/packages/rogue/src/state.ts @@ -70,6 +70,11 @@ export interface RunOptions { archetype?: RogueArchetype | null; /** 類型的依據(選舉紀錄或出身) */ archetypeBasis?: string | null; + /** 對手的類型與依據(真實人物才有;rival.ts RIVAL_TYPES) */ + rivalArchetype?: RogueArchetype | null; + rivalArchetypeBasis?: string | null; + /** 玩家的聲望(unlocks.ts):決定哪些核心牌、幕僚已經解鎖;null 是全部解鎖 */ + reputation?: number | null; } export interface RunOrigin { @@ -276,8 +281,8 @@ export interface RunState { viral?: { used: boolean; boost: boolean }; /** 你翻走對手的本命區:對手下週少幾個行動 */ rivalStun?: number; - /** 這局的行事曆(docs/25 第 4 節):辯論、民調、黑函在第幾週;舊存檔、短局沒有,用固定週次 */ - schedule?: { debate: number; poll: number; crisis: number }; + /** 這局的行事曆(docs/25 第 4 節):辯論、民調、黑函在第幾週、地方事件週;舊存檔、短局沒有,用固定週次 */ + schedule?: Schedule; /** 這局對手的規則(docs/25 第 3 節,rival.ts 的 RIVAL_RULES);舊存檔沒有 */ rivalRules?: string[]; /** 這週翻區已經抽了幾張(每週最多 FLIP_DRAW_MAX) */ @@ -293,6 +298,14 @@ export interface RunState { result: RogueResult | null; } +export interface Schedule { + debate: number; + poll: number; + crisis: number; + /** 地方事件週:第幾週、哪個事件(data.ts EVENTS 裡有 local 的);舊存檔沒有 */ + local?: { week: number; event: string }[]; +} + export const SAVE_VERSION = 2; export const TOTAL_WEEKS = 8; export const HAND_SIZE = 5; diff --git a/backend/packages/rogue/src/unlocks.ts b/backend/packages/rogue/src/unlocks.ts new file mode 100644 index 0000000..3f9e69d --- /dev/null +++ b/backend/packages/rogue/src/unlocks.ts @@ -0,0 +1,26 @@ +import type { RunState } from "./state.ts"; + +/** + * 聲望解鎖(docs/25 第 8 節):流派核心牌與改規則的幕僚一開始鎖住,聲望到了才會出現在下一站、物資行、民調獎勵。 + * 聲望 = 打完的局數 + 勝場(輸了也有 1 點,贏了 2 點);前端記在 progress.ts,開局時帶給伺服器。 + * 先解鎖的是簡單好懂的(走透透、鐵腿),越後面越需要搭配。 + */ +export const UNLOCKS: Readonly> = { + legwork: 1, + iron_legs: 2, + buzz: 3, + meme_editor: 4, + network: 5, + faction_broker: 6, + turntable: 8, + crisis_flip: 10, + carpetads: 12, + actuary: 14, + doorstep: 16, + explainer: 18, + wargame: 20, + microdonate: 22, +}; + +/** 這局還沒解鎖;沒帶聲望(模擬、舊存檔、每日一戰、新手教學)全部解鎖 */ +export const isLocked = (s: RunState, id: string): boolean => s.options.reputation != null && (UNLOCKS[id] ?? 0) > s.options.reputation; diff --git a/backend/packages/rogue/src/view.ts b/backend/packages/rogue/src/view.ts index 9ea3ea8..2331599 100644 --- a/backend/packages/rogue/src/view.ts +++ b/backend/packages/rogue/src/view.ts @@ -5,11 +5,12 @@ import { blockedReason, cardCost, counterable, attackable, defOf, playCard } fro import { CRISIS_CHOICES, DEBATE_MOVES, PRESS_BY_ID, STOP_EVENT_BY_ID, type Choice } from "./content.ts"; import { ORIGINS } from "@election2026/protocol"; import { ULTIMATES, deficit, suggestTowns, ultMultiplier, ultReady } from "./ultimate.ts"; -import { CARD_BY_ID, EVENTS, KEYWORD_LABELS, ORIGIN_CARDS, POWERS, REPORTER_PENALTY, REWARD_CARDS, cardDef, findCard, upgradable, type CardDef } from "./data.ts"; +import { CARD_BY_ID, EVENT_BY_ID, EVENTS, KEYWORD_LABELS, TRAIT_LABELS, ORIGIN_CARDS, POWERS, REPORTER_PENALTY, REWARD_CARDS, cardDef, findCard, upgradable, type CardDef } from "./data.ts"; import { FEATS } from "./feats.ts"; +import { UNLOCKS } from "./unlocks.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_RULES, RIVAL_TRAITS, intentDamp, intentLabel } from "./rival.ts"; +import { BIG_RALLY_WEEK, RIVAL_RULES, RIVAL_TRAITS, RIVAL_TYPES, intentDamp, intentLabel } from "./rival.ts"; import { encounterById, fillVars, MINIGAME_INFO, pickInDoor, PRICES, SKIP_MONEY, STOP_LABELS } from "./route.ts"; import { bestArg, choiceBlocked, debateSure, scheduleOf } from "./scenes.ts"; import { electionForecast } from "./rules.ts"; @@ -304,6 +305,28 @@ function identityOf(s: RunState): RogueView["identity"] { const def = ARCHETYPES[arch]; return { archetype: arch, name: def.name, skill: def.skill, weakness: def.weakness, basis: s.options.archetypeBasis ?? null, home: s.homeBasis?.you ?? "", rivalHome: s.homeBasis?.rival ?? "" }; } +/** 對手的類型(docs/25):真實人物才有 */ +function rivalTypeOf(s: RunState): RogueView["rivalType"] { + const arch = s.options.rivalArchetype; + if (!arch) return null; + return { archetype: arch, name: ARCHETYPES[arch].name, skill: RIVAL_TYPES[arch].skill, weakness: RIVAL_TYPES[arch].weakness, basis: s.options.rivalArchetypeBasis ?? null }; +} + +/** 行事曆:辯論、民調、黑函、對手大型造勢、地方事件週 */ +function scheduleView(s: RunState): NonNullable { + const { debate, poll, crisis, local } = scheduleOf(s); + return { + debate, + poll, + crisis, + bigRally: s.totalWeeks >= BIG_RALLY_WEEK ? BIG_RALLY_WEEK : null, + local: (local ?? []).flatMap((l) => { + const e = EVENT_BY_ID.get(l.event); + return e ? [{ week: l.week, id: e.id, title: e.title, short: e.short ?? e.title.slice(0, 1) }] : []; + }), + }; +} + export function toView(s: RunState): RogueView { const ev = eventOf(s); const big = s.nextBig; @@ -335,9 +358,10 @@ 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 }, + schedule: s.options.tutorial ? null : scheduleView(s), 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], + rivalType: rivalTypeOf(s), towns: s.towns.map((t) => ({ code: t.code, name: t.name, @@ -357,7 +381,7 @@ export function toView(s: RunState): RogueView { })), intents: s.intents.map((i) => ({ id: i.id, kind: i.kind, label: intentLabel(s, i), town: i.town, amount: Math.round(i.amount), cut: i.cut, big: !!i.big })), nextBig: big && big.town ? { week: BIG_RALLY_WEEK, town: big.town, label: intentLabel(s, big), amount: Math.round(big.amount) } : null, - event: { id: ev.id, title: ev.title, text: ev.text }, + event: { id: ev.id, title: ev.title, text: ev.local ? `${ev.text}這週在:${s.towns.filter((t) => t.traits.includes(ev.local!)).map((t) => t.name).join("、")}` : ev.text }, hand: s.hand.map((c) => cardView(s, c)), drawCount: s.draw.length, discardCount: s.discard.length, @@ -426,16 +450,31 @@ function cardHow(c: CardDef): string { return c.effect.kind === "kneel" ? `${where};最後 3 週才會出現` : where; } +/** 要聲望解鎖的牌、幕僚:說明前面加上解鎖條件 */ +const unlockHow = (id: string, how: string): string => (UNLOCKS[id] ? `聲望 ${UNLOCKS[id]} 解鎖(每打完一局 +1,贏了再 +1);之後:${how}` : how); + export function catalog(): RogueCatalog { return { abilities: (Object.keys(ABILITY_LABELS) as (keyof typeof ABILITY_LABELS)[]).map((id) => ({ id, label: ABILITY_LABELS[id], effect: ABILITY_EFFECTS[id] })), policyHome: { ...POLICY_HOME }, buildings: BUILDINGS.map(({ perk: _perk, ...b }) => ({ ...b, levels: [...b.levels], cost: [...b.cost] })), - cards: [...REWARD_CARDS, ...ORIGIN_CARDS, ...[...CARD_BY_ID.values()].filter((c) => c.rarity === "basic" || c.rarity === "status")].map((c) => ({ ...cardOffer(null, c.id), how: cardHow(c) })), - advisors: ADVISORS.map((a) => ({ id: a.id, name: a.name, text: a.text, art: a.art, school: a.school, how: "招募幕僚(偶數週一定有這扇門)、競選物資行、地方抉擇;政治生涯當選後可以帶 2 位到下一場" })), + cards: [...REWARD_CARDS, ...ORIGIN_CARDS, ...[...CARD_BY_ID.values()].filter((c) => c.rarity === "basic" || c.rarity === "status")].map((c) => ({ + ...cardOffer(null, c.id), + how: unlockHow(c.id, cardHow(c)), + unlock: UNLOCKS[c.id] ?? null, + })), + advisors: ADVISORS.map((a) => ({ + id: a.id, + name: a.name, + text: a.text, + art: a.art, + school: a.school, + how: unlockHow(a.id, "招募幕僚(偶數週一定有這扇門)、競選物資行、地方抉擇;政治生涯當選後可以帶 2 位到下一場"), + unlock: UNLOCKS[a.id] ?? null, + })), feats: FEATS.map((f) => ({ ...f })), ascension: [...ASCENSION], - events: EVENTS.map((e) => ({ id: e.id, title: e.title, text: e.text, how: "每週開始時隨機發生,多打幾週就會遇到" })), + events: EVENTS.map((e) => ({ id: e.id, title: e.title, text: e.text, how: e.local ? `地方事件週:縣市裡有${TRAIT_LABELS[e.local]}的區,開局就可能排進行事曆` : "每週開始時隨機發生,多打幾週就會遇到" })), archetypes: (Object.keys(ARCHETYPES) as (keyof typeof ARCHETYPES)[]).map((id) => ({ id, name: ARCHETYPES[id].name, skill: ARCHETYPES[id].skill, weakness: ARCHETYPES[id].weakness })), }; } diff --git a/backend/packages/rogue/test/identity.test.ts b/backend/packages/rogue/test/identity.test.ts index a55c280..065b199 100644 --- a/backend/packages/rogue/test/identity.test.ts +++ b/backend/packages/rogue/test/identity.test.ts @@ -148,12 +148,12 @@ describe("候選人類型", () => { expect(two.energy).toBe(8); }); - it("資深型:辯論多一張論點、回應記者追問不花體力;年輕人多的區 ×0.85", () => { + it("資深型:辯論多一張論點、回應記者追問不花體力;年輕人多的區 ×0.9", () => { const s = withHand(createRun(LEANED, "r", 1, { archetype: "eloquence" }), ["reporter", "canvass"]); expect(ok(playCard(s, "t0", null)).energy).toBe(9); const plain = withHand(createRun(LEANED, "r", 1), ["canvass"]); const young = (x: RunState) => town(ok(playCard(x, x.hand.find((c) => c.id === "canvass")!.uid, "A")), "A").you - town(x, "A").you; - expect(young(s)).toBeCloseTo(young(plain) * 0.85); + expect(young(s)).toBeCloseTo(young(plain) * 0.9); }); it("財務型:每週多 150 萬;清廉型:收入 −20%、記者追問不會被塞進牌組", () => { diff --git a/backend/packages/rogue/test/schools.test.ts b/backend/packages/rogue/test/schools.test.ts index 8d89c8f..dcf72a6 100644 --- a/backend/packages/rogue/test/schools.test.ts +++ b/backend/packages/rogue/test/schools.test.ts @@ -1,10 +1,14 @@ import { describe, expect, it } from "vitest"; -import { REWARD_CARDS } from "../src/data.ts"; +import { BUZZ_STEP, EXPLAINER_STEP } from "../src/cards.ts"; +import { cardDef, REWARD_CARDS } from "../src/data.ts"; import { executeIntent } from "../src/rival.ts"; -import { createRun, endWeek, playCard } from "../src/rules.ts"; +import { prepareRoute } from "../src/route.ts"; +import { createRun, endWeek, FINANCE_CAP, playCard } from "../src/rules.ts"; +import type { Stop } from "../src/state.ts"; import { FLAG_LEAD, type Intent, type RunState, type TownState } from "../src/state.ts"; +import { isLocked, UNLOCKS } from "../src/unlocks.ts"; import { catalog } from "../src/view.ts"; -import { SETUP, must } from "./fixtures.ts"; +import { SETUP, must, toPlan } from "./fixtures.ts"; /** 流派核心牌與改規則的幕僚(docs/25 第 2 節) */ @@ -55,7 +59,7 @@ describe("流派核心牌", () => { expect(gained(two, three)).toBeCloseTo(base * 1.16, 0); }); - it("挨家挨戶:這週出過牌的區越多越強(最多 5 區)", () => { + it("遍地開花:這週出過牌的區越多越強(最多 5 區)", () => { const s = bare(["canvass", "canvass", "doorstep"]); const after2 = ok(playCard(ok(playCard(s, "t0", "A")), "t1", "B")); const first = bare(["doorstep"]); @@ -63,23 +67,23 @@ describe("流派核心牌", () => { expect(gained(after2, ok(playCard(after2, "t2", "D")))).toBeCloseTo(alone * 3, 0); }); - it("樁腳網:週末還沒被用掉的樁腳,兩成變成你在那區的票", () => { + 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); + expect(after.log.some((l) => l.text === "樁腳網・甲區" && l.votes === 300)).toBe(true); }); - it("聲量滾雪球:空戰牌累積聲量,每點 +3%;懶人包每點再 +5%", () => { + it("聲量滾雪球:空戰牌累積聲量,每點 +5%;懶人包每點再 +6%", () => { 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); + expect(gained(one, ok(playCard(one, "t1", null)))).toBeCloseTo(base * (1 + BUZZ_STEP), -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); + expect(gained(ex, ok(playCard(ex, "t0", null)))).toBeCloseTo(gained(exPlain, ok(playCard(exPlain, "t0", null))) * (1 + 4 * EXPLAINER_STEP), -1); }); it("反將一軍:批評剩一半,擋下的一半變成你的全市票", () => { @@ -88,17 +92,23 @@ describe("流派核心牌", () => { 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 === "反將一軍:擋下的批評變成你的票")!; + const back = s.log.find((l) => l.text === "反將一軍:擋下的行動變成你的票")!; expect(back.votes).toBe(250); expect(before).toBeGreaterThan(0); }); - it("沙盤推演:每週第一張擋對手的牌不花體力", () => { + 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); + const s = bare(["clarify", "clarify", "clarify"], { powers: ["wargame"], intents: [attack] }); + const two = ok(playCard(ok(playCard(s, "t0", null)), "t1", null)); + expect(two.energy).toBe(9); + expect(ok(playCard(two, "t2", null)).energy).toBe(8); + }); + + it("聲量滾雪球:空戰牌的花費 −30%", () => { + const s = bare(["tv"], { powers: ["buzz"] }); + const plain = bare(["tv"]); + expect(s.money - ok(playCard(s, "t0", null)).money).toBe(Math.round((plain.money - ok(playCard(plain, "t0", null)).money) * 0.7)); }); it("地毯式廣告:花光資金,每 100 萬全市 +票;小額募款:每面旗多 60 萬", () => { @@ -151,3 +161,73 @@ describe("流派幕僚", () => { expect(after.log.find((l) => l.text.startsWith("精算師"))!.text).toContain("50 萬"); }); }); + +describe("聲望解鎖", () => { + it("核心牌、新幕僚都要聲望解鎖;圖鑑寫出解鎖條件", () => { + expect(Object.keys(UNLOCKS)).toHaveLength(14); + const c = catalog(); + expect(c.cards.find((x) => x.id === "legwork")).toMatchObject({ unlock: 1 }); + expect(c.cards.find((x) => x.id === "legwork")!.how).toContain("聲望 1 解鎖"); + expect(c.advisors.find((x) => x.id === "actuary")).toMatchObject({ unlock: 14 }); + expect(c.cards.find((x) => x.id === "canvass")!.unlock).toBeNull(); + }); + + it("聲望不夠的不會出現在下一站;沒帶聲望(模擬、舊存檔)、每日一戰全部解鎖", () => { + const offered = new Set(); + for (let seed = 1; seed <= 60; seed++) { + const s = must(endWeek(toPlan(createRun(SETUP, "r", seed, { reputation: 0 })))); + for (const stop of (s.routeStops ?? []) as Stop[]) { + if (stop.kind === "card" || stop.kind === "advisor") for (const id of stop.options) offered.add(id); + if (stop.kind === "shop") for (const i of stop.items) offered.add(i.id); + } + } + expect(offered.size).toBeGreaterThan(10); + for (const id of Object.keys(UNLOCKS)) expect(offered.has(id)).toBe(false); + const fresh = createRun(SETUP, "r", 1, { reputation: 5 }); + expect(isLocked(fresh, "network")).toBe(false); + expect(isLocked(fresh, "faction_broker")).toBe(true); + expect(isLocked(createRun(SETUP, "r", 1), "microdonate")).toBe(false); + expect(isLocked(createRun(SETUP, "r", 1, { reputation: 0, daily: "2026-10-29" }), "microdonate")).toBe(false); + }); +}); + +describe("流派傾向", () => { + /** 很多局的下一站裡出現的牌(拜會地方、物資行) */ + const offered = (extra: string[]) => { + const ids: string[] = []; + for (let seed = 1; seed <= 150; seed++) { + const s = toPlan(createRun(SETUP, "r", seed)); + s.draw.push(...extra.map((id, i) => ({ uid: `x${i}`, id }))); + prepareRoute(s); + for (const stop of (s.routeStops ?? []) as Stop[]) { + if (stop.kind === "card") ids.push(...stop.options); + if (stop.kind === "shop") ids.push(...stop.items.filter((i) => i.kind === "card").map((i) => i.id)); + } + } + return ids; + }; + const share = (ids: string[], ok: (id: string) => boolean) => ids.filter(ok).length / ids.length; + + it("牌組裡地面牌多,下一站的地面牌、地面核心牌比較常出現", () => { + const plain = offered([]); + const ground = offered(["door", "door", "night", "park"]); + const isGround = (id: string) => cardDef(id)!.tags.includes("ground"); + const isCore = (id: string) => id === "legwork" || id === "doorstep"; + expect(share(ground, isGround)).toBeGreaterThan(share(plain, isGround) + 0.1); + expect(share(ground, isCore)).toBeGreaterThan(share(plain, isCore) * 1.8); + }); +}); + +describe("財務型:錢多好辦事", () => { + it("週末依手上的資金加票,最多算 1,000 萬", () => { + const votes = (money: number) => { + const s = { ...bare([]), money, options: { ...bare([]).options, archetype: "finance" as const } }; + return must(endWeek(s)).log.find((l) => l.text === "財務型:手上的資金換成廣告曝光")?.votes ?? 0; + }; + // 收入進帳之後才算(收入也算進去);不是財務型沒有 + expect(must(endWeek({ ...bare([]), money: 1000 })).log.some((l) => l.text.startsWith("財務型"))).toBe(false); + expect(votes(500)).toBeGreaterThan(0); + expect(votes(FINANCE_CAP * 3)).toBeCloseTo(votes(FINANCE_CAP), -1); + expect(votes(FINANCE_CAP)).toBeGreaterThan(votes(100) * 1.5); + }); +}); diff --git a/backend/packages/rogue/test/variety.test.ts b/backend/packages/rogue/test/variety.test.ts index 7cc5737..99c35c8 100644 --- a/backend/packages/rogue/test/variety.test.ts +++ b/backend/packages/rogue/test/variety.test.ts @@ -1,7 +1,8 @@ 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 type { RogueArchetype } from "@election2026/protocol"; +import { applyRivalRules, executeIntent, planIntents, RIVAL_RULES, RIVAL_TYPES } 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"; @@ -63,7 +64,96 @@ describe("行事曆每局不同", () => { 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 }); + const { local, ...fixed } = when; + expect(toView(s).schedule).toMatchObject({ ...fixed, bigRally: 7, local: (local ?? []).map((l) => ({ week: l.week, id: l.event })) }); + }); +}); + +describe("地方事件週", () => { + /** 甲區宮廟多、乙區客家庄 */ + const LOCAL: RogueSetup = { + ...LEANED, + towns: LEANED.towns.map((t, i) => ({ ...t, traits: i === 0 ? ["temples"] : i === 1 ? ["hakka"] : [] })), + }; + + it("依縣市特色排 1–2 個,在第 2–6 週、不和辯論/民調/黑函、對手大型造勢同週;沒有符合的特色就沒有", () => { + const kinds = new Set(); + for (let seed = 1; seed <= 30; seed++) { + const { debate, poll, crisis, local } = createRun(LOCAL, "r", seed).schedule!; + expect(local!.length).toBeGreaterThanOrEqual(1); + expect(local!.length).toBeLessThanOrEqual(2); + for (const l of local!) { + expect(l.week).toBeGreaterThanOrEqual(2); + expect(l.week).toBeLessThanOrEqual(6); + expect([debate, poll, crisis]).not.toContain(l.week); + kinds.add(l.event); + } + } + expect([...kinds].sort()).toEqual(["procession", "yimin"]); + const plain: RogueSetup = { ...LEANED, towns: LEANED.towns.map((t) => ({ ...t, traits: [] })) }; + expect(createRun(plain, "r", 1).schedule!.local).toEqual([]); + }); + + it("到了那週就是那個事件;只加成有那個特色的區(雙方都算)", () => { + let s = createRun(LOCAL, "r", 4); + s.schedule = { ...s.schedule!, local: [{ week: 2, event: "procession" }] }; + s = must(endWeek(toPlan(s))); + s = toPlan(must(choose(s, "skip"))); + expect(s.week).toBe(2); + expect(s.event).toBe("procession"); + const view = toView(s); + expect(view.event.text).toContain("甲區"); + const t = bare(s, [], ["temple", "temple"]); + const at = (code: string) => { + const after = ok(playCard(t, "t0", code)); + return town(after, code).you - town(t, code).you; + }; + // 宮廟參拜在宮廟多的區本來就 ×2,遶境週再 ×2;別區不受影響 + const calm = { ...t, event: "calm" }; + const calmAt = (code: string) => town(ok(playCard(calm, "t0", code)), code).you - town(calm, code).you; + expect(at("A") / calmAt("A")).toBeCloseTo(2, 1); + expect(at("C") / calmAt("C")).toBeCloseTo(1, 1); + }); +}); + +describe("對手的類型", () => { + const withRival = (arch: RogueArchetype) => createRun(LEANED, "r", 7, { rivalArchetype: arch }); + + it("畫面看得到對手的類型、強項、弱點;沒有類型是 null", () => { + expect(toView(withRival("media")).rivalType).toMatchObject({ archetype: "media", name: "媒體型", skill: RIVAL_TYPES.media.skill }); + expect(toView(createRun(LEANED, "r", 7)).rivalType).toBeNull(); + }); + + it("組織型對手的樁腳 +40%、空戰 −10%", () => { + const base = { ...createRun(LEANED, "r", 1), week: 4 }; + const amount = (arch: RogueArchetype | null, kind: "stake" | "tv") => { + const s = { ...structuredClone(base), options: { ...base.options, rivalArchetype: arch }, rivalRules: [] }; + for (let rng = 1; rng < 300; rng++) { + const i = planIntents({ ...structuredClone(s), rng }).find((x) => x.kind === kind && !x.town); + if (i) return i.amount; + const j = planIntents({ ...structuredClone(s), rng }).find((x) => x.kind === kind && x.town === "A"); + if (j) return j.amount; + } + throw new Error(`沒有 ${kind}`); + }; + expect(amount("organization", "stake") / amount(null, "stake")).toBeCloseTo(1.4, 1); + expect(amount("organization", "tv") / amount(null, "tv")).toBeCloseTo(0.9, 1); + }); + + it("媒體型對手被比較文宣多傷 20%,清廉型少 20%;類型相近的規則比較常抽到", () => { + const hurt = (arch: RogueArchetype | null) => { + const s = bare({ ...createRun(LEANED, "r", 1), options: { ...createRun(LEANED, "r", 1).options, rivalArchetype: arch } }, [], ["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("media") / hurt(null)).toBeCloseTo(1.2, 1); + expect(hurt("integrity") / hurt(null)).toBeCloseTo(0.8, 1); + const count = (arch: RogueArchetype | null) => { + let n = 0; + for (let seed = 1; seed <= 200; seed++) if (createRun(LEANED, "r", seed, { rivalArchetype: arch }).rivalRules!.some((r) => RIVAL_TYPES.organization.rules.includes(r))) n++; + return n; + }; + expect(count("organization")).toBeGreaterThan(count(null)); }); }); diff --git a/backend/packages/scenarios/test/registry.test.ts b/backend/packages/scenarios/test/registry.test.ts index 853efe5..cc72aa5 100644 --- a/backend/packages/scenarios/test/registry.test.ts +++ b/backend/packages/scenarios/test/registry.test.ts @@ -22,7 +22,8 @@ describe.skipIf(!built)("全台劇本目錄", () => { for (const row of Object.values(s.actual?.byVillage ?? {})) for (const id of Object.keys(row)) expect(ids.has(id), `${s.id} ${id}`).toBe(true); for (const c of s.candidates) expect(c.aiStyle, `${s.id} ${c.name}`).not.toBe("dirty"); } - }); + // 讀全部劇本、逐里比對:整套測試平行跑時會超過預設的 5 秒 + }, 20_000); it("臺北市有 12 位候選人,黃珊珊用民眾黨支持的槽位", async () => { const reg = await loadScenarioRegistry(); diff --git a/web/public/cards/actuary.webp b/web/public/cards/actuary.webp new file mode 100644 index 0000000..4a33a31 Binary files /dev/null and b/web/public/cards/actuary.webp differ diff --git a/web/public/cards/ad_blitz.webp b/web/public/cards/ad_blitz.webp new file mode 100644 index 0000000..d72f6bf Binary files /dev/null and b/web/public/cards/ad_blitz.webp differ diff --git a/web/public/cards/blooming_districts.webp b/web/public/cards/blooming_districts.webp new file mode 100644 index 0000000..d2ee4de Binary files /dev/null and b/web/public/cards/blooming_districts.webp differ diff --git a/web/public/cards/crisis_flip.webp b/web/public/cards/crisis_flip.webp new file mode 100644 index 0000000..f69d4e4 Binary files /dev/null and b/web/public/cards/crisis_flip.webp differ diff --git a/web/public/cards/donation_box.webp b/web/public/cards/donation_box.webp new file mode 100644 index 0000000..2e212f2 Binary files /dev/null and b/web/public/cards/donation_box.webp differ diff --git a/web/public/cards/explainer_cards.webp b/web/public/cards/explainer_cards.webp new file mode 100644 index 0000000..0f9c7aa Binary files /dev/null and b/web/public/cards/explainer_cards.webp differ diff --git a/web/public/cards/faction_broker.webp b/web/public/cards/faction_broker.webp new file mode 100644 index 0000000..d84c1f5 Binary files /dev/null and b/web/public/cards/faction_broker.webp differ diff --git a/web/public/cards/iron_legs.webp b/web/public/cards/iron_legs.webp new file mode 100644 index 0000000..bd27a93 Binary files /dev/null and b/web/public/cards/iron_legs.webp differ diff --git a/web/public/cards/local_network.webp b/web/public/cards/local_network.webp new file mode 100644 index 0000000..6291df6 Binary files /dev/null and b/web/public/cards/local_network.webp differ diff --git a/web/public/cards/meme_editor.webp b/web/public/cards/meme_editor.webp new file mode 100644 index 0000000..f756b4a Binary files /dev/null and b/web/public/cards/meme_editor.webp differ diff --git a/web/public/cards/snowball_buzz.webp b/web/public/cards/snowball_buzz.webp new file mode 100644 index 0000000..403a74e Binary files /dev/null and b/web/public/cards/snowball_buzz.webp differ diff --git a/web/public/cards/turn_the_tables.webp b/web/public/cards/turn_the_tables.webp new file mode 100644 index 0000000..63a4ed4 Binary files /dev/null and b/web/public/cards/turn_the_tables.webp differ diff --git a/web/public/cards/walk_everywhere.webp b/web/public/cards/walk_everywhere.webp new file mode 100644 index 0000000..1c2ee0d Binary files /dev/null and b/web/public/cards/walk_everywhere.webp differ diff --git a/web/public/cards/war_room.webp b/web/public/cards/war_room.webp new file mode 100644 index 0000000..1a28fd8 Binary files /dev/null and b/web/public/cards/war_room.webp differ diff --git a/web/src/game/api.ts b/web/src/game/api.ts index 0d27010..603d71b 100644 --- a/web/src/game/api.ts +++ b/web/src/game/api.ts @@ -1,5 +1,6 @@ import { ApiError, RogueArea, RogueCatalog, RogueView, ScenarioSummary, type CareerAbilities, type CustomCandidate, type IslandPerk, type PolicySpec, RogueVillageList, type MiniGameKind } from "@election2026/protocol"; import type { Topology } from "topojson-specification"; +import { reputation } from "./rogue/progress.ts"; /** 遊戲 API:所有回應都用協定的 Zod 定義驗證,格式不符就報錯(docs/16) */ async function request(url: string, schema: { parse(x: unknown): T }, body?: unknown): Promise { @@ -52,10 +53,13 @@ export interface RogueCreateOptions { abilities?: CareerAbilities; perks?: IslandPerk[]; policies?: PolicySpec[]; + /** 聲望(解鎖核心牌、新幕僚);沒給就用這台裝置的進度 */ + reputation?: number; } export const rogueApi = { - create: (scenarioId: string, candidateId: string, options: RogueCreateOptions = {}) => request("/api/rogue/runs", CreateRogueResponse, { scenarioId, candidateId, ...options }), + create: (scenarioId: string, candidateId: string, options: RogueCreateOptions = {}) => + request("/api/rogue/runs", CreateRogueResponse, { scenarioId, candidateId, reputation: reputation(), ...options }), tutorial: () => request("/api/rogue/tutorial", CreateRogueResponse, {}), catalog: () => request("/api/rogue/catalog", RogueCatalog), get: (id: string) => request(`/api/rogue/runs/${encodeURIComponent(id)}`, RogueView), diff --git a/web/src/game/rogue/Collection.tsx b/web/src/game/rogue/Collection.tsx index c6fd2be..e1ee112 100644 --- a/web/src/game/rogue/Collection.tsx +++ b/web/src/game/rogue/Collection.tsx @@ -20,7 +20,7 @@ import { sfx } from "../audio/sfx.ts"; import { GameScene, SceneStat } from "../ui/GameScene.tsx"; import { AdvisorFace, OfferFace, cardKind } from "./cards.tsx"; import { CompletionPanel } from "./Completion.tsx"; -import { loadProgress, type Progress } from "./progress.ts"; +import { loadProgress, reputation, type Progress } from "./progress.ts"; import "./collection.css"; /** @@ -109,6 +109,9 @@ function buildSections(catalog: RogueCatalog, progress: Progress): Record (got ? "已收錄" : unlock && unlock > rep ? `聲望 ${unlock} 解鎖(目前 ${rep})` : how); const sortedCards = catalog.cards .map((c) => ({ c, kind: cardKind(c.tags) })) @@ -118,7 +121,7 @@ function buildSections(catalog: RogueCatalog, progress: Progress): Record }; + return { id: c.id, name: c.name, desc: c.text, meta: meta.filter(Boolean).join("・"), howLabel: "怎麼拿到", how, got, cap: capOf(got, how, c.unlock), group: kind.id, face: }; }); const schoolLabels = new Map(SCHOOLS.map((s) => [s.id, s.label])); @@ -129,7 +132,7 @@ function buildSections(catalog: RogueCatalog, progress: Progress): Record }; + return { id: a.id, name: a.name, desc: a.text, meta: `${school}幕僚`, howLabel: "怎麼拿到", how, got, cap: capOf(got, how, a.unlock), group: a.school, face: }; }); const events = catalog.events.map((e): Entry => { diff --git a/web/src/game/rogue/Completion.tsx b/web/src/game/rogue/Completion.tsx index 11d9833..3173942 100644 --- a/web/src/game/rogue/Completion.tsx +++ b/web/src/game/rogue/Completion.tsx @@ -13,7 +13,7 @@ const pct = (x: number) => `${Math.round(x * 100)}%`; /** 大廳:一條進度+四個數字,點了去圖鑑的完成度 */ export function CompletionStrip({ progress, catalog }: { progress: Progress; catalog: RogueCatalog | null }) { - const { parts, percent } = completion(progress, catalog?.feats.length ?? 0); + const { parts, percent } = completion(progress, catalog); return ( @@ -29,7 +29,7 @@ export function CompletionStrip({ progress, catalog }: { progress: Progress; cat /** 圖鑑:完成度總覽、全台制霸地圖、類型逆風挑戰表 */ export function CompletionPanel({ progress, catalog }: { progress: Progress; catalog: RogueCatalog }) { - const { parts, percent } = completion(progress, catalog.feats.length); + const { parts, percent } = completion(progress, catalog); const conquered = progress.conquered ?? {}; const best = progress.typeBest ?? {}; const levels = catalog.ascension.length; // 逆風 0–10 diff --git a/web/src/game/rogue/brief.tsx b/web/src/game/rogue/brief.tsx index 6ca7f5c..b7ddb46 100644 --- a/web/src/game/rogue/brief.tsx +++ b/web/src/game/rogue/brief.tsx @@ -49,7 +49,13 @@ export function briefNews(view: RogueView, last: readonly RogueLog[] | null) { : []), // 這局對手的規則、大場面在第幾週(docs/25):第一週說 ...(view.week === 1 ? view.rivalRules.map((r) => `這局對手規則「${r.name}」:${r.text}`) : []), - ...(view.week === 1 && view.schedule ? [`這局的大場面:第 ${view.schedule.debate} 週電視辯論、第 ${view.schedule.poll} 週民調、第 ${view.schedule.crisis} 週黑函危機`] : []), + ...(view.week === 1 && view.schedule + ? [ + `這局的大場面:第 ${view.schedule.debate} 週電視辯論、第 ${view.schedule.poll} 週民調、第 ${view.schedule.crisis} 週黑函危機${view.schedule.local.map((l) => `、第 ${l.week} 週${l.title}`).join("")}`, + ] + : []), + // 對手的類型(docs/25):第一週說 + ...(view.week === 1 && view.rivalType ? [`${view.rival.name}是${view.rivalType.name}:${view.rivalType.skill};弱點:${view.rivalType.weakness}`] : []), // 候選人特色(docs/25):第一週介紹類型、技能、本命區 ...(view.week === 1 && view.identity ? [`你是${view.identity.name}:${view.identity.skill};弱點:${view.identity.weakness}${view.identity.home ? `。本命區:${view.identity.home}` : ""}`] diff --git a/web/src/game/rogue/finale.tsx b/web/src/game/rogue/finale.tsx index d901a5a..f1591de 100644 --- a/web/src/game/rogue/finale.tsx +++ b/web/src/game/rogue/finale.tsx @@ -1,5 +1,5 @@ -import type { RogueResult, RogueView } from "@election2026/protocol"; -import { ArrowRight, Coins, Flame, Home, Landmark, MapPin, Medal, RotateCcw, Share2, SkipForward, Swords, Trophy } from "lucide-react"; +import type { RogueCatalog, RogueResult, RogueView } from "@election2026/protocol"; +import { ArrowRight, Coins, Flame, Home, Landmark, MapPin, Medal, RotateCcw, Share2, SkipForward, Sparkles, Swords, Trophy } from "lucide-react"; import { useEffect, useMemo, useRef, useState, type ReactNode } from "react"; import { api, rogueApi } from "../api.ts"; import { CandidateBadge } from "../art/Badge.tsx"; @@ -11,7 +11,7 @@ import { num, pct, raceLabel, signed } from "./labels.ts"; import { pointsForRun } from "../island/data.ts"; import { addPoints } from "../island/store.ts"; import { coinsForRun, earnCoins } from "../shop/wardrobe.ts"; -import { recordRun, TERRITORIES, todayKey, type RunRecord } from "./progress.ts"; +import { recordRun, TERRITORIES, todayKey, unlockList, type RunRecord } from "./progress.ts"; import "./rogue-finale.css"; /** @@ -48,16 +48,32 @@ function coinsOnce(view: RogueView, record: RunRecord): { coins: number; reason: return earnCoins(earned.coins, earned.reason, view.runId) ? earned : null; } -let featNames: Promise> | null = null; -function loadFeatNames() { - featNames ??= rogueApi - .catalog() - .then((c) => new Map(c.feats.map((f) => [f.id, { name: f.name, text: f.text }]))) - .catch(() => { - featNames = null; - return new Map(); - }); - return featNames; +let catalogOnce: Promise | null = null; +/** 圖鑑目錄(成就名稱、聲望解鎖);讀不到就下次再試 */ +function loadCatalog() { + catalogOnce ??= rogueApi.catalog().catch(() => { + catalogOnce = null; + return null; + }); + return catalogOnce; +} + +/** 聲望(docs/25 第 8 節):這局解鎖了什麼、下一個要幾點 */ +function ReputationLine({ record, catalog }: { record: RunRecord; catalog: RogueCatalog | null }) { + const { before, after } = record.reputation; + if (!catalog || after === before) return null; + const unlocks = unlockList(catalog); + const fresh = unlocks.filter((u) => u.at > before && u.at <= after); + const next = unlocks.find((u) => u.at > after); + if (fresh.length === 0 && !next) return null; + return ( +

+ 聲望 +{after - before}({after}) + {fresh.length > 0 + ? `:解鎖${fresh.map((u) => `${u.kind === "card" ? "核心牌" : "幕僚"}「${u.name}」`).join("、")}!之後的下一站會出現` + : `:再 ${next!.at - after} 點解鎖「${next!.name}」`} +

+ ); } function useReducedMotion(): boolean { @@ -362,7 +378,8 @@ function ResultPanel({ onHome: () => void; }) { const r = view.result!; - const [feats, setFeats] = useState>(new Map()); + const [catalog, setCatalog] = useState(null); + const feats = useMemo(() => new Map((catalog?.feats ?? []).map((f) => [f.id, { name: f.name, text: f.text }])), [catalog]); const [sharing, setSharing] = useState(null); const tutorial = view.options.tutorial; const names = useMemo(() => new Map(view.towns.map((t) => [t.code, t.name])), [view.towns]); @@ -411,7 +428,7 @@ function ResultPanel({ useEffect(() => { let alive = true; - void loadFeatNames().then((m) => alive && setFeats(m)); + void loadCatalog().then((c) => alive && setCatalog(c)); if (record.newFeats.length > 0) sfx.good(); return () => { alive = false; @@ -500,6 +517,7 @@ function ResultPanel({
看制霸地圖

)} + {!tutorial && } {record.typeRecord && view.identity && (

{view.identity.name}的新紀錄:贏下逆風 {record.typeRecord.level} 級 diff --git a/web/src/game/rogue/parts.tsx b/web/src/game/rogue/parts.tsx index 4d0502c..141dbfd 100644 --- a/web/src/game/rogue/parts.tsx +++ b/web/src/game/rogue/parts.tsx @@ -5,7 +5,7 @@ import { CardArt } from "../art/CardArt.tsx"; import { AdvisorFace, CardFace } from "./cards.tsx"; import { INTENT_ICONS, TRAIT_LABELS, attackable, counterable, num, overall, pct, signed, townShare, raceLabel, weekLabel } from "./labels.ts"; -/** 行事曆(docs/25):這一週有什麼大場面(辯論、民調、黑函、對手大型造勢、選前之夜) */ +/** 行事曆(docs/25):這一週有什麼大場面(辯論、民調、黑函、對手大型造勢、地方事件週、選前之夜) */ function weekMark(view: RogueView, week: number): { short: string; label: string } | null { const s = view.schedule; if (!s) return null; @@ -13,6 +13,8 @@ function weekMark(view: RogueView, week: number): { short: string; label: string if (week === s.poll) return { short: "民", label: "民調公布" }; if (week === s.crisis) return { short: "函", label: "匿名黑函危機" }; if (week === s.bigRally) return { short: "勢", label: `${view.rival.name}大型造勢` }; + const local = s.local.find((l) => l.week === week); + if (local) return { short: local.short, label: `地方事件週・${local.title}` }; if (week === view.totalWeeks) return { short: "夜", label: "選前之夜" }; return null; } @@ -148,6 +150,11 @@ export function IntentList({ view, previews, onPick, targeting }: { view: RogueV

{view.rival.name}這週要做 + {view.rivalType && ( + + {view.rivalType.name} + + )} {view.rivalTrait.name} @@ -181,6 +188,11 @@ export function IntentList({ view, previews, onPick, targeting }: { view: RogueV

)} {view.intents.some((i) => i.kind === "attack") &&

全市的批評樁腳擋不了:用「澄清記者會」「事實查核」,沒擋下會多一張「記者追問」。

} + {view.rivalType && ( +

+ {view.rivalType.name}:{view.rivalType.skill};弱點:{view.rivalType.weakness} +

+ )}

{view.rivalTrait.name}:{view.rivalTrait.text}

{view.rivalRules.map((r) => (

diff --git a/web/src/game/rogue/progress.ts b/web/src/game/rogue/progress.ts index ab04d7d..7458565 100644 --- a/web/src/game/rogue/progress.ts +++ b/web/src/game/rogue/progress.ts @@ -1,4 +1,4 @@ -import { RogueArchetype, type RogueView } from "@election2026/protocol"; +import { RogueArchetype, type RogueCatalog, type RogueView } from "@election2026/protocol"; import { rogueApi } from "../api.ts"; import { COUNTIES } from "../counties.ts"; @@ -118,8 +118,26 @@ export const PRESIDENT_CODE = "00000"; export const TERRITORIES: readonly [string, string][] = [...COUNTIES, [PRESIDENT_CODE, "總統大選"]]; const territoryName = (code: string): string | null => TERRITORIES.find(([c]) => c === code)?.[1] ?? null; +/** 聲望(docs/25 第 8 節):打完的局數+勝場(輸了 +1、贏了 +2),解鎖流派核心牌與新幕僚;開局帶給伺服器 */ +export const reputation = (p: Progress = loadProgress()): number => p.runs + p.wins; + +export interface Unlock { + id: string; + name: string; + kind: "card" | "advisor"; + at: number; +} + +/** 圖鑑裡要聲望解鎖的牌、幕僚(門檻由低到高) */ +export function unlockList(catalog: Pick): Unlock[] { + return [ + ...catalog.cards.flatMap((c) => (c.unlock ? [{ id: c.id, name: c.name, kind: "card" as const, at: c.unlock }] : [])), + ...catalog.advisors.flatMap((a) => (a.unlock ? [{ id: a.id, name: a.name, kind: "advisor" as const, at: a.unlock }] : [])), + ].sort((a, b) => a.at - b.at); +} + export interface CompletionPart { - id: "map" | "types" | "climb" | "feats"; + id: "map" | "types" | "climb" | "unlocks" | "feats"; label: string; hint: string; done: number; @@ -127,18 +145,25 @@ export interface CompletionPart { } /** - * 完成度(docs/25:讓人一場接一場、想把東西收集完):全台制霸、六種類型都贏過、每種類型的逆風挑戰、成就。 - * percent 是四項的平均;featTotal 是成就總數(圖鑑目錄給) + * 完成度(docs/25:讓人一場接一場、想把東西收集完):全台制霸、六種類型都贏過、每種類型的逆風挑戰、聲望解鎖、成就。 + * percent 是各項的平均;成就總數、要解鎖的東西從圖鑑目錄來(還沒載入時這兩項不算) */ -export function completion(p: Progress, featTotal: number): { parts: CompletionPart[]; percent: number } { +export function completion(p: Progress, catalog: Pick | null): { parts: CompletionPart[]; percent: number } { const types = RogueArchetype.options; const best = p.typeBest ?? {}; const parts: CompletionPart[] = [ { id: "map", label: "全台制霸", hint: "22 個縣市和總統大選,每一塊都打贏一次", done: Object.keys(p.conquered ?? {}).length, total: TERRITORIES.length }, { id: "types", label: "六種類型", hint: "媒體、組織、資深、財務、清廉、黑馬型都贏過", done: types.filter((t) => best[t] !== undefined).length, total: types.length }, { id: "climb", label: "類型逆風挑戰", hint: "每種類型從逆風 0 一路贏到逆風 10", done: types.reduce((a, t) => a + (best[t] === undefined ? 0 : best[t]! + 1), 0), total: types.length * (MAX_ASCENSION + 1) }, - { id: "feats", label: "成就", hint: "圖鑑裡的成就", done: Object.keys(p.feats).length, total: Math.max(featTotal, Object.keys(p.feats).length) }, ]; + if (catalog) { + const unlocks = unlockList(catalog); + const rep = reputation(p); + parts.push( + { id: "unlocks", label: "聲望解鎖", hint: "每打完一局聲望 +1、贏了再 +1,解鎖流派核心牌與新幕僚", done: unlocks.filter((u) => u.at <= rep).length, total: unlocks.length }, + { id: "feats", label: "成就", hint: "圖鑑裡的成就", done: Object.keys(p.feats).length, total: Math.max(catalog.feats.length, Object.keys(p.feats).length) }, + ); + } const percent = parts.reduce((a, x) => a + (x.total ? Math.min(1, x.done / x.total) : 0), 0) / parts.length; return { parts, percent }; } @@ -154,6 +179,8 @@ export interface RunRecord { unlocked: number | null; /** 這個劇本的新紀錄 */ record: boolean; + /** 聲望:這局之前、之後 */ + reputation: { before: number; after: number }; progress: Progress; } @@ -197,7 +224,7 @@ export async function backfillPlayed(): Promise> export function recordRun(view: RogueView): RunRecord { const p = loadProgress(); const r = view.result; - if (!r || p.recorded.includes(view.runId)) return { newFeats: [], conquered: null, typeRecord: null, unlocked: null, record: false, progress: p }; + if (!r || p.recorded.includes(view.runId)) return { newFeats: [], conquered: null, typeRecord: null, unlocked: null, record: false, reputation: { before: reputation(p), after: reputation(p) }, progress: p }; const today = todayKey(); const newFeats = r.feats.filter((f) => !p.feats[f]); const feats = { @@ -255,5 +282,5 @@ export function recordRun(view: RogueView): RunRecord { typeBest: typeRecord ? { ...p.typeBest, [typeRecord.archetype]: typeRecord.level } : p.typeBest, }; saveProgress(next); - return { newFeats, conquered: conquered ? territoryName(conquered) : null, typeRecord, unlocked, record, progress: next }; + return { newFeats, conquered: conquered ? territoryName(conquered) : null, typeRecord, unlocked, record, reputation: { before: reputation(p), after: reputation(next) }, progress: next }; } diff --git a/web/src/game/rogue/rogue-finale.css b/web/src/game/rogue/rogue-finale.css index bc5c06f..5a6ec60 100644 --- a/web/src/game/rogue/rogue-finale.css +++ b/web/src/game/rogue/rogue-finale.css @@ -157,5 +157,6 @@ /* 小鎮幣(服裝店,docs/24) */ .rgn-unlock.is-coins { flex-wrap: wrap; justify-content: center; border-radius: 16px; background: var(--signal); color: var(--signal-ink); font-size: 15px; animation-delay: 320ms; } .rgn-unlock.is-coins a { font-weight: 900; color: inherit; text-decoration: underline; text-underline-offset: 3px; } +.rgn-unlock.is-rep { flex-wrap: wrap; justify-content: center; border-radius: 16px; background: var(--ink); color: var(--surface); font-size: 15px; animation-delay: 260ms; } .rgn-close { margin: 0; font-size: 14px; color: var(--muted); } .rgn-close b { color: var(--ink); } diff --git a/web/src/game/rogue/rogue.css b/web/src/game/rogue/rogue.css index 72c7ae8..b9f6b47 100644 --- a/web/src/game/rogue/rogue.css +++ b/web/src/game/rogue/rogue.css @@ -46,6 +46,8 @@ .rg-weeks li.is-done { background: color-mix(in srgb, var(--ink) 18%, var(--surface)); color: var(--ink); } .rg-weeks li small { margin-left: 1px; font-family: var(--font-serif); font-size: 10px; color: var(--stamp); } .rg-trait-chip.is-rule { margin-left: 4px; background: var(--stamp); color: #fff; } +.rg-trait-chip.is-type { background: var(--ink); color: var(--surface); border-color: var(--ink); } +.rg-trait-chip.is-type + .rg-trait-chip { margin-left: 4px; } .rg-hint.is-rule { color: var(--stamp); } .rg-hint.is-contract { padding: 4px 8px; border-radius: 8px; background: color-mix(in srgb, var(--signal) 25%, var(--surface)); color: var(--ink); font-weight: 700; } .rg-hint.is-contract.is-done { background: color-mix(in srgb, #1f8a4c 22%, var(--surface)); } diff --git a/web/test/rogue-progress.test.ts b/web/test/rogue-progress.test.ts index 37293ff..99d8060 100644 --- a/web/test/rogue-progress.test.ts +++ b/web/test/rogue-progress.test.ts @@ -1,6 +1,6 @@ -import type { RogueView } from "@election2026/protocol"; +import type { RogueCatalog, RogueView } from "@election2026/protocol"; import { beforeEach, describe, expect, it } from "vitest"; -import { completion, dailyPick, loadProgress, PRESIDENT_CODE, recordRun, TERRITORIES, todayKey } from "../src/game/rogue/progress.ts"; +import { completion, dailyPick, loadProgress, PRESIDENT_CODE, recordRun, reputation, TERRITORIES, todayKey, unlockList } from "../src/game/rogue/progress.ts"; /** 測試用的 localStorage(vitest 跑在 Node,沒有瀏覽器的儲存空間) */ function fakeStorage(): Storage { @@ -112,12 +112,26 @@ describe("完成度:全台制霸、類型逆風挑戰(docs/25)", () => { expect(recordRun(inCounty(finished("b", true, 1), "68000", "media")).typeRecord).toEqual({ archetype: "media", level: 1 }); expect(recordRun(inCounty(finished("c", true, 0), "68000", "media")).typeRecord).toBeNull(); expect(recordRun(inCounty(finished("d", false, 3), "68000", "finance")).typeRecord).toBeNull(); - const { parts, percent } = completion(loadProgress(), 22); + // 四局、贏三局:聲望 7,解鎖門檻 1、5、8 的三樣裡拿到兩樣 + const catalog = { + feats: Array.from({ length: 22 }, (_, i) => ({ id: `f${i}`, name: "", text: "" })), + cards: [{ id: "legwork", name: "走透透", unlock: 1 }, { id: "turntable", name: "反將一軍", unlock: 8 }, { id: "canvass", name: "掃街拜票", unlock: null }], + advisors: [{ id: "network", name: "樁腳網", unlock: 5 }], + } as unknown as RogueCatalog; + const { parts, percent } = completion(loadProgress(), catalog); const by = Object.fromEntries(parts.map((p) => [p.id, p])); expect(by.map).toMatchObject({ done: 1, total: TERRITORIES.length }); expect(by.types).toMatchObject({ done: 1, total: 6 }); expect(by.climb).toMatchObject({ done: 2, total: 66 }); + expect(by.unlocks).toMatchObject({ done: 2, total: 3 }); expect(by.feats).toMatchObject({ done: 1, total: 22 }); - expect(percent).toBeCloseTo((1 / 23 + 1 / 6 + 2 / 66 + 1 / 22) / 4); + expect(percent).toBeCloseTo((1 / 23 + 1 / 6 + 2 / 66 + 2 / 3 + 1 / 22) / 5); + expect(unlockList(catalog).map((u) => u.id)).toEqual(["legwork", "network", "turntable"]); + expect(reputation()).toBe(7); + }); + + it("聲望:輸了 +1、贏了 +2;結果記下這局前後的聲望", () => { + expect(recordRun(inCounty(finished("x", false), "68000", null)).reputation).toEqual({ before: 0, after: 1 }); + expect(recordRun(inCounty(finished("y", true), "68000", null)).reputation).toEqual({ before: 1, after: 3 }); }); });