Phase 3: Split DebugTab.tsx into functional components
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 4m17s

This commit is contained in:
Refactoring Agent
2026-04-24 14:12:52 +02:00
parent 23d0a129c1
commit d6b85d6367
11 changed files with 924 additions and 861 deletions
+19 -26
View File
@@ -5,7 +5,7 @@ import { create } from 'zustand';
import { persist } from 'zustand/middleware';
import { SPELLS_DEF, GUARDIANS, HOURS_PER_TICK } from '../constants';
import type { GameAction, SpellState } from '../types';
import { getFloorMaxHP, getFloorElement, calcDamage } from '../utils';
import { getFloorMaxHP, getFloorElement, calcDamage, canAffordSpellCost, deductSpellCost } from '../utils';
import { usePrestigeStore } from './prestigeStore';
export interface CombatState {
@@ -141,15 +141,16 @@ export const useCombatStore = create<CombatState>()(
) => {
const state = get();
const logMessages: string[] = [];
let totalManaGathered = 0;
if (state.currentAction !== 'climb') {
return { rawMana, elements, logMessages };
return { rawMana, elements, logMessages, totalManaGathered };
}
const spellId = state.activeSpell;
const spellDef = SPELLS_DEF[spellId];
if (!spellDef) {
return { rawMana, elements, logMessages };
return { rawMana, elements, logMessages, totalManaGathered };
}
// Calculate cast speed
@@ -164,28 +165,14 @@ export const useCombatStore = create<CombatState>()(
let floorMaxHP = state.floorMaxHP;
// Process complete casts
while (castProgress >= 1) {
// Check if we can afford the spell
const cost = spellDef.cost;
let canCast = false;
while (castProgress >= 1 && canAffordSpellCost(spellDef.cost, rawMana, elements)) {
// Deduct spell cost
const afterCost = deductSpellCost(spellDef.cost, rawMana, elements);
rawMana = afterCost.rawMana;
elements = afterCost.elements;
totalManaGathered += spellDef.cost.amount;
if (cost.type === 'raw') {
canCast = rawMana >= cost.amount;
if (canCast) rawMana -= cost.amount;
} else if (cost.element) {
const elem = elements[cost.element];
canCast = elem && elem.unlocked && elem.current >= cost.amount;
if (canCast) {
elements = {
...elements,
[cost.element]: { ...elem, current: elem.current - cost.amount },
};
}
}
if (!canCast) break;
// Calculate damage
// Calculate base damage
const floorElement = getFloorElement(currentFloor);
const damage = calcDamage(
{ skills, signedPacts: usePrestigeStore.getState().signedPacts },
@@ -193,8 +180,14 @@ export const useCombatStore = create<CombatState>()(
floorElement
);
// Let gameStore apply damage modifiers (executioner, berserker, spell echo)
const result = onDamageDealt(damage);
rawMana = result.rawMana;
elements = result.elements;
const finalDamage = result.modifiedDamage || damage;
// Apply damage
floorHP = Math.max(0, floorHP - damage);
floorHP = Math.max(0, floorHP - finalDamage);
castProgress -= 1;
// Check if floor is cleared
@@ -223,7 +216,7 @@ export const useCombatStore = create<CombatState>()(
castProgress,
});
return { rawMana, elements, logMessages };
return { rawMana, elements, logMessages, totalManaGathered };
},
resetCombat: (startFloor: number, spellsToKeep: string[] = []) => {