From b7a91abc5ddeab5da87417e9c3538d26cf189231 Mon Sep 17 00:00:00 2001 From: n8n-gitea Date: Wed, 6 May 2026 12:42:25 +0200 Subject: [PATCH] fix: handle undefined state/obj in mana calculations to prevent runtime error --- src/components/game/StatsTab/ManaStatsSection.tsx | 2 +- src/lib/game/store-modules/computed-stats.ts | 2 +- src/lib/game/store/computed.ts | 2 +- src/lib/game/utils/mana-utils.ts | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/game/StatsTab/ManaStatsSection.tsx b/src/components/game/StatsTab/ManaStatsSection.tsx index 31e0a93..be24615 100644 --- a/src/components/game/StatsTab/ManaStatsSection.tsx +++ b/src/components/game/StatsTab/ManaStatsSection.tsx @@ -56,7 +56,7 @@ export function ManaStatsSection({ {(() => { const mw = skillTiers?.manaWell || 1; const tieredSkillId = mw > 1 ? `manaWell_t${mw}` : 'manaWell'; - const level = skills[tieredSkillId] || skills.manaWell || 0; + const level = (skills || {})[tieredSkillId] || (skills || {}).manaWell || 0; const tierMult = getTierMultiplier(tieredSkillId); return `+${fmt(level * 100 * tierMult)} (${level} lvl × 100 × ${tierMult}x tier)`; })()} diff --git a/src/lib/game/store-modules/computed-stats.ts b/src/lib/game/store-modules/computed-stats.ts index efef34d..da861e1 100644 --- a/src/lib/game/store-modules/computed-stats.ts +++ b/src/lib/game/store-modules/computed-stats.ts @@ -29,7 +29,7 @@ export function computeMaxMana( ): number { const pu = state.prestigeUpgrades; const skillMult = (effects as any)?.skillLevelMultiplier || 1; - const base = 100 + (state.skills.manaWell || 0) * 100 * skillMult + (pu.manaWell || 0) * 500; + const base = 100 + ((state.skills || {}).manaWell || 0) * 100 * skillMult + ((pu || {}).manaWell || 0) * 500; // Check if we need to compute effects from equipment if (!effects && state.equipmentInstances && state.equippedInstances) { diff --git a/src/lib/game/store/computed.ts b/src/lib/game/store/computed.ts index 917f03e..a1e184e 100755 --- a/src/lib/game/store/computed.ts +++ b/src/lib/game/store/computed.ts @@ -34,7 +34,7 @@ export function computeMaxMana( const base = 100 + manaWellLevel.level * 100 * manaWellLevel.tierMultiplier + - (pu.manaWell || 0) * 500; + ((pu || {}).manaWell || 0) * 500; const computedEffects = effects ?? computeEffects(skillUpgrades, skillTiers); // Apply MANA_HEART bonus (+10% per loop, compounds) diff --git a/src/lib/game/utils/mana-utils.ts b/src/lib/game/utils/mana-utils.ts index 1db4ccb..0abc383 100644 --- a/src/lib/game/utils/mana-utils.ts +++ b/src/lib/game/utils/mana-utils.ts @@ -12,8 +12,8 @@ export function computeMaxMana( const pu = state.prestigeUpgrades; const base = 100 + - (state.skills.manaWell || 0) * 100 + - (pu.manaWell || 0) * 500; + ((state.skills || {}).manaWell || 0) * 100 + + ((pu || {}).manaWell || 0) * 500; // Apply upgrade effects if provided if (effects) { @@ -34,9 +34,9 @@ export function computeRegen( const temporalBonus = 1 + (pu.temporalEcho || 0) * 0.1; const base = 2 + - (state.skills.manaFlow || 0) * 1 + - (state.skills.manaSpring || 0) * 2 + - (pu.manaFlow || 0) * 0.5; + ((state.skills || {}).manaFlow || 0) * 1 + + ((state.skills || {}).manaSpring || 0) * 2 + + ((pu || {}).manaFlow || 0) * 0.5; let regen = base * temporalBonus; @@ -90,8 +90,8 @@ export function computeEffectiveRegen( export function computeClickMana(state: Pick): number { return ( 1 + - (state.skills.manaTap || 0) * 1 + - (state.skills.manaSurge || 0) * 3 + ((state.skills || {}).manaTap || 0) * 1 + + ((state.skills || {}).manaSurge || 0) * 3 ); }