[Critical] [Bug] Preparation mana never deducted — free equipment preparation exploit #353
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?
Severity: Critical
File:
src/lib/game/crafting-actions/preparation-actions.ts(lines 22-41)Description:
startPreparing()validates that the player has enough raw mana (rawMana < costs.manaTotal→ reject), but it never actually deducts the mana from the player's mana store. It only stores the cost inpreparationProgress.manaCostPaidfor tracking/refund purposes.Additionally,
cancelPreparation()(lines 44-58) readsprogress.manaCostPaidand adds it back torawMana. Since nothing was ever deducted, this creates mana from nothing.Impact: Infinite mana generation exploit:
This breaks the entire game economy.
Fix needed:
startPreparing()must calluseManaStore.setState(...)to deduct the mana cost from the player's raw mana pool, similar to howstartFabricatorCrafting()inequipment-crafting.tscorrectly deducts mana.Fix applied.
startPreparing()validated that the player had enough raw mana but never actually deducted it from the mana store. Additionally,cancelPreparation()refundsmanaCostPaid— since nothing was ever deducted, this created mana from nothing.Root cause: Missing
useManaStore.setState()call to deduct mana after validation passes.Fix: Added
useManaStore.setState((s) => ({ rawMana: s.rawMana - costs.manaTotal }));after the mana check instartPreparing().All 1141 tests pass.
Review complete — fix verified.
startPreparing()now correctly deductscosts.manaTotalfromrawManaviauseManaStore.setState()after validation passes. The cancel-then-refund path no longer creates mana from nothing — the net effect of prepare→cancel always leaves the player with ≤ their starting mana.bug-353-preparation-mana.test.ts: 3/3 tests passNo remaining issues.