Bug: Discipline conversion can push mana negative when multiple conversions share a source #223
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bug Description
When multiple discipline conversion effects drain from the same source mana type (e.g. raw or fire) in the same tick, each conversion checks affordability independently but applies drains sequentially. This means N conversions can each pass the
rawMana >= draincheck individually, but collectively drain more than available.Code Location
src/lib/game/stores/gameStore.tslines 214-236:Impact
High. Raw mana or element mana can go below 0 when multiple conversion disciplines are active. Negative mana bypasses the
spendRawManaguard (rawMana < amountreturns true when rawMana is -5 and amount is 3), allowing further spending and corrupting game state.Fix Required
Either:
rawMana = Math.max(0, rawMana - conversionAmount)Fixed: Added re-check of remaining mana after initial validation in the discipline conversion loop in gameStore.ts. Also added Math.max(0, ...) guard on element mana deductions to prevent negative values when multiple disciplines share a source.