From 8a6a2f7662770246ee819485b38062fabd6f41a0 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Wed, 25 Feb 2026 09:22:02 -0500 Subject: [PATCH] Add ethereal keyword to endTurn --- src/state.js | 36 ++++++++++++++++++++++++++++++++---- src/state.test.js | 16 ++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/state.js b/src/state.js index a5cc1bb..7b87730 100644 --- a/src/state.js +++ b/src/state.js @@ -201,10 +201,24 @@ export function endTurn(state, playerIndex) { // endTurn(state, playerIndex) — new form: marks one player done if (playerIndex === undefined) { const player = state.players[0]; + const retained = []; + const exhausted = []; + const discarded = []; + for (const cardId of player.hand) { + const card = getCard(cardId); + if (card.keywords?.includes("retain")) { + retained.push(cardId); + } else if (card.keywords?.includes("ethereal")) { + exhausted.push(cardId); + } else { + discarded.push(cardId); + } + } const updatedPlayer = { ...player, - hand: [], - discardPile: [...player.discardPile, ...player.hand], + hand: retained, + discardPile: [...player.discardPile, ...discarded], + exhaustPile: [...player.exhaustPile, ...exhausted], }; const players = state.players.map((p, i) => (i === 0 ? updatedPlayer : p)); return { @@ -218,10 +232,24 @@ export function endTurn(state, playerIndex) { if (state.combat.playersReady.includes(playerIndex)) return state; const player = state.players[playerIndex]; + const retained = []; + const exhausted = []; + const discarded = []; + for (const cardId of player.hand) { + const card = getCard(cardId); + if (card.keywords?.includes("retain")) { + retained.push(cardId); + } else if (card.keywords?.includes("ethereal")) { + exhausted.push(cardId); + } else { + discarded.push(cardId); + } + } const updatedPlayer = { ...player, - hand: [], - discardPile: [...player.discardPile, ...player.hand], + hand: retained, + discardPile: [...player.discardPile, ...discarded], + exhaustPile: [...player.exhaustPile, ...exhausted], }; const players = state.players.map((p, i) => i === playerIndex ? updatedPlayer : p, diff --git a/src/state.test.js b/src/state.test.js index 4df948d..9604f55 100644 --- a/src/state.test.js +++ b/src/state.test.js @@ -337,6 +337,22 @@ describe("playCard - exhaust", () => { }); }); +describe("endTurn - ethereal", () => { + test("ethereal cards in hand exhaust at end of turn", () => { + let state = createCombatState("ironclad", "jaw_worm"); + const player = { + ...state.player, + hand: ["strike_r", "carnage", "defend_r"], + }; + state = { ...state, player, players: [player] }; + const next = endTurn(state); + expect(next.player.exhaustPile).toContain("carnage"); + expect(next.player.discardPile).toContain("strike_r"); + expect(next.player.discardPile).toContain("defend_r"); + expect(next.player.hand).toHaveLength(0); + }); +}); + describe("playCard - unplayable", () => { test("unplayable card cannot be played", () => { let state = createCombatState("ironclad", "jaw_worm");