feat: add encounter roster visibility and kill actions
- persist independent Hide Disabled and Hide Dead encounter controls - keep dead PCs exempt from Hide Dead while allowing Hide Disabled to hide any inactive participant - add confirmed Kill action that sets zero HP, dead, and inactive without deleting - add undoable Heal Full action above Revive - fix random initiative reroll test flake
This commit is contained in:
1 parent
0e7bc7c099
commit
15347bfdc8
5 files changed
+300
-27
No files matched your search
@@ -1,9 +1,9 @@
|
||||
// Generic (non-5e) ruleset: no death saves, negative HP allowed, down status.
|
||||
const shared = require('@ttrpg/shared');
|
||||
const { mockCtx } = require('./_helpers');
|
||||
const { mockCtx, undoLast } = require('./_helpers');
|
||||
const {
|
||||
buildCharacterParticipant, buildMonsterParticipant,
|
||||
startEncounter, applyHpChange, deathSave, markDead, reviveParticipant,
|
||||
startEncounter, applyHpChange, deathSave, markDead, reviveParticipant, healFullParticipant,
|
||||
} = shared;
|
||||
|
||||
function char(id, hp = 100) {
|
||||
@@ -121,25 +121,48 @@ describe('generic ruleset', () => {
|
||||
expect(p.isActive).toBe(true);
|
||||
});
|
||||
|
||||
test('markDead sets status dead (character, stays active)', async () => {
|
||||
test('markDead kills and disables character', async () => {
|
||||
const { ctx } = mockCtx();
|
||||
let e = enc([char('a', 10)]);
|
||||
let e = enc([{ ...char('a', 10), tempHp: 4, deathSaveSuccesses: 2, deathSaveFailures: 1 }]);
|
||||
e = await startEncounter(e, ctx);
|
||||
e = await applyHpChange(e, 'a', 'damage', 10, ctx); // down
|
||||
const newEnc = await markDead(e, 'a', ctx);
|
||||
const p = newEnc.participants.find(x => x.id === 'a');
|
||||
expect(p.status).toBe('dead');
|
||||
expect(p.isActive).toBe(true);
|
||||
expect(p).toMatchObject({
|
||||
currentHp: 0, tempHp: 0, status: 'dead', isActive: false,
|
||||
deathSaveSuccesses: 0, deathSaveFailures: 0, stableRegainHours: null,
|
||||
});
|
||||
|
||||
const undone = await undoLast(ctx, newEnc);
|
||||
expect(undone.participants.find(x => x.id === 'a')).toMatchObject({
|
||||
currentHp: 10, tempHp: 4, status: 'conscious', isActive: true,
|
||||
deathSaveSuccesses: 2, deathSaveFailures: 1,
|
||||
});
|
||||
});
|
||||
|
||||
test('markDead on monster = dead + inactive', async () => {
|
||||
test('healFullParticipant restores dead participant to full, active, conscious; undo restores death', async () => {
|
||||
const { ctx } = mockCtx();
|
||||
let e = enc([{ ...char('a', 20), currentHp: 0, status: 'dead', isActive: false, deathSaveSuccesses: 2, deathSaveFailures: 1, conditions: ['unconscious'], stableRegainHours: 3 }]);
|
||||
const healed = await healFullParticipant(e, 'a', ctx);
|
||||
expect(healed.participants[0]).toMatchObject({
|
||||
currentHp: 20, status: 'conscious', isActive: true,
|
||||
deathSaveSuccesses: 0, deathSaveFailures: 0, stableRegainHours: null,
|
||||
});
|
||||
expect(healed.participants[0].conditions).not.toContain('unconscious');
|
||||
|
||||
const undone = await undoLast(ctx, healed);
|
||||
expect(undone.participants[0]).toMatchObject({ currentHp: 0, status: 'dead', isActive: false, stableRegainHours: 3 });
|
||||
expect(undone.participants[0].conditions).toContain('unconscious');
|
||||
});
|
||||
|
||||
test('markDead on monster = 0 HP + dead + inactive', async () => {
|
||||
const { ctx } = mockCtx();
|
||||
let e = enc([mon('m', 10)]);
|
||||
e = await startEncounter(e, ctx);
|
||||
e = await applyHpChange(e, 'm', 'damage', 5, ctx); // down (5hp)
|
||||
e = await applyHpChange(e, 'm', 'damage', 5, ctx); // 5 HP remain
|
||||
const newEnc = await markDead(e, e.participants[0].id, ctx);
|
||||
const p = newEnc.participants[0];
|
||||
expect(p.status).toBe('dead');
|
||||
expect(p.currentHp).toBe(0);
|
||||
expect(p.isActive).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
@@ -51,7 +51,6 @@ describe('rerollAllInitiatives', () => {
|
||||
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);
|
||||
|
||||
+69
-7
@@ -237,6 +237,7 @@ function expandUndo(entry, currentEnc) {
|
||||
case 'death_save':
|
||||
case 'stabilize':
|
||||
case 'revive':
|
||||
case 'heal_full':
|
||||
case 'mark_dead':
|
||||
case 'deactivate_dead_monster': {
|
||||
// Full death-state restore: currentHp, status, death-save counters,
|
||||
@@ -249,6 +250,7 @@ function expandUndo(entry, currentEnc) {
|
||||
const restoreFields = (vals) => {
|
||||
const out = {};
|
||||
if (vals.currentHp !== undefined) out.currentHp = vals.currentHp;
|
||||
if (vals.tempHp !== undefined) out.tempHp = vals.tempHp;
|
||||
if (vals.status !== undefined) out.status = vals.status;
|
||||
if (vals.deathSaveSuccesses !== undefined) out.deathSaveSuccesses = vals.deathSaveSuccesses;
|
||||
if (vals.deathSaveFailures !== undefined) out.deathSaveFailures = vals.deathSaveFailures;
|
||||
@@ -1206,30 +1208,90 @@ async function reviveParticipant(encounter, participantId, ctx) {
|
||||
return commit(encounter, patch, log, ctx);
|
||||
}
|
||||
|
||||
// markDead: DM manually sets status dead. Both rulesets. Monster = auto-inactive.
|
||||
async function healFullParticipant(encounter, participantId, ctx) {
|
||||
const participant = (encounter.participants || []).find(p => p.id === participantId);
|
||||
if (!participant) throw new Error('Participant not found.');
|
||||
const status = participant.status || (participant.currentHp <= 0 ? 'down' : 'conscious');
|
||||
const oldValues = {
|
||||
currentHp: participant.currentHp,
|
||||
status,
|
||||
deathSaveSuccesses: participant.deathSaveSuccesses || 0,
|
||||
deathSaveFailures: participant.deathSaveFailures || 0,
|
||||
stableRegainHours: participant.stableRegainHours !== undefined ? participant.stableRegainHours : null,
|
||||
isActive: participant.isActive,
|
||||
conditions: [...(participant.conditions || [])],
|
||||
};
|
||||
const updates = {
|
||||
currentHp: participant.maxHp,
|
||||
status: 'conscious',
|
||||
deathSaveSuccesses: 0,
|
||||
deathSaveFailures: 0,
|
||||
stableRegainHours: null,
|
||||
isActive: true,
|
||||
};
|
||||
const updatedParticipants = (encounter.participants || []).map(p =>
|
||||
p.id === participantId ? { ...p, ...withDeathStatusConditions(p, updates) } : p
|
||||
);
|
||||
const newP = updatedParticipants.find(p => p.id === participantId);
|
||||
const newValues = {
|
||||
currentHp: newP.currentHp,
|
||||
status: newP.status,
|
||||
deathSaveSuccesses: newP.deathSaveSuccesses || 0,
|
||||
deathSaveFailures: newP.deathSaveFailures || 0,
|
||||
stableRegainHours: newP.stableRegainHours !== undefined ? newP.stableRegainHours : null,
|
||||
isActive: newP.isActive,
|
||||
conditions: [...(newP.conditions || [])],
|
||||
};
|
||||
return commit(encounter, { participants: updatedParticipants }, {
|
||||
type: 'heal_full', participantId, participantName: participant.name,
|
||||
message: `${participant.name} healed to full (${participant.maxHp} HP)`,
|
||||
delta: { currentHp: participant.maxHp, status: 'conscious', isActive: true },
|
||||
undo: { oldValues, newValues },
|
||||
}, ctx);
|
||||
}
|
||||
|
||||
// markDead: DM manually kills participant. Sets 0 HP + inactive.
|
||||
async function markDead(encounter, participantId, ctx) {
|
||||
const participant = (encounter.participants || []).find(p => p.id === participantId);
|
||||
if (!participant) throw new Error('Participant not found.');
|
||||
if (participant.status === 'dead') return encounter;
|
||||
const oldValues = {
|
||||
currentHp: participant.currentHp,
|
||||
tempHp: participant.tempHp || 0,
|
||||
status: participant.status || 'conscious',
|
||||
deathSaveSuccesses: participant.deathSaveSuccesses || 0,
|
||||
deathSaveFailures: participant.deathSaveFailures || 0,
|
||||
stableRegainHours: participant.stableRegainHours !== undefined ? participant.stableRegainHours : null,
|
||||
isActive: participant.isActive,
|
||||
conditions: [...(participant.conditions || [])],
|
||||
};
|
||||
const updates = { status: 'dead', ...(participant.type === 'monster' ? { isActive: false } : {}) };
|
||||
const updates = {
|
||||
currentHp: 0,
|
||||
tempHp: 0,
|
||||
status: 'dead',
|
||||
deathSaveSuccesses: 0,
|
||||
deathSaveFailures: 0,
|
||||
stableRegainHours: null,
|
||||
isActive: false,
|
||||
};
|
||||
const updatedParticipants = (encounter.participants || []).map(p =>
|
||||
p.id === participantId ? { ...p, ...withDeathStatusConditions(p, updates) } : p
|
||||
);
|
||||
const newP = updatedParticipants.find(p => p.id === participantId);
|
||||
const newValues = {
|
||||
currentHp: newP.currentHp, status: newP.status,
|
||||
isActive: newP.isActive, conditions: [...(newP.conditions || [])],
|
||||
currentHp: newP.currentHp,
|
||||
tempHp: newP.tempHp || 0,
|
||||
status: newP.status,
|
||||
deathSaveSuccesses: newP.deathSaveSuccesses || 0,
|
||||
deathSaveFailures: newP.deathSaveFailures || 0,
|
||||
stableRegainHours: newP.stableRegainHours !== undefined ? newP.stableRegainHours : null,
|
||||
isActive: newP.isActive,
|
||||
conditions: [...(newP.conditions || [])],
|
||||
};
|
||||
return commit(encounter, { participants: updatedParticipants }, {
|
||||
type: 'mark_dead', participantId, participantName: participant.name,
|
||||
message: `${participant.name} marked dead`,
|
||||
delta: { status: 'dead' },
|
||||
message: `${participant.name} killed`,
|
||||
delta: { status: 'dead', currentHp: 0, isActive: false },
|
||||
undo: { oldValues, newValues },
|
||||
}, ctx);
|
||||
}
|
||||
@@ -1389,7 +1451,7 @@ module.exports = {
|
||||
makeEffect, makeParticipant, buildCharacterParticipant, buildMonsterParticipant,
|
||||
startEncounter, nextTurn, togglePause,
|
||||
addParticipant, addParticipants, updateParticipant, removeParticipant,
|
||||
toggleParticipantActive, applyHpChange, setTempHp, deathSave, stabilizeParticipant, reviveParticipant, markDead, toggleCondition,
|
||||
toggleParticipantActive, applyHpChange, setTempHp, deathSave, stabilizeParticipant, reviveParticipant, healFullParticipant, markDead, toggleCondition,
|
||||
addEffect, updateEffect, removeEffect,
|
||||
reorderParticipants, endEncounter, rerollAllInitiatives,
|
||||
activateDisplay, clearDisplay, toggleHidePlayerHp,
|
||||
|
||||
Reference in new issue
Block a user