2026-07-03 17:59:41 -04:00
|
|
|
// Unified behavior (App main): death flips isActive=false, dead participant
|
|
|
|
|
// removed from active rotation, skipped by nextTurn. deathSave is a manual
|
|
|
|
|
// DM action (button), not tied to rotation. turnOrderIds unchanged on death
|
|
|
|
|
// (only isActive flag flips). Revive (heal from 0) reactivates.
|
|
|
|
|
//
|
|
|
|
|
// Previous "M4: dead stays in rotation" concept reversed by unification.
|
2026-06-30 13:57:55 -04:00
|
|
|
|
|
|
|
|
const shared = require('@ttrpg/shared');
|
|
|
|
|
const { makeParticipant, startEncounter, nextTurn, applyHpChange, deathSave } = shared;
|
|
|
|
|
|
|
|
|
|
function p(id, init, extra = {}) {
|
|
|
|
|
return makeParticipant({
|
|
|
|
|
id, name: id, type: 'monster',
|
|
|
|
|
initiative: init, maxHp: 100, currentHp: 100,
|
|
|
|
|
...extra,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
function pc(id, init, extra = {}) {
|
|
|
|
|
return makeParticipant({
|
|
|
|
|
id, name: id, type: 'character',
|
|
|
|
|
initiative: init, maxHp: 100, currentHp: 100,
|
|
|
|
|
...extra,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
function enc(ps) {
|
|
|
|
|
return { name:'t', participants:ps, isStarted:false, isPaused:false,
|
|
|
|
|
round:0, currentTurnParticipantId:null, turnOrderIds:[] };
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-03 17:59:41 -04:00
|
|
|
describe('unified: death deactivates, dead skipped in rotation', () => {
|
|
|
|
|
test('dead PC not removed from turnOrderIds (stays in list, inactive)', () => {
|
2026-06-30 13:57:55 -04:00
|
|
|
const ps = [pc('a', 20), pc('b', 15), pc('c', 10)];
|
|
|
|
|
let e = enc(ps);
|
|
|
|
|
e = { ...e, ...startEncounter(e).patch };
|
|
|
|
|
const orderBefore = e.turnOrderIds.slice();
|
|
|
|
|
// kill b
|
|
|
|
|
e = { ...e, ...applyHpChange(e, 'b', 'damage', 100).patch };
|
|
|
|
|
expect(e.turnOrderIds).toEqual(orderBefore);
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-03 17:59:41 -04:00
|
|
|
test('dead PC skipped by nextTurn (isActive=false)', () => {
|
2026-06-30 13:57:55 -04:00
|
|
|
const ps = [pc('a', 20), pc('b', 15), pc('c', 10)];
|
|
|
|
|
let e = enc(ps);
|
|
|
|
|
e = { ...e, ...startEncounter(e).patch };
|
|
|
|
|
// kill b
|
|
|
|
|
e = { ...e, ...applyHpChange(e, 'b', 'damage', 100).patch };
|
2026-07-03 17:59:41 -04:00
|
|
|
// advance: a→c (b skipped, inactive)
|
2026-06-30 13:57:55 -04:00
|
|
|
e = { ...e, ...nextTurn(e).patch };
|
2026-07-03 17:59:41 -04:00
|
|
|
expect(e.currentTurnParticipantId).toBe('c');
|
2026-06-30 13:57:55 -04:00
|
|
|
});
|
|
|
|
|
|
2026-07-03 17:59:41 -04:00
|
|
|
test('dead PC deathSave fires on manual call (not via rotation)', () => {
|
2026-06-30 13:57:55 -04:00
|
|
|
const ps = [pc('a', 20), pc('b', 15)];
|
|
|
|
|
let e = enc(ps);
|
|
|
|
|
e = { ...e, ...startEncounter(e).patch };
|
|
|
|
|
// kill b (current = a)
|
|
|
|
|
e = { ...e, ...applyHpChange(e, 'b', 'damage', 100).patch };
|
2026-07-03 17:59:41 -04:00
|
|
|
// b is dead: DM can still fire deathSave (manual action)
|
2026-06-30 13:57:55 -04:00
|
|
|
const r = deathSave(e, 'b', 1);
|
|
|
|
|
expect(r.patch).toBeTruthy();
|
|
|
|
|
const b = r.patch.participants.find(x => x.id === 'b');
|
|
|
|
|
expect(b.deathSaves).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
2026-07-03 17:59:41 -04:00
|
|
|
// D1 unification: shared now matches App main — death flips isActive=false.
|
|
|
|
|
// Dead participant removed from active rotation (skipped by nextTurn).
|
|
|
|
|
test('dead PC auto-set isActive=false by applyHpChange', () => {
|
2026-06-30 13:57:55 -04:00
|
|
|
const ps = [pc('a', 20), pc('b', 15)];
|
|
|
|
|
let e = enc(ps);
|
|
|
|
|
e = { ...e, ...startEncounter(e).patch };
|
|
|
|
|
e = { ...e, ...applyHpChange(e, 'b', 'damage', 100).patch };
|
|
|
|
|
const b = e.participants.find(x => x.id === 'b');
|
2026-07-03 17:59:41 -04:00
|
|
|
expect(b.isActive).toBe(false);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('revive (heal from 0) reactivates participant', () => {
|
|
|
|
|
const ps = [pc('a', 20), pc('b', 15)];
|
|
|
|
|
let e = enc(ps);
|
|
|
|
|
e = { ...e, ...startEncounter(e).patch };
|
|
|
|
|
e = { ...e, ...applyHpChange(e, 'b', 'damage', 100).patch };
|
|
|
|
|
const dead = e.participants.find(x => x.id === 'b');
|
|
|
|
|
expect(dead.isActive).toBe(false);
|
|
|
|
|
// heal b back up
|
|
|
|
|
e = { ...e, ...applyHpChange(e, 'b', 'heal', 50).patch };
|
|
|
|
|
const revived = e.participants.find(x => x.id === 'b');
|
|
|
|
|
expect(revived.isActive).toBe(true);
|
|
|
|
|
expect(revived.currentHp).toBe(50);
|
|
|
|
|
expect(revived.deathSaves).toBe(0);
|
2026-06-30 13:57:55 -04:00
|
|
|
});
|
|
|
|
|
});
|