198 lines
7.3 KiB
TypeScript
198 lines
7.3 KiB
TypeScript
import { BarChart3, Camera, FileText, Mic, ScrollText, type LucideIcon } from "lucide-react";
|
||
import { useEffect, useMemo, useRef, useState } from "react";
|
||
import { Avatar, avatarFromSeed } from "../../art/Avatar.tsx";
|
||
import { sfx } from "../../audio/sfx.ts";
|
||
import { GameShell, Pops, usePops, useShake } from "./Shell.tsx";
|
||
import { clamp, rng, shuffle } from "./rng.ts";
|
||
import type { TermGameProps } from "./types.ts";
|
||
|
||
/**
|
||
* 質詢:虛構的部長、局長在台上一句一句回答,有些話是「破綻」(和事實不合的說法)。
|
||
* 破綻出現時打出對的證據卡(預算書、公文、現場照片、數據)就得分;客套話時亂打會扣分。
|
||
* 官員都是虛構職位,不對應真人。
|
||
*/
|
||
|
||
type Evidence = "budget" | "memo" | "photo" | "data";
|
||
|
||
const EVIDENCE: Record<Evidence, { label: string; Icon: LucideIcon }> = {
|
||
budget: { label: "預算書", Icon: ScrollText },
|
||
memo: { label: "公文", Icon: FileText },
|
||
photo: { label: "現場照片", Icon: Camera },
|
||
data: { label: "數據", Icon: BarChart3 },
|
||
};
|
||
|
||
interface Line {
|
||
text: string;
|
||
/** 破綻要用哪一張證據;客套話是 null */
|
||
flaw: Evidence | null;
|
||
}
|
||
|
||
interface Official {
|
||
title: string;
|
||
topic: string;
|
||
flaws: Line[];
|
||
}
|
||
|
||
const FLUFF = ["謝謝委員關心,我們非常重視。", "這部分我們會持續跟地方溝通。", "委員的建議我們回去研究。", "這個問題很複雜,需要時間。", "我們一直都很努力。", "請委員給我們一點時間。"];
|
||
|
||
const OFFICIALS: readonly Official[] = [
|
||
{
|
||
title: "交通部長",
|
||
topic: "捷運延伸線",
|
||
flaws: [
|
||
{ text: "這條線的經費早就編好了。", flaw: "budget" },
|
||
{ text: "工地現在已經全面復工。", flaw: "photo" },
|
||
{ text: "每天搭乘人數超過十萬人次。", flaw: "data" },
|
||
{ text: "我們從來沒收到地方的陳情。", flaw: "memo" },
|
||
],
|
||
},
|
||
{
|
||
title: "衛福部長",
|
||
topic: "長照據點",
|
||
flaws: [
|
||
{ text: "長照據點已經普及到每一個里。", flaw: "data" },
|
||
{ text: "人力缺口的預算去年就補足了。", flaw: "budget" },
|
||
{ text: "據點的設備都是全新的。", flaw: "photo" },
|
||
{ text: "我們早就發文請各縣市改善。", flaw: "memo" },
|
||
],
|
||
},
|
||
{
|
||
title: "教育部長",
|
||
topic: "老舊校舍補強",
|
||
flaws: [
|
||
{ text: "老舊校舍都完成補強了。", flaw: "photo" },
|
||
{ text: "補強經費一毛都沒有少。", flaw: "budget" },
|
||
{ text: "家長滿意度高達九成。", flaw: "data" },
|
||
{ text: "公文寫得很清楚,明年才要做。", flaw: "memo" },
|
||
],
|
||
},
|
||
{
|
||
title: "環境部長",
|
||
topic: "工業區空污",
|
||
flaws: [
|
||
{ text: "空氣品質一年比一年好。", flaw: "data" },
|
||
{ text: "改善經費都已經撥下去了。", flaw: "budget" },
|
||
{ text: "那幾間工廠我們都稽查過了。", flaw: "photo" },
|
||
{ text: "地方從來沒有反映過這件事。", flaw: "memo" },
|
||
],
|
||
},
|
||
];
|
||
|
||
export function InterpellationGame({ seed, level, characterName, onFinish }: TermGameProps) {
|
||
const script = useMemo(() => {
|
||
const r = rng(seed);
|
||
const pair = shuffle(r, OFFICIALS).slice(0, 2);
|
||
return pair.map((o, k) => {
|
||
const fluff = shuffle(r, FLUFF).slice(0, 4).map((text) => ({ text, flaw: null }) as Line);
|
||
return { ...o, face: avatarFromSeed(`official-${seed}-${k}`, { female: r() < 0.4 }), lines: shuffle(r, [...o.flaws, ...fluff]) };
|
||
});
|
||
}, [seed]);
|
||
const lineMs = Math.round(3400 - level * 1100);
|
||
const totalFlaws = script.reduce((a, o) => a + o.lines.filter((l) => l.flaw).length, 0);
|
||
const [phase, setPhase] = useState<"intro" | "play" | "done">("intro");
|
||
const [o, setO] = useState(0);
|
||
const [k, setK] = useState(0);
|
||
const [hits, setHits] = useState(0);
|
||
const [wrong, setWrong] = useState(0);
|
||
const [sweat, setSweat] = useState(0);
|
||
const [final, setFinal] = useState(0);
|
||
const answered = useRef(new Set<string>());
|
||
const [shake, doShake] = useShake();
|
||
const [pops, pop] = usePops();
|
||
const score = (h: number, w: number) => clamp((h / Math.max(1, totalFlaws)) * 100 - w * 6, 0, 100);
|
||
|
||
useEffect(() => {
|
||
if (phase !== "play") return;
|
||
const t = setTimeout(() => {
|
||
const official = script[o]!;
|
||
if (k + 1 < official.lines.length) setK(k + 1);
|
||
else if (o + 1 < script.length) {
|
||
setO(o + 1);
|
||
setK(0);
|
||
setSweat(0);
|
||
sfx.gong();
|
||
} else {
|
||
const s = score(hits, wrong);
|
||
setFinal(s);
|
||
setPhase("done");
|
||
if (s >= 70) sfx.applause();
|
||
}
|
||
}, lineMs);
|
||
return () => clearTimeout(t);
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||
}, [phase, o, k]);
|
||
|
||
const official = script[o]!;
|
||
const line = official.lines[k]!;
|
||
const key = `${o}-${k}`;
|
||
|
||
const use = (e: Evidence) => {
|
||
if (answered.current.has(key)) return;
|
||
answered.current.add(key);
|
||
if (line.flaw === e) {
|
||
setHits((h) => h + 1);
|
||
setSweat((x) => x + 1);
|
||
sfx.stamp();
|
||
sfx.combo(hits);
|
||
doShake("large");
|
||
pop("破綻!", "boom", 40 + Math.random() * 20, 26);
|
||
} else {
|
||
setWrong((w) => w + 1);
|
||
sfx.bad();
|
||
doShake("small");
|
||
pop(line.flaw ? "證據不對" : "委員別鬧了", "bad", 40 + Math.random() * 20, 26);
|
||
}
|
||
};
|
||
|
||
return (
|
||
<GameShell
|
||
title="質詢"
|
||
rule="官員一句一句回答,聽到和事實不合的「破綻」時,打出對的證據卡:經費→預算書、有沒有發文→公文、現場狀況→照片、人數比例→數據。客套話別亂打。"
|
||
icon={<Mic size={22} />}
|
||
phase={phase}
|
||
onStart={() => {
|
||
answered.current.clear();
|
||
setPhase("play");
|
||
}}
|
||
score={final}
|
||
verdict={final >= 75 ? `${characterName}的質詢上了晚間新聞,官員冒汗的畫面被瘋傳。` : final >= 45 ? "有幾個問題問到重點。" : "這次質詢被說準備不夠。"}
|
||
onContinue={() => onFinish(Math.round(final))}
|
||
shake={shake}
|
||
>
|
||
<div className="tm-play tm-inter">
|
||
<div className="tm-inter-stage">
|
||
<div className={`tm-official${sweat >= 2 ? " is-sweating" : ""}`}>
|
||
<Avatar spec={official.face} size={96} talking />
|
||
<span className="tm-nameplate">
|
||
{official.title}
|
||
</span>
|
||
{sweat > 0 && <span className="tm-sweat" aria-label={`冒汗 ${sweat}`}>{"💧".repeat(Math.min(3, sweat))}</span>}
|
||
</div>
|
||
<div className="tm-bubble" key={key}>
|
||
<small>
|
||
質詢主題:{official.topic}・第 {o + 1}/{script.length} 位
|
||
</small>
|
||
<p>「{line.text}」</p>
|
||
<i className="tm-line-timer" style={{ animationDuration: `${lineMs}ms` }} />
|
||
</div>
|
||
</div>
|
||
<div className="tm-score-line">
|
||
破綻 <b>{hits}</b>/{totalFlaws}・失誤 <b>{wrong}</b>
|
||
</div>
|
||
<div className="tm-evidence">
|
||
{(Object.keys(EVIDENCE) as Evidence[]).map((e) => {
|
||
const { label, Icon } = EVIDENCE[e];
|
||
return (
|
||
<button key={e} type="button" className="tm-evi" onClick={() => use(e)}>
|
||
<Icon size={26} aria-hidden />
|
||
<b>{label}</b>
|
||
</button>
|
||
);
|
||
})}
|
||
</div>
|
||
<Pops pops={pops} />
|
||
</div>
|
||
</GameShell>
|
||
);
|
||
}
|