捏人物的開局能力改成政治生涯那五項
捏人物原本配的是舊模式留下的知名度、口才、謀略、財力、人脈,和政治生涯升等的口才、組織、媒體、財務、清廉對不上:謀略沒作用、清廉配不到,知名度、財力和出身還暗中改開局得票和資金。 - 捏人物直接配五項能力:總共 5 點、每項最多 2 點,出身和黨的 +1 用鎖住的格子標出來,升等再加到 5 級 - 政治生涯角色卡加圖例,分開局和升等加的 - 拿掉藏起來的效果:同一個政黨不同出身,開局得票一樣;勝率變化在雜訊內 - 舊存檔自動換算,升等加的點保留;前端多送舊格式,舊伺服器也收得下 - 說明在 docs/27 第 6 節 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha3X8mHVJgT7svdEw9F
This commit is contained in:
parent
2b0fd1ab33
commit
ada398fded
|
|
@ -164,12 +164,23 @@ describe.skipIf(!built)("API", () => {
|
||||||
name: "林小桃",
|
name: "林小桃",
|
||||||
party: null,
|
party: null,
|
||||||
background: "網紅",
|
background: "網紅",
|
||||||
stats: { fame: 6, eloquence: 5, strategy: 4, wealth: 5, network: 5 },
|
points: { eloquence: 2, organization: 0, media: 1, finance: 2, integrity: 0 },
|
||||||
avatar,
|
avatar,
|
||||||
replace: null,
|
replace: null,
|
||||||
...over,
|
...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 () => {
|
it("政治生涯:自創角色以新候選人加入,或取代同黨的候選人;帶過來的幕僚和牌", async () => {
|
||||||
const add = await createRun({ scenarioId: "local2022-10018", candidateId: "custom", custom: custom(), even: true, career: { stage: 2 } });
|
const add = await createRun({ scenarioId: "local2022-10018", candidateId: "custom", custom: custom(), even: true, career: { stage: 2 } });
|
||||||
expect(add.statusCode).toBe(201);
|
expect(add.statusCode).toBe(201);
|
||||||
|
|
@ -224,7 +235,7 @@ describe.skipIf(!built)("API", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("政治生涯:點數超過上限、用真實人物的名字、帶狀態牌都會被拒絕", async () => {
|
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: "蔣萬安" }) });
|
const res = await createRun({ scenarioId: scenario.id, candidateId: "custom", custom: custom({ name: "蔣萬安" }) });
|
||||||
expect(res.statusCode).toBe(400);
|
expect(res.statusCode).toBe(400);
|
||||||
expect(res.json().error).toContain("真實人物");
|
expect(res.json().error).toContain("真實人物");
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import { readFile } from "node:fs/promises";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { parseArgs } from "node:util";
|
import { parseArgs } from "node:util";
|
||||||
import { CUSTOM_ID, withCustomCandidate } from "@election2026/content";
|
import { CUSTOM_ID, withCustomCandidate } from "@election2026/content";
|
||||||
|
import { DEFAULT_POINTS } from "@election2026/protocol";
|
||||||
import { DEFAULT_PACKS_ROOT } from "@election2026/pack-loader";
|
import { DEFAULT_PACKS_ROOT } from "@election2026/pack-loader";
|
||||||
import { runBot, type BotName } from "@election2026/rogue";
|
import { runBot, type BotName } from "@election2026/rogue";
|
||||||
import { COUNCIL_WEEKS, VILLAGE_WEEKS, councilSetup, districtOfVillage, villageSetup, type CouncilDistrict } from "@election2026/rogue/local";
|
import { COUNCIL_WEEKS, VILLAGE_WEEKS, councilSetup, districtOfVillage, villageSetup, type CouncilDistrict } from "@election2026/rogue/local";
|
||||||
|
|
@ -31,7 +32,7 @@ async function main(): Promise<void> {
|
||||||
const base = await loadWorld(id);
|
const base = await loadWorld(id);
|
||||||
const topology = JSON.parse(await readFile(join(DEFAULT_PACKS_ROOT, base.scenario.packId, "topology.json"), "utf-8")) as TopologyLike;
|
const topology = JSON.parse(await readFile(join(DEFAULT_PACKS_ROOT, base.scenario.packId, "topology.json"), "utf-8")) as TopologyLike;
|
||||||
for (const party of PARTIES) {
|
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 world = { ...base, scenario };
|
||||||
const empty = (): Partial<Record<BotName, number[]>> => Object.fromEntries(BOTS.map((b) => [b, []]));
|
const empty = (): Partial<Record<BotName, number[]>> => Object.fromEntries(BOTS.map((b) => [b, []]));
|
||||||
const results: Record<string, Partial<Record<BotName, number[]>>> = { 里長: empty(), 議員: empty() };
|
const results: Record<string, Partial<Record<BotName, number[]>>> = { 里長: empty(), 議員: empty() };
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
import { parseArgs } from "node:util";
|
import { parseArgs } from "node:util";
|
||||||
import { CUSTOM_ID, withCustomCandidate } from "@election2026/content";
|
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 { runBot, type BotName } from "@election2026/rogue";
|
||||||
import { buildSetup } from "@election2026/rogue/setup";
|
import { buildSetup } from "@election2026/rogue/setup";
|
||||||
import { loadWorld } from "./world.ts";
|
import { loadWorld } from "./world.ts";
|
||||||
|
|
@ -17,7 +17,7 @@ const PARTIES = ["民主進步黨", "台灣民眾黨", "時代力量", null] as
|
||||||
const BACKGROUNDS: Background[] = ["律師", "基層里長", "網紅"];
|
const BACKGROUNDS: Background[] = ["律師", "基層里長", "網紅"];
|
||||||
const BOTS: BotName[] = ["casual", "greedy"];
|
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 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):輪流加在口才、組織、媒體 */
|
/** 政治生涯升級拿到的技能點(POINTS=4 約等於立委關的 Lv 5):輪流加在口才、組織、媒體 */
|
||||||
function withPoints(a: ReturnType<typeof originAbilities>, n: number): ReturnType<typeof originAbilities> {
|
function withPoints(a: ReturnType<typeof originAbilities>, n: number): ReturnType<typeof originAbilities> {
|
||||||
|
|
@ -41,7 +41,7 @@ async function main(): Promise<void> {
|
||||||
const same = party ? base.scenario.candidates.find((c) => c.party === party) : undefined;
|
const same = party ? base.scenario.candidates.find((c) => c.party === party) : undefined;
|
||||||
const won: Partial<Record<BotName, number[]>> = { casual: [], greedy: [] } as Partial<Record<BotName, number[]>>;
|
const won: Partial<Record<BotName, number[]>> = { casual: [], greedy: [] } as Partial<Record<BotName, number[]>>;
|
||||||
for (const background of BACKGROUNDS) {
|
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()) };
|
const world = { ...base, scenario: withCustomCandidate(base.scenario, custom, new Set()) };
|
||||||
// REAL=1:政治生涯的條件(照真實底盤、最多落後 15 點,有大絕招)
|
// REAL=1:政治生涯的條件(照真實底盤、最多落後 15 點,有大絕招)
|
||||||
const setup = buildSetup(world, CUSTOM_ID, process.env.REAL ? { even: false, maxGap: Number(process.env.GAP ?? 0.15) } : { even: true });
|
const setup = buildSetup(world, CUSTOM_ID, process.env.REAL ? { even: false, maxGap: Number(process.env.GAP ?? 0.15) } : { even: true });
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
import { parseArgs } from "node:util";
|
import { parseArgs } from "node:util";
|
||||||
import { CUSTOM_ID, withCustomCandidate } from "@election2026/content";
|
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 { runBot, type BotName, type RogueSetup } from "@election2026/rogue";
|
||||||
import { buildSetup } from "@election2026/rogue/setup";
|
import { buildSetup } from "@election2026/rogue/setup";
|
||||||
import { loadWorld } from "./world.ts";
|
import { loadWorld } from "./world.ts";
|
||||||
|
|
@ -43,7 +43,7 @@ async function main(): Promise<void> {
|
||||||
for (const base of worlds) {
|
for (const base of worlds) {
|
||||||
const party = "民主進步黨";
|
const party = "民主進步黨";
|
||||||
const same = base.scenario.candidates.find((c) => c.party === 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 world = { ...base, scenario: withCustomCandidate(base.scenario, custom, new Set()) };
|
||||||
const setup = withGap(buildSetup(world, CUSTOM_ID, { even: true }), gap);
|
const setup = withGap(buildSetup(world, CUSTOM_ID, { even: true }), gap);
|
||||||
const origin = { background: custom.background, party, kind: partyKind(party) };
|
const origin = { background: custom.background, party, kind: partyKind(party) };
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
import { parseArgs } from "node:util";
|
import { parseArgs } from "node:util";
|
||||||
import { CUSTOM_ID, withCustomCandidate } from "@election2026/content";
|
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 { runBot, type BotName } from "@election2026/rogue";
|
||||||
import { VILLAGE_WEEKS, villageSetup } from "@election2026/rogue/local";
|
import { VILLAGE_WEEKS, villageSetup } from "@election2026/rogue/local";
|
||||||
import { loadWorld } from "./world.ts";
|
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 PARTIES = ["民主進步黨", "中國國民黨", null] as const;
|
||||||
const BOTS: BotName[] = ["idle", "casual", "greedy"];
|
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 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 mean = (xs: number[]) => xs.reduce((a, b) => a + b, 0) / (xs.length || 1);
|
||||||
const pct = (x: number) => `${(x * 100).toFixed(0)}%`;
|
const pct = (x: number) => `${(x * 100).toFixed(0)}%`;
|
||||||
|
|
@ -27,7 +27,7 @@ async function main(): Promise<void> {
|
||||||
for (const id of COUNTIES) {
|
for (const id of COUNTIES) {
|
||||||
const base = await loadWorld(id);
|
const base = await loadWorld(id);
|
||||||
for (const party of PARTIES) {
|
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 world = { ...base, scenario: withCustomCandidate(base.scenario, custom, new Set()) };
|
||||||
const won: Partial<Record<BotName, number[]>> = { idle: [], casual: [], greedy: [] } as Partial<Record<BotName, number[]>>;
|
const won: Partial<Record<BotName, number[]>> = { idle: [], casual: [], greedy: [] } as Partial<Record<BotName, number[]>>;
|
||||||
const margins: number[] = [];
|
const margins: number[] = [];
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ web/src/game/rogue/Career.tsx(進度 tongsuan.rogue.career.v3;v1、v2 的進
|
||||||
- 立委:講解法條(拼條文、選白話說明讓過半委員接受)+質詢+搶主席台(鬧劇版,沒有人受傷;黨團只寫我方/對方)
|
- 立委:講解法條(拼條文、選白話說明讓過半委員接受)+質詢+搶主席台(鬧劇版,沒有人受傷;黨團只寫我方/對方)
|
||||||
- 縣市長:分配預算(四個虛構分區的滿意度)+颱風救災
|
- 縣市長:分配預算(四個虛構分區的滿意度)+颱風救災
|
||||||
- 任期結果:五項能力經驗(每 4 點升一級,最高 5 級)、政績點、下一場開局聲勢 0–2、資金 0–300 萬,以及虛構的任期回顧標題。可以跳過任期(沒有加成)。
|
- 任期結果:五項能力經驗(每 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)
|
### 練等(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、開局一張「黨部動員掃街」;包袱是第 3 或第 4 週的「黨中央風波」(手上一張,那週沒回應全市掉票,週末就消失)。
|
||||||
- 民眾黨:資金中等、媒體 +1。
|
- 民眾黨:資金中等、媒體 +1。
|
||||||
- 其他政黨、無黨籍:資金少;開局得票多 0.2 個百分點、記者追問掉的票少一成五,政治生涯經驗 ×1.2。
|
- 其他政黨、無黨籍:資金少;開局得票多 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%。
|
- 平衡(apps/sim/src/party-balance.ts,2026-10-27):勢均力敵開局、逆風 2,打得好的玩家大黨 98%、民眾黨 96%、小黨與無黨籍 98%;隨手玩 23%/32%/35%。
|
||||||
- 畫面:捏人物的「出身」格子寫加成、「政黨」下面寫黨的資源與代價;政治生涯角色卡也列出來。
|
- 畫面:捏人物的「出身」格子寫加成、「政黨」下面寫黨的資源與代價;政治生涯角色卡也列出來。
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# 27 選戰卡牌第五版:趕場、政見支票,與資源瘦身
|
# 27 選戰卡牌第五版:趕場、政見支票,與資源瘦身
|
||||||
|
|
||||||
> 2026-10-30。使用者要求:「研究一下目前的遊戲機制,網路上好玩的桌遊機制,引人入勝,然後針對資源來說,前後端量都要再小一點,載入速度更快一點。」
|
> 2026-10-30。使用者要求:「研究一下目前的遊戲機制,網路上好玩的桌遊機制,引人入勝,然後針對資源來說,前後端量都要再小一點,載入速度更快一點。」
|
||||||
> 本文件記錄:資源怎麼量、改了什麼、改完多快;桌遊機制研究;新增的兩個機制(趕場、政見支票)與平衡量測。
|
> 本文件記錄:資源怎麼量、改了什麼、改完多快;桌遊機制研究;新增的兩個機制(趕場、政見支票)與平衡量測;開局能力和升等改成同一套(第 6 節)。
|
||||||
|
|
||||||
## 1. 資源與載入速度
|
## 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. 之後可以做
|
## 5. 之後可以做
|
||||||
|
|
||||||
- 第 2 節排名 3–7 的機制;負面選戰溫度計最便宜,可以順便補強攻防流派。
|
- 第 2 節排名 3–7 的機制;負面選戰溫度計最便宜,可以順便補強攻防流派。
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { cleanAvatar, type CustomCandidate, type PartySlotKey } from "@election2
|
||||||
/**
|
/**
|
||||||
* 把玩家的自創角色放進劇本(docs/04、docs/15)。
|
* 把玩家的自創角色放進劇本(docs/04、docs/15)。
|
||||||
* 取代某位候選人時沿用他的號次與「個人魅力」校準值(代表那個位置的基本盤);
|
* 取代某位候選人時沿用他的號次與「個人魅力」校準值(代表那個位置的基本盤);
|
||||||
* 以新候選人加入時,從一般小黨候選人的水準起步,再看知名度點數。
|
* 以新候選人加入時,從一般小黨候選人的水準起步。
|
||||||
* 頭像照部件目錄清洗(docs/24):看不懂的部件代號換成預設值,不擋開局。
|
* 頭像照部件目錄清洗(docs/24):看不懂的部件代號換成預設值,不擋開局。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -12,19 +12,12 @@ export const CUSTOM_ID = "custom";
|
||||||
|
|
||||||
const SLOT: Record<string, PartySlotKey> = { 民主進步黨: "a", 中國國民黨: "b", 台灣民眾黨: "c" };
|
const SLOT: Record<string, PartySlotKey> = { 民主進步黨: "a", 中國國民黨: "b", 台灣民眾黨: "c" };
|
||||||
|
|
||||||
/** 出身的加成(設計文件 04 的出身表,數值是遊戲設定) */
|
/**
|
||||||
const BACKGROUND: Record<CustomCandidate["background"], Partial<{ awareness: number; eloquence: number; strategy: number; money: number; machine: number; fundraising: number }>> = {
|
* 選戰卡牌只看五項能力(protocol/origins.ts:捏人物配的點+出身+黨的資源,docs/27 第 6 節)。
|
||||||
醫師: { eloquence: 6, awareness: 0.03 },
|
* 引擎這邊的知名度、口才、資金、組織固定用舊版捏人物每項 5 點的數值(平衡模擬一直用這組),
|
||||||
律師: { eloquence: 10 },
|
* 只依政黨分大黨、民眾黨、其他;捏人物的點數和出身不再暗中改開局得票和資金。
|
||||||
教授: { eloquence: 6, strategy: 4 },
|
*/
|
||||||
前藝人: { awareness: 0.12 },
|
const STAT_POINTS = 5;
|
||||||
網紅: { 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 },
|
|
||||||
};
|
|
||||||
|
|
||||||
export class CustomCandidateError extends Error {}
|
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 slot = (custom.party && SLOT[custom.party]) || "other";
|
||||||
const major = slot === "a" || slot === "b";
|
const major = slot === "a" || slot === "b";
|
||||||
const bonus = BACKGROUND[custom.background];
|
const n = STAT_POINTS;
|
||||||
const { fame, eloquence, strategy, wealth, network } = custom.stats;
|
|
||||||
const others = scenario.candidates.filter((c) => c.id !== replaced?.id);
|
const others = scenario.candidates.filter((c) => c.id !== replaced?.id);
|
||||||
const minorAppeals = others.map((c) => c.appeal ?? 0).sort((a, b) => a - b);
|
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 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) + wealth * 2_000_000 + (bonus.money ?? 0);
|
const startingMoney = (major ? 12_000_000 : slot === "c" ? 5_000_000 : 2_000_000) + n * 2_000_000;
|
||||||
const candidate: ScenarioCandidate = {
|
const candidate: ScenarioCandidate = {
|
||||||
id: CUSTOM_ID,
|
id: CUSTOM_ID,
|
||||||
name,
|
name,
|
||||||
|
|
@ -50,15 +42,15 @@ export function withCustomCandidate(scenario: Scenario, custom: CustomCandidate,
|
||||||
slot,
|
slot,
|
||||||
number: replaced?.number ?? Math.max(...scenario.candidates.map((c) => c.number)) + 1,
|
number: replaced?.number ?? Math.max(...scenario.candidates.map((c) => c.number)) + 1,
|
||||||
description: `${custom.background}出身,${custom.party ? `${custom.party}提名` : "無黨籍參選"}。(自創角色)`,
|
description: `${custom.background}出身,${custom.party ? `${custom.party}提名` : "無黨籍參選"}。(自創角色)`,
|
||||||
awareness: Math.min(0.85, Math.max(0.15, 0.25 + fame * 0.04 + (bonus.awareness ?? 0))),
|
awareness: 0.25 + n * 0.04,
|
||||||
eloquence: Math.min(100, 30 + eloquence * 6 + (bonus.eloquence ?? 0)),
|
eloquence: 30 + n * 6,
|
||||||
strategy: Math.min(100, 30 + strategy * 6 + (bonus.strategy ?? 0)),
|
strategy: 30 + n * 6,
|
||||||
startingMoney,
|
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,
|
realFinance: null,
|
||||||
wealth: 2_000_000 + wealth * 2_000_000,
|
wealth: 2_000_000 + n * 2_000_000,
|
||||||
machine: Math.min(0.9, 0.05 + network * 0.03 + (major ? 0.15 : 0) + (bonus.machine ?? 0)),
|
machine: 0.05 + n * 0.03 + (major ? 0.15 : 0),
|
||||||
staff: Math.min(6, 2 + Math.floor(network / 3) + (major ? 1 : 0)),
|
staff: 2 + Math.floor(n / 3) + (major ? 1 : 0),
|
||||||
appeal: replaced?.appeal ?? newcomerAppeal,
|
appeal: replaced?.appeal ?? newcomerAppeal,
|
||||||
aiStyle: "balanced",
|
aiStyle: "balanced",
|
||||||
avatar: cleanAvatar(custom.avatar).spec,
|
avatar: cleanAvatar(custom.avatar).spec,
|
||||||
|
|
|
||||||
|
|
@ -469,8 +469,19 @@ export type ScenarioListItem = z.infer<typeof ScenarioListItem>;
|
||||||
|
|
||||||
/** 自創角色的出身(docs/04) */
|
/** 自創角色的出身(docs/04) */
|
||||||
export const BACKGROUNDS = ["醫師", "律師", "教授", "前藝人", "網紅", "政二代", "基層里長", "企業家", "前官員", "社運出身"] as const;
|
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<typeof StartPoints>;
|
||||||
|
|
||||||
|
/** 舊版捏人物的點數(知名度、口才、謀略、財力、人脈,各 0–10、總共 25 點):舊存檔、還沒更新的畫面會送,換算見 origins.ts 的 legacyPoints */
|
||||||
export const STATS = ["fame", "eloquence", "strategy", "wealth", "network"] as const;
|
export const STATS = ["fame", "eloquence", "strategy", "wealth", "network"] as const;
|
||||||
/** 能力點數:五項各 0–10,總共 25 點 */
|
|
||||||
export const STAT_BUDGET = 25;
|
export const STAT_BUDGET = 25;
|
||||||
export const STAT_MAX = 10;
|
export const STAT_MAX = 10;
|
||||||
|
|
||||||
|
|
@ -483,12 +494,14 @@ export const CustomCandidate = z
|
||||||
.refine((p) => PARTY_SET.has(p), { message: "不是台灣歷屆選舉出現過的政黨" })
|
.refine((p) => PARTY_SET.has(p), { message: "不是台灣歷屆選舉出現過的政黨" })
|
||||||
.nullable(),
|
.nullable(),
|
||||||
background: z.enum(BACKGROUNDS),
|
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,
|
avatar: AvatarSpecSchema,
|
||||||
/** 取代劇本裡的某位候選人(沿用號次);null 表示以新候選人加入 */
|
/** 取代劇本裡的某位候選人(沿用號次);null 表示以新候選人加入 */
|
||||||
replace: z.string().nullable(),
|
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<typeof CustomCandidate>;
|
export type CustomCandidate = z.infer<typeof CustomCandidate>;
|
||||||
|
|
||||||
export const CreateMatchRequest = z.object({
|
export const CreateMatchRequest = z.object({
|
||||||
|
|
|
||||||
|
|
@ -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";
|
import type { CareerAbilities } from "./rogue.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -8,6 +8,8 @@ import type { CareerAbilities } from "./rogue.ts";
|
||||||
* 民眾黨媒體 +1;其他政黨和無黨籍資源少,但形象清新(開局得票略多、記者追問掉的票少),政治生涯經驗 ×1.2。
|
* 民眾黨媒體 +1;其他政黨和無黨籍資源少,但形象清新(開局得票略多、記者追問掉的票少),政治生涯經驗 ×1.2。
|
||||||
* 只套在自創角色上(真實候選人照真實的資源)。數字是遊戲設定,用 apps/sim/src/party-balance.ts 模擬調過:
|
* 只套在自創角色上(真實候選人照真實的資源)。數字是遊戲設定,用 apps/sim/src/party-balance.ts 模擬調過:
|
||||||
* 打得好的玩家各黨勝率 96–98%,隨手玩 23–35%(2026-10-27,4 個劇本 × 3 種出身 × 16 個種子)。
|
* 打得好的玩家各黨勝率 96–98%,隨手玩 23–35%(2026-10-27,4 個劇本 × 3 種出身 × 16 個種子)。
|
||||||
|
* 開局能力(docs/27 第 6 節):捏人物直接配這五項(總共 5 點、每項最多 2 點),加上出身、黨的資源,就是政治生涯角色卡上開局的等級;
|
||||||
|
* 捏人物的點數和出身不再暗中改開局得票和資金。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type Background = (typeof BACKGROUNDS)[number];
|
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));
|
const clampLevel = (n: number) => Math.max(0, Math.min(5, n));
|
||||||
|
|
||||||
|
/** 角色能力每一級的效果(捏人物、政治生涯角色卡、圖鑑都照這份寫;規則在 rogue 的 cards.ts、rules.ts、scenes.ts) */
|
||||||
|
export const ABILITY_EFFECTS: Record<AbilityId, string> = {
|
||||||
|
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。
|
* 舊版捏人物的點數(知名度、口才、謀略、財力、人脈,各 0–10)換成開局能力點:
|
||||||
* 點數換算:(點數 − 3) ÷ 3 四捨五入,最多 2 級;口才看口才、組織看人脈、媒體看知名度、財務看財力;清廉沒有點數,只看出身。
|
* 照舊的換算 (點數 − 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 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 out: StartPoints = { eloquence: lv(stats.eloquence), organization: lv(stats.network), media: lv(stats.fame), finance: lv(stats.wealth), integrity: 0 };
|
||||||
const origin = ORIGINS[c.background];
|
const order: AbilityId[] = ["integrity", "eloquence", "organization", "media", "finance"];
|
||||||
if (origin) out[origin.ability] = clampLevel(out[origin.ability] + 1);
|
for (let n = sumPoints(out); n > START_POINTS; n--) out[order.reduce((a, b) => (out[b] > out[a] ? b : a))] -= 1;
|
||||||
const party = PARTY_RESOURCES[partyKind(c.party)].ability;
|
for (let n = sumPoints(out); n < START_POINTS; n++) out[order.reduce((a, b) => (out[b] < out[a] ? b : a))] += 1;
|
||||||
if (party) out[party] = clampLevel(out[party] + 1);
|
|
||||||
return out;
|
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,專屬牌「法律諮詢站」」 */
|
/** 「律師:口才 +1,專屬牌「法律諮詢站」」 */
|
||||||
export function originBonusText(background: Background): string {
|
export function originBonusText(background: Background): string {
|
||||||
const o = ORIGINS[background];
|
const o = ORIGINS[background];
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -41,15 +41,6 @@ export const ABILITY_LABELS: Record<keyof CareerAbilities, string> = {
|
||||||
integrity: "清廉",
|
integrity: "清廉",
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 角色能力的效果說明(畫面用) */
|
|
||||||
export const ABILITY_EFFECTS: Record<keyof CareerAbilities, string> = {
|
|
||||||
eloquence: "記者會、座談類的牌每級 +4%;3 級起辯論多一張論點,5 級看得出最好的論點",
|
|
||||||
organization: "樁腳每級 +10%、地面牌每級 +3%",
|
|
||||||
media: "媒體牌每級 +5%、爆紅機率每級 +3%",
|
|
||||||
finance: "開局資金每級 +80 萬、每週收入每級 +15 萬",
|
|
||||||
integrity: "黑函損失每級 −12%、記者追問掉票每級 −15%",
|
|
||||||
};
|
|
||||||
|
|
||||||
// ── 政策工坊 ──
|
// ── 政策工坊 ──
|
||||||
|
|
||||||
const TARGET: Record<PolicySpec["target"], { trait: RogueTrait; label: string }> = {
|
const TARGET: Record<PolicySpec["target"], { trait: RogueTrait; label: string }> = {
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@ import { ADVISOR_BY_ID, ADVISORS } from "./advisors.ts";
|
||||||
import { ARCHETYPES } from "./archetypes.ts";
|
import { ARCHETYPES } from "./archetypes.ts";
|
||||||
import { blockedReason, cardCost, counterable, attackable, defOf, playCard } from "./cards.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 { 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 { 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 { 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 { FEATS } from "./feats.ts";
|
||||||
import { UNLOCKS } from "./unlocks.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 { ASCENSION, eventOf, has, momentumMax } from "./mechanics.ts";
|
||||||
import { RIVAL_RULES, bigRallyWeek, RIVAL_TRAITS, RIVAL_TYPES, intentDamp, intentLabel } from "./rival.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";
|
import { encounterById, fillVars, MINIGAME_INFO, pickInDoor, PRICES, SKIP_MONEY, STOP_LABELS } from "./route.ts";
|
||||||
|
|
|
||||||
|
|
@ -91,9 +91,18 @@ export interface RogueOutlook {
|
||||||
rematch?: boolean;
|
rematch?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 還沒重啟的舊版伺服器一定要 stats(舊版捏人物的點數);新版只看 points,這組每項 5 點對新版沒有作用 */
|
||||||
|
const OLD_SERVER_STATS = { fame: 5, eloquence: 5, strategy: 5, wealth: 5, network: 5 };
|
||||||
|
|
||||||
export const rogueApi = {
|
export const rogueApi = {
|
||||||
create: (scenarioId: string, candidateId: string, options: RogueCreateOptions = {}) =>
|
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, {}),
|
tutorial: () => request("/api/rogue/tutorial", CreateRogueResponse, {}),
|
||||||
outlook: async (scenarioId: string, candidateId: string): Promise<RogueOutlook> => {
|
outlook: async (scenarioId: string, candidateId: string): Promise<RogueOutlook> => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { DEFAULT_POINTS, type StartPoints } from "@election2026/protocol";
|
||||||
import { Crown, Save, Sparkles } from "lucide-react";
|
import { Crown, Save, Sparkles } from "lucide-react";
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState, type KeyboardEvent } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState, type KeyboardEvent } from "react";
|
||||||
import { peopleApi } from "../api.ts";
|
import { peopleApi } from "../api.ts";
|
||||||
|
|
@ -6,12 +7,12 @@ import { setMusic } from "../audio/music.ts";
|
||||||
import { sfx } from "../audio/sfx.ts";
|
import { sfx } from "../audio/sfx.ts";
|
||||||
import { GameScene, SceneStat } from "../ui/GameScene.tsx";
|
import { GameScene, SceneStat } from "../ui/GameScene.tsx";
|
||||||
import { deleteCharacter, loadCharacters, saveCharacter } from "./characters.ts";
|
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 { loadProgress } from "../rogue/progress.ts";
|
||||||
import { itemState } from "../shop/unlocks.ts";
|
import { itemState } from "../shop/unlocks.ts";
|
||||||
import { useWardrobe } from "../shop/wardrobe.ts";
|
import { useWardrobe } from "../shop/wardrobe.ts";
|
||||||
import { ExtraTab, FaceTab, GearTab, HairTab, OutfitTab, PropsTab, StyleTab, type LooksCtx } from "./LooksTabs.tsx";
|
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 { SavedRail } from "./SavedRail.tsx";
|
||||||
import { Stage } from "./Stage.tsx";
|
import { Stage } from "./Stage.tsx";
|
||||||
import "./creator.css";
|
import "./creator.css";
|
||||||
|
|
@ -22,7 +23,7 @@ const NAME_CHECK_MS = 650;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 捏人物(docs/15):競選總部的更衣間。中間是站在講台後面的角色,旁邊(手機在下面)是分頁:
|
* 捏人物(docs/15):競選總部的更衣間。中間是站在講台後面的角色,旁邊(手機在下面)是分頁:
|
||||||
* 臉部、髮型、服裝、配件、行頭(帽子、背心、彩帶、胸花)、道具(手持物、外框)、畫風、名字與政黨、出身、能力點數。
|
* 臉部、髮型、服裝、配件、行頭(帽子、背心、彩帶、胸花)、道具(手持物、外框)、畫風、名字與政黨、出身、開局能力(政治生涯那五項)。
|
||||||
* 最下面「存起來,去政治生涯」。新部位照部件目錄列(docs/24),沒拿到的灰色、寫怎麼拿到。
|
* 最下面「存起來,去政治生涯」。新部位照部件目錄列(docs/24),沒拿到的灰色、寫怎麼拿到。
|
||||||
* 角色存在這台瀏覽器(左邊的衣櫃);名字不能和真實候選人相同(這裡先查參選人資料,開局時伺服器也會再檢查)。
|
* 角色存在這台瀏覽器(左邊的衣櫃);名字不能和真實候選人相同(這裡先查參選人資料,開局時伺服器也會再檢查)。
|
||||||
*/
|
*/
|
||||||
|
|
@ -34,7 +35,7 @@ export function CreatorScreen({ charId }: { charId: string | null }) {
|
||||||
const [name, setNameRaw] = useState(saved?.name ?? "");
|
const [name, setNameRaw] = useState(saved?.name ?? "");
|
||||||
const [party, setPartyRaw] = useState<Party>(saved?.party ?? null);
|
const [party, setPartyRaw] = useState<Party>(saved?.party ?? null);
|
||||||
const [background, setBackgroundRaw] = useState<Background>(saved?.background ?? "社運出身");
|
const [background, setBackgroundRaw] = useState<Background>(saved?.background ?? "社運出身");
|
||||||
const [stats, setStats] = useState(saved?.stats ?? { fame: 5, eloquence: 5, strategy: 5, wealth: 5, network: 5 });
|
const [points, setPoints] = useState<StartPoints>(saved?.points ?? DEFAULT_POINTS);
|
||||||
const [savedNow, setSavedNow] = useState(false);
|
const [savedNow, setSavedNow] = useState(false);
|
||||||
const [tab, setTab] = useState<TabId>("face");
|
const [tab, setTab] = useState<TabId>("face");
|
||||||
const [pulse, setPulse] = useState(0);
|
const [pulse, setPulse] = useState(0);
|
||||||
|
|
@ -94,15 +95,15 @@ export function CreatorScreen({ charId }: { charId: string | null }) {
|
||||||
};
|
};
|
||||||
}, [trimmed, nameOk, speak]);
|
}, [trimmed, nameOk, speak]);
|
||||||
|
|
||||||
const used = STAT_KEYS.reduce((sum, k) => sum + stats[k], 0);
|
const used = ABILITY_IDS.reduce((sum, k) => sum + points[k], 0);
|
||||||
const left = STAT_BUDGET - used;
|
const left = START_POINTS - used;
|
||||||
const valid = nameOk && !isReal && left >= 0;
|
const valid = nameOk && !isReal && left >= 0;
|
||||||
const problem: { text: string; tab: TabId } | null = !nameOk
|
const problem: { text: string; tab: TabId } | null = !nameOk
|
||||||
? { text: "先到「名字」取個名字", tab: "name" }
|
? { text: "先到「名字」取個名字", tab: "name" }
|
||||||
: isReal
|
: isReal
|
||||||
? { text: "名字和真實參選人一樣,換一個", tab: "name" }
|
? { text: "名字和真實參選人一樣,換一個", tab: "name" }
|
||||||
: left < 0
|
: left < 0
|
||||||
? { text: "能力點數超過了,減一些", tab: "stats" }
|
? { text: "開局能力點數超過了,減一些", tab: "stats" }
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
/** 每次改東西:角色彈一下,「已存好」變回「先存起來」 */
|
/** 每次改東西:角色彈一下,「已存好」變回「先存起來」 */
|
||||||
|
|
@ -131,9 +132,9 @@ export function CreatorScreen({ charId }: { charId: string | null }) {
|
||||||
touched();
|
touched();
|
||||||
speak(`我是${originText(b)}!`);
|
speak(`我是${originText(b)}!`);
|
||||||
};
|
};
|
||||||
const changeStats = (next: typeof stats) => {
|
const changePoints = (next: StartPoints) => {
|
||||||
if (next === stats) return;
|
if (next === points) return;
|
||||||
setStats(next);
|
setPoints(next);
|
||||||
sfx.click();
|
sfx.click();
|
||||||
touched();
|
touched();
|
||||||
};
|
};
|
||||||
|
|
@ -146,7 +147,7 @@ export function CreatorScreen({ charId }: { charId: string | null }) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const save = () => {
|
const save = () => {
|
||||||
saveCharacter({ id, name: trimmed, party, background, stats, avatar });
|
saveCharacter({ id, name: trimmed, party, background, points, avatar });
|
||||||
setList(loadCharacters());
|
setList(loadCharacters());
|
||||||
setSavedNow(true);
|
setSavedNow(true);
|
||||||
};
|
};
|
||||||
|
|
@ -257,12 +258,14 @@ export function CreatorScreen({ charId }: { charId: string | null }) {
|
||||||
)}
|
)}
|
||||||
{tab === "origin" && <OriginTab background={background} setBackground={setBackground} />}
|
{tab === "origin" && <OriginTab background={background} setBackground={setBackground} />}
|
||||||
{tab === "stats" && (
|
{tab === "stats" && (
|
||||||
<StatsTab
|
<AbilitiesTab
|
||||||
stats={stats}
|
points={points}
|
||||||
|
background={background}
|
||||||
|
party={party}
|
||||||
left={left}
|
left={left}
|
||||||
onBump={(k: StatKey, d) => changeStats(bumpStat(stats, k, d))}
|
onBump={(k: AbilityKey, d) => changePoints(bumpPoint(points, k, d))}
|
||||||
onSetAll={(v) => changeStats(Object.fromEntries(STAT_KEYS.map((k) => [k, v])) as typeof stats)}
|
onSetAll={(v) => changePoints(Object.fromEntries(ABILITY_IDS.map((k) => [k, v])) as StartPoints)}
|
||||||
onRandom={() => changeStats(randomStats())}
|
onRandom={() => changePoints(randomPoints())}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -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 { Check, Minus, Plus, RotateCcw, Search, Shuffle, Trash2 } from "lucide-react";
|
||||||
import { useEffect, useState, type CSSProperties } from "react";
|
import { useEffect, useState, type CSSProperties } from "react";
|
||||||
import type { AvatarSpec } from "../art/Avatar.tsx";
|
import type { AvatarSpec } from "../art/Avatar.tsx";
|
||||||
import { Poster } from "../art/Poster.tsx";
|
import { Poster } from "../art/Poster.tsx";
|
||||||
import { PartyFlag, hasPartyFlag } from "../PartyFlag.tsx";
|
import { PartyFlag, hasPartyFlag } from "../PartyFlag.tsx";
|
||||||
import { partyFacts, searchParties } from "../parties.ts";
|
import { partyFacts, searchParties } from "../parties.ts";
|
||||||
import {
|
import { ABILITY_LOOK } from "../rogue/CareerSheet.tsx";
|
||||||
BACKGROUND_INFO,
|
import { MAX_LEVEL } from "../rogue/careerRules.ts";
|
||||||
BACKGROUNDS,
|
import { ABILITY_IDS, BACKGROUND_ICON, BACKGROUNDS, PARTIES, START_POINT_MAX, START_POINTS, originText, partyOf, type AbilityKey, type Background, type Party } from "./options.ts";
|
||||||
PARTIES,
|
|
||||||
STAT_BUDGET,
|
|
||||||
STAT_KEYS,
|
|
||||||
STAT_LABELS,
|
|
||||||
STAT_MAX,
|
|
||||||
originText,
|
|
||||||
partyOf,
|
|
||||||
type Background,
|
|
||||||
type Party,
|
|
||||||
type StatKey,
|
|
||||||
} from "./options.ts";
|
|
||||||
import { Section } from "./Pickers.tsx";
|
import { Section } from "./Pickers.tsx";
|
||||||
|
|
||||||
export const NAME_MIN = 2;
|
export const NAME_MIN = 2;
|
||||||
|
|
@ -122,14 +111,14 @@ export function OriginTab({ background, setBackground }: { background: Backgroun
|
||||||
<div className="cr-origins" role="radiogroup" aria-label="出身">
|
<div className="cr-origins" role="radiogroup" aria-label="出身">
|
||||||
{BACKGROUNDS.map((b) => {
|
{BACKGROUNDS.map((b) => {
|
||||||
const on = b === background;
|
const on = b === background;
|
||||||
const { note, Icon } = BACKGROUND_INFO[b];
|
const Icon = BACKGROUND_ICON[b];
|
||||||
return (
|
return (
|
||||||
<button key={b} type="button" role="radio" aria-checked={on} className={`cr-origin${on ? " is-on" : ""}`} onClick={() => !on && setBackground(b)}>
|
<button key={b} type="button" role="radio" aria-checked={on} className={`cr-origin${on ? " is-on" : ""}`} onClick={() => !on && setBackground(b)}>
|
||||||
<span className="cr-origin-ic" aria-hidden>
|
<span className="cr-origin-ic" aria-hidden>
|
||||||
<Icon size={22} />
|
<Icon size={22} />
|
||||||
</span>
|
</span>
|
||||||
<b>{originText(b)}</b>
|
<b>{originText(b)}</b>
|
||||||
<small>{originBonusText(b) || note}</small>
|
<small>{originBonusText(b)}</small>
|
||||||
{on && (
|
{on && (
|
||||||
<span className="cr-tick" aria-hidden>
|
<span className="cr-tick" aria-hidden>
|
||||||
<Check size={14} strokeWidth={3.5} />
|
<Check size={14} strokeWidth={3.5} />
|
||||||
|
|
@ -142,22 +131,29 @@ export function OriginTab({ background, setBackground }: { background: Backgroun
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
type Stats = CustomCandidate["stats"];
|
/**
|
||||||
|
* 開局能力(docs/27 第 6 節):就是政治生涯角色卡上的五項能力。斜線格是出身、黨給的(不能自己點),
|
||||||
export function StatsTab({
|
* 實心格是自己配的,空格之後在政治生涯升等再加(每項最多 5 級)。
|
||||||
stats,
|
*/
|
||||||
|
export function AbilitiesTab({
|
||||||
|
points,
|
||||||
|
background,
|
||||||
|
party,
|
||||||
left,
|
left,
|
||||||
onBump,
|
onBump,
|
||||||
onSetAll,
|
onSetAll,
|
||||||
onRandom,
|
onRandom,
|
||||||
}: {
|
}: {
|
||||||
stats: Stats;
|
points: StartPoints;
|
||||||
|
background: Background;
|
||||||
|
party: Party;
|
||||||
left: number;
|
left: number;
|
||||||
onBump: (k: StatKey, d: 1 | -1) => void;
|
onBump: (k: AbilityKey, d: 1 | -1) => void;
|
||||||
onSetAll: (v: number) => void;
|
onSetAll: (v: number) => void;
|
||||||
onRandom: () => void;
|
onRandom: () => void;
|
||||||
}) {
|
}) {
|
||||||
const even = Math.floor(STAT_BUDGET / STAT_KEYS.length);
|
const fixed = fixedAbilities(background, party);
|
||||||
|
const res = PARTY_RESOURCES[partyKind(party)];
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={`cr-pot${left < 0 ? " is-over" : left === 0 ? " is-done" : ""}`} aria-live="polite">
|
<div className={`cr-pot${left < 0 ? " is-over" : left === 0 ? " is-done" : ""}`} aria-live="polite">
|
||||||
|
|
@ -165,12 +161,12 @@ export function StatsTab({
|
||||||
<span className="cr-pot-txt">
|
<span className="cr-pot-txt">
|
||||||
<b>{left < 0 ? `超過 ${-left} 點,請減一些` : left === 0 ? "點數都分完了" : `還剩 ${left} 點可以加`}</b>
|
<b>{left < 0 ? `超過 ${-left} 點,請減一些` : left === 0 ? "點數都分完了" : `還剩 ${left} 點可以加`}</b>
|
||||||
<small>
|
<small>
|
||||||
總共 {STAT_BUDGET} 點,每項最多 {STAT_MAX} 點
|
總共 {START_POINTS} 點,每項自己最多配 {START_POINT_MAX} 點
|
||||||
</small>
|
</small>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="cr-pot-tools">
|
<div className="cr-pot-tools">
|
||||||
<button type="button" className="cr-tool" onClick={() => onSetAll(even)}>
|
<button type="button" className="cr-tool" onClick={() => onSetAll(1)}>
|
||||||
平均分配
|
平均分配
|
||||||
</button>
|
</button>
|
||||||
<button type="button" className="cr-tool" onClick={onRandom}>
|
<button type="button" className="cr-tool" onClick={onRandom}>
|
||||||
|
|
@ -180,34 +176,69 @@ export function StatsTab({
|
||||||
<RotateCcw size={16} aria-hidden /> 全部歸零
|
<RotateCcw size={16} aria-hidden /> 全部歸零
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<p className="cr-ab-legend">
|
||||||
|
<span>
|
||||||
|
<span className="cr-pips is-key" aria-hidden>
|
||||||
|
<i className="is-fixed" />
|
||||||
|
</span>
|
||||||
|
出身、黨給的
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
<span className="cr-pips is-key" aria-hidden>
|
||||||
|
<i className="is-on" />
|
||||||
|
</span>
|
||||||
|
自己配的
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
<span className="cr-pips is-key" aria-hidden>
|
||||||
|
<i />
|
||||||
|
</span>
|
||||||
|
政治生涯升等再加
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
<ul className="cr-stats">
|
<ul className="cr-stats">
|
||||||
{STAT_KEYS.map((k) => {
|
{ABILITY_IDS.map((k) => {
|
||||||
const v = stats[k];
|
const own = points[k];
|
||||||
const { label, note } = STAT_LABELS[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 (
|
return (
|
||||||
<li key={k} className="cr-stat">
|
<li key={k} className="cr-stat" style={{ ["--ab" as string]: color } as CSSProperties}>
|
||||||
<p className="cr-stat-txt">
|
<p className="cr-stat-txt">
|
||||||
|
<span className="cr-ab-ic" aria-hidden>
|
||||||
|
<Icon size={16} />
|
||||||
|
</span>
|
||||||
<b>{label}</b>
|
<b>{label}</b>
|
||||||
<small>{note}</small>
|
{from.map((f) => (
|
||||||
|
<span key={f} className="cr-ab-tag">
|
||||||
|
{f} +1
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
<small>{ABILITY_EFFECTS[k]}</small>
|
||||||
</p>
|
</p>
|
||||||
<div className="cr-stat-ctl">
|
<div className="cr-stat-ctl">
|
||||||
<button type="button" className="cr-step" aria-label={`${label}減一點`} disabled={v <= 0} onClick={() => onBump(k, -1)}>
|
<button type="button" className="cr-step" aria-label={`${label}減一點`} disabled={own <= 0} onClick={() => onBump(k, -1)}>
|
||||||
<Minus size={20} strokeWidth={3} aria-hidden />
|
<Minus size={20} strokeWidth={3} aria-hidden />
|
||||||
</button>
|
</button>
|
||||||
<span className="cr-pips" role="meter" aria-label={label} aria-valuemin={0} aria-valuemax={STAT_MAX} aria-valuenow={v}>
|
<span className="cr-pips" role="meter" aria-label={`${label}:開局 ${lv} 級(自己配 ${own})`} aria-valuemin={0} aria-valuemax={MAX_LEVEL} aria-valuenow={lv}>
|
||||||
{Array.from({ length: STAT_MAX }, (_, i) => (
|
{Array.from({ length: MAX_LEVEL }, (_, i) => (
|
||||||
<i key={i} className={i < v ? "is-on" : ""} />
|
<i key={i} className={i < fixed[k] ? "is-fixed" : i < lv ? "is-on" : ""} />
|
||||||
))}
|
))}
|
||||||
</span>
|
</span>
|
||||||
<button type="button" className="cr-step is-plus" aria-label={`${label}加一點`} disabled={v >= STAT_MAX || left <= 0} onClick={() => onBump(k, 1)}>
|
<button type="button" className="cr-step is-plus" aria-label={`${label}加一點`} disabled={own >= START_POINT_MAX || left <= 0} onClick={() => onBump(k, 1)}>
|
||||||
<Plus size={20} strokeWidth={3} aria-hidden />
|
<Plus size={20} strokeWidth={3} aria-hidden />
|
||||||
</button>
|
</button>
|
||||||
<b className="cr-stat-val">{v}</b>
|
<b className="cr-stat-val">
|
||||||
|
<small>Lv</small>
|
||||||
|
{lv}
|
||||||
|
</b>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</ul>
|
</ul>
|
||||||
|
<p className="cr-note">這五項就是政治生涯角色卡上的能力:開局等級=自己配的+出身+黨的資源,之後每升一級拿 1 點往上加,每項最多 {MAX_LEVEL} 級。出身在「出身」分頁換,政黨在「名字」分頁換。</p>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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";
|
const KEY = "tongsuan.characters";
|
||||||
|
|
||||||
export type SavedCharacter = Omit<CustomCandidate, "replace"> & { id: string };
|
/** 開局能力存在 points(docs/27 第 6 節);舊存檔的 stats 讀進來就換算掉 */
|
||||||
|
export type SavedCharacter = Omit<CustomCandidate, "replace" | "points" | "stats"> & { 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):照部件目錄檢查,看不懂的部件代號換成預設、壞掉的欄位丟掉,存檔壞掉也不會當機。
|
* 讀存檔時清洗頭像(docs/24):照部件目錄檢查,看不懂的部件代號換成預設、壞掉的欄位丟掉,存檔壞掉也不會當機。
|
||||||
* 舊存檔的頭像本來就合法,原封不動。
|
* 舊存檔的頭像本來就合法,原封不動;舊版的能力點數換成開局能力點。
|
||||||
*/
|
*/
|
||||||
function cleanCharacter(raw: unknown): SavedCharacter | null {
|
function cleanCharacter(raw: unknown): SavedCharacter | null {
|
||||||
if (!raw || typeof raw !== "object") return null;
|
if (!raw || typeof raw !== "object") return null;
|
||||||
const c = raw as SavedCharacter;
|
const c = raw as SavedCharacter;
|
||||||
if (typeof c.id !== "string" || typeof c.name !== "string") return null;
|
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[] {
|
export function loadCharacters(): SavedCharacter[] {
|
||||||
|
|
|
||||||
|
|
@ -303,10 +303,14 @@
|
||||||
.cr-tool:active { transform: translate(2px, 2px); box-shadow: none; }
|
.cr-tool:active { transform: translate(2px, 2px); box-shadow: none; }
|
||||||
.cr-stats { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
|
.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 { 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 b { font-family: var(--font-serif); font-size: 17px; }
|
||||||
.cr-stat-txt small { color: var(--muted); font-size: 12px; font-weight: 600; }
|
.cr-stat-txt small { flex-basis: 100%; color: var(--muted); font-size: 12px; font-weight: 600; line-height: 1.4; }
|
||||||
.cr-stat-ctl { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px 32px; align-items: center; gap: 8px; }
|
.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 {
|
.cr-step {
|
||||||
width: 44px; height: 44px; display: grid; place-items: center; padding: 0;
|
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);
|
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.is-plus { background: var(--signal); color: var(--signal-ink); }
|
||||||
.cr-step:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; }
|
.cr-step:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; }
|
||||||
.cr-step:disabled { opacity: 0.35; 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 { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; height: 24px; padding: 0 4px; }
|
||||||
.cr-pips i.is-on { background: var(--stamp); transform: none; }
|
.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-stat-val { font: 900 26px/1 var(--font-num); font-variant-numeric: tabular-nums; text-align: right; }
|
.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; }
|
.cr-cta { grid-area: cta; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: stretch; gap: 12px; }
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
import {
|
||||||
Briefcase,
|
Briefcase,
|
||||||
Building2,
|
Building2,
|
||||||
|
|
@ -27,7 +27,7 @@ import { FEATURED_PARTIES, partyShort, partySlot } from "../parties.ts";
|
||||||
/** 捏人物的選項清單(docs/15)。顏色色盤在 art/palette.ts,這裡只放「選哪一種」。 */
|
/** 捏人物的選項清單(docs/15)。顏色色盤在 art/palette.ts,這裡只放「選哪一種」。 */
|
||||||
|
|
||||||
export type Option<T> = { id: T; label: string };
|
export type Option<T> = { id: T; label: string };
|
||||||
export type StatKey = keyof CustomCandidate["stats"];
|
export type AbilityKey = keyof StartPoints;
|
||||||
export type Party = CustomCandidate["party"];
|
export type Party = CustomCandidate["party"];
|
||||||
export type Background = CustomCandidate["background"];
|
export type Background = CustomCandidate["background"];
|
||||||
|
|
||||||
|
|
@ -90,31 +90,22 @@ export const partyOf = (id: Party): PartyOption => ({
|
||||||
/** 直接列出來的政黨:推出候選人最多的幾個+無黨籍;其他政黨到「更多政黨」搜尋(parties.ts) */
|
/** 直接列出來的政黨:推出候選人最多的幾個+無黨籍;其他政黨到「更多政黨」搜尋(parties.ts) */
|
||||||
export const PARTIES: PartyOption[] = [...FEATURED_PARTIES.map(partyOf), partyOf(null)];
|
export const PARTIES: PartyOption[] = [...FEATURED_PARTIES.map(partyOf), partyOf(null)];
|
||||||
|
|
||||||
export const BACKGROUND_INFO: Record<Background, { note: string; Icon: LucideIcon }> = {
|
export const BACKGROUND_ICON: Record<Background, LucideIcon> = {
|
||||||
醫師: { note: "口才加分,長輩較信任", Icon: Stethoscope },
|
醫師: Stethoscope,
|
||||||
律師: { note: "口才大幅加分", Icon: Scale },
|
律師: Scale,
|
||||||
教授: { note: "口才與謀略加分", Icon: GraduationCap },
|
教授: GraduationCap,
|
||||||
前藝人: { note: "知名度大幅加分", Icon: Mic },
|
前藝人: Mic,
|
||||||
網紅: { note: "知名度加分,小額募款多三成", Icon: Smartphone },
|
網紅: Smartphone,
|
||||||
政二代: { note: "地方組織現成,知名度加分", Icon: Landmark },
|
政二代: Landmark,
|
||||||
基層里長: { note: "地方組織強,但全市知名度較低", Icon: Home },
|
基層里長: Home,
|
||||||
企業家: { note: "多 800 萬起始資金", Icon: Briefcase },
|
企業家: Briefcase,
|
||||||
前官員: { note: "謀略加分,知名度加分", Icon: Building2 },
|
前官員: Building2,
|
||||||
社運出身: { note: "知名度與口才小幅加分", Icon: Megaphone },
|
社運出身: 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 originText = (b: Background): string => (b.endsWith("出身") ? b : `${b}出身`);
|
||||||
|
|
||||||
export const STAT_KEYS: StatKey[] = ["fame", "eloquence", "strategy", "wealth", "network"];
|
|
||||||
export const STAT_LABELS: Record<StatKey, { label: string; note: string }> = {
|
|
||||||
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";
|
export type TabId = "face" | "hair" | "outfit" | "extra" | "gear" | "props" | "style" | "name" | "origin" | "stats";
|
||||||
/** 外觀分頁(新部位的分頁照目錄的 slots.tab 放:gear 行頭、props 道具、extra 配件的口罩) */
|
/** 外觀分頁(新部位的分頁照目錄的 slots.tab 放:gear 行頭、props 道具、extra 配件的口罩) */
|
||||||
export const TABS: { id: TabId; label: string; title: string; Icon: LucideIcon }[] = [
|
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: "style", label: "畫風", title: "漫畫、Q 版、像素、貼紙", Icon: Palette },
|
||||||
{ id: "name", label: "名字", title: "名字、政黨", Icon: IdCard },
|
{ id: "name", label: "名字", title: "名字、政黨", Icon: IdCard },
|
||||||
{ id: "origin", label: "出身", title: "出身會影響開局", Icon: UserRound },
|
{ 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(超過時只能減) */
|
/** 開局能力加減一點:每項 0–START_POINT_MAX,總和不超過 START_POINTS(超過時只能減) */
|
||||||
export function bumpStat(stats: CustomCandidate["stats"], key: StatKey, delta: 1 | -1): CustomCandidate["stats"] {
|
export function bumpPoint(points: StartPoints, key: AbilityKey, delta: 1 | -1): StartPoints {
|
||||||
const used = STAT_KEYS.reduce((sum, k) => sum + stats[k], 0);
|
const used = ABILITY_IDS.reduce((sum, k) => sum + points[k], 0);
|
||||||
const next = stats[key] + delta;
|
const next = points[key] + delta;
|
||||||
if (next < 0 || next > STAT_MAX) return stats;
|
if (next < 0 || next > START_POINT_MAX) return points;
|
||||||
if (delta > 0 && used >= STAT_BUDGET) return stats;
|
if (delta > 0 && used >= START_POINTS) return points;
|
||||||
return { ...stats, [key]: next };
|
return { ...points, [key]: next };
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 隨機把點數分完(每項不超過上限) */
|
/** 隨機把點數分完(每項不超過上限) */
|
||||||
export function randomStats(rand: () => number = Math.random): CustomCandidate["stats"] {
|
export function randomPoints(rand: () => number = Math.random): StartPoints {
|
||||||
const stats = { fame: 0, eloquence: 0, strategy: 0, wealth: 0, network: 0 };
|
const points: StartPoints = { eloquence: 0, organization: 0, media: 0, finance: 0, integrity: 0 };
|
||||||
for (let left = STAT_BUDGET; left > 0; ) {
|
for (let left = START_POINTS; left > 0; left -= 1) {
|
||||||
const open = STAT_KEYS.filter((k) => stats[k] < STAT_MAX);
|
const open = ABILITY_IDS.filter((k) => points[k] < START_POINT_MAX);
|
||||||
if (open.length === 0) break;
|
if (open.length === 0) break;
|
||||||
const k = open[Math.floor(rand() * open.length)]!;
|
points[open[Math.floor(rand() * open.length)]!] += 1;
|
||||||
stats[k] += 1;
|
|
||||||
left -= 1;
|
|
||||||
}
|
}
|
||||||
return stats;
|
return points;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 { ArrowLeft, ArrowRight, Check, Dices, Home, Landmark, Play, Shirt, UserPlus, X } from "lucide-react";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { peopleApi } from "../api.ts";
|
import { peopleApi } from "../api.ts";
|
||||||
|
|
@ -40,20 +40,13 @@ function QuickCharacter({ onDone, onCancel }: { onDone: (c: SavedCharacter) => v
|
||||||
};
|
};
|
||||||
}, [trimmed, valid]);
|
}, [trimmed, valid]);
|
||||||
const isReal = realHit === trimmed;
|
const isReal = realHit === trimmed;
|
||||||
const per = Math.floor(STAT_BUDGET / 5);
|
|
||||||
const create = () => {
|
const create = () => {
|
||||||
const c: SavedCharacter = {
|
const c: SavedCharacter = {
|
||||||
id: `c-${Date.now()}`,
|
id: `c-${Date.now()}`,
|
||||||
name: trimmed,
|
name: trimmed,
|
||||||
party,
|
party,
|
||||||
background,
|
background,
|
||||||
stats: {
|
points: { ...DEFAULT_POINTS },
|
||||||
fame: per,
|
|
||||||
eloquence: per,
|
|
||||||
strategy: per,
|
|
||||||
wealth: per,
|
|
||||||
network: per,
|
|
||||||
},
|
|
||||||
avatar,
|
avatar,
|
||||||
};
|
};
|
||||||
saveCharacter(c);
|
saveCharacter(c);
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@ import { partyColor } from "../parties.ts";
|
||||||
import type { Ability } from "../career/term/types.ts";
|
import type { Ability } from "../career/term/types.ts";
|
||||||
import { ABILITY_IDS, ABILITY_LABELS, MAX_LEVEL, toNext, type CareerState } from "./careerRules.ts";
|
import { ABILITY_IDS, ABILITY_LABELS, MAX_LEVEL, toNext, type CareerState } from "./careerRules.ts";
|
||||||
|
|
||||||
/** 五項能力的圖示與顏色(和標題畫面選單同一組顏色) */
|
/** 五項能力的圖示與顏色(和標題畫面選單同一組顏色;捏人物的「能力」分頁也用這組) */
|
||||||
const ABILITY_LOOK: Record<Ability, { Icon: LucideIcon; color: string }> = {
|
export const ABILITY_LOOK: Record<Ability, { Icon: LucideIcon; color: string }> = {
|
||||||
eloquence: { Icon: Megaphone, color: "#d61f2c" },
|
eloquence: { Icon: Megaphone, color: "#d61f2c" },
|
||||||
organization: { Icon: Users, color: "#1f8a4c" },
|
organization: { Icon: Users, color: "#1f8a4c" },
|
||||||
media: { Icon: Tv, color: "#2f6fd1" },
|
media: { Icon: Tv, color: "#2f6fd1" },
|
||||||
|
|
@ -99,7 +99,7 @@ export function CareerSheet({
|
||||||
<div className="cs-ab-main">
|
<div className="cs-ab-main">
|
||||||
<div className="cs-ab-top">
|
<div className="cs-ab-top">
|
||||||
<b>{ABILITY_LABELS[id]}</b>
|
<b>{ABILITY_LABELS[id]}</b>
|
||||||
<span className="cs-bar" aria-label={`${lv}/${MAX_LEVEL} 級`}>
|
<span className="cs-bar" aria-label={`${lv}/${MAX_LEVEL} 級(開局 ${career.base[id]}、升等加 ${lv - career.base[id]})`}>
|
||||||
{Array.from({ length: MAX_LEVEL }, (_, i) => (
|
{Array.from({ length: MAX_LEVEL }, (_, i) => (
|
||||||
<i key={i} className={i < career.base[id] ? "is-base" : i < lv ? "is-on" : ""} />
|
<i key={i} className={i < career.base[id] ? "is-base" : i < lv ? "is-on" : ""} />
|
||||||
))}
|
))}
|
||||||
|
|
@ -114,6 +114,20 @@ export function CareerSheet({
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</ul>
|
</ul>
|
||||||
|
<p className="cs-legend">
|
||||||
|
<span>
|
||||||
|
<span className="cs-bar" aria-hidden>
|
||||||
|
<i className="is-base" />
|
||||||
|
</span>
|
||||||
|
開局(捏人物配的+出身+黨)
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
<span className="cs-bar" aria-hidden>
|
||||||
|
<i className="is-on" />
|
||||||
|
</span>
|
||||||
|
升等加的
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
|
||||||
<footer className="cs-foot">
|
<footer className="cs-foot">
|
||||||
{spent > 0 && (
|
{spent > 0 && (
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { MINOR_EXP_MULT, originAbilities, partyKind, type CareerAbilities } from "@election2026/protocol";
|
import { MINOR_EXP_MULT, originAbilities, partyKind, type CareerAbilities } from "@election2026/protocol";
|
||||||
import type { Ability } from "../career/term/types.ts";
|
import type { Ability } from "../career/term/types.ts";
|
||||||
import type { SavedCharacter } from "../creator/characters.ts";
|
import { withPoints, type SavedCharacter } from "../creator/characters.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 政治生涯的練等規則(docs/23、18 第 44 項):純函式,畫面在 Career.tsx。
|
* 政治生涯的練等規則(docs/23、18 第 44 項):純函式,畫面在 Career.tsx。
|
||||||
|
|
@ -52,7 +52,7 @@ export interface CareerState {
|
||||||
term?: { stage: number; runId: string } | null;
|
term?: { stage: number; runId: string } | null;
|
||||||
/** 剛打完的那一局拿到的經驗(地圖上的戰報) */
|
/** 剛打完的那一局拿到的經驗(地圖上的戰報) */
|
||||||
report?: { runId: string; stage: number; won: boolean; exp: number; levels: number; why: string } | null;
|
report?: { runId: string; stage: number; won: boolean; exp: number; levels: number; why: string } | null;
|
||||||
/** 開局能力用哪一版規則算的(2=出身與黨的資源,18 第 53 項);舊存檔沒有 */
|
/** 開局能力用哪一版規則算的(2=出身與黨的資源,18 第 53 項;3=捏人物直接配五項能力,docs/27 第 6 節);舊存檔沒有 */
|
||||||
originRules?: number;
|
originRules?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,21 +78,21 @@ export const clamp = (x: number, lo: number, hi: number) => Math.max(lo, Math.mi
|
||||||
export const emptyTiers = (): Record<number, TierRecord> => Object.fromEntries(STAGES.map((s) => [s.stage, { runs: 0, wins: 0, best: null, topExtra: -1 }]));
|
export const emptyTiers = (): Record<number, TierRecord> => Object.fromEntries(STAGES.map((s) => [s.stage, { runs: 0, wins: 0, best: null, topExtra: -1 }]));
|
||||||
export const noCarry = (): Carry => ({ advisors: [], cards: [], money: 0, momentum: 0 });
|
export const noCarry = (): Carry => ({ advisors: [], cards: [], money: 0, momentum: 0 });
|
||||||
|
|
||||||
/** 開局能力:照捏人物的點數換算(平均 5 點是 1 級),清廉看出身 */
|
/** 開局能力:捏人物配的點+出身+黨的資源(規則在 protocol/origins.ts,伺服器的自由選戰用同一份) */
|
||||||
/** 開局能力:捏人物點數+出身+黨的資源(規則在 protocol/origins.ts,伺服器的自由選戰用同一份) */
|
|
||||||
export function startAbilities(c: SavedCharacter): CareerAbilities {
|
export function startAbilities(c: SavedCharacter): CareerAbilities {
|
||||||
return originAbilities(c);
|
return originAbilities(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 舊存檔的開局能力換成新規則(出身與黨的資源):自己加的點保留,開局那部分照新規則重算 */
|
/** 舊存檔的開局能力換成新規則:升等自己加的點保留,開局那部分照新規則重算(角色的舊版點數換成開局能力點) */
|
||||||
export function withOriginRules(c: CareerState): CareerState {
|
export function withOriginRules(c: CareerState): CareerState {
|
||||||
if (c.originRules === ORIGIN_RULES) return c;
|
if (c.originRules === ORIGIN_RULES) return c;
|
||||||
const base = startAbilities(c.character);
|
const character = withPoints(c.character);
|
||||||
|
const base = startAbilities(character);
|
||||||
const abilities = { ...c.abilities };
|
const abilities = { ...c.abilities };
|
||||||
for (const id of ABILITY_IDS) abilities[id] = clamp(c.abilities[id] - c.base[id] + base[id], 0, MAX_LEVEL);
|
for (const id of ABILITY_IDS) abilities[id] = clamp(c.abilities[id] - c.base[id] + base[id], 0, MAX_LEVEL);
|
||||||
return { ...c, base, abilities, originRules: ORIGIN_RULES };
|
return { ...c, character, base, abilities, originRules: ORIGIN_RULES };
|
||||||
}
|
}
|
||||||
export const ORIGIN_RULES = 2;
|
export const ORIGIN_RULES = 3;
|
||||||
|
|
||||||
/** 舊版(五關一路往上、或立委起跳三關)的進度換成練等版:選上過的關記下來,等級照選上的關估 */
|
/** 舊版(五關一路往上、或立委起跳三關)的進度換成練等版:選上過的關記下來,等級照選上的關估 */
|
||||||
export function migrate(raw: Record<string, unknown>, version: 1 | 2): CareerState {
|
export function migrate(raw: Record<string, unknown>, version: 1 | 2): CareerState {
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,8 @@
|
||||||
.cs-bar i { width: 17px; height: 12px; border: 2px solid #111419; border-radius: 4px; background: var(--surface); transform: skewX(-12deg); }
|
.cs-bar i { width: 17px; height: 12px; border: 2px solid #111419; border-radius: 4px; background: var(--surface); transform: skewX(-12deg); }
|
||||||
.cs-bar i.is-base { background: color-mix(in srgb, var(--ab) 50%, #fff); }
|
.cs-bar i.is-base { background: color-mix(in srgb, var(--ab) 50%, #fff); }
|
||||||
.cs-bar i.is-on { background: var(--ab); }
|
.cs-bar i.is-on { background: var(--ab); }
|
||||||
|
.cs-legend { --ab: #6b7080; margin: -2px 0 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; font-weight: 700; color: var(--muted); }
|
||||||
|
.cs-legend > span { display: inline-flex; align-items: center; gap: 6px; }
|
||||||
.cs-plus { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line); background: none; color: var(--line); font: inherit; font-weight: 900; font-size: 20px; line-height: 1; cursor: default; }
|
.cs-plus { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line); background: none; color: var(--line); font: inherit; font-weight: 900; font-size: 20px; line-height: 1; cursor: default; }
|
||||||
.cs-plus.is-hot { border: 3px solid #111419; background: var(--signal); color: #111419; box-shadow: 2px 2px 0 #111419; cursor: pointer; transition: transform 140ms var(--ease-out); }
|
.cs-plus.is-hot { border: 3px solid #111419; background: var(--signal); color: #111419; box-shadow: 2px 2px 0 #111419; cursor: pointer; transition: transform 140ms var(--ease-out); }
|
||||||
.cs-plus.is-hot:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 #111419; }
|
.cs-plus.is-hot:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 #111419; }
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { emptyTiers, gainExp, highestOpen, noCarry, runExp, startAbilities, toNe
|
||||||
const base = { eloquence: 1, organization: 1, media: 1, finance: 1, integrity: 1 };
|
const base = { eloquence: 1, organization: 1, media: 1, finance: 1, integrity: 1 };
|
||||||
const fresh = (over: Partial<CareerState> = {}): CareerState => ({
|
const fresh = (over: Partial<CareerState> = {}): CareerState => ({
|
||||||
id: "c",
|
id: "c",
|
||||||
character: { id: "x", name: "林小美", party: "民主進步黨", background: "基層里長", stats: { fame: 5, eloquence: 5, strategy: 5, wealth: 5, network: 5 }, avatar: {} as never },
|
character: { id: "x", name: "林小美", party: "民主進步黨", background: "基層里長", points: { eloquence: 1, organization: 1, media: 1, finance: 1, integrity: 1 }, avatar: {} as never },
|
||||||
county: { code: "64000", name: "高雄市" },
|
county: { code: "64000", name: "高雄市" },
|
||||||
village: null,
|
village: null,
|
||||||
villageTown: null,
|
villageTown: null,
|
||||||
|
|
@ -66,16 +66,18 @@ describe("出身與黨的資源(18 第 53 項)", () => {
|
||||||
expect(runExp(minor, 1, true, "B", 0).why).toContain("無黨籍 ×1.2");
|
expect(runExp(minor, 1, true, "B", 0).why).toContain("無黨籍 ×1.2");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("開局能力:點數+出身 +1+黨的資源 +1;舊存檔換新規則時保留自己加的點", () => {
|
it("開局能力:捏人物配的點+出身 +1+黨的資源 +1;舊存檔換新規則時保留升等加的點", () => {
|
||||||
const c = fresh();
|
const c = fresh();
|
||||||
// 基層里長:組織 +1;民進黨(大黨):組織 +1;點數 5 → 每項 1 級
|
// 基層里長:組織 +1;民進黨(大黨):組織 +1;每項自己配 1 點
|
||||||
expect(startAbilities(c.character)).toEqual({ eloquence: 1, organization: 3, media: 1, finance: 1, integrity: 0 });
|
expect(startAbilities(c.character)).toEqual({ eloquence: 1, organization: 3, media: 1, finance: 1, integrity: 1 });
|
||||||
const old = { ...c, base: { eloquence: 1, organization: 1, media: 1, finance: 1, integrity: 1 }, abilities: { eloquence: 3, organization: 1, media: 1, finance: 1, integrity: 1 } };
|
// 第 2 版規則的存檔:角色還是舊版的點數(每項 5 點 → 清廉 0 級),升等在口才加了 2 點
|
||||||
|
const legacy = { ...c.character, points: undefined, stats: { fame: 5, eloquence: 5, strategy: 5, wealth: 5, network: 5 } } as unknown as CareerState["character"];
|
||||||
|
const old = { ...c, character: legacy, originRules: 2, base: { eloquence: 1, organization: 3, media: 1, finance: 1, integrity: 0 }, abilities: { eloquence: 3, organization: 3, media: 1, finance: 1, integrity: 0 } };
|
||||||
const next = withOriginRules(old);
|
const next = withOriginRules(old);
|
||||||
|
expect(next.character.points).toEqual({ eloquence: 1, organization: 1, media: 1, finance: 1, integrity: 1 });
|
||||||
|
expect("stats" in next.character).toBe(false);
|
||||||
expect(next.base).toEqual(startAbilities(c.character));
|
expect(next.base).toEqual(startAbilities(c.character));
|
||||||
expect(next.abilities.eloquence).toBe(3);
|
expect(next.abilities).toEqual({ eloquence: 3, organization: 3, media: 1, finance: 1, integrity: 1 });
|
||||||
expect(next.abilities.organization).toBe(3);
|
|
||||||
expect(next.abilities.integrity).toBe(0);
|
|
||||||
expect(withOriginRules(next)).toBe(next);
|
expect(withOriginRules(next)).toBe(next);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
import { DEFAULT_POINTS, START_POINTS, START_POINT_MAX } from "@election2026/protocol";
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { withPoints, type SavedCharacter } from "../src/game/creator/characters.ts";
|
||||||
|
import { ABILITY_IDS, bumpPoint, randomPoints } from "../src/game/creator/options.ts";
|
||||||
|
|
||||||
|
/** docs/27 第 6 節:捏人物的開局能力就是政治生涯那五項 */
|
||||||
|
|
||||||
|
const sum = (p: Record<string, number>) => Object.values(p).reduce((a, b) => a + b, 0);
|
||||||
|
|
||||||
|
describe("捏人物的開局能力", () => {
|
||||||
|
it("每項最多 2 點、總共 5 點;超過時只能減", () => {
|
||||||
|
const two = bumpPoint(bumpPoint({ ...DEFAULT_POINTS, eloquence: 0 }, "media", 1), "media", 1);
|
||||||
|
expect(two.media).toBe(START_POINT_MAX);
|
||||||
|
expect(bumpPoint(two, "media", 1)).toBe(two);
|
||||||
|
expect(bumpPoint(DEFAULT_POINTS, "finance", 1)).toBe(DEFAULT_POINTS);
|
||||||
|
expect(bumpPoint(DEFAULT_POINTS, "finance", -1).finance).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("隨機配點一定分完、每項不超過上限", () => {
|
||||||
|
let seed = 1;
|
||||||
|
const rand = () => ((seed = (seed * 16807) % 2147483647) / 2147483647);
|
||||||
|
for (let i = 0; i < 50; i++) {
|
||||||
|
const p = randomPoints(rand);
|
||||||
|
expect(sum(p)).toBe(START_POINTS);
|
||||||
|
for (const k of ABILITY_IDS) expect(p[k]).toBeLessThanOrEqual(START_POINT_MAX);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("舊存檔(知名度、謀略那五項)讀進來換成開局能力點", () => {
|
||||||
|
const old = { id: "x", name: "林小美", party: null, background: "律師", stats: { fame: 10, eloquence: 4, strategy: 3, wealth: 4, network: 4 }, avatar: {} } as unknown as SavedCharacter;
|
||||||
|
const next = withPoints(old);
|
||||||
|
expect("stats" in next).toBe(false);
|
||||||
|
expect(next.points.media).toBe(2);
|
||||||
|
expect(sum(next.points)).toBe(START_POINTS);
|
||||||
|
const fresh = { ...next };
|
||||||
|
expect(withPoints(fresh)).toBe(fresh);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue