fix: deduct raw mana cost when starting pact ritual (Issue #306)
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m18s
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m18s
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# Circular Dependencies
|
||||
Generated: 2026-06-08T08:31:14.048Z
|
||||
Generated: 2026-06-08T08:59:26.002Z
|
||||
Found: 1 circular chain(s) — these MUST be fixed before modifying involved files.
|
||||
|
||||
1. 1) stores/golem-combat-actions.ts > stores/golem-combat-helpers.ts
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"_meta": {
|
||||
"generated": "2026-06-08T08:31:12.188Z",
|
||||
"generated": "2026-06-08T08:59:24.090Z",
|
||||
"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."
|
||||
},
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { useCombatStore } from '../stores/combatStore';
|
||||
import { useManaStore } from '../stores/manaStore';
|
||||
import { usePrestigeStore } from '../stores/prestigeStore';
|
||||
import { getGuardianForFloor } from '../data/guardian-encounters';
|
||||
import { getFloorMaxHP } from '../utils';
|
||||
import { ErrorCode } from '../utils/result';
|
||||
|
||||
@@ -231,6 +233,7 @@ describe('PrestigeStore', () => {
|
||||
|
||||
describe('startPactRitual', () => {
|
||||
it('should start ritual when conditions met', () => {
|
||||
useManaStore.setState({ rawMana: 100000 });
|
||||
usePrestigeStore.setState({ defeatedGuardians: [10], signedPacts: [], insight: 10000 });
|
||||
const result = usePrestigeStore.getState().startPactRitual(10, 100000);
|
||||
expect(result.success).toBe(true);
|
||||
@@ -271,6 +274,37 @@ describe('PrestigeStore', () => {
|
||||
expect(result.code).toBe(ErrorCode.INSUFFICIENT_MANA);
|
||||
}
|
||||
});
|
||||
|
||||
it('should deduct raw mana cost when starting ritual', () => {
|
||||
// Get the guardian to know the exact pact cost
|
||||
const guardian = getGuardianForFloor(10);
|
||||
expect(guardian).not.toBeNull();
|
||||
const cost = guardian!.pactCost;
|
||||
|
||||
// Set up: give mana store enough raw mana
|
||||
useManaStore.setState({ rawMana: cost + 500 });
|
||||
usePrestigeStore.setState({ defeatedGuardians: [10], signedPacts: [], pactSlots: 1 });
|
||||
|
||||
const manaBefore = useManaStore.getState().rawMana;
|
||||
const result = usePrestigeStore.getState().startPactRitual(10, manaBefore);
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(usePrestigeStore.getState().pactRitualFloor).toBe(10);
|
||||
// Raw mana cost must be deducted
|
||||
expect(useManaStore.getState().rawMana).toBe(manaBefore - cost);
|
||||
});
|
||||
|
||||
it('should NOT deduct raw mana when ritual fails (e.g. not defeated)', () => {
|
||||
useManaStore.setState({ rawMana: 100000 });
|
||||
usePrestigeStore.setState({ defeatedGuardians: [], signedPacts: [], pactSlots: 1 });
|
||||
|
||||
const manaBefore = useManaStore.getState().rawMana;
|
||||
const result = usePrestigeStore.getState().startPactRitual(10, manaBefore);
|
||||
|
||||
expect(result.success).toBe(false);
|
||||
// Mana must NOT be deducted on failure
|
||||
expect(useManaStore.getState().rawMana).toBe(manaBefore);
|
||||
});
|
||||
});
|
||||
|
||||
describe('cancelPactRitual', () => {
|
||||
|
||||
@@ -131,6 +131,11 @@ export const usePrestigeStore = create<PrestigeStore>()(
|
||||
if (rawMana < guardian.pactCost) return fail(ErrorCode.INSUFFICIENT_MANA, `Need ${guardian.pactCost} raw mana, have ${rawMana}`);
|
||||
if (state.pactRitualFloor !== null) return fail(ErrorCode.RITUAL_IN_PROGRESS, `A pact ritual is already in progress for floor ${state.pactRitualFloor}`);
|
||||
|
||||
// Deduct raw mana cost upfront (spec §2.2 step 7)
|
||||
const manaStore = useManaStore.getState();
|
||||
const deducted = manaStore.spendRawMana(guardian.pactCost);
|
||||
if (!deducted) return fail(ErrorCode.INSUFFICIENT_MANA, `Need ${guardian.pactCost} raw mana, have ${manaStore.rawMana}`);
|
||||
|
||||
set({
|
||||
pactRitualFloor: floor,
|
||||
pactRitualProgress: 0,
|
||||
|
||||
Reference in New Issue
Block a user