Attribute Buffer charges to the card or potion that granted them #310

Merged
nelsong6 merged 1 commit from claude/buffer-charge-ledger into main 2026-08-08 23:42:42 -07:00
nelsong6 commented 2026-08-08 23:42:32 -07:00 (Migrated from github.com)

Buffer merges every application into one Counter power, so the first pass (#308) pooled all outcomes onto the power aggregate. That was the wrong precedent.

Free Attack and Free Skill pool because Unrelenting and Pounce are their only sources, so pooling costs them nothing. Buffer has two — the Buffer card and Lucky Tonic — which makes the right analogues PlayerBlockLedger and the Poison ownership ledger, both multi-contributor and both already solved with a contributor ledger documented as heuristic.

Buffer is also more determinate than block, not less: charges are discrete, so a spend consumes exactly one ledger unit rather than an arbitrary slice of a fungible pool.

The ledger

PendingCombat.PlayerBufferLedger holds a BufferChargeChunk per application with its owning card instance or potion sequence. A confirmed spend pops one charge oldest-first and credits that chunk''s owner with the prevented HP.

  • Charges granted are exact, not heuristic — the application event names its source. cardSource for the card; a new LuckyTonic.OnUse frame for the potion, which applies Buffer with a null card source and previously had no way to be told apart from the card.
  • Only the absorb order is a convention, and FIFO matches the Block ledger''s absorb order.
  • Unowned chunks (dev console, anything unattributed) absorb their charge without crediting anyone.

Surfaces

  • CardAggregate gains per-card charges granted/used and HP loss prevented; rows sit alongside the existing per-card block rows.
  • PotionRunHistoryEntry gains the same three. Lucky Tonic had no Buffer rows at all before this — everything it granted was displaying on the Buffer card.
  • The pooled PowerAggregate stays as the power family total, the same layering as per-card block alongside the shared block pool.

Tests

BufferChargeLedgerTests pins the FIFO invariant headlessly through a RunBufferLedgerForTest seam mirroring RunBlockLedgerForTest: oldest-first across mixed card/potion sources, two Buffer copies each owning only their own charges, unspent charges crediting no prevention, and spends past the end of the ledger crediting nobody.

Fixture and SchemaLoadingTests assertions added for the new persisted fields, including that the pooled total stays greater than either contributor alone.

Notes

  • The primer paragraph from #308 that recorded the wrong conclusion is rewritten, so the next agent does not inherit it.
  • LuckyTonic.OnUse is a newly introduced Harmony target, so potion attribution needs one full game restart before it resolves live — the same restart already pending for the BufferPower hooks from #308.
  • Tests not run, per the repo''s user-owned verification rule. Both projects compile clean.
Buffer merges every application into one Counter power, so the first pass ([#308](https://github.com/romaine-life/spirelens/pull/308)) pooled all outcomes onto the power aggregate. That was the wrong precedent. Free Attack and Free Skill pool because Unrelenting and Pounce are their **only** sources, so pooling costs them nothing. Buffer has two — the Buffer card and Lucky Tonic — which makes the right analogues `PlayerBlockLedger` and the Poison ownership ledger, both multi-contributor and both already solved with a contributor ledger documented as heuristic. Buffer is also *more* determinate than block, not less: charges are discrete, so a spend consumes exactly one ledger unit rather than an arbitrary slice of a fungible pool. ## The ledger `PendingCombat.PlayerBufferLedger` holds a `BufferChargeChunk` per application with its owning card instance or potion sequence. A confirmed spend pops one charge oldest-first and credits that chunk''s owner with the prevented HP. - **Charges granted are exact**, not heuristic — the application event names its source. `cardSource` for the card; a new `LuckyTonic.OnUse` frame for the potion, which applies Buffer with a null card source and previously had no way to be told apart from the card. - **Only the absorb order is a convention**, and FIFO matches the Block ledger''s absorb order. - Unowned chunks (dev console, anything unattributed) absorb their charge without crediting anyone. ## Surfaces - `CardAggregate` gains per-card charges granted/used and HP loss prevented; rows sit alongside the existing per-card block rows. - `PotionRunHistoryEntry` gains the same three. **Lucky Tonic had no Buffer rows at all before this** — everything it granted was displaying on the Buffer card. - The pooled `PowerAggregate` stays as the power family total, the same layering as per-card block alongside the shared block pool. ## Tests `BufferChargeLedgerTests` pins the FIFO invariant headlessly through a `RunBufferLedgerForTest` seam mirroring `RunBlockLedgerForTest`: oldest-first across mixed card/potion sources, two Buffer copies each owning only their own charges, unspent charges crediting no prevention, and spends past the end of the ledger crediting nobody. Fixture and `SchemaLoadingTests` assertions added for the new persisted fields, including that the pooled total stays greater than either contributor alone. ## Notes - The primer paragraph from #308 that recorded the wrong conclusion is rewritten, so the next agent does not inherit it. - `LuckyTonic.OnUse` is a newly introduced Harmony target, so potion attribution needs one full game restart before it resolves live — the same restart already pending for the `BufferPower` hooks from #308. - Tests not run, per the repo''s user-owned verification rule. Both projects compile clean.
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!310
No description provided.