Track the gold Membership Card actually saved #318

Merged
nelsong6 merged 1 commit from claude/membership-card-gold-stats-f120ab into main 2026-08-12 20:43:39 -07:00
nelsong6 commented 2026-08-12 20:40:52 -07:00 (Migrated from github.com)

Membership Card had no stats. It also has no activation callback — it only
overrides ModifyMerchantPrice, and MerchantEntry.Cost re-runs that whole
chain on every read, including the reads the shop UI makes just to draw price
labels. Counting hook calls would be meaningless, so the observed unit is a
completed purchase.

Gold saved

Measured marginally. Inside the purchase prefix the entry's Cost is read
twice, the second time with only this relic's own override short-circuited to
return originalPrice. Both reads run the rest of the chain, so The Courier's
overlapping 20% stays credited to The Courier and the game's own final (int)
truncation applies to both sides. The suppression flag is thread-static, armed
for exactly one nested read, released in a finally.

The snapshot is taken before the purchase runs, not at
Hook.AfterItemPurchased: OnTryPurchaseWrapper restocks or clears the entry
— recalculating _cost for a different item — between charging the player
and announcing the sale. MerchantCardRemovalEntry declares its own cancelable
wrapper instead of calling the shared one, so both get the prefix.
Hook.AfterItemPurchased then supplies the authoritative goldSpent and fires
only on success; a free (ignoreCost) purchase reports zero and records no
saving.

Gold held / earned after purchase

Neither needed a new observation point. The shop pays through
PlayerCmd.LoseGold before RelicCmd.Obtain, so the balance at the existing
obtain hook is already the gold held after buying the relic — stamped once,
never overwritten. Gold earned afterwards is every gain at the established
RunTracker.RecordRunGoldGain boundary while the relic is held; ownership only
begins at the purchase, so that needs no stored cutoff floor and survives
Continue and Core hot reload for free.

Melted wax relics drop out of IterateHookListeners, which makes both the
discount measurement and the held-period gain stop on their own.

Notes

  • Persisted fields are additive, with a Fixtures/RunSchema fixture and
    matching SchemaLoadingTests assertions.
  • Attribution note added to docs/sts2-runtime-primer.md.
  • Four new Harmony targets. Verified installed via [CUS-diag] after hot
    reload (432 classes patched, 0 failed). Because the merchant purchase path
    had already JIT-compiled in that process, behavioral checking needs one full
    game restart first — see the primer's newly-added-target rule.
  • Tests and live behavioral verification not run, per the repo's user-owned
    verification rule. Both projects compile clean.
Membership Card had no stats. It also has no activation callback — it only overrides `ModifyMerchantPrice`, and `MerchantEntry.Cost` re-runs that whole chain on every read, including the reads the shop UI makes just to draw price labels. Counting hook calls would be meaningless, so the observed unit is a completed purchase. ## Gold saved Measured marginally. Inside the purchase prefix the entry's `Cost` is read twice, the second time with only this relic's own override short-circuited to return `originalPrice`. Both reads run the rest of the chain, so The Courier's overlapping 20% stays credited to The Courier and the game's own final `(int)` truncation applies to both sides. The suppression flag is thread-static, armed for exactly one nested read, released in a `finally`. The snapshot is taken before the purchase runs, not at `Hook.AfterItemPurchased`: `OnTryPurchaseWrapper` restocks or clears the entry — recalculating `_cost` for a *different* item — between charging the player and announcing the sale. `MerchantCardRemovalEntry` declares its own cancelable wrapper instead of calling the shared one, so both get the prefix. `Hook.AfterItemPurchased` then supplies the authoritative `goldSpent` and fires only on success; a free (`ignoreCost`) purchase reports zero and records no saving. ## Gold held / earned after purchase Neither needed a new observation point. The shop pays through `PlayerCmd.LoseGold` before `RelicCmd.Obtain`, so the balance at the existing obtain hook is already the gold held after buying the relic — stamped once, never overwritten. Gold earned afterwards is every gain at the established `RunTracker.RecordRunGoldGain` boundary while the relic is held; ownership only begins at the purchase, so that needs no stored cutoff floor and survives Continue and Core hot reload for free. Melted wax relics drop out of `IterateHookListeners`, which makes both the discount measurement and the held-period gain stop on their own. ## Notes - Persisted fields are additive, with a `Fixtures/RunSchema` fixture and matching `SchemaLoadingTests` assertions. - Attribution note added to `docs/sts2-runtime-primer.md`. - Four new Harmony targets. Verified installed via `[CUS-diag]` after hot reload (432 classes patched, 0 failed). Because the merchant purchase path had already JIT-compiled in that process, behavioral checking needs one full game restart first — see the primer's newly-added-target rule. - Tests and live behavioral verification 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!318
No description provided.