Skip to content

A hazard's damage that an AI GM rolls and then sends for a creature lands on it, where the call was answered "already applied" and the creature lost nothing - #1074

Open
Smoebo wants to merge 1 commit into
Lebbitheplow:mainfrom
Smoebo:fix/hazard-total-not-swallowed
Open

Smoebo wants to merge 1 commit into
Lebbitheplow:mainfrom
Smoebo:fix/hazard-total-not-swallowed

Conversation

@Smoebo

@Smoebo Smoebo commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

This is the small pull request #1073 says will follow. It is on main, apart from the roll-record door (#915), and does not build what #1073 proposes.

What a table sees

On an AI GM's turn the tools offer two calls for harm no creature's attack deals: request_roll of kind damage, then apply_damage with that total. Run on main and on this commit:

Before Now
The total sent for a creature by its id, source: "hazard" answered ok, "That damage was already applied when the roll resolved", and the creature lost nothing (100 of 100 after a 5) lands once (95 of 100)
The same number sent a second time refused by the number gate the same
The same call with the creature named by its display name landed (95 of 100) the same
A rolled total sent for a character (5 poison), on the after-fight card 5 taken, and 5 dealt on that character's own line 5 taken, 0 dealt

So the damage was lost when the model named the creature by its id and landed when it used the name.

The cause

rolls.applied with rolls.target_enemy_id says "the server landed this roll's damage on that enemy". The engine writes it as a blow's dice resolve (landRoll). The double-apply guard in damage_enemy (encounter-tools.ts) reads it, and answers "already applied" for a number equal to a blow landed on that creature this turn. The after-fight card (encounter-summary.ts) reads it as damage dealt by the character the roll was made for.

The number gate (ai-gate.ts number) used the same stamp for something else: "this total has paid for a bare number". It wrote whatever the number was sent for into the target column: the text sent as enemyId, a character's id, or "split". Sent for a creature by its id, the roll the gate had just stamped for this very call was what the guard then found. And the card counted any total stamped this way as a blow landed on an enemy.

The fix

A roll that pays for what an AI GM sends is stamped with markRollPaid (src/lib/db/rolls.ts), which marks it spent and names no target. Both of the gate's stamps use it: the total behind a bare number, and the check behind a trap's hold lifted (escapeRolled, which wrote escape:<trap> into the same column; nothing read that text). The target column is now written only where the server lands a blow itself (landRoll, and the opportunity attack's own stamp), so its readers read what they were written for. The guard's code is not touched.

What else changes

All of it follows from a paid total no longer naming a target:

  • The after-fight card credits no character for a total rolled with request_roll and then sent. Before, a total rolled with a characterId and sent for a creature by name, or shared out through targets, was counted on that character's line. By the tools' own rule this is harm no creature's attack deals, and a fall's or a trap's dice are on nobody's line already. The party's total is not lower for it: it never reads less than the enemies lost. The targets case was run before and after (5 on the line, then 0, the total 5 both times); the by-name case is read in the code.
  • The dice evidence Ask reads (ask.ts) tagged such a total ", applied", also when the guard had swallowed it. It now carries no tag, as a fall's dice carry none. Read in the code, not run.
  • Two hazards that come to the same total, sent for one creature by its id in one turn, both land, where neither did. Read in the code, not run.

Not covered

Tests

  • scripts/test-enforce-ai-gates.mjs, three new cases.
    • Two fail on the source as it was (run four times, the same two each time): the two-call path lands once, the paying roll names no target, and the same number again is refused by the number gate; a rolled total sent for a character counts nothing as dealt on the fight's card.
    • One passes before and after, to pin what is left as it was: after pc_attack lands a blow, its number sent bare is refused by the number gate, and dice for the same creature that come to the same total are answered "already applied".
  • scripts/test-ai-gate-in-turn.mjs (the net's hold lifted after a rolled check), test-encounter-summary, test-enforce-roll-record, test-name-lookups and test-text-comparisons pass on this commit.
  • npm test on Windows, on this commit: 1,263 of 1,268 files passed. Four of the five that failed fail on main on my machine for its own setup: test-backup-in-app and test-backup-restore (Git Bash's tar reads C: as a host), test-enforce-last-combat and test-enforce-monster-blocks (no sqlite3 command). The fifth, test-enforce-narrator, failed one case ("An agent program's narration is checked against the live encounter", 201 where it expects 409). Run alone it failed 1 time in 3 on this commit and 3 times in 8 on the source as it was, so it comes and goes on main too; I did not look for its cause.
  • npx tsc --noEmit -p ., npm run dead-code, lint on the changed files and npm run build pass on this commit.
  • A reader went through the first version cold. It found no path that still loses the reported damage and none that lands damage twice, confirmed by its own runs the two cases that fail on the old source, and named the same-total case and the spent-roll case above, both as they were on main. It corrected the wording of two comments, the third test's title and the commit message, and found the two other readers of the stamp (ask.ts, authored-spend-more.ts swarmDieBack) now listed above and in the code. The corrected version was not read cold again.

Checks

  • npm run lint, npm test and npm run build pass, and the change has a test that fails without it. (Lint on the changed files. npm test: see Tests.)
  • Anything a player sees has screenshots below: the website and the app, day and night themes, phone width. (None. No screen changes.)
  • No hostnames, IP addresses, logs, keys, .env files or players' names in the code, the tests or this description.

Settings, options and controls

  • This adds no new setting, toggle, option or other control.

🤖 Generated with Claude Code

…ands on it, where the call was answered "already applied" and the creature lost nothing

On an AI GM's turn the tools offer two calls for harm no creature's attack
deals: request_roll of kind damage, then apply_damage with that total. Sent
for a creature by its id, the second call answered ok with "That damage was
already applied when the roll resolved" and took no hit points.

The number gate (ai-gate.ts) stamped the roll that paid for a bare number
with whatever the number was sent for, in the column that says which enemy
the server landed a blow on. The double-apply guard in damage_enemy reads
that column, so it took the roll the gate had just stamped for this very
call as a blow already landed. The after-fight card reads it too, and
counted any total stamped this way as damage dealt by the character the
roll was made for: poison a hero took read as damage that hero dealt.

A roll that pays for what an AI GM sends is now stamped with markRollPaid,
which names no target: the total behind a bare number, and the check behind
a trap's hold lifted. The target column is written only where the server
lands a blow itself, so its readers read what they were written for. The
guard is unchanged: harm the server rolls that comes to the same total as a
blow already landed on that creature this turn is still answered "already
applied".

Tests (test-enforce-ai-gates): the two-call path lands once and the same
number again is refused by the number gate; a rolled total sent for a
character counts nothing as dealt on the fight's card; and, pinned as it
was, a landed blow's number sent bare is refused and dice that come to the
same total are answered "already applied".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant