Add ironclad end-of-combat heal passive

This commit is contained in:
Jared Miller 2026-02-25 09:26:14 -05:00
parent dd343be64a
commit ac45cb8758
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
3 changed files with 45 additions and 7 deletions

View file

@ -4,6 +4,7 @@ import { initEnemies } from "./enemies.js";
import { render } from "./render.js";
import {
createRunState,
endCombat,
pickReward,
revealRewards,
skipRewards,
@ -27,19 +28,14 @@ function startNewRun() {
}
function startNextCombat() {
run = { ...run, combatCount: run.combatCount + 1 };
state = createCombatFromRun(run, "jaw_worm");
state = startTurn(state);
revealed = null;
render(state, revealed);
}
function syncRunHp() {
run = { ...run, hp: state.players[0].hp };
}
function handleVictory() {
syncRunHp();
run = endCombat(run, state.players[0].hp);
const result = revealRewards(run);
revealed = result.revealed;
run = result.run;
@ -51,7 +47,7 @@ function handleVictory() {
}
function handleDefeat() {
syncRunHp();
run = { ...run, hp: state.players[0].hp };
state = {
...state,
combat: { ...state.combat, phase: "ended", result: "defeat" },

View file

@ -13,6 +13,14 @@ export function createRunState(character) {
};
}
export function endCombat(run, combatHp) {
let hp = combatHp;
if (run.character === "ironclad") {
hp = Math.min(hp + 1, run.maxHp);
}
return { ...run, hp, combatCount: run.combatCount + 1 };
}
export function revealRewards(run) {
const count = Math.min(3, run.cardRewardsDeck.length);
const revealed = run.cardRewardsDeck.slice(0, count);

View file

@ -3,6 +3,7 @@ import { getAllCards, initCards } from "./cards.js";
import { initEnemies } from "./enemies.js";
import {
createRunState,
endCombat,
pickReward,
revealRewards,
skipRewards,
@ -55,6 +56,39 @@ describe("createRunState", () => {
});
});
describe("endCombat", () => {
test("ironclad heals 1 HP after combat", () => {
const run = { ...createRunState("ironclad"), hp: 8 };
const updated = endCombat(run, 8);
expect(updated.hp).toBe(9);
expect(updated.combatCount).toBe(1);
});
test("ironclad heal does not exceed maxHp", () => {
const run = { ...createRunState("ironclad"), hp: 11, maxHp: 11 };
const updated = endCombat(run, 11);
expect(updated.hp).toBe(11);
});
test("non-ironclad characters do not heal", () => {
const run = {
character: "silent",
hp: 8,
maxHp: 13,
combatCount: 0,
};
const updated = endCombat(run, 8);
expect(updated.hp).toBe(8);
});
test("combatCount increments", () => {
const run = createRunState("ironclad");
const after1 = endCombat(run, run.hp);
const after2 = endCombat(after1, after1.hp);
expect(after2.combatCount).toBe(2);
});
});
describe("rewards", () => {
test("revealRewards removes 3 from rewards deck and returns them", () => {
const run = createRunState("ironclad");