Spaces:
Sleeping
Sleeping
Commit ·
afe51fd
1
Parent(s): 4337686
feat(web): 單人傷害飄字 + 受擊抖動
Browse files每次 dispatch 的傷害事件 → 在敵/我區飄字 + 被打一方抖一下:
- 造成傷害 → 敵人區飄紅色 -N、敵人抖
- 怪物反擊/聖裁反噬 → 我方區飄 -N(反噬紫色)、我方抖
- 回血 → 綠色 +N
reduced-motion 改純淡出、不位移不抖。補足單人原本只有一行文字、無手感的問題。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- packages/web/src/App.tsx +38 -2
- packages/web/src/styles.css +19 -0
packages/web/src/App.tsx
CHANGED
|
@@ -180,6 +180,7 @@ export function App() {
|
|
| 180 |
const [screen, setScreen] = useState<Screen>(pvpJoinCode ? "pvp" : "start");
|
| 181 |
const [game, setGame] = useState<GameState | null>(null);
|
| 182 |
const [message, setMessage] = useState<string>("");
|
|
|
|
| 183 |
const [uploadStatus, setUploadStatus] = useState<string>("");
|
| 184 |
const [ghostMsg, setGhostMsg] = useState<string>("");
|
| 185 |
const [heroName, setHeroName] = useState<string>(loadHeroName); // 勇者名字(本地記憶)
|
|
@@ -208,6 +209,7 @@ export function App() {
|
|
| 208 |
const { state, events } = step(prev, action);
|
| 209 |
actionsRef.current.push(action);
|
| 210 |
setMessage(describeEvents(events));
|
|
|
|
| 211 |
// 破第 11 關 → 打包整場 GhostRecord 上傳(模式 A,03 §4)。除錯局(maxLevel≠11)不上傳,避免重播驗證誤判。
|
| 212 |
if (state.phase === "VICTORY" && !uploadedRef.current && state.maxLevel === MAX_LEVEL) {
|
| 213 |
uploadedRef.current = true;
|
|
@@ -349,6 +351,7 @@ export function App() {
|
|
| 349 |
<Battle
|
| 350 |
game={game}
|
| 351 |
message={message}
|
|
|
|
| 352 |
uploadStatus={uploadStatus}
|
| 353 |
ghostMsg={ghostMsg}
|
| 354 |
dispatch={dispatch}
|
|
@@ -361,6 +364,7 @@ export function App() {
|
|
| 361 |
function Battle({
|
| 362 |
game,
|
| 363 |
message,
|
|
|
|
| 364 |
uploadStatus,
|
| 365 |
ghostMsg,
|
| 366 |
dispatch,
|
|
@@ -369,6 +373,7 @@ function Battle({
|
|
| 369 |
}: {
|
| 370 |
game: GameState;
|
| 371 |
message: string;
|
|
|
|
| 372 |
uploadStatus: string;
|
| 373 |
ghostMsg: string;
|
| 374 |
dispatch: (a: Action) => void;
|
|
@@ -405,6 +410,35 @@ function Battle({
|
|
| 405 |
const [tutSeen, setTutSeen] = useState(() => { try { return !!localStorage.getItem("wcg_tut_seen"); } catch { return true; } });
|
| 406 |
const dismissTut = () => { setTutSeen(true); try { localStorage.setItem("wcg_tut_seen", "1"); } catch { /* ignore */ } };
|
| 407 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
return (
|
| 409 |
<div className="battle">
|
| 410 |
{stageShow !== null && (
|
|
@@ -421,7 +455,8 @@ function Battle({
|
|
| 421 |
</div>
|
| 422 |
|
| 423 |
{/* 怪物:左=名字/HP/數值/意圖;右=立繪 + 立繪下方的能量條 */}
|
| 424 |
-
<div className=
|
|
|
|
| 425 |
<div className="enemy-info">
|
| 426 |
<div className="name">{m.name}</div>
|
| 427 |
<Bar value={m.hp} max={m.maxHp} kind="hp" label={`HP ${m.hp}/${m.maxHp}`} />
|
|
@@ -465,7 +500,8 @@ function Battle({
|
|
| 465 |
</div>
|
| 466 |
|
| 467 |
{/* 玩家狀態 */}
|
| 468 |
-
<div className=
|
|
|
|
| 469 |
<Bar value={p.hp} max={p.maxHp + p.tempMaxHp} kind="hp" label={`HP ${p.hp}/${p.maxHp + p.tempMaxHp}${p.tempMaxHp ? `(臨時+${p.tempMaxHp})` : ""}`} />
|
| 470 |
{p.classType === "BARBARIAN" ? (
|
| 471 |
<span className="stat">扣血計數(N) {p.n}</span>
|
|
|
|
| 180 |
const [screen, setScreen] = useState<Screen>(pvpJoinCode ? "pvp" : "start");
|
| 181 |
const [game, setGame] = useState<GameState | null>(null);
|
| 182 |
const [message, setMessage] = useState<string>("");
|
| 183 |
+
const [evtPulse, setEvtPulse] = useState<{ events: GameEvent[]; n: number }>({ events: [], n: 0 }); // 供戰鬥畫面做傷害飄字/受擊
|
| 184 |
const [uploadStatus, setUploadStatus] = useState<string>("");
|
| 185 |
const [ghostMsg, setGhostMsg] = useState<string>("");
|
| 186 |
const [heroName, setHeroName] = useState<string>(loadHeroName); // 勇者名字(本地記憶)
|
|
|
|
| 209 |
const { state, events } = step(prev, action);
|
| 210 |
actionsRef.current.push(action);
|
| 211 |
setMessage(describeEvents(events));
|
| 212 |
+
setEvtPulse((p) => ({ events, n: p.n + 1 })); // 觸發傷害飄字/受擊動畫
|
| 213 |
// 破第 11 關 → 打包整場 GhostRecord 上傳(模式 A,03 §4)。除錯局(maxLevel≠11)不上傳,避免重播驗證誤判。
|
| 214 |
if (state.phase === "VICTORY" && !uploadedRef.current && state.maxLevel === MAX_LEVEL) {
|
| 215 |
uploadedRef.current = true;
|
|
|
|
| 351 |
<Battle
|
| 352 |
game={game}
|
| 353 |
message={message}
|
| 354 |
+
evtPulse={evtPulse}
|
| 355 |
uploadStatus={uploadStatus}
|
| 356 |
ghostMsg={ghostMsg}
|
| 357 |
dispatch={dispatch}
|
|
|
|
| 364 |
function Battle({
|
| 365 |
game,
|
| 366 |
message,
|
| 367 |
+
evtPulse,
|
| 368 |
uploadStatus,
|
| 369 |
ghostMsg,
|
| 370 |
dispatch,
|
|
|
|
| 373 |
}: {
|
| 374 |
game: GameState;
|
| 375 |
message: string;
|
| 376 |
+
evtPulse: { events: GameEvent[]; n: number };
|
| 377 |
uploadStatus: string;
|
| 378 |
ghostMsg: string;
|
| 379 |
dispatch: (a: Action) => void;
|
|
|
|
| 410 |
const [tutSeen, setTutSeen] = useState(() => { try { return !!localStorage.getItem("wcg_tut_seen"); } catch { return true; } });
|
| 411 |
const dismissTut = () => { setTutSeen(true); try { localStorage.setItem("wcg_tut_seen", "1"); } catch { /* ignore */ } };
|
| 412 |
|
| 413 |
+
// 傷害飄字 + 受擊抖動:解析每次 dispatch 的事件,在敵/我區飄 -N/+N、並讓被打的一方抖一下
|
| 414 |
+
const [floats, setFloats] = useState<{ id: number; text: string; target: "enemy" | "player"; cls: string }[]>([]);
|
| 415 |
+
const [shake, setShake] = useState<{ enemy: boolean; player: boolean }>({ enemy: false, player: false });
|
| 416 |
+
const floatId = useRef(0);
|
| 417 |
+
useEffect(() => {
|
| 418 |
+
const evts = evtPulse.events;
|
| 419 |
+
if (!evts.length) return;
|
| 420 |
+
const spawned: { id: number; text: string; target: "enemy" | "player"; cls: string }[] = [];
|
| 421 |
+
let hitEnemy = false, hitPlayer = false;
|
| 422 |
+
for (const e of evts) {
|
| 423 |
+
if (e.type === "PLAYER_DEAL_DAMAGE" && e.dealt > 0) { spawned.push({ id: ++floatId.current, text: `-${e.dealt}`, target: "enemy", cls: "dmg" }); hitEnemy = true; }
|
| 424 |
+
else if (e.type === "MONSTER_ATTACK" && e.damage > 0) { spawned.push({ id: ++floatId.current, text: `-${e.damage}`, target: "player", cls: "dmg" }); hitPlayer = true; }
|
| 425 |
+
else if (e.type === "MONSTER_REFLECT" && e.damage > 0) { spawned.push({ id: ++floatId.current, text: `-${e.damage}`, target: "player", cls: "reflect" }); hitPlayer = true; }
|
| 426 |
+
else if (e.type === "HEAL" && e.amount > 0) { spawned.push({ id: ++floatId.current, text: `+${e.amount}`, target: "player", cls: "heal" }); }
|
| 427 |
+
}
|
| 428 |
+
if (spawned.length) {
|
| 429 |
+
setFloats((f) => [...f, ...spawned]);
|
| 430 |
+
const ids = new Set(spawned.map((x) => x.id));
|
| 431 |
+
setTimeout(() => setFloats((f) => f.filter((x) => !ids.has(x.id))), 1000);
|
| 432 |
+
}
|
| 433 |
+
if (hitEnemy || hitPlayer) {
|
| 434 |
+
setShake({ enemy: hitEnemy, player: hitPlayer });
|
| 435 |
+
setTimeout(() => setShake({ enemy: false, player: false }), 360);
|
| 436 |
+
}
|
| 437 |
+
}, [evtPulse.n]); // eslint-disable-line react-hooks/exhaustive-deps
|
| 438 |
+
|
| 439 |
+
const enemyFloats = floats.filter((f) => f.target === "enemy");
|
| 440 |
+
const playerFloats = floats.filter((f) => f.target === "player");
|
| 441 |
+
|
| 442 |
return (
|
| 443 |
<div className="battle">
|
| 444 |
{stageShow !== null && (
|
|
|
|
| 455 |
</div>
|
| 456 |
|
| 457 |
{/* 怪物:左=名字/HP/數值/意圖;右=立繪 + 立繪下方的能量條 */}
|
| 458 |
+
<div className={`enemy${shake.enemy ? " shake" : ""}`}>
|
| 459 |
+
{enemyFloats.length > 0 && <div className="float-layer" aria-hidden="true">{enemyFloats.map((f) => <span key={f.id} className={`dmg-float ${f.cls}`}>{f.text}</span>)}</div>}
|
| 460 |
<div className="enemy-info">
|
| 461 |
<div className="name">{m.name}</div>
|
| 462 |
<Bar value={m.hp} max={m.maxHp} kind="hp" label={`HP ${m.hp}/${m.maxHp}`} />
|
|
|
|
| 500 |
</div>
|
| 501 |
|
| 502 |
{/* 玩家狀態 */}
|
| 503 |
+
<div className={`player-stats${shake.player ? " shake" : ""}`}>
|
| 504 |
+
{playerFloats.length > 0 && <div className="float-layer" aria-hidden="true">{playerFloats.map((f) => <span key={f.id} className={`dmg-float ${f.cls}`}>{f.text}</span>)}</div>}
|
| 505 |
<Bar value={p.hp} max={p.maxHp + p.tempMaxHp} kind="hp" label={`HP ${p.hp}/${p.maxHp + p.tempMaxHp}${p.tempMaxHp ? `(臨時+${p.tempMaxHp})` : ""}`} />
|
| 506 |
{p.classType === "BARBARIAN" ? (
|
| 507 |
<span className="stat">扣血計數(N) {p.n}</span>
|
packages/web/src/styles.css
CHANGED
|
@@ -347,6 +347,8 @@ html, body, #root {
|
|
| 347 |
.card, .node-inner, .bar-fill, .reveal-bar .bar-fill.hp, .pile-card, .pile-arrow, .btn, .pile-ind { transition: none !important; }
|
| 348 |
.card:hover, .pile-card:hover, .btn:hover { transform: none !important; }
|
| 349 |
.ring-pulse, .ring { animation: none !important; }
|
|
|
|
|
|
|
| 350 |
}
|
| 351 |
|
| 352 |
/* 首次遊玩教學覆蓋層 */
|
|
@@ -357,6 +359,23 @@ html, body, #root {
|
|
| 357 |
.tut-list b { color: var(--gold); }
|
| 358 |
.tut-note { background: rgba(217, 178, 90, .12); border-left: 3px solid var(--gold); padding: 8px 12px; border-radius: 6px; font-size: 14px; color: var(--text); margin: 10px 0 14px; }
|
| 359 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
/* 能量:格子狀格槽(亮起數=目前能量) */
|
| 361 |
.enemy-energy { display: flex; flex-direction: column; align-items: center; gap: 5px; }
|
| 362 |
.ee-label { font-size: 13px; color: var(--muted); letter-spacing: .5px; }
|
|
|
|
| 347 |
.card, .node-inner, .bar-fill, .reveal-bar .bar-fill.hp, .pile-card, .pile-arrow, .btn, .pile-ind { transition: none !important; }
|
| 348 |
.card:hover, .pile-card:hover, .btn:hover { transform: none !important; }
|
| 349 |
.ring-pulse, .ring { animation: none !important; }
|
| 350 |
+
.shake { animation: none !important; }
|
| 351 |
+
.dmg-float { animation: floatFade .9s ease forwards !important; left: 50%; top: 38%; transform: translateX(-50%); } /* 改純淡出、不位移 */
|
| 352 |
}
|
| 353 |
|
| 354 |
/* 首次遊玩教學覆蓋層 */
|
|
|
|
| 359 |
.tut-list b { color: var(--gold); }
|
| 360 |
.tut-note { background: rgba(217, 178, 90, .12); border-left: 3px solid var(--gold); padding: 8px 12px; border-radius: 6px; font-size: 14px; color: var(--text); margin: 10px 0 14px; }
|
| 361 |
|
| 362 |
+
/* 傷害飄字 + 受擊抖動 */
|
| 363 |
+
.enemy, .player-stats { position: relative; }
|
| 364 |
+
.float-layer { position: absolute; inset: 0; pointer-events: none; overflow: visible; z-index: 5; }
|
| 365 |
+
.dmg-float { position: absolute; left: 50%; top: 38%; font-size: 30px; font-weight: 900; text-shadow: 0 2px 6px rgba(0,0,0,.7), 0 0 2px rgba(0,0,0,.9); white-space: nowrap; animation: floatUp 1s ease-out forwards; }
|
| 366 |
+
.dmg-float.dmg { color: #ff5a5a; }
|
| 367 |
+
.dmg-float.reflect { color: #c98aff; }
|
| 368 |
+
.dmg-float.heal { color: var(--hp); }
|
| 369 |
+
@keyframes floatUp {
|
| 370 |
+
0% { opacity: 0; transform: translate(-50%, 12px) scale(.7); }
|
| 371 |
+
18% { opacity: 1; transform: translate(-50%, 0) scale(1.15); }
|
| 372 |
+
35% { transform: translate(-50%, -6px) scale(1); }
|
| 373 |
+
100% { opacity: 0; transform: translate(-50%, -48px) scale(1); }
|
| 374 |
+
}
|
| 375 |
+
.shake { animation: hitShake .36s ease; }
|
| 376 |
+
@keyframes hitShake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-5px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }
|
| 377 |
+
@keyframes floatFade { 0%,55% { opacity: 1; } 100% { opacity: 0; } }
|
| 378 |
+
|
| 379 |
/* 能量:格子狀格槽(亮起數=目前能量) */
|
| 380 |
.enemy-energy { display: flex; flex-direction: column; align-items: center; gap: 5px; }
|
| 381 |
.ee-label { font-size: 13px; color: var(--muted); letter-spacing: .5px; }
|