M1: Attack damage attribution #5

Closed
opened 2026-04-19 16:27:18 -07:00 by nelsong6 · 1 comment
nelsong6 commented 2026-04-19 16:27:18 -07:00 (Migrated from github.com)

Goal

First real code. Hook card-played and enemy-took-damage events. For every attack card played, record 4 numbers:

  • `raw_damage_intended` — what the card tried to deal (after strength, vulnerability, etc.)
  • `blocked_by_target` — how much enemy block absorbed
  • `overkill` — damage past the enemy's HP (wasted)
  • `effective_damage` — what actually counted (raw − blocked − overkill)

Done when

  • Per-run JSON written at `/mods/CardStats/runs/.json` (or similar)
  • File includes `schema_version: 1` (see #4)
  • File includes both aggregates (`{ STRIKE: { plays, total_intended, total_overkill, ... } }`) and event log (one entry per card-played)
  • Block cards and utility cards show up with `plays` count but null attribution (those come in M2/M3)
  • Manual test: play a run, look at the JSON, numbers tell a coherent story

Out of scope

  • In-game UI (that's M4)
  • Block attribution (#1, M2)
  • Utility closure (M3)
  • Run history integration (M5)

Hook discovery needed

  • Which game method handles "card deals damage to enemy"?
  • Where is enemy block applied in the damage pipeline? (Need to separate incoming damage from absorbed)
  • What Harmony hook style — prefix, postfix, transpiler?

Will require ILSpy exploration of `sts2.dll`.

## Goal First real code. Hook card-played and enemy-took-damage events. For every attack card played, record 4 numbers: - \`raw_damage_intended\` — what the card tried to deal (after strength, vulnerability, etc.) - \`blocked_by_target\` — how much enemy block absorbed - \`overkill\` — damage past the enemy's HP (wasted) - \`effective_damage\` — what actually counted (raw − blocked − overkill) ## Done when - Per-run JSON written at \`<game>/mods/CardStats/runs/<run-id>.json\` (or similar) - File includes \`schema_version: 1\` (see #4) - File includes both aggregates (\`{ STRIKE: { plays, total_intended, total_overkill, ... } }\`) and event log (one entry per card-played) - Block cards and utility cards show up with \`plays\` count but null attribution (those come in M2/M3) - Manual test: play a run, look at the JSON, numbers tell a coherent story ## Out of scope - In-game UI (that's M4) - Block attribution (#1, M2) - Utility closure (M3) - Run history integration (M5) ## Hook discovery needed - Which game method handles \"card deals damage to enemy\"? - Where is enemy block applied in the damage pipeline? (Need to separate incoming damage from absorbed) - What Harmony hook style — prefix, postfix, transpiler? Will require ILSpy exploration of \`sts2.dll\`.
nelsong6 commented 2026-04-19 16:58:39 -07:00 (Migrated from github.com)

M1 done and verified live.

Implementation: Single Harmony postfix on `CombatHistory.Add` routes every `CardPlayFinishedEntry` and `DamageReceivedEntry` (with non-null `CardSource`) into `RunTracker`. The game's own `DamageResult` struct already exposes `BlockedDamage` / `UnblockedDamage` / `OverkillDamage` / `WasTargetKilled` — no need to reverse-engineer the damage pipeline.

Combat boundary behavior (per project requirement): events accumulate in an in-memory pending-combat buffer during combat; commit to the run file only on `CombatManager.CombatEnded`. Mid-combat crashes/aborts don't corrupt the persistent record.

Run metadata: captured on `RunManager.RunStarted` — character, ascension, starting floor. Floor updated on each combat end.

Test (Necrobinder, attack vs. Thieving Hopper):
```json
"STRIKE_NECROBINDER": {
"plays": 1,
"total_intended": 6,
"total_blocked": 0,
"total_overkill": 0,
"total_effective": 6,
"kills": 0
}
```
Strike dealt 6 damage to a full-HP Thieving Hopper. All four attribution numbers correct. File written to `%APPDATA%/SlayTheSpire2/CardStats/runs/.json`.

Commits:

  • 7ca5f63 — initial M1 impl
  • b8b417e — combat-boundary + metadata refactor

Deferred to follow-up issues: M2 block (#1 heuristic), M3 utility closure, M4 UI, run outcome detection.

M1 done and verified live. **Implementation:** Single Harmony postfix on \`CombatHistory.Add\` routes every \`CardPlayFinishedEntry\` and \`DamageReceivedEntry\` (with non-null \`CardSource\`) into \`RunTracker\`. The game's own \`DamageResult\` struct already exposes \`BlockedDamage\` / \`UnblockedDamage\` / \`OverkillDamage\` / \`WasTargetKilled\` — no need to reverse-engineer the damage pipeline. **Combat boundary behavior (per project requirement):** events accumulate in an in-memory pending-combat buffer during combat; commit to the run file only on \`CombatManager.CombatEnded\`. Mid-combat crashes/aborts don't corrupt the persistent record. **Run metadata:** captured on \`RunManager.RunStarted\` — character, ascension, starting floor. Floor updated on each combat end. **Test (Necrobinder, attack vs. Thieving Hopper):** \`\`\`json \"STRIKE_NECROBINDER\": { \"plays\": 1, \"total_intended\": 6, \"total_blocked\": 0, \"total_overkill\": 0, \"total_effective\": 6, \"kills\": 0 } \`\`\` Strike dealt 6 damage to a full-HP Thieving Hopper. All four attribution numbers correct. File written to \`%APPDATA%/SlayTheSpire2/CardStats/runs/<uuid>.json\`. **Commits:** - 7ca5f63 — initial M1 impl - b8b417e — combat-boundary + metadata refactor **Deferred to follow-up issues:** M2 block (#1 heuristic), M3 utility closure, M4 UI, run outcome detection.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
romaine-life/spirelens#5
No description provided.