feat: death-save display, stable-hour recovery, reroll-all initiative
- Player display: death-save pips for dying participants (3 successes / 3 failures), stable shows note without pips - stableRegainHours: 1d4 hours rolled on natural stabilization (3rd save success, manual stabilize, revive-to-stable); cleared on heal, damage-while-stable, inline HP edit, and death; undo/redo round-trips through all paths - Roster writeback: end-of-encounter sync writes stable hours to characters (stable -> hours, conscious -> null); character card badge shows hours; stable state carried into new encounters via buildCharacterParticipant; editor Cur HP > 0 clears - End-combat message corrected: states turn position and round reset while initiative values are kept - Reroll All Initiative: d20 + initMod for every participant in a single write, undoable, pre-combat or paused only; confirmation modal in UI, hidden during active combat - Add All (Roll Init) hoisted to Add Participants header row so it stays visible when the section is collapsed; header title remains the collapse toggle
This commit is contained in:
1 parent
8ecd31d570
commit
8d71f0ba4b
9 files changed
+664
-33
No files matched your search
@@ -0,0 +1,99 @@
|
||||
'use strict';
|
||||
|
||||
// Stable regain hours: stabilization rolls 1d4, persists until healed/revived.
|
||||
// 3rd death save -> stable; manual stabilize -> stable; revive dead -> stable (5e).
|
||||
|
||||
const {
|
||||
makeParticipant,
|
||||
startEncounter,
|
||||
applyHpChange,
|
||||
deathSave,
|
||||
stabilizeParticipant,
|
||||
reviveParticipant,
|
||||
} = require('@ttrpg/shared');
|
||||
const { mockCtx } = require('./_helpers');
|
||||
|
||||
function pc(id, extra = {}) {
|
||||
return makeParticipant({
|
||||
id,
|
||||
name: id,
|
||||
type: 'character',
|
||||
initiative: 10,
|
||||
maxHp: 100,
|
||||
currentHp: 100,
|
||||
...extra,
|
||||
});
|
||||
}
|
||||
|
||||
function enc(participants, extra = {}) {
|
||||
return {
|
||||
id: 'e1',
|
||||
name: 'stable-hours-test',
|
||||
participants,
|
||||
isStarted: false,
|
||||
isPaused: false,
|
||||
round: 0,
|
||||
currentTurnParticipantId: null,
|
||||
turnOrderIds: [],
|
||||
...extra,
|
||||
};
|
||||
}
|
||||
|
||||
const part = e => e.participants.find(p => p.id === 'a');
|
||||
|
||||
async function dyingEnc() {
|
||||
const { ctx } = mockCtx();
|
||||
let e = enc([pc('a')]);
|
||||
e = await startEncounter(e, ctx);
|
||||
e = await applyHpChange(e, 'a', 'damage', 100, ctx);
|
||||
return { e, ctx };
|
||||
}
|
||||
|
||||
describe('stableRegainHours', () => {
|
||||
test('3rd death save success rolls 1d4 and stores stableRegainHours', async () => {
|
||||
const { e, ctx } = await dyingEnc();
|
||||
let out = e;
|
||||
for (let i = 0; i < 3; i++) out = (await deathSave(out, 'a', 'success', ctx)).enc;
|
||||
const p = part(out);
|
||||
expect(p.status).toBe('stable');
|
||||
expect(p.stableRegainHours).toBeGreaterThanOrEqual(1);
|
||||
expect(p.stableRegainHours).toBeLessThanOrEqual(4);
|
||||
});
|
||||
|
||||
test('manual stabilize also rolls and stores hours', async () => {
|
||||
const { e, ctx } = await dyingEnc();
|
||||
const out = await stabilizeParticipant(e, 'a', ctx);
|
||||
const p = part(out);
|
||||
expect(p.status).toBe('stable');
|
||||
expect(p.stableRegainHours).toBeGreaterThanOrEqual(1);
|
||||
expect(p.stableRegainHours).toBeLessThanOrEqual(4);
|
||||
});
|
||||
|
||||
test('heal clears stableRegainHours', async () => {
|
||||
const { e, ctx } = await dyingEnc();
|
||||
let out = await stabilizeParticipant(e, 'a', ctx);
|
||||
expect(part(out).stableRegainHours).toBeGreaterThanOrEqual(1);
|
||||
out = await applyHpChange(out, 'a', 'heal', 5, ctx);
|
||||
expect(part(out).status).toBe('conscious');
|
||||
expect(part(out).stableRegainHours == null).toBe(true);
|
||||
});
|
||||
|
||||
test('reviveParticipant to stable rolls fresh hours', async () => {
|
||||
const { e, ctx } = await dyingEnc();
|
||||
let out = e;
|
||||
for (let i = 0; i < 3; i++) out = (await deathSave(out, 'a', 'fail', ctx)).enc;
|
||||
expect(part(out).status).toBe('dead');
|
||||
out = await reviveParticipant(out, 'a', ctx);
|
||||
const p = part(out);
|
||||
expect(p.status).toBe('stable');
|
||||
expect(p.stableRegainHours).toBeGreaterThanOrEqual(1);
|
||||
expect(p.stableRegainHours).toBeLessThanOrEqual(4);
|
||||
});
|
||||
|
||||
test('dying (not yet stable) has no stableRegainHours', async () => {
|
||||
const { e, ctx } = await dyingEnc();
|
||||
const out = (await deathSave(e, 'a', 'fail', ctx)).enc;
|
||||
expect(part(out).status).toBe('dying');
|
||||
expect(part(out).stableRegainHours == null).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user