V1.5.0: death saves for characters at 0 HP

- A character at 0 HP is Dying, Stable or Dead. The tallies live on the
  character, so the sheet and the encounter card always agree.
- Death saves are typed in as the d20 showed: 10 or more succeeds, less
  fails, a 1 fails twice, a 20 puts the character back up at 1 HP. Three
  successes make them stable; three failures kill.
- Damage taken at 0 HP is a failed save and ends stable. A blow that leaves
  as much as max HP still to take after reaching 0 kills outright.
- Healing from 0 clears the tallies. The dead cannot be healed; the DM
  revives them at 1 HP.
- A player rolls and stabilises for their own character; the DM for anyone,
  and only the DM sets tallies by hand or revives.
- The party overview, campaign list and quick stats show the state.
- All packages at version 1.5.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 12:37:38 +02:00
co-authored by Claude Opus 5.5
parent 4362b7423e
commit ec48b65481
24 changed files with 666 additions and 33 deletions
+88 -1
View File
@@ -584,7 +584,7 @@ describe('hit points', () => {
const full = (await patch(playerAuth, { currentHp: 9999 })).body.character;
expect(full.currentHp).toBe(level5.sheet.hp.max);
expect((await patch(playerAuth, { currentHp: -50 })).body.character.currentHp).toBe(0);
expect((await patch(playerAuth, { currentHp: -1 })).body.character.currentHp).toBe(0);
await patch(playerAuth, { currentHp: 9999 });
const level1 = (await patch(dmAuth, { level: 1 })).body.character;
@@ -1973,6 +1973,93 @@ describe('temporary hit points', () => {
});
});
describe('death saves', () => {
itIfDb('start at 0 HP, are settled by three of a kind, and end with healing', async () => {
const { dmAuth, playerAuth, campaign } = await setupCampaign('deathsaves');
const heroId = await buildCharacter(campaign.id, playerAuth, 'Fallen');
const ch = `/characters/${heroId}`;
const sheet = async () => (await request(app).get(ch).set(playerAuth)).body.character;
const hp = (auth, currentHp) => request(app).patch(ch).set(auth).send({ currentHp });
const save = (auth, body) => request(app).post(`${ch}/death-saves`).set(auth).send(body);
const max = (await sheet()).sheet.hp.max;
expect((await sheet()).deathSaves).toEqual({ state: 'UP', successes: 0, failures: 0 });
// No saves while standing, and a save is a d20.
expect((await save(playerAuth, { action: 'roll', roll: 12 })).status).toBe(400);
await hp(playerAuth, 0);
expect((await sheet()).deathSaves).toEqual({ state: 'DYING', successes: 0, failures: 0 });
expect((await save(playerAuth, { action: 'roll', roll: 21 })).status).toBe(400);
// 10 and up succeeds, below fails, and a 1 fails twice.
expect((await save(playerAuth, { action: 'roll', roll: 10 })).body.character.deathSaves).toEqual({ state: 'DYING', successes: 1, failures: 0 });
expect((await save(playerAuth, { action: 'roll', roll: 9 })).body.character.deathSaves).toEqual({ state: 'DYING', successes: 1, failures: 1 });
// Being hit while down is a failed save; healing clears the lot.
expect((await hp(dmAuth, -1)).body.character.deathSaves).toEqual({ state: 'DYING', successes: 1, failures: 2 });
expect((await hp(playerAuth, 3)).body.character.deathSaves).toEqual({ state: 'UP', successes: 0, failures: 0 });
// Three successes: stable, at 0 HP, with nothing left to roll.
await hp(playerAuth, 0);
for (const roll of [15, 11, 19]) await save(playerAuth, { action: 'roll', roll });
let now = await sheet();
expect([now.currentHp, now.deathSaves]).toEqual([0, { state: 'STABLE', successes: 0, failures: 0 }]);
expect((await save(playerAuth, { action: 'roll', roll: 12 })).status).toBe(400);
// Damage ends that; a 20 puts them back up with 1 HP.
expect((await hp(dmAuth, -1)).body.character.deathSaves).toEqual({ state: 'DYING', successes: 0, failures: 1 });
now = (await save(playerAuth, { action: 'roll', roll: 20 })).body.character;
expect([now.currentHp, now.deathSaves]).toEqual([1, { state: 'UP', successes: 0, failures: 0 }]);
// Someone else can steady them without a roll.
await hp(playerAuth, 0);
expect((await save(playerAuth, { action: 'stabilize' })).body.character.deathSaves.state).toBe('STABLE');
// The tallies are the DM's to set by hand; a 1 on top of two failures kills.
expect((await save(playerAuth, { action: 'set', successes: 0, failures: 0 })).status).toBe(403);
expect((await save(dmAuth, { action: 'set', successes: 2, failures: 2 })).body.character.deathSaves).toEqual({ state: 'DYING', successes: 2, failures: 2 });
expect((await save(playerAuth, { action: 'roll', roll: 1 })).body.character.deathSaves.state).toBe('DEAD');
// The dead can't be healed or roll; only the DM brings them back.
expect((await hp(playerAuth, max)).status).toBe(400);
expect((await save(playerAuth, { action: 'roll', roll: 20 })).status).toBe(400);
expect((await save(playerAuth, { action: 'revive' })).status).toBe(403);
now = (await save(dmAuth, { action: 'revive' })).body.character;
expect([now.currentHp, now.deathSaves]).toEqual([1, { state: 'UP', successes: 0, failures: 0 }]);
});
itIfDb('follow the character into an encounter, where one huge blow kills outright', async () => {
const { dmAuth, playerAuth, campaign } = await setupCampaign('deathsaves-enc');
const heroId = await buildCharacter(campaign.id, playerAuth, 'Doomed');
const ch = `/characters/${heroId}`;
const max = (await request(app).get(ch).set(playerAuth)).body.character.sheet.hp.max;
const e = `/encounters/${(await request(app).post(`/campaigns/${campaign.id}/encounters`).set(dmAuth).send({ name: 'Last Stand' })).body.encounter.id}`;
const row = (await request(app).post(`${e}/participants`).set(dmAuth).send({ characterId: heroId })).body.participant;
const strike = (currentHp) => request(app).patch(`${e}/participants/${row.id}`).set(dmAuth).send({ currentHp });
const combatant = async () => (await request(app).get(e).set(playerAuth)).body.encounter.participants[0];
// Temp HP that soaks the whole blow keeps them on their feet.
await request(app).patch(ch).set(playerAuth).send({ tempHp: 2 });
await strike(max - 2);
expect((await combatant()).characterCombatInfo.deathSaves.state).toBe('UP');
// Dropped by the DM in the tracker; the player's own save shows there.
await strike(1 - max); // max - 1 past zero: one short of killing outright
expect((await combatant()).characterCombatInfo.deathSaves).toEqual({ state: 'DYING', successes: 0, failures: 0 });
await request(app).post(`${ch}/death-saves`).set(playerAuth).send({ action: 'roll', roll: 4 });
expect((await combatant()).characterCombatInfo.deathSaves).toEqual({ state: 'DYING', successes: 0, failures: 1 });
// The party list carries it too.
const listed = (await request(app).get(`/campaigns/${campaign.id}/characters`).set(dmAuth)).body.characters.find((c) => c.id === heroId);
expect(listed.deathSaves.state).toBe('DYING');
// Healed, then hit for max HP more than they have left.
await strike(max);
await strike(-max);
expect((await combatant()).characterCombatInfo.deathSaves.state).toBe('DEAD');
expect((await strike(5)).status).toBe(400);
});
});
describe('silver and copper', () => {
itIfDb('are kept as separate coins, exchanged at fixed worth, given and rewarded', async () => {
const { dmAuth, playerAuth, campaign } = await setupCampaign('coins');