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
+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