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,78 @@
|
||||
'use strict';
|
||||
|
||||
// rerollAllInitiatives: bulk d20+initMod for every participant.
|
||||
// Single commit, single log, undo restores old values + order.
|
||||
|
||||
const {
|
||||
makeParticipant,
|
||||
startEncounter,
|
||||
rerollAllInitiatives,
|
||||
} = require('@ttrpg/shared');
|
||||
const { mockCtx, undoLast } = require('./_helpers');
|
||||
|
||||
function part(id, init, initMod, extra = {}) {
|
||||
return makeParticipant({
|
||||
id, name: id, type: initMod !== undefined ? 'monster' : 'character',
|
||||
initiative: init, initMod, maxHp: 20, currentHp: 20, ...extra,
|
||||
});
|
||||
}
|
||||
|
||||
function enc(participants, extra = {}) {
|
||||
return {
|
||||
id: 'e1', name: 'reroll-all-test', participants,
|
||||
isStarted: false, isPaused: false, round: 0,
|
||||
currentTurnParticipantId: null, turnOrderIds: [],
|
||||
...extra,
|
||||
};
|
||||
}
|
||||
|
||||
const find = (e, id) => e.participants.find(p => p.id === id);
|
||||
|
||||
describe('rerollAllInitiatives', () => {
|
||||
test('rolls d20+initMod for every participant; single write', async () => {
|
||||
const { ctx, storage } = mockCtx();
|
||||
const e = enc([part('a', 10, 5), part('b', 8, 2), part('c', 15, 0)]);
|
||||
|
||||
const out = await rerollAllInitiatives(e, ctx);
|
||||
|
||||
for (const id of ['a', 'b', 'c']) {
|
||||
const p = find(out, id);
|
||||
const mod = id === 'a' ? 5 : id === 'b' ? 2 : 0;
|
||||
expect(p.initiative).toBeGreaterThanOrEqual(mod + 1);
|
||||
expect(p.initiative).toBeLessThanOrEqual(mod + 20);
|
||||
}
|
||||
// one write for the whole operation
|
||||
expect(storage.calls.filter(c => c.fn === 'updateDoc' && c.path === 'encounters/e1')).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('undo restores exact old initiatives and order', async () => {
|
||||
const { ctx } = mockCtx();
|
||||
const e = enc([part('a', 10, 5), part('b', 8, 2)]);
|
||||
const orderBefore = [...e.turnOrderIds];
|
||||
|
||||
const out = await rerollAllInitiatives(e, ctx);
|
||||
expect(find(out, 'a').initiative).not.toBe(10);
|
||||
|
||||
const undone = await undoLast(ctx, out);
|
||||
expect(find(undone, 'a').initiative).toBe(10);
|
||||
expect(find(undone, 'b').initiative).toBe(8);
|
||||
expect(undone.turnOrderIds).toEqual(orderBefore);
|
||||
});
|
||||
|
||||
test('inactive participants rerolled too (they stay inactive)', async () => {
|
||||
const { ctx } = mockCtx();
|
||||
const e = enc([part('a', 10, 1), part('b', 9, 1, { isActive: false })]);
|
||||
|
||||
const out = await rerollAllInitiatives(e, ctx);
|
||||
expect(find(out, 'b').isActive).toBe(false);
|
||||
expect(find(out, 'b').initiative).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
|
||||
test('throws during active combat (not paused)', async () => {
|
||||
const { ctx } = mockCtx();
|
||||
let e = enc([part('a', 10, 1)]);
|
||||
e = await startEncounter(e, ctx);
|
||||
|
||||
await expect(rerollAllInitiatives({ ...e, isPaused: false }, ctx)).rejects.toThrow(/paused/i);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user