story: lifeGain event, authoritative gameOver.life, document story seed (night-review #69 notes)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 22:16:56 -05:00
co-authored by Claude Opus 5.5
parent 83a3afef1b
commit 39ffe409cb
5 changed files with 33 additions and 3 deletions
+2
View File
@@ -137,6 +137,8 @@ export function renderEvent(nar: Narrator, ev: StoryEvent, index: number, viewer
if (ev.source) v.source = M(ev.source);
return nar.sentence('playerDamage', index, v, opts.preferSource && ev.source ? ['source'] : []);
}
case 'lifeGain':
return nar.sentence('lifeGain', index, { player: P(ev.seat), source: M(ev.source), n: N(ev.amount), life: N(ev.life) });
case 'effectDamage':
return nar.sentence('effectDamage', index, { source: M(ev.source), target: M(ev.target), n: N(ev.amount) });
case 'destroyed':
+2 -1
View File
@@ -69,11 +69,12 @@ function facts(record: MatchRecord): Facts {
const played: Played[] = [];
const destroyed: string[] = [];
record.events.forEach((e, i) => {
if (e.kind === 'playerDamage') life[e.seat] = Math.max(0, e.life);
if (e.kind === 'playerDamage' || e.kind === 'lifeGain') life[e.seat] = Math.max(0, e.life);
if (e.kind === 'deploy' || e.kind === 'cast') played.push({ id: e.card, seat: e.seat, order: i });
if (e.kind === 'adopt') played.push({ id: e.doctrine, seat: e.seat, order: i });
if (e.kind === 'destroyed') destroyed.push(e.card);
});
if (over.life) { life[0] = Math.max(0, over.life[0]); life[1] = Math.max(0, over.life[1]); }
const winner: Seat = over.winner ?? 0;
return { winner, draw: over.winner === null, loser: winner === 0 ? 1 : 0, reason: over.reason, turns: over.turn, life, played, destroyed };
}
+5
View File
@@ -40,6 +40,11 @@ export const LOG_TEMPLATES = {
'{source} dealt {n} damage to {player}, leaving {life} Notability.',
"{player}'s Notability fell to {life}.",
],
lifeGain: [
'{player} gained {n} Notability from {source} ({life} total).',
'{source} restored {n} Notability to {player}.',
"{player}'s Notability rose to {life} ({source}).",
],
effectDamage: [
'{source} dealt {n} damage to {target}.',
'{target} took {n} damage from {source}.',
+9 -2
View File
@@ -40,6 +40,8 @@ export type StoryEvent =
| { kind: 'block'; seat: Seat; blocker: string; attacker: string; power: number; toughness: number }
/** `seat` is the player who lost Notability; `life` is what remains. */
| { kind: 'playerDamage'; seat: Seat; source?: string; amount: number; life: number }
/** `life` is the new total. */
| { kind: 'lifeGain'; seat: Seat; source: string; amount: number; life: number }
| { kind: 'effectDamage'; source: string; target: string; amount: number }
| { kind: 'destroyed'; card: string }
| { kind: 'tokenCreated'; seat: Seat; source: string; token: string; count: number }
@@ -50,7 +52,8 @@ export type StoryEvent =
| { kind: 'connected'; seat: Seat; a: string; b: string; reason: string }
| { kind: 'rivalry'; a: string; b: string; reason: string }
/** winner null = draw (both players reached 0 at once). */
| { kind: 'gameOver'; winner: Seat | null; reason: GameOverReason; turn: number };
/** `life`: final Notability per seat, authoritative when present (duel-core carries it). */
| { kind: 'gameOver'; winner: Seat | null; reason: GameOverReason; turn: number; life?: [number, number] };
export interface StoryPlayer {
/** Display name of the seat (account display name or "Bot (Normal)"). */
@@ -59,7 +62,11 @@ export interface StoryPlayer {
export interface MatchRecord {
matchId: string;
/** Match seed (the same one the engine used). Drives template variants. */
/**
* Story seed: drives template variants only. NOT the engine seed: a client rendering
* logFor text must never learn the engine seed (it would reveal library order). The host
* derives it, e.g. sha256(engineSeed + ':story'). Recaps after the match may use either.
*/
seed: number | string;
/** Match date, ISO `YYYY-MM-DD`. No clock is read by the story code. */
date: string;
+15
View File
@@ -239,3 +239,18 @@ test('tokens are named plainly and never cited; draws are recorded as inconclusi
assert.match(r.lead, /ended in a draw\./);
assert.ok(r.references.every(x => x.revisionId !== undefined));
});
test('final Notability: lifeGain is tracked, and gameOver.life wins when present', () => {
const ev: StoryEvent[] = [
T(1), { kind: 'deploy', seat: 0, card: 'a2' },
{ kind: 'playerDamage', seat: 0, amount: 18, life: 2 },
{ kind: 'lifeGain', seat: 0, source: 'a2', amount: 10, life: 12 },
{ kind: 'playerDamage', seat: 1, amount: 20, life: 0 },
{ kind: 'gameOver', winner: 0, reason: 'life', turn: 1 },
];
const r = recap({ ...record, events: ev });
assert.equal(r.infobox.result, 'Decisive alice victory'); // 12 vs 0, not Pyrrhic at 2
assert.ok(renderLog({ ...record, events: ev }).lines.some(l => /Notability/.test(l.text) && /12/.test(l.text)));
const withFinal = recap({ ...record, events: [...ev.slice(0, -1), { kind: 'gameOver', winner: 0, reason: 'life', turn: 1, life: [3, 0] }] });
assert.equal(withFinal.infobox.result, 'Pyrrhic alice victory');
});