fix: reject negative amounts in spendRawMana, spendElementMana, addRawMana, addElementMana, and unlockElement to prevent mana exploit
Build and Publish Mana Loop Docker Image / build-and-publish (push) Failing after 1m4s

This commit is contained in:
2026-06-10 21:48:29 +02:00
parent 33be133813
commit 7440b63b2e
3 changed files with 7 additions and 3 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
# Circular Dependencies
Generated: 2026-06-10T11:13:04.646Z
Generated: 2026-06-10T18:50:03.343Z
Found: 3 circular chain(s) — these MUST be fixed before modifying involved files.
1. 1) stores/golem-combat-actions.ts > stores/golem-combat-helpers.ts
+1 -1
View File
@@ -1,6 +1,6 @@
{
"_meta": {
"generated": "2026-06-10T11:13:02.589Z",
"generated": "2026-06-10T18:50:01.087Z",
"description": "Import dependency graph for src/lib/game. Keys are files, values are arrays of files they import.",
"usage": "To find what a file affects, search for its path in the VALUES. To find what a file depends on, look at its KEY entry."
},
+5 -1
View File
@@ -76,6 +76,7 @@ export const useManaStore = create<ManaStore>()(
},
addRawMana: (amount: number, maxMana: number) => {
if (amount < 0) return;
set((state) => ({
rawMana: Math.min(state.rawMana + amount, maxMana),
totalManaGathered: state.totalManaGathered + amount,
@@ -84,7 +85,7 @@ export const useManaStore = create<ManaStore>()(
spendRawMana: (amount: number) => {
const state = get();
if (state.rawMana < amount) return false;
if (amount < 0 || state.rawMana < amount) return false;
set({ rawMana: state.rawMana - amount });
return true;
},
@@ -102,6 +103,7 @@ export const useManaStore = create<ManaStore>()(
unlockElement: (element: string, cost: number) => {
const state = get();
if (cost < 0) return fail(ErrorCode.INVALID_INPUT, `Unlock cost cannot be negative`);
if (state.elements[element]?.unlocked) return fail(ErrorCode.INVALID_INPUT, `Element ${element} is already unlocked`);
if (state.rawMana < cost) return fail(ErrorCode.INSUFFICIENT_MANA, `Need ${cost} raw mana, have ${state.rawMana}`);
@@ -116,6 +118,7 @@ export const useManaStore = create<ManaStore>()(
},
addElementMana: (element: string, amount: number, max: number) => {
if (amount < 0) return;
set((state) => {
const elem = state.elements[element];
if (!elem) return state;
@@ -129,6 +132,7 @@ export const useManaStore = create<ManaStore>()(
const state = get();
const elem = state.elements[element];
if (!elem) return fail(ErrorCode.INVALID_ELEMENT, `Element ${element} does not exist`);
if (amount < 0) return fail(ErrorCode.INVALID_INPUT, `Cannot spend negative mana`);
if (elem.current < amount) return fail(ErrorCode.INSUFFICIENT_MANA, `Need ${amount} ${element} mana, have ${elem.current}`);
set({ elements: { ...state.elements, [element]: { ...elem, current: elem.current - amount } } });