Add ethereal keyword to endTurn
This commit is contained in:
parent
e05663d1c7
commit
8a6a2f7662
2 changed files with 48 additions and 4 deletions
36
src/state.js
36
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,
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Reference in a new issue