import { flagOwner } from "./mechanics.ts"; import type { RunState } from "./state.ts"; /** 成就(docs/22):開票時算這局拿到哪些;解鎖紀錄存在玩家自己的瀏覽器 */ export interface FeatDef { id: string; name: string; text: string; } export const FEATS: readonly FeatDef[] = [ { id: "win", name: "凍蒜!", text: "當選一次" }, { id: "landslide", name: "壓倒性勝利", text: "贏 8 個百分點以上" }, { id: "squeaker", name: "驚險過關", text: "贏不到 1 個百分點" }, { id: "comeback", name: "逆轉勝", text: "第 4 週民調落後 3 個百分點以上,最後當選" }, { id: "underdog", name: "以小搏大", text: "開局底盤落後 5 個百分點以上,最後當選" }, { id: "all_flags", name: "全區插旗", text: "開票時每一區都插著你的旗" }, { id: "clean", name: "乾淨選戰", text: "沒打過任何攻擊牌就當選" }, { id: "debate_sweep", name: "辯論三戰全勝", text: "電視辯論三回合都贏" }, { id: "crisis_zero", name: "黑函零損失", text: "匿名黑函危機沒有掉任何一票" }, { id: "combo4", name: "四連拳", text: "同一週在同一區打出 4 種不同的牌" }, { id: "flipper", name: "翻轉王", text: "一局翻轉 5 個區" }, { id: "big_hit", name: "一張定江山", text: "一張牌在一區拉到相當於全市 0.6% 的票" }, { id: "thin_deck", name: "精實牌組", text: "牌組 8 張以下當選" }, { id: "rich", name: "財源滾滾", text: "資金超過 3,000 萬" }, { id: "full_staff", name: "滿編團隊", text: "帶滿 5 位幕僚" }, { id: "shopper", name: "物資行常客", text: "一局買 4 樣東西" }, { id: "asc5", name: "逆風高手", text: "逆風 5 級以上當選" }, { id: "asc10", name: "逆風傳說", text: "逆風 10 級當選" }, { id: "daily", name: "每日一戰", text: "完成一場每日一戰" }, { id: "career_legislator", name: "國會新科", text: "政治生涯:選上立委" }, { id: "career_mayor", name: "地方首長", text: "政治生涯:選上縣市長" }, { id: "career_president", name: "登上大位", text: "政治生涯:選上總統" }, ]; export function featsOf(s: RunState, won: boolean, margin: number): string[] { const deck = s.draw.length + s.discard.length + s.hand.length; const ok: Record = { win: won, landslide: won && margin >= 0.08, squeaker: won && margin < 0.01, comeback: won && s.stats.pollGap >= 3, underdog: won && s.startGap <= -5, all_flags: s.towns.every((t) => flagOwner(t) === "you"), clean: won && s.stats.attacks === 0, debate_sweep: s.stats.debateWins >= 3, crisis_zero: s.crisisDone && s.stats.crisisLoss === 0, combo4: s.stats.maxCombo >= 4, flipper: s.stats.flips >= 5, big_hit: s.stats.bigHit >= 6000, thin_deck: won && deck <= 8, rich: s.money >= 3000, full_staff: s.advisors.length >= 5, shopper: s.stats.bought >= 4, asc5: won && s.options.ascension >= 5, asc10: won && s.options.ascension >= 10, daily: s.options.daily !== null, career_legislator: won && s.options.career?.stage === 1, career_mayor: won && s.options.career?.stage === 2, career_president: won && s.options.career?.stage === 3, }; return FEATS.filter((f) => ok[f.id]).map((f) => f.id); }