Pair per-card energy generated with energy wasted #331

Merged
nelsong6 merged 5 commits from claude/energy-wasted-ledger into main 2026-10-17 09:49:59 -07:00
nelsong6 commented 2026-09-09 23:55:27 -07:00 (Migrated from github.com)

TotalEnergyGenerated has had no counterpart since it landed. A card that
hands you 2 energy on a turn you have nothing left to spend it on scores the
same 2 as one that fuels a kill — the number reads as pure profit and isn't.
This is the same unpaired-stat gap as took/shown, in the energy column.

Approach

Energy is a single fungible pool, so this reuses the provenance ledger the
block stats already run on, under the same stated convention:

  • every arbitrated gain appends an EnergyChunk owned by one source — a card
    instance, a relic id, or nobody;
  • spends consume the ledger FIFO;
  • the leftover the turn-start refill discards is charged LIFO;
  • the player's own refill and orb energy enter untagged, so waste lands on
    them before it lands on a card.

The two seams

Neither is the obvious hook, and both are recorded in the primer:

  • PlayerCombatState.LoseEnergy is the spend point, not the finished card
    play. The pool is already short by a card's cost while that card is still
    resolving, so inferring the spend afterwards would make a mid-resolution gain
    reconcile as LIFO waste rather than a FIFO spend — and blame the wrong
    card.
  • PlayerCombatState.ResetEnergy is the waste point, patched as a prefix
    because the leftover is unreadable afterwards. Hook.AfterEnergyReset fires
    on both branches of CombatManager.SetupPlayerTurn and cannot tell a reset
    from a conserve. ResetEnergy is only reached when the pool is genuinely
    thrown away, so energy conservation needs no handling at all: those chunks
    survive into the next turn and stay spendable.

Energy still in the pool when combat ends is wasted too, alongside the existing
block flush.

Surfaces

  • Card tooltip gains used/wasted rows beside the block rows they mirror.
  • Every relic "energy generated" row gains its wasted counterpart.
  • Deck-view sort menu gains Energy wasted under Cost.

Verification

  • New EnergyLedgerConservationTests pin FIFO-spend / LIFO-waste, that the
    untagged refill absorbs waste instead of blaming a card, and relic ownership.
  • energy-wasted-ledger-run.json fixture plus SchemaLoadingTests cases for
    both new persisted fields, and a case proving older runs default to zero
    wasted rather than failing to load.

Restart note: LoseEnergy and ResetEnergy were unpatched earlier in the
running process, so per the primer's "Newly Added Harmony Targets Need One Full
Restart" finding, behavioral verification needs one full game restart. Hot
reload installed both classes (437 patched, 0 failed).

🤖 Generated with Claude Code

`TotalEnergyGenerated` has had no counterpart since it landed. A card that hands you 2 energy on a turn you have nothing left to spend it on scores the same 2 as one that fuels a kill — the number reads as pure profit and isn't. This is the same unpaired-stat gap as took/shown, in the energy column. ## Approach Energy is a single fungible pool, so this reuses the provenance ledger the block stats already run on, under the same stated convention: - every arbitrated gain appends an `EnergyChunk` owned by one source — a card instance, a relic id, or nobody; - spends consume the ledger FIFO; - the leftover the turn-start refill discards is charged LIFO; - the player's own refill and orb energy enter untagged, so waste lands on them before it lands on a card. ## The two seams Neither is the obvious hook, and both are recorded in the primer: - **`PlayerCombatState.LoseEnergy` is the spend point**, not the finished card play. The pool is already short by a card's cost while that card is still resolving, so inferring the spend afterwards would make a mid-resolution gain reconcile as LIFO *waste* rather than a FIFO *spend* — and blame the wrong card. - **`PlayerCombatState.ResetEnergy` is the waste point**, patched as a prefix because the leftover is unreadable afterwards. `Hook.AfterEnergyReset` fires on *both* branches of `CombatManager.SetupPlayerTurn` and cannot tell a reset from a conserve. `ResetEnergy` is only reached when the pool is genuinely thrown away, so energy conservation needs no handling at all: those chunks survive into the next turn and stay spendable. Energy still in the pool when combat ends is wasted too, alongside the existing block flush. ## Surfaces - Card tooltip gains used/wasted rows beside the block rows they mirror. - Every relic "energy generated" row gains its wasted counterpart. - Deck-view sort menu gains **Energy wasted** under Cost. ## Verification - New `EnergyLedgerConservationTests` pin FIFO-spend / LIFO-waste, that the untagged refill absorbs waste instead of blaming a card, and relic ownership. - `energy-wasted-ledger-run.json` fixture plus `SchemaLoadingTests` cases for both new persisted fields, and a case proving older runs default to zero wasted rather than failing to load. **Restart note:** `LoseEnergy` and `ResetEnergy` were unpatched earlier in the running process, so per the primer's "Newly Added Harmony Targets Need One Full Restart" finding, behavioral verification needs one full game restart. Hot reload installed both classes (437 patched, 0 failed). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
nelsong6 commented 2026-09-09 23:59:26 -07:00 (Migrated from github.com)

Follow-up commit d36eab7: the pair was going in as two extra rows mirroring the block stats, not as the single x/y row #330 established. Card tooltip now renders one ⚡ gained/wasted 8/3 38% row in both full and compact views, dropping the standalone gained row and the derived used row.

The relic side keeps a separate zero-suppressed row on purpose. Only relics whose gain runs through a PlayerEnergyGain attribution window — Happy Flower, Nunchaku, Booming Conch, Gremlin Horn, and the turn-energy relics — put an owned chunk in the ledger. Art of War, Seal of Gold and the max-energy relics (Prismatic Gem, Pumpkin Candle, Spiked Gauntlets, Blood-Soaked Rose) reach the pool by routes that ledger untagged, so pairing them would print 0 wasted and assert something never measured. Suppressing at zero says "not attributed"; pairing can follow once those routes are ledgered.

Follow-up commit `d36eab7`: the pair was going in as two extra rows mirroring the block stats, not as the single `x/y` row #330 established. Card tooltip now renders one `⚡ gained/wasted 8/3 38%` row in both full and compact views, dropping the standalone gained row and the derived used row. The relic side keeps a separate zero-suppressed row on purpose. Only relics whose gain runs through a `PlayerEnergyGain` attribution window — Happy Flower, Nunchaku, Booming Conch, Gremlin Horn, and the turn-energy relics — put an *owned* chunk in the ledger. Art of War, Seal of Gold and the max-energy relics (Prismatic Gem, Pumpkin Candle, Spiked Gauntlets, Blood-Soaked Rose) reach the pool by routes that ledger untagged, so pairing them would print `0 wasted` and assert something never measured. Suppressing at zero says "not attributed"; pairing can follow once those routes are ledgered.
nelsong6 commented 2026-09-11 10:01:37 -07:00 (Migrated from github.com)

18cc2af: the refill is no longer one ownerless block.

MaxEnergy is the character's base folded through Hook.ModifyMaxEnergy, which runs each combat hook listener in turn and passes the running total on. Replaying that fold at both refill points recovers each source's exact contribution, so the allowance enters as ordered chunks — base first, then each max-energy relic in the game's own listener order. Max-energy relics (Prismatic Gem, Pumpkin Candle, Spiked Gauntlets, Blood-Soaked Rose) now own their point of the pool and inherit the existing FIFO-spend / LIFO-waste convention. No invented rule, no proportional fractions.

AddMaxEnergyToCurrent gets the same split — it wastes nothing, but the incoming allowance still needs its sources named.

Remaining unattributed: Art of War and Seal of Gold, which pass through GainEnergy but arm no attribution window.

`18cc2af`: the refill is no longer one ownerless block. `MaxEnergy` is the character's base folded through `Hook.ModifyMaxEnergy`, which runs each combat hook listener in turn and passes the running total on. Replaying that fold at both refill points recovers each source's exact contribution, so the allowance enters as ordered chunks — base first, then each max-energy relic in the game's own listener order. Max-energy relics (Prismatic Gem, Pumpkin Candle, Spiked Gauntlets, Blood-Soaked Rose) now own their point of the pool and inherit the existing FIFO-spend / LIFO-waste convention. No invented rule, no proportional fractions. `AddMaxEnergyToCurrent` gets the same split — it wastes nothing, but the incoming allowance still needs its sources named. Remaining unattributed: Art of War and Seal of Gold, which pass through `GainEnergy` but arm no attribution window.
nelsong6 commented 2026-09-11 10:59:17 -07:00 (Migrated from github.com)

c85afdf: all three remaining unowned routes are ledgered, and the relic row is now a real pair.

Art of War, Seal of Gold and Venerable Tea Set each measure their own gain from a before/after pool delta rather than through an attribution window. Tea Set wasn't in the two I named earlier — it turned up only by enumerating every writer of RelicAggregate.EnergyGenerated.

They arm a new PlayerEnergyLedgerOwner window: names the chunk's owner, credits nothing. An ordinary PlayerEnergyGain window would tag the chunk and double EnergyGenerated; removing their own counting instead would have left those stats asserted only by test seams nothing calls.

With every route owned, a relic's 0 wasted is a measurement rather than an absence of one — so the relic tooltip folds into one generated/wasted row, same convention as the card tooltip and #330. That changed the rendered value for 13 relic tooltips and 1 card tooltip; their assertions moved with it.

Full suite: 2150 passed, 0 failed. One of those 14 failures predated this commit — the card-side pairing in d36eab7 went out without a full suite run.

`c85afdf`: all three remaining unowned routes are ledgered, and the relic row is now a real pair. Art of War, Seal of Gold and **Venerable Tea Set** each measure their own gain from a before/after pool delta rather than through an attribution window. Tea Set wasn't in the two I named earlier — it turned up only by enumerating every writer of `RelicAggregate.EnergyGenerated`. They arm a new `PlayerEnergyLedgerOwner` window: names the chunk's owner, credits nothing. An ordinary `PlayerEnergyGain` window would tag the chunk *and* double `EnergyGenerated`; removing their own counting instead would have left those stats asserted only by test seams nothing calls. With every route owned, a relic's `0 wasted` is a measurement rather than an absence of one — so the relic tooltip folds into one `generated/wasted` row, same convention as the card tooltip and #330. That changed the rendered value for 13 relic tooltips and 1 card tooltip; their assertions moved with it. Full suite: 2150 passed, 0 failed. One of those 14 failures predated this commit — the card-side pairing in `d36eab7` went out without a full suite run.
Sign in to join this conversation.
No reviewers
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!331
No description provided.