From ada398fdeda34061aa1cc851c665292cfda61a4c Mon Sep 17 00:00:00 2001 From: daniel wang Date: Fri, 30 Oct 2026 19:47:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8D=8F=E4=BA=BA=E7=89=A9=E7=9A=84=E9=96=8B?= =?UTF-8?q?=E5=B1=80=E8=83=BD=E5=8A=9B=E6=94=B9=E6=88=90=E6=94=BF=E6=B2=BB?= =?UTF-8?q?=E7=94=9F=E6=B6=AF=E9=82=A3=E4=BA=94=E9=A0=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 捏人物原本配的是舊模式留下的知名度、口才、謀略、財力、人脈,和政治生涯升等的口才、組織、媒體、財務、清廉對不上:謀略沒作用、清廉配不到,知名度、財力和出身還暗中改開局得票和資金。 - 捏人物直接配五項能力:總共 5 點、每項最多 2 點,出身和黨的 +1 用鎖住的格子標出來,升等再加到 5 級 - 政治生涯角色卡加圖例,分開局和升等加的 - 拿掉藏起來的效果:同一個政黨不同出身,開局得票一樣;勝率變化在雜訊內 - 舊存檔自動換算,升等加的點保留;前端多送舊格式,舊伺服器也收得下 - 說明在 docs/27 第 6 節 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Uirha3X8mHVJgT7svdEw9F --- backend/apps/server/test/server.test.ts | 15 ++- backend/apps/sim/src/career-balance.ts | 3 +- backend/apps/sim/src/party-balance.ts | 6 +- backend/apps/sim/src/ultimate-balance.ts | 4 +- backend/apps/sim/src/village-balance.ts | 6 +- backend/docs/23-career-and-meta.md | 4 +- backend/docs/27-gameplay-v5-and-assets.md | 29 ++++- backend/packages/content/src/custom.ts | 42 +++---- backend/packages/protocol/src/game.ts | 19 +++- backend/packages/protocol/src/origins.ts | 52 +++++++-- .../packages/protocol/test/origins.test.ts | 34 ++++++ backend/packages/rogue/src/meta.ts | 9 -- backend/packages/rogue/src/view.ts | 4 +- web/src/game/api.ts | 11 +- web/src/game/creator/CreatorScreen.tsx | 35 +++--- web/src/game/creator/IdentityTabs.tsx | 105 ++++++++++++------ web/src/game/creator/characters.ts | 18 ++- web/src/game/creator/creator.css | 22 ++-- web/src/game/creator/options.ts | 67 +++++------ web/src/game/rogue/CareerSetup.tsx | 11 +- web/src/game/rogue/CareerSheet.tsx | 20 +++- web/src/game/rogue/careerRules.ts | 16 +-- web/src/game/rogue/rogue-career.css | 2 + web/test/career-rules.test.ts | 18 +-- web/test/creator-points.test.ts | 38 +++++++ 25 files changed, 396 insertions(+), 194 deletions(-) create mode 100644 backend/packages/protocol/test/origins.test.ts create mode 100644 web/test/creator-points.test.ts diff --git a/backend/apps/server/test/server.test.ts b/backend/apps/server/test/server.test.ts index 4e73da1..fade344 100644 --- a/backend/apps/server/test/server.test.ts +++ b/backend/apps/server/test/server.test.ts @@ -164,12 +164,23 @@ describe.skipIf(!built)("API", () => { name: "林小桃", party: null, background: "網紅", - stats: { fame: 6, eloquence: 5, strategy: 4, wealth: 5, network: 5 }, + points: { eloquence: 2, organization: 0, media: 1, finance: 2, integrity: 0 }, avatar, replace: null, ...over, }); + it("自創角色:開局能力=捏人物配的點+出身+黨的資源;舊版畫面只送 stats 也能開局", async () => { + const res = await createRun({ scenarioId: scenario.id, candidateId: "custom", custom: custom() }); + expect(res.statusCode).toBe(201); + // 網紅:媒體 +1;無黨籍沒有黨的資源 + expect(RogueView.parse((res.json() as { view: unknown }).view).options.abilities).toEqual({ eloquence: 2, organization: 0, media: 2, finance: 2, integrity: 0 }); + const { points: _points, ...old } = custom({ stats: { fame: 5, eloquence: 5, strategy: 5, wealth: 5, network: 5 } }); + const legacy = await createRun({ scenarioId: scenario.id, candidateId: "custom", custom: old }); + expect(legacy.statusCode).toBe(201); + expect(RogueView.parse((legacy.json() as { view: unknown }).view).options.abilities).toEqual({ eloquence: 1, organization: 1, media: 2, finance: 1, integrity: 1 }); + }); + it("政治生涯:自創角色以新候選人加入,或取代同黨的候選人;帶過來的幕僚和牌", async () => { const add = await createRun({ scenarioId: "local2022-10018", candidateId: "custom", custom: custom(), even: true, career: { stage: 2 } }); expect(add.statusCode).toBe(201); @@ -224,7 +235,7 @@ describe.skipIf(!built)("API", () => { }); it("政治生涯:點數超過上限、用真實人物的名字、帶狀態牌都會被拒絕", async () => { - expect((await createRun({ scenarioId: scenario.id, candidateId: "custom", custom: custom({ stats: { fame: 10, eloquence: 10, strategy: 10, wealth: 0, network: 0 } }) })).statusCode).toBe(400); + expect((await createRun({ scenarioId: scenario.id, candidateId: "custom", custom: custom({ points: { eloquence: 2, organization: 2, media: 2, finance: 0, integrity: 0 } }) })).statusCode).toBe(400); const res = await createRun({ scenarioId: scenario.id, candidateId: "custom", custom: custom({ name: "蔣萬安" }) }); expect(res.statusCode).toBe(400); expect(res.json().error).toContain("真實人物"); diff --git a/backend/apps/sim/src/career-balance.ts b/backend/apps/sim/src/career-balance.ts index 8265f91..c0323a0 100644 --- a/backend/apps/sim/src/career-balance.ts +++ b/backend/apps/sim/src/career-balance.ts @@ -8,6 +8,7 @@ import { readFile } from "node:fs/promises"; import { join } from "node:path"; import { parseArgs } from "node:util"; import { CUSTOM_ID, withCustomCandidate } from "@election2026/content"; +import { DEFAULT_POINTS } from "@election2026/protocol"; import { DEFAULT_PACKS_ROOT } from "@election2026/pack-loader"; import { runBot, type BotName } from "@election2026/rogue"; import { COUNCIL_WEEKS, VILLAGE_WEEKS, councilSetup, districtOfVillage, villageSetup, type CouncilDistrict } from "@election2026/rogue/local"; @@ -31,7 +32,7 @@ async function main(): Promise { const base = await loadWorld(id); const topology = JSON.parse(await readFile(join(DEFAULT_PACKS_ROOT, base.scenario.packId, "topology.json"), "utf-8")) as TopologyLike; for (const party of PARTIES) { - const scenario = withCustomCandidate(base.scenario, { name: "測試人", party, background: "基層里長", stats: { fame: 5, eloquence: 5, strategy: 5, wealth: 5, network: 5 }, avatar: { ...avatar }, replace: null }, new Set()); + const scenario = withCustomCandidate(base.scenario, { name: "測試人", party, background: "基層里長", points: DEFAULT_POINTS, avatar: { ...avatar }, replace: null }, new Set()); const world = { ...base, scenario }; const empty = (): Partial> => Object.fromEntries(BOTS.map((b) => [b, []])); const results: Record>> = { 里長: empty(), 議員: empty() }; diff --git a/backend/apps/sim/src/party-balance.ts b/backend/apps/sim/src/party-balance.ts index ebbfafc..d964d45 100644 --- a/backend/apps/sim/src/party-balance.ts +++ b/backend/apps/sim/src/party-balance.ts @@ -7,7 +7,7 @@ */ import { parseArgs } from "node:util"; import { CUSTOM_ID, withCustomCandidate } from "@election2026/content"; -import { originAbilities, partyKind, type Background } from "@election2026/protocol"; +import { DEFAULT_POINTS, originAbilities, partyKind, type Background } from "@election2026/protocol"; import { runBot, type BotName } from "@election2026/rogue"; import { buildSetup } from "@election2026/rogue/setup"; import { loadWorld } from "./world.ts"; @@ -17,7 +17,7 @@ const PARTIES = ["民主進步黨", "台灣民眾黨", "時代力量", null] as const BACKGROUNDS: Background[] = ["律師", "基層里長", "網紅"]; const BOTS: BotName[] = ["casual", "greedy"]; const avatar = { skin: "#eebd98", hair: "bob", hairColor: "#2f2520", outfit: "blouse", suit: "#24324a", shirt: "#f7f5f0", tie: "#b3262d", glasses: true, beard: false, bg: "#dfe8f0" } as const; -const stats = { fame: 5, eloquence: 5, strategy: 5, wealth: 5, network: 5 }; +const points = DEFAULT_POINTS; /** 政治生涯升級拿到的技能點(POINTS=4 約等於立委關的 Lv 5):輪流加在口才、組織、媒體 */ function withPoints(a: ReturnType, n: number): ReturnType { @@ -41,7 +41,7 @@ async function main(): Promise { const same = party ? base.scenario.candidates.find((c) => c.party === party) : undefined; const won: Partial> = { casual: [], greedy: [] } as Partial>; for (const background of BACKGROUNDS) { - const custom = { name: "測試人", party, background, stats, avatar: { ...avatar }, replace: same?.id ?? null }; + const custom = { name: "測試人", party, background, points, avatar: { ...avatar }, replace: same?.id ?? null }; const world = { ...base, scenario: withCustomCandidate(base.scenario, custom, new Set()) }; // REAL=1:政治生涯的條件(照真實底盤、最多落後 15 點,有大絕招) const setup = buildSetup(world, CUSTOM_ID, process.env.REAL ? { even: false, maxGap: Number(process.env.GAP ?? 0.15) } : { even: true }); diff --git a/backend/apps/sim/src/ultimate-balance.ts b/backend/apps/sim/src/ultimate-balance.ts index 48aef8f..d990351 100644 --- a/backend/apps/sim/src/ultimate-balance.ts +++ b/backend/apps/sim/src/ultimate-balance.ts @@ -7,7 +7,7 @@ */ import { parseArgs } from "node:util"; import { CUSTOM_ID, withCustomCandidate } from "@election2026/content"; -import { originAbilities, partyKind } from "@election2026/protocol"; +import { DEFAULT_POINTS, originAbilities, partyKind } from "@election2026/protocol"; import { runBot, type BotName, type RogueSetup } from "@election2026/rogue"; import { buildSetup } from "@election2026/rogue/setup"; import { loadWorld } from "./world.ts"; @@ -43,7 +43,7 @@ async function main(): Promise { for (const base of worlds) { const party = "民主進步黨"; const same = base.scenario.candidates.find((c) => c.party === party); - const custom = { name: "測試人", party, background: "律師" as const, stats: { fame: 5, eloquence: 5, strategy: 5, wealth: 5, network: 5 }, avatar: { ...avatar }, replace: same?.id ?? null }; + const custom = { name: "測試人", party, background: "律師" as const, points: DEFAULT_POINTS, avatar: { ...avatar }, replace: same?.id ?? null }; const world = { ...base, scenario: withCustomCandidate(base.scenario, custom, new Set()) }; const setup = withGap(buildSetup(world, CUSTOM_ID, { even: true }), gap); const origin = { background: custom.background, party, kind: partyKind(party) }; diff --git a/backend/apps/sim/src/village-balance.ts b/backend/apps/sim/src/village-balance.ts index f2b12ed..57062c0 100644 --- a/backend/apps/sim/src/village-balance.ts +++ b/backend/apps/sim/src/village-balance.ts @@ -6,7 +6,7 @@ */ import { parseArgs } from "node:util"; import { CUSTOM_ID, withCustomCandidate } from "@election2026/content"; -import { originAbilities, partyKind } from "@election2026/protocol"; +import { DEFAULT_POINTS, originAbilities, partyKind } from "@election2026/protocol"; import { runBot, type BotName } from "@election2026/rogue"; import { VILLAGE_WEEKS, villageSetup } from "@election2026/rogue/local"; import { loadWorld } from "./world.ts"; @@ -15,7 +15,7 @@ const COUNTIES = ["taoyuan-2022-mayor", "local2022-63000", "local2022-64000", "l const PARTIES = ["民主進步黨", "中國國民黨", null] as const; const BOTS: BotName[] = ["idle", "casual", "greedy"]; const avatar = { skin: "#eebd98", hair: "bob", hairColor: "#2f2520", outfit: "blouse", suit: "#24324a", shirt: "#f7f5f0", tie: "#b3262d", glasses: true, beard: false, bg: "#dfe8f0" } as const; -const stats = { fame: 5, eloquence: 5, strategy: 5, wealth: 5, network: 5 }; +const points = DEFAULT_POINTS; const mean = (xs: number[]) => xs.reduce((a, b) => a + b, 0) / (xs.length || 1); const pct = (x: number) => `${(x * 100).toFixed(0)}%`; @@ -27,7 +27,7 @@ async function main(): Promise { for (const id of COUNTIES) { const base = await loadWorld(id); for (const party of PARTIES) { - const custom = { name: "測試人", party, background: "基層里長" as const, stats, avatar: { ...avatar }, replace: null }; + const custom = { name: "測試人", party, background: "基層里長" as const, points, avatar: { ...avatar }, replace: null }; const world = { ...base, scenario: withCustomCandidate(base.scenario, custom, new Set()) }; const won: Partial> = { idle: [], casual: [], greedy: [] } as Partial>; const margins: number[] = []; diff --git a/backend/docs/23-career-and-meta.md b/backend/docs/23-career-and-meta.md index 9c9a9e2..5599f98 100644 --- a/backend/docs/23-career-and-meta.md +++ b/backend/docs/23-career-and-meta.md @@ -59,7 +59,7 @@ web/src/game/rogue/Career.tsx(進度 tongsuan.rogue.career.v3;v1、v2 的進 - 立委:講解法條(拼條文、選白話說明讓過半委員接受)+質詢+搶主席台(鬧劇版,沒有人受傷;黨團只寫我方/對方) - 縣市長:分配預算(四個虛構分區的滿意度)+颱風救災 - 任期結果:五項能力經驗(每 4 點升一級,最高 5 級)、政績點、下一場開局聲勢 0–2、資金 0–300 萬,以及虛構的任期回顧標題。可以跳過任期(沒有加成)。 -- **五項能力**(0–5 級,開局照捏人物的點數換算):口才(記者會、座談類的牌每級 +4%;3 級起辯論多一張論點;5 級看得出最好的論點)、組織(樁腳每級 +10%、地面牌每級 +3%)、媒體(媒體牌每級 +5%、爆紅機率每級 +3%)、財務(開局資金每級 +80 萬、每週收入每級 +15 萬)、清廉(黑函損失每級 −12%、記者追問掉票每級 −15%)。 +- **五項能力**(0–5 級,開局=捏人物直接配的點+出身+黨的資源,docs/27 第 6 節):口才(記者會、座談類的牌每級 +4%;3 級起辯論多一張論點;5 級看得出最好的論點)、組織(樁腳每級 +10%、地面牌每級 +3%)、媒體(媒體牌每級 +5%、爆紅機率每級 +3%)、財務(開局資金每級 +80 萬、每週收入每級 +15 萬)、清廉(黑函損失每級 −12%、記者追問掉票每級 −15%)。 ### 練等(18 第 44 項,規則在 web/src/game/rogue/careerRules.ts) @@ -86,7 +86,7 @@ web/src/game/rogue/Career.tsx(進度 tongsuan.rogue.career.v3;v1、v2 的進 - 大黨(民進黨、國民黨):開局資金多、組織 +1、開局一張「黨部動員掃街」;包袱是第 3 或第 4 週的「黨中央風波」(手上一張,那週沒回應全市掉票,週末就消失)。 - 民眾黨:資金中等、媒體 +1。 - 其他政黨、無黨籍:資金少;開局得票多 0.2 個百分點、記者追問掉的票少一成五,政治生涯經驗 ×1.2。 -- 起始能力=捏人物點數換算(0–2 級)+出身 +1+黨的資源 +1。政治生涯的舊存檔讀取時換成新規則(自己加的點保留);自由選戰的自創角色也套用同一套能力。 +- 起始能力=捏人物配的開局能力點(總共 5 點、每項最多 2 點;2026-10-30 以前是知名度、謀略那五項換算,docs/27 第 6 節)+出身 +1+黨的資源 +1。政治生涯的舊存檔讀取時換成新規則(自己加的點保留);自由選戰的自創角色也套用同一套能力。 - 平衡(apps/sim/src/party-balance.ts,2026-10-27):勢均力敵開局、逆風 2,打得好的玩家大黨 98%、民眾黨 96%、小黨與無黨籍 98%;隨手玩 23%/32%/35%。 - 畫面:捏人物的「出身」格子寫加成、「政黨」下面寫黨的資源與代價;政治生涯角色卡也列出來。 diff --git a/backend/docs/27-gameplay-v5-and-assets.md b/backend/docs/27-gameplay-v5-and-assets.md index f061a20..e5d3e8a 100644 --- a/backend/docs/27-gameplay-v5-and-assets.md +++ b/backend/docs/27-gameplay-v5-and-assets.md @@ -1,7 +1,7 @@ # 27 選戰卡牌第五版:趕場、政見支票,與資源瘦身 > 2026-10-30。使用者要求:「研究一下目前的遊戲機制,網路上好玩的桌遊機制,引人入勝,然後針對資源來說,前後端量都要再小一點,載入速度更快一點。」 -> 本文件記錄:資源怎麼量、改了什麼、改完多快;桌遊機制研究;新增的兩個機制(趕場、政見支票)與平衡量測。 +> 本文件記錄:資源怎麼量、改了什麼、改完多快;桌遊機制研究;新增的兩個機制(趕場、政見支票)與平衡量測;開局能力和升等改成同一套(第 6 節)。 ## 1. 資源與載入速度 @@ -105,6 +105,33 @@ docs/26 第 2 節已經借了《殺戮尖塔》的意圖、《冷戰熱鬥》的 - 抽哪三張用這局種子另外起一串亂數,不動到局裡的亂數:同一個種子的其他內容和沒有支票時一樣(挑戰朋友、每日一戰、測試都靠這點)。 - 模擬玩家一律不開,連「什麼都不做」的基準也不開(它們不會照著目標打),平衡報告和逐張地圖校準不受影響。會打的人可以挑自己做得到的,算是技術的回報。 +## 6. 開局能力和升等是同一套(`protocol/origins.ts`) + +> 使用者回報:「總覺得一開始選的能力,跟升等之後可以增加的,好像沒關係?」 + +**原本的問題**:捏人物的「能力」是經典模式(2026-10-26 刪掉)留下來的知名度、口才、謀略、財力、人脈,各 0–10、共 25 點;政治生涯升等加的是口才、組織、媒體、財務、清廉。開局時在背後換算((點數 − 3) ÷ 3 四捨五入、最多 2 級),畫面上都沒寫: + +- 只有口才同名;知名度→媒體、人脈→組織、財力→財務。**謀略完全沒有作用**,清廉不能配(只有醫師、社運出身 +1)。 +- 換算是看不到的階梯:0–4 點都是 0 級、5–7 點都是 1 級。 +- 說明文字(失言機率、自掏腰包上限、幕僚人數、祕密行動)是經典模式的,選戰卡牌裡沒有。 +- **藏起來的效果**:知名度、財力、人脈和出身還會經過舊引擎的候選人數值(知名度、資金、組織)改開局得票和資金。彰化縣長的劇本知名度配滿,開局 31.6% → 48.7%(勢均力敵也多約 5 個百分點),所以「知名度配滿」是最強的配法;前藝人、政二代開局多約 1 個百分點,企業家多 60–90 萬。 + +**改成**: + +- 捏人物的「能力」分頁就是那五項(同樣的圖示、顏色、5 格能力條):**總共 5 點、每項自己最多配 2 點**(平均分配=每項 1 點,政治生涯「快速捏一個」也用這組)。斜線格是出身、黨給的(各 +1,旁邊標「律師 +1」「大黨 +1」),實心格是自己配的,虛線空格是之後升等再加(每項最多 5 級)。每項寫每一級的效果(`ABILITY_EFFECTS`,捏人物、角色卡、圖鑑共用一份)。 +- 政治生涯角色卡的能力條加圖例:淺色=開局(捏人物配的+出身+黨),深色=升等加的。 +- 藏起來的效果拿掉:`content/custom.ts` 給引擎的知名度、口才、資金、組織固定用舊版每項 5 點的數值(平衡模擬一直用這組),只依政黨分大黨、民眾黨、其他。黨的資源寫著的「資金多/中等/少」照舊。 +- 相容:`CustomCandidate.points` 是新的開局能力點;`stats`(舊版點數)變成選填。舊存檔讀進來用 `legacyPoints` 換算(舊的階梯,再補滿或扣回 5 點:補的先給清廉,扣的從最多的扣);政治生涯存檔的規則版本 2 → 3,開局那部分重算、升等加的點保留(舊存檔每項 5 點的角色清廉多 1 級)。前端開局時另外送每項 5 點的 `stats`,還沒重啟的舊版伺服器也收(政治生涯本來就自己送能力,不受影響)。 + +**平衡**(政治生涯的條件:照真實底盤、最多落後 10 個百分點、逆風 2;桃園市第 1 選區立委、台中市長 × 大黨/無黨籍 × 10 種出身 × 10 個種子): + +| | 開局得票(同一黨的 10 種出身) | 隨手玩 | 打得好 | +|---|---|---:|---:| +| 改前 | 差到 2.3 個百分點(前藝人、政二代最高,基層里長最低) | 8.8% | 70.3% | +| 改後 | 完全一樣 | 8.0% | 68.0% | + +勝率的差距在雜訊範圍內(每種玩家 800 局,打得好的標準誤約 1.6 個百分點)。 + ## 5. 之後可以做 - 第 2 節排名 3–7 的機制;負面選戰溫度計最便宜,可以順便補強攻防流派。 diff --git a/backend/packages/content/src/custom.ts b/backend/packages/content/src/custom.ts index acff9ee..d91bc99 100644 --- a/backend/packages/content/src/custom.ts +++ b/backend/packages/content/src/custom.ts @@ -4,7 +4,7 @@ import { cleanAvatar, type CustomCandidate, type PartySlotKey } from "@election2 /** * 把玩家的自創角色放進劇本(docs/04、docs/15)。 * 取代某位候選人時沿用他的號次與「個人魅力」校準值(代表那個位置的基本盤); - * 以新候選人加入時,從一般小黨候選人的水準起步,再看知名度點數。 + * 以新候選人加入時,從一般小黨候選人的水準起步。 * 頭像照部件目錄清洗(docs/24):看不懂的部件代號換成預設值,不擋開局。 */ @@ -12,19 +12,12 @@ export const CUSTOM_ID = "custom"; const SLOT: Record = { 民主進步黨: "a", 中國國民黨: "b", 台灣民眾黨: "c" }; -/** 出身的加成(設計文件 04 的出身表,數值是遊戲設定) */ -const BACKGROUND: Record> = { - 醫師: { eloquence: 6, awareness: 0.03 }, - 律師: { eloquence: 10 }, - 教授: { eloquence: 6, strategy: 4 }, - 前藝人: { awareness: 0.12 }, - 網紅: { awareness: 0.06, fundraising: 1.3 }, - 政二代: { machine: 0.1, awareness: 0.04 }, - 基層里長: { machine: 0.08, awareness: -0.04 }, - 企業家: { money: 8_000_000 }, - 前官員: { strategy: 10, awareness: 0.04 }, - 社運出身: { awareness: 0.04, eloquence: 4 }, -}; +/** + * 選戰卡牌只看五項能力(protocol/origins.ts:捏人物配的點+出身+黨的資源,docs/27 第 6 節)。 + * 引擎這邊的知名度、口才、資金、組織固定用舊版捏人物每項 5 點的數值(平衡模擬一直用這組), + * 只依政黨分大黨、民眾黨、其他;捏人物的點數和出身不再暗中改開局得票和資金。 + */ +const STAT_POINTS = 5; export class CustomCandidateError extends Error {} @@ -36,12 +29,11 @@ export function withCustomCandidate(scenario: Scenario, custom: CustomCandidate, // 民進黨、國民黨、民眾黨有自己的選民槽位;其他政黨和無黨籍一樣算「其他」 const slot = (custom.party && SLOT[custom.party]) || "other"; const major = slot === "a" || slot === "b"; - const bonus = BACKGROUND[custom.background]; - const { fame, eloquence, strategy, wealth, network } = custom.stats; + const n = STAT_POINTS; const others = scenario.candidates.filter((c) => c.id !== replaced?.id); const minorAppeals = others.map((c) => c.appeal ?? 0).sort((a, b) => a - b); - const newcomerAppeal = (minorAppeals[Math.min(1, minorAppeals.length - 1)] ?? 0) + fame * 0.15; - const startingMoney = (major ? 12_000_000 : slot === "c" ? 5_000_000 : 2_000_000) + wealth * 2_000_000 + (bonus.money ?? 0); + const newcomerAppeal = (minorAppeals[Math.min(1, minorAppeals.length - 1)] ?? 0) + n * 0.15; + const startingMoney = (major ? 12_000_000 : slot === "c" ? 5_000_000 : 2_000_000) + n * 2_000_000; const candidate: ScenarioCandidate = { id: CUSTOM_ID, name, @@ -50,15 +42,15 @@ export function withCustomCandidate(scenario: Scenario, custom: CustomCandidate, slot, number: replaced?.number ?? Math.max(...scenario.candidates.map((c) => c.number)) + 1, description: `${custom.background}出身,${custom.party ? `${custom.party}提名` : "無黨籍參選"}。(自創角色)`, - awareness: Math.min(0.85, Math.max(0.15, 0.25 + fame * 0.04 + (bonus.awareness ?? 0))), - eloquence: Math.min(100, 30 + eloquence * 6 + (bonus.eloquence ?? 0)), - strategy: Math.min(100, 30 + strategy * 6 + (bonus.strategy ?? 0)), + awareness: 0.25 + n * 0.04, + eloquence: 30 + n * 6, + strategy: 30 + n * 6, startingMoney, - fundraising: Math.round(((major ? 1_500_000 : slot === "c" ? 600_000 : 250_000) + wealth * 100_000) * (bonus.fundraising ?? 1)), + fundraising: (major ? 1_500_000 : slot === "c" ? 600_000 : 250_000) + n * 100_000, realFinance: null, - wealth: 2_000_000 + wealth * 2_000_000, - machine: Math.min(0.9, 0.05 + network * 0.03 + (major ? 0.15 : 0) + (bonus.machine ?? 0)), - staff: Math.min(6, 2 + Math.floor(network / 3) + (major ? 1 : 0)), + wealth: 2_000_000 + n * 2_000_000, + machine: 0.05 + n * 0.03 + (major ? 0.15 : 0), + staff: 2 + Math.floor(n / 3) + (major ? 1 : 0), appeal: replaced?.appeal ?? newcomerAppeal, aiStyle: "balanced", avatar: cleanAvatar(custom.avatar).spec, diff --git a/backend/packages/protocol/src/game.ts b/backend/packages/protocol/src/game.ts index 03b5569..22a9d24 100644 --- a/backend/packages/protocol/src/game.ts +++ b/backend/packages/protocol/src/game.ts @@ -469,8 +469,19 @@ export type ScenarioListItem = z.infer; /** 自創角色的出身(docs/04) */ export const BACKGROUNDS = ["醫師", "律師", "教授", "前藝人", "網紅", "政二代", "基層里長", "企業家", "前官員", "社運出身"] as const; +/** + * 自創角色的開局能力點(捏人物的「能力」分頁):五項就是政治生涯角色卡上的五項能力,總共 5 點、每項自己最多配 2 點; + * 出身、黨的資源另外各加 1 級(origins.ts),之後政治生涯升等再往上加,每項最多 5 級。 + */ +export const ABILITY_IDS = ["eloquence", "organization", "media", "finance", "integrity"] as const; +export const START_POINTS = 5; +export const START_POINT_MAX = 2; +const startPoint = z.number().int().min(0).max(START_POINT_MAX); +export const StartPoints = z.object({ eloquence: startPoint, organization: startPoint, media: startPoint, finance: startPoint, integrity: startPoint }); +export type StartPoints = z.infer; + +/** 舊版捏人物的點數(知名度、口才、謀略、財力、人脈,各 0–10、總共 25 點):舊存檔、還沒更新的畫面會送,換算見 origins.ts 的 legacyPoints */ export const STATS = ["fame", "eloquence", "strategy", "wealth", "network"] as const; -/** 能力點數:五項各 0–10,總共 25 點 */ export const STAT_BUDGET = 25; export const STAT_MAX = 10; @@ -483,12 +494,14 @@ export const CustomCandidate = z .refine((p) => PARTY_SET.has(p), { message: "不是台灣歷屆選舉出現過的政黨" }) .nullable(), background: z.enum(BACKGROUNDS), - stats: z.object(Object.fromEntries(STATS.map((k) => [k, z.number().int().min(0).max(STAT_MAX)])) as Record<(typeof STATS)[number], z.ZodNumber>), + points: StartPoints.optional(), + stats: z.object(Object.fromEntries(STATS.map((k) => [k, z.number().int().min(0).max(STAT_MAX)])) as Record<(typeof STATS)[number], z.ZodNumber>).optional(), avatar: AvatarSpecSchema, /** 取代劇本裡的某位候選人(沿用號次);null 表示以新候選人加入 */ replace: z.string().nullable(), }) - .refine((c) => STATS.reduce((sum, k) => sum + c.stats[k], 0) <= STAT_BUDGET, { message: `能力點數總共最多 ${STAT_BUDGET} 點`, path: ["stats"] }); + .refine((c) => !c.points || ABILITY_IDS.reduce((sum, k) => sum + c.points![k], 0) <= START_POINTS, { message: `開局能力總共最多 ${START_POINTS} 點`, path: ["points"] }) + .refine((c) => !c.stats || STATS.reduce((sum, k) => sum + c.stats![k], 0) <= STAT_BUDGET, { message: `能力點數總共最多 ${STAT_BUDGET} 點`, path: ["stats"] }); export type CustomCandidate = z.infer; export const CreateMatchRequest = z.object({ diff --git a/backend/packages/protocol/src/origins.ts b/backend/packages/protocol/src/origins.ts index 7e0ea31..4bd0f60 100644 --- a/backend/packages/protocol/src/origins.ts +++ b/backend/packages/protocol/src/origins.ts @@ -1,4 +1,4 @@ -import type { BACKGROUNDS } from "./game.ts"; +import { ABILITY_IDS, START_POINTS, type BACKGROUNDS, type StartPoints } from "./game.ts"; import type { CareerAbilities } from "./rogue.ts"; /** @@ -8,6 +8,8 @@ import type { CareerAbilities } from "./rogue.ts"; * 民眾黨媒體 +1;其他政黨和無黨籍資源少,但形象清新(開局得票略多、記者追問掉的票少),政治生涯經驗 ×1.2。 * 只套在自創角色上(真實候選人照真實的資源)。數字是遊戲設定,用 apps/sim/src/party-balance.ts 模擬調過: * 打得好的玩家各黨勝率 96–98%,隨手玩 23–35%(2026-10-27,4 個劇本 × 3 種出身 × 16 個種子)。 + * 開局能力(docs/27 第 6 節):捏人物直接配這五項(總共 5 點、每項最多 2 點),加上出身、黨的資源,就是政治生涯角色卡上開局的等級; + * 捏人物的點數和出身不再暗中改開局得票和資金。 */ export type Background = (typeof BACKGROUNDS)[number]; @@ -66,20 +68,52 @@ export const MINOR_REPORTER_MULT = 0.85; const clampLevel = (n: number) => Math.max(0, Math.min(5, n)); +/** 角色能力每一級的效果(捏人物、政治生涯角色卡、圖鑑都照這份寫;規則在 rogue 的 cards.ts、rules.ts、scenes.ts) */ +export const ABILITY_EFFECTS: Record = { + eloquence: "記者會、座談類的牌每級 +4%;3 級起辯論多一張論點,5 級看得出最好的論點", + organization: "樁腳每級 +10%、地面牌每級 +3%", + media: "媒體牌每級 +5%、爆紅機率每級 +3%", + finance: "開局資金每級 +80 萬、每週收入每級 +15 萬", + integrity: "黑函損失每級 −12%、記者追問掉票每級 −15%", +}; + +/** 「平均分配」:五項各 1 點(政治生涯快速捏人物也用這組) */ +export const DEFAULT_POINTS: StartPoints = { eloquence: 1, organization: 1, media: 1, finance: 1, integrity: 1 }; + +const sumPoints = (p: StartPoints) => ABILITY_IDS.reduce((a, k) => a + p[k], 0); + /** - * 自創角色的起始能力(0–5):捏人物點數換算(0–2 級)+出身那一項 +1+黨的資源那一項 +1。 - * 點數換算:(點數 − 3) ÷ 3 四捨五入,最多 2 級;口才看口才、組織看人脈、媒體看知名度、財務看財力;清廉沒有點數,只看出身。 + * 舊版捏人物的點數(知名度、口才、謀略、財力、人脈,各 0–10)換成開局能力點: + * 照舊的換算 (點數 − 3) ÷ 3 四捨五入、最多 2(口才→口才、人脈→組織、知名度→媒體、財力→財務,謀略沒有對應), + * 再補滿或扣回 5 點:補的先給清廉(舊版不能配),再給點數最少的;扣的從點數最多的扣。 */ -export function originAbilities(c: { stats: { fame: number; eloquence: number; wealth: number; network: number }; background: Background; party: string | null }): CareerAbilities { +export function legacyPoints(stats?: { fame: number; eloquence: number; wealth: number; network: number }): StartPoints { + if (!stats) return { ...DEFAULT_POINTS }; const lv = (n: number) => Math.max(0, Math.min(2, Math.round((n - 3) / 3))); - const out: CareerAbilities = { eloquence: lv(c.stats.eloquence), organization: lv(c.stats.network), media: lv(c.stats.fame), finance: lv(c.stats.wealth), integrity: 0 }; - const origin = ORIGINS[c.background]; - if (origin) out[origin.ability] = clampLevel(out[origin.ability] + 1); - const party = PARTY_RESOURCES[partyKind(c.party)].ability; - if (party) out[party] = clampLevel(out[party] + 1); + const out: StartPoints = { eloquence: lv(stats.eloquence), organization: lv(stats.network), media: lv(stats.fame), finance: lv(stats.wealth), integrity: 0 }; + const order: AbilityId[] = ["integrity", "eloquence", "organization", "media", "finance"]; + for (let n = sumPoints(out); n > START_POINTS; n--) out[order.reduce((a, b) => (out[b] > out[a] ? b : a))] -= 1; + for (let n = sumPoints(out); n < START_POINTS; n++) out[order.reduce((a, b) => (out[b] < out[a] ? b : a))] += 1; return out; } +/** 出身、黨的資源給的等級(不能自己點;捏人物畫面上鎖住的格子) */ +export function fixedAbilities(background: Background, party: string | null): CareerAbilities { + const out: CareerAbilities = { eloquence: 0, organization: 0, media: 0, finance: 0, integrity: 0 }; + const origin = ORIGINS[background]; + if (origin) out[origin.ability] += 1; + const res = PARTY_RESOURCES[partyKind(party)].ability; + if (res) out[res] += 1; + return out; +} + +/** 自創角色的開局能力(0–5):捏人物配的點+出身那一項 +1+黨的資源那一項 +1(舊存檔沒有 points,照 legacyPoints 換算) */ +export function originAbilities(c: { points?: StartPoints; stats?: { fame: number; eloquence: number; wealth: number; network: number }; background: Background; party: string | null }): CareerAbilities { + const own = c.points ?? legacyPoints(c.stats); + const fixed = fixedAbilities(c.background, c.party); + return Object.fromEntries(ABILITY_IDS.map((k) => [k, clampLevel(own[k] + fixed[k])])) as CareerAbilities; +} + /** 「律師:口才 +1,專屬牌「法律諮詢站」」 */ export function originBonusText(background: Background): string { const o = ORIGINS[background]; diff --git a/backend/packages/protocol/test/origins.test.ts b/backend/packages/protocol/test/origins.test.ts new file mode 100644 index 0000000..ec40616 --- /dev/null +++ b/backend/packages/protocol/test/origins.test.ts @@ -0,0 +1,34 @@ +import { describe, expect, it } from "vitest"; +import { CustomCandidate, DEFAULT_POINTS, START_POINTS, fixedAbilities, legacyPoints, originAbilities } from "../src/index.ts"; + +/** docs/27 第 6 節:捏人物直接配政治生涯的五項能力 */ + +const avatar = { skin: "#eebd98", hair: "bob", hairColor: "#2f2520", outfit: "blouse", suit: "#24324a", shirt: "#f7f5f0", tie: "#b3262d", glasses: true, beard: false, bg: "#dfe8f0" }; +const base = { name: "測試人", party: null, background: "律師" as const, avatar, replace: null }; + +describe("開局能力", () => { + it("開局等級=自己配的點+出身+黨的資源", () => { + const points = { eloquence: 2, organization: 0, media: 1, finance: 2, integrity: 0 }; + expect(fixedAbilities("律師", "民主進步黨")).toEqual({ eloquence: 1, organization: 1, media: 0, finance: 0, integrity: 0 }); + expect(originAbilities({ points, background: "律師", party: "民主進步黨" })).toEqual({ eloquence: 3, organization: 1, media: 1, finance: 2, integrity: 0 }); + expect(originAbilities({ points: DEFAULT_POINTS, background: "醫師", party: null })).toEqual({ eloquence: 1, organization: 1, media: 1, finance: 1, integrity: 2 }); + }); + + it("點數超過 5 點、單項超過 2 點都不行;舊版的 stats 還收", () => { + expect(CustomCandidate.safeParse({ ...base, points: DEFAULT_POINTS }).success).toBe(true); + expect(CustomCandidate.safeParse({ ...base, points: { ...DEFAULT_POINTS, eloquence: 2 } }).success).toBe(false); + expect(CustomCandidate.safeParse({ ...base, points: { ...DEFAULT_POINTS, eloquence: 3, organization: 0 } }).success).toBe(false); + expect(CustomCandidate.safeParse({ ...base, stats: { fame: 5, eloquence: 5, strategy: 5, wealth: 5, network: 5 } }).success).toBe(true); + }); + + it("舊存檔的點數照舊的換算,補滿或扣回 5 點;謀略沒有作用", () => { + expect(legacyPoints({ fame: 5, eloquence: 5, wealth: 5, network: 5 })).toEqual(DEFAULT_POINTS); + expect(legacyPoints(undefined)).toEqual(DEFAULT_POINTS); + const fame = legacyPoints({ fame: 10, eloquence: 4, wealth: 4, network: 4 }); + expect(fame.media).toBe(2); + expect(Object.values(fame).reduce((a, b) => a + b, 0)).toBe(START_POINTS); + const maxed = legacyPoints({ fame: 8, eloquence: 8, wealth: 8, network: 1 }); + expect(Object.values(maxed).reduce((a, b) => a + b, 0)).toBe(START_POINTS); + expect(Math.max(...Object.values(maxed))).toBe(2); + }); +}); diff --git a/backend/packages/rogue/src/meta.ts b/backend/packages/rogue/src/meta.ts index 81981e9..bdbff19 100644 --- a/backend/packages/rogue/src/meta.ts +++ b/backend/packages/rogue/src/meta.ts @@ -41,15 +41,6 @@ export const ABILITY_LABELS: Record = { integrity: "清廉", }; -/** 角色能力的效果說明(畫面用) */ -export const ABILITY_EFFECTS: Record = { - eloquence: "記者會、座談類的牌每級 +4%;3 級起辯論多一張論點,5 級看得出最好的論點", - organization: "樁腳每級 +10%、地面牌每級 +3%", - media: "媒體牌每級 +5%、爆紅機率每級 +3%", - finance: "開局資金每級 +80 萬、每週收入每級 +15 萬", - integrity: "黑函損失每級 −12%、記者追問掉票每級 −15%", -}; - // ── 政策工坊 ── const TARGET: Record = { diff --git a/backend/packages/rogue/src/view.ts b/backend/packages/rogue/src/view.ts index 7089791..f95fffa 100644 --- a/backend/packages/rogue/src/view.ts +++ b/backend/packages/rogue/src/view.ts @@ -3,12 +3,12 @@ import { ADVISOR_BY_ID, ADVISORS } from "./advisors.ts"; import { ARCHETYPES } from "./archetypes.ts"; import { blockedReason, cardCost, counterable, attackable, defOf, playCard } from "./cards.ts"; import { CRISIS_CHOICES, DEBATE_MOVES, PRESS_BY_ID, STOP_EVENT_BY_ID, type Choice } from "./content.ts"; -import { ORIGINS } from "@election2026/protocol"; +import { ABILITY_EFFECTS, ORIGINS } from "@election2026/protocol"; import { ULTIMATES, suggestTowns, ultDeficit, ultMultiplier, ultReady } from "./ultimate.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 { ABILITY_LABELS, BUILDINGS, POLICY_HOME } from "./meta.ts"; import { ASCENSION, eventOf, has, momentumMax } from "./mechanics.ts"; import { RIVAL_RULES, bigRallyWeek, RIVAL_TRAITS, RIVAL_TYPES, intentDamp, intentLabel } from "./rival.ts"; import { encounterById, fillVars, MINIGAME_INFO, pickInDoor, PRICES, SKIP_MONEY, STOP_LABELS } from "./route.ts"; diff --git a/web/src/game/api.ts b/web/src/game/api.ts index 5dadba4..378fadd 100644 --- a/web/src/game/api.ts +++ b/web/src/game/api.ts @@ -91,9 +91,18 @@ export interface RogueOutlook { rematch?: boolean; } +/** 還沒重啟的舊版伺服器一定要 stats(舊版捏人物的點數);新版只看 points,這組每項 5 點對新版沒有作用 */ +const OLD_SERVER_STATS = { fame: 5, eloquence: 5, strategy: 5, wealth: 5, network: 5 }; + export const rogueApi = { create: (scenarioId: string, candidateId: string, options: RogueCreateOptions = {}) => - request("/api/rogue/runs", CreateRogueResponse, { scenarioId, candidateId, reputation: reputation(), ...options }), + request("/api/rogue/runs", CreateRogueResponse, { + scenarioId, + candidateId, + reputation: reputation(), + ...options, + ...(options.custom ? { custom: { stats: OLD_SERVER_STATS, ...options.custom } } : {}), + }), tutorial: () => request("/api/rogue/tutorial", CreateRogueResponse, {}), outlook: async (scenarioId: string, candidateId: string): Promise => { try { diff --git a/web/src/game/creator/CreatorScreen.tsx b/web/src/game/creator/CreatorScreen.tsx index 98aff10..8305868 100644 --- a/web/src/game/creator/CreatorScreen.tsx +++ b/web/src/game/creator/CreatorScreen.tsx @@ -1,3 +1,4 @@ +import { DEFAULT_POINTS, type StartPoints } from "@election2026/protocol"; import { Crown, Save, Sparkles } from "lucide-react"; import { useCallback, useEffect, useMemo, useRef, useState, type KeyboardEvent } from "react"; import { peopleApi } from "../api.ts"; @@ -6,12 +7,12 @@ import { setMusic } from "../audio/music.ts"; import { sfx } from "../audio/sfx.ts"; import { GameScene, SceneStat } from "../ui/GameScene.tsx"; import { deleteCharacter, loadCharacters, saveCharacter } from "./characters.ts"; -import { NAME_MAX, NAME_MIN, NameTab, OriginTab, StatsTab } from "./IdentityTabs.tsx"; +import { AbilitiesTab, NAME_MAX, NAME_MIN, NameTab, OriginTab } from "./IdentityTabs.tsx"; import { loadProgress } from "../rogue/progress.ts"; import { itemState } from "../shop/unlocks.ts"; import { useWardrobe } from "../shop/wardrobe.ts"; import { ExtraTab, FaceTab, GearTab, HairTab, OutfitTab, PropsTab, StyleTab, type LooksCtx } from "./LooksTabs.tsx"; -import { STAT_BUDGET, STAT_KEYS, TABS, bumpStat, originText, partyOf, randomStats, type Background, type Party, type StatKey, type TabId } from "./options.ts"; +import { ABILITY_IDS, START_POINTS, TABS, bumpPoint, originText, partyOf, randomPoints, type AbilityKey, type Background, type Party, type TabId } from "./options.ts"; import { SavedRail } from "./SavedRail.tsx"; import { Stage } from "./Stage.tsx"; import "./creator.css"; @@ -22,7 +23,7 @@ const NAME_CHECK_MS = 650; /** * 捏人物(docs/15):競選總部的更衣間。中間是站在講台後面的角色,旁邊(手機在下面)是分頁: - * 臉部、髮型、服裝、配件、行頭(帽子、背心、彩帶、胸花)、道具(手持物、外框)、畫風、名字與政黨、出身、能力點數。 + * 臉部、髮型、服裝、配件、行頭(帽子、背心、彩帶、胸花)、道具(手持物、外框)、畫風、名字與政黨、出身、開局能力(政治生涯那五項)。 * 最下面「存起來,去政治生涯」。新部位照部件目錄列(docs/24),沒拿到的灰色、寫怎麼拿到。 * 角色存在這台瀏覽器(左邊的衣櫃);名字不能和真實候選人相同(這裡先查參選人資料,開局時伺服器也會再檢查)。 */ @@ -34,7 +35,7 @@ export function CreatorScreen({ charId }: { charId: string | null }) { const [name, setNameRaw] = useState(saved?.name ?? ""); const [party, setPartyRaw] = useState(saved?.party ?? null); const [background, setBackgroundRaw] = useState(saved?.background ?? "社運出身"); - const [stats, setStats] = useState(saved?.stats ?? { fame: 5, eloquence: 5, strategy: 5, wealth: 5, network: 5 }); + const [points, setPoints] = useState(saved?.points ?? DEFAULT_POINTS); const [savedNow, setSavedNow] = useState(false); const [tab, setTab] = useState("face"); const [pulse, setPulse] = useState(0); @@ -94,15 +95,15 @@ export function CreatorScreen({ charId }: { charId: string | null }) { }; }, [trimmed, nameOk, speak]); - const used = STAT_KEYS.reduce((sum, k) => sum + stats[k], 0); - const left = STAT_BUDGET - used; + const used = ABILITY_IDS.reduce((sum, k) => sum + points[k], 0); + const left = START_POINTS - used; const valid = nameOk && !isReal && left >= 0; const problem: { text: string; tab: TabId } | null = !nameOk ? { text: "先到「名字」取個名字", tab: "name" } : isReal ? { text: "名字和真實參選人一樣,換一個", tab: "name" } : left < 0 - ? { text: "能力點數超過了,減一些", tab: "stats" } + ? { text: "開局能力點數超過了,減一些", tab: "stats" } : null; /** 每次改東西:角色彈一下,「已存好」變回「先存起來」 */ @@ -131,9 +132,9 @@ export function CreatorScreen({ charId }: { charId: string | null }) { touched(); speak(`我是${originText(b)}!`); }; - const changeStats = (next: typeof stats) => { - if (next === stats) return; - setStats(next); + const changePoints = (next: StartPoints) => { + if (next === points) return; + setPoints(next); sfx.click(); touched(); }; @@ -146,7 +147,7 @@ export function CreatorScreen({ charId }: { charId: string | null }) { }; const save = () => { - saveCharacter({ id, name: trimmed, party, background, stats, avatar }); + saveCharacter({ id, name: trimmed, party, background, points, avatar }); setList(loadCharacters()); setSavedNow(true); }; @@ -257,12 +258,14 @@ export function CreatorScreen({ charId }: { charId: string | null }) { )} {tab === "origin" && } {tab === "stats" && ( - changeStats(bumpStat(stats, k, d))} - onSetAll={(v) => changeStats(Object.fromEntries(STAT_KEYS.map((k) => [k, v])) as typeof stats)} - onRandom={() => changeStats(randomStats())} + onBump={(k: AbilityKey, d) => changePoints(bumpPoint(points, k, d))} + onSetAll={(v) => changePoints(Object.fromEntries(ABILITY_IDS.map((k) => [k, v])) as StartPoints)} + onRandom={() => changePoints(randomPoints())} /> )} diff --git a/web/src/game/creator/IdentityTabs.tsx b/web/src/game/creator/IdentityTabs.tsx index 187d0d5..52dd382 100644 --- a/web/src/game/creator/IdentityTabs.tsx +++ b/web/src/game/creator/IdentityTabs.tsx @@ -1,24 +1,13 @@ -import { PARTY_RECORDS, PARTY_RESOURCES, originBonusText, partyKind, type CustomCandidate } from "@election2026/protocol"; +import { ABILITY_EFFECTS, ABILITY_NAMES, ORIGINS, PARTY_RECORDS, PARTY_RESOURCES, fixedAbilities, originBonusText, partyKind, type StartPoints } from "@election2026/protocol"; import { Check, Minus, Plus, RotateCcw, Search, Shuffle, Trash2 } from "lucide-react"; import { useEffect, useState, type CSSProperties } from "react"; import type { AvatarSpec } from "../art/Avatar.tsx"; import { Poster } from "../art/Poster.tsx"; import { PartyFlag, hasPartyFlag } from "../PartyFlag.tsx"; import { partyFacts, searchParties } from "../parties.ts"; -import { - BACKGROUND_INFO, - BACKGROUNDS, - PARTIES, - STAT_BUDGET, - STAT_KEYS, - STAT_LABELS, - STAT_MAX, - originText, - partyOf, - type Background, - type Party, - type StatKey, -} from "./options.ts"; +import { ABILITY_LOOK } from "../rogue/CareerSheet.tsx"; +import { MAX_LEVEL } from "../rogue/careerRules.ts"; +import { ABILITY_IDS, BACKGROUND_ICON, BACKGROUNDS, PARTIES, START_POINT_MAX, START_POINTS, originText, partyOf, type AbilityKey, type Background, type Party } from "./options.ts"; import { Section } from "./Pickers.tsx"; export const NAME_MIN = 2; @@ -122,14 +111,14 @@ export function OriginTab({ background, setBackground }: { background: Backgroun
{BACKGROUNDS.map((b) => { const on = b === background; - const { note, Icon } = BACKGROUND_INFO[b]; + const Icon = BACKGROUND_ICON[b]; return (
+

+ + + + + 出身、黨給的 + + + + + + 自己配的 + + + + + + 政治生涯升等再加 + +

    - {STAT_KEYS.map((k) => { - const v = stats[k]; - const { label, note } = STAT_LABELS[k]; + {ABILITY_IDS.map((k) => { + const own = points[k]; + const lv = own + fixed[k]; + const label = ABILITY_NAMES[k]; + const { Icon, color } = ABILITY_LOOK[k]; + const from = [ORIGINS[background]?.ability === k ? background : null, res.ability === k ? res.label : null].filter((x): x is string => x !== null); return ( -
  • +
  • + + + {label} - {note} + {from.map((f) => ( + + {f} +1 + + ))} + {ABILITY_EFFECTS[k]}

    - - - {Array.from({ length: STAT_MAX }, (_, i) => ( - + + {Array.from({ length: MAX_LEVEL }, (_, i) => ( + ))} - - {v} + + Lv + {lv} +
  • ); })}
+

這五項就是政治生涯角色卡上的能力:開局等級=自己配的+出身+黨的資源,之後每升一級拿 1 點往上加,每項最多 {MAX_LEVEL} 級。出身在「出身」分頁換,政黨在「名字」分頁換。

); } diff --git a/web/src/game/creator/characters.ts b/web/src/game/creator/characters.ts index ef5faf1..6da08b9 100644 --- a/web/src/game/creator/characters.ts +++ b/web/src/game/creator/characters.ts @@ -1,19 +1,29 @@ -import { DEFAULT_AVATAR_SPEC, parseAvatarLoose, type CustomCandidate } from "@election2026/protocol"; +import { ABILITY_IDS, DEFAULT_AVATAR_SPEC, START_POINTS, StartPoints, legacyPoints, parseAvatarLoose, type CustomCandidate } from "@election2026/protocol"; /** 玩家捏好的角色存在這台瀏覽器裡(只是方便下次再用;讀不到就是空的) */ const KEY = "tongsuan.characters"; -export type SavedCharacter = Omit & { id: string }; +/** 開局能力存在 points(docs/27 第 6 節);舊存檔的 stats 讀進來就換算掉 */ +export type SavedCharacter = Omit & { id: string; points: StartPoints }; + +/** 舊存檔(捏人物還是知名度、謀略那五項的時候):stats 換成開局能力點 */ +export function withPoints(c: SavedCharacter & { stats?: CustomCandidate["stats"] }): SavedCharacter { + const { stats, ...rest } = c; + const ok = StartPoints.safeParse(c.points); + const points = ok.success && ABILITY_IDS.reduce((a, k) => a + ok.data[k], 0) <= START_POINTS ? ok.data : null; + if (points && !stats) return c; + return { ...rest, points: points ?? legacyPoints(stats) }; +} /** * 讀存檔時清洗頭像(docs/24):照部件目錄檢查,看不懂的部件代號換成預設、壞掉的欄位丟掉,存檔壞掉也不會當機。 - * 舊存檔的頭像本來就合法,原封不動。 + * 舊存檔的頭像本來就合法,原封不動;舊版的能力點數換成開局能力點。 */ function cleanCharacter(raw: unknown): SavedCharacter | null { if (!raw || typeof raw !== "object") return null; const c = raw as SavedCharacter; if (typeof c.id !== "string" || typeof c.name !== "string") return null; - return { ...c, avatar: parseAvatarLoose(c.avatar) ?? DEFAULT_AVATAR_SPEC }; + return { ...withPoints(c), avatar: parseAvatarLoose(c.avatar) ?? DEFAULT_AVATAR_SPEC }; } export function loadCharacters(): SavedCharacter[] { diff --git a/web/src/game/creator/creator.css b/web/src/game/creator/creator.css index 2f6f426..7983185 100644 --- a/web/src/game/creator/creator.css +++ b/web/src/game/creator/creator.css @@ -303,10 +303,14 @@ .cr-tool:active { transform: translate(2px, 2px); box-shadow: none; } .cr-stats { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; } .cr-stat { display: grid; gap: 6px; padding: 10px 12px; border: 3px solid var(--ink); border-radius: 14px; background: var(--surface-2); } -.cr-stat-txt { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; } +.cr-stat-txt { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; } .cr-stat-txt b { font-family: var(--font-serif); font-size: 17px; } -.cr-stat-txt small { color: var(--muted); font-size: 12px; font-weight: 600; } -.cr-stat-ctl { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px 32px; align-items: center; gap: 8px; } +.cr-stat-txt small { flex-basis: 100%; color: var(--muted); font-size: 12px; font-weight: 600; line-height: 1.4; } +.cr-ab-ic { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--ab); color: #fff; border: 2px solid var(--ink); } +.cr-ab-tag { padding: 1px 8px; border-radius: 999px; background: color-mix(in srgb, var(--ab) 20%, transparent); font-size: 11.5px; font-weight: 900; } +.cr-ab-legend { margin: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; font-weight: 700; color: var(--muted); } +.cr-ab-legend > span { display: inline-flex; align-items: center; gap: 6px; } +.cr-stat-ctl { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px 48px; align-items: center; gap: 8px; } .cr-step { width: 44px; height: 44px; display: grid; place-items: center; padding: 0; border: 3px solid var(--ink); border-radius: 12px; background: var(--surface); color: var(--ink); box-shadow: 2px 2px 0 var(--shadow-ink); @@ -315,10 +319,14 @@ .cr-step.is-plus { background: var(--signal); color: var(--signal-ink); } .cr-step:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; } .cr-step:disabled { opacity: 0.35; box-shadow: none; } -.cr-pips { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); align-items: end; gap: 3px; height: 26px; } -.cr-pips i { height: 100%; border-radius: 4px; background: color-mix(in srgb, var(--ink) 14%, transparent); transform: scaleY(0.45); transform-origin: 50% 100%; transition: transform 220ms var(--ease-out); } -.cr-pips i.is-on { background: var(--stamp); transform: none; } -.cr-stat-val { font: 900 26px/1 var(--font-num); font-variant-numeric: tabular-nums; text-align: right; } +/* 能力條:和政治生涯角色卡同一個樣子(斜的格子);斜線=出身、黨給的,實心=自己配的,虛線空格=之後升等再加 */ +.cr-pips { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; height: 24px; padding: 0 4px; } +.cr-pips i { border: 2px dashed color-mix(in srgb, var(--ink) 40%, transparent); border-radius: 5px; transform: skewX(-12deg); transition: background-color 180ms var(--ease-out); } +.cr-pips i.is-on, .cr-pips i.is-fixed { border: 2px solid var(--ink); background-color: color-mix(in srgb, var(--ab) 55%, #fff); } +.cr-pips i.is-fixed { background-image: repeating-linear-gradient(135deg, transparent 0 4px, rgb(255 255 255 / 0.6) 4px 7px); } +.cr-pips.is-key { --ab: #6b7080; display: inline-grid; grid-template-columns: 18px; height: 14px; padding: 0 2px; } +.cr-stat-val { font: 900 26px/1 var(--font-num); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; } +.cr-stat-val small { font-size: 12px; margin-right: 1px; } /* ── 下面的大按鈕 ── */ .cr-cta { grid-area: cta; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: stretch; gap: 12px; } diff --git a/web/src/game/creator/options.ts b/web/src/game/creator/options.ts index 34f367f..76c94ec 100644 --- a/web/src/game/creator/options.ts +++ b/web/src/game/creator/options.ts @@ -1,4 +1,4 @@ -import { BACKGROUNDS, STAT_BUDGET, STAT_MAX, avatarItem, slotItems, type CustomCandidate } from "@election2026/protocol"; +import { ABILITY_IDS, BACKGROUNDS, START_POINTS, START_POINT_MAX, avatarItem, slotItems, type CustomCandidate, type StartPoints } from "@election2026/protocol"; import { Briefcase, Building2, @@ -27,7 +27,7 @@ import { FEATURED_PARTIES, partyShort, partySlot } from "../parties.ts"; /** 捏人物的選項清單(docs/15)。顏色色盤在 art/palette.ts,這裡只放「選哪一種」。 */ export type Option = { id: T; label: string }; -export type StatKey = keyof CustomCandidate["stats"]; +export type AbilityKey = keyof StartPoints; export type Party = CustomCandidate["party"]; export type Background = CustomCandidate["background"]; @@ -90,31 +90,22 @@ export const partyOf = (id: Party): PartyOption => ({ /** 直接列出來的政黨:推出候選人最多的幾個+無黨籍;其他政黨到「更多政黨」搜尋(parties.ts) */ export const PARTIES: PartyOption[] = [...FEATURED_PARTIES.map(partyOf), partyOf(null)]; -export const BACKGROUND_INFO: Record = { - 醫師: { note: "口才加分,長輩較信任", Icon: Stethoscope }, - 律師: { note: "口才大幅加分", Icon: Scale }, - 教授: { note: "口才與謀略加分", Icon: GraduationCap }, - 前藝人: { note: "知名度大幅加分", Icon: Mic }, - 網紅: { note: "知名度加分,小額募款多三成", Icon: Smartphone }, - 政二代: { note: "地方組織現成,知名度加分", Icon: Landmark }, - 基層里長: { note: "地方組織強,但全市知名度較低", Icon: Home }, - 企業家: { note: "多 800 萬起始資金", Icon: Briefcase }, - 前官員: { note: "謀略加分,知名度加分", Icon: Building2 }, - 社運出身: { note: "知名度與口才小幅加分", Icon: Megaphone }, +export const BACKGROUND_ICON: Record = { + 醫師: Stethoscope, + 律師: Scale, + 教授: GraduationCap, + 前藝人: Mic, + 網紅: Smartphone, + 政二代: Landmark, + 基層里長: Home, + 企業家: Briefcase, + 前官員: Building2, + 社運出身: Megaphone, }; -export { BACKGROUNDS, STAT_BUDGET, STAT_MAX }; +export { ABILITY_IDS, BACKGROUNDS, START_POINTS, START_POINT_MAX }; /** 「醫師」→「醫師出身」;「社運出身」本身就有出身兩個字 */ export const originText = (b: Background): string => (b.endsWith("出身") ? b : `${b}出身`); -export const STAT_KEYS: StatKey[] = ["fame", "eloquence", "strategy", "wealth", "network"]; -export const STAT_LABELS: Record = { - fame: { label: "知名度", note: "開局有多少人認識你" }, - eloquence: { label: "口才", note: "上節目、記者會的效果與失言機率" }, - strategy: { label: "謀略", note: "選戰判斷、祕密行動" }, - wealth: { label: "財力", note: "起始資金與自掏腰包上限" }, - network: { label: "人脈", note: "地方組織與幕僚人數" }, -}; - export type TabId = "face" | "hair" | "outfit" | "extra" | "gear" | "props" | "style" | "name" | "origin" | "stats"; /** 外觀分頁(新部位的分頁照目錄的 slots.tab 放:gear 行頭、props 道具、extra 配件的口罩) */ export const TABS: { id: TabId; label: string; title: string; Icon: LucideIcon }[] = [ @@ -127,27 +118,25 @@ export const TABS: { id: TabId; label: string; title: string; Icon: LucideIcon } { id: "style", label: "畫風", title: "漫畫、Q 版、像素、貼紙", Icon: Palette }, { id: "name", label: "名字", title: "名字、政黨", Icon: IdCard }, { id: "origin", label: "出身", title: "出身會影響開局", Icon: UserRound }, - { id: "stats", label: "能力", title: `${STAT_BUDGET} 點自由分配`, Icon: Sparkles }, + { id: "stats", label: "能力", title: `開局能力:${START_POINTS} 點自由分配`, Icon: Sparkles }, ]; -/** 能力加減一點:每項 0–STAT_MAX,總和不超過 STAT_BUDGET(超過時只能減) */ -export function bumpStat(stats: CustomCandidate["stats"], key: StatKey, delta: 1 | -1): CustomCandidate["stats"] { - const used = STAT_KEYS.reduce((sum, k) => sum + stats[k], 0); - const next = stats[key] + delta; - if (next < 0 || next > STAT_MAX) return stats; - if (delta > 0 && used >= STAT_BUDGET) return stats; - return { ...stats, [key]: next }; +/** 開局能力加減一點:每項 0–START_POINT_MAX,總和不超過 START_POINTS(超過時只能減) */ +export function bumpPoint(points: StartPoints, key: AbilityKey, delta: 1 | -1): StartPoints { + const used = ABILITY_IDS.reduce((sum, k) => sum + points[k], 0); + const next = points[key] + delta; + if (next < 0 || next > START_POINT_MAX) return points; + if (delta > 0 && used >= START_POINTS) return points; + return { ...points, [key]: next }; } /** 隨機把點數分完(每項不超過上限) */ -export function randomStats(rand: () => number = Math.random): CustomCandidate["stats"] { - const stats = { fame: 0, eloquence: 0, strategy: 0, wealth: 0, network: 0 }; - for (let left = STAT_BUDGET; left > 0; ) { - const open = STAT_KEYS.filter((k) => stats[k] < STAT_MAX); +export function randomPoints(rand: () => number = Math.random): StartPoints { + const points: StartPoints = { eloquence: 0, organization: 0, media: 0, finance: 0, integrity: 0 }; + for (let left = START_POINTS; left > 0; left -= 1) { + const open = ABILITY_IDS.filter((k) => points[k] < START_POINT_MAX); if (open.length === 0) break; - const k = open[Math.floor(rand() * open.length)]!; - stats[k] += 1; - left -= 1; + points[open[Math.floor(rand() * open.length)]!] += 1; } - return stats; + return points; } diff --git a/web/src/game/rogue/CareerSetup.tsx b/web/src/game/rogue/CareerSetup.tsx index 583f079..e448c6d 100644 --- a/web/src/game/rogue/CareerSetup.tsx +++ b/web/src/game/rogue/CareerSetup.tsx @@ -1,4 +1,4 @@ -import { BACKGROUNDS, PARTY_RECORDS, STAT_BUDGET, type CustomCandidate } from "@election2026/protocol"; +import { BACKGROUNDS, DEFAULT_POINTS, PARTY_RECORDS, type CustomCandidate } from "@election2026/protocol"; import { ArrowLeft, ArrowRight, Check, Dices, Home, Landmark, Play, Shirt, UserPlus, X } from "lucide-react"; import { useEffect, useMemo, useState } from "react"; import { peopleApi } from "../api.ts"; @@ -40,20 +40,13 @@ function QuickCharacter({ onDone, onCancel }: { onDone: (c: SavedCharacter) => v }; }, [trimmed, valid]); const isReal = realHit === trimmed; - const per = Math.floor(STAT_BUDGET / 5); const create = () => { const c: SavedCharacter = { id: `c-${Date.now()}`, name: trimmed, party, background, - stats: { - fame: per, - eloquence: per, - strategy: per, - wealth: per, - network: per, - }, + points: { ...DEFAULT_POINTS }, avatar, }; saveCharacter(c); diff --git a/web/src/game/rogue/CareerSheet.tsx b/web/src/game/rogue/CareerSheet.tsx index b6ec126..c661d2d 100644 --- a/web/src/game/rogue/CareerSheet.tsx +++ b/web/src/game/rogue/CareerSheet.tsx @@ -5,8 +5,8 @@ import { partyColor } from "../parties.ts"; import type { Ability } from "../career/term/types.ts"; import { ABILITY_IDS, ABILITY_LABELS, MAX_LEVEL, toNext, type CareerState } from "./careerRules.ts"; -/** 五項能力的圖示與顏色(和標題畫面選單同一組顏色) */ -const ABILITY_LOOK: Record = { +/** 五項能力的圖示與顏色(和標題畫面選單同一組顏色;捏人物的「能力」分頁也用這組) */ +export const ABILITY_LOOK: Record = { eloquence: { Icon: Megaphone, color: "#d61f2c" }, organization: { Icon: Users, color: "#1f8a4c" }, media: { Icon: Tv, color: "#2f6fd1" }, @@ -99,7 +99,7 @@ export function CareerSheet({
{ABILITY_LABELS[id]} - + {Array.from({ length: MAX_LEVEL }, (_, i) => ( ))} @@ -114,6 +114,20 @@ export function CareerSheet({ ); })} +

+ + + + + 開局(捏人物配的+出身+黨) + + + + + + 升等加的 + +