[priority: high] Discipline tab shows NaN for stat bonuses and perk effects #184
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?
Bug: NaN displayed in Discipline tab for stat bonuses and perks
Description
The Discipline tab shows "NaN" in multiple places:
Stat Bonus: NaN/sec on Max Mana(NaN/sec with perks)— seen on "Raw Mana Mastery"Every 100 XP: +25 Max Mana — +14825.00/secshowing wildly wrong valuesRoot Cause Analysis
The issue is in
/src/lib/game/effects/discipline-effects.tsand/src/lib/game/utils/discipline-math.ts:calculateStatBonus(baseValue, xp, scalingFactor)— Whenxpis 0 (discipline exists but hasn't started accumulating XP), the function correctly returns 0 due to theif (xp <= 0) return 0;guard. However, the perk bonus computation incomputeTotalPerkBonusForStat()indisciplines-utils.tsmay be computing tiers incorrectly.computePerkCurrentEffect()indisciplines-utils.tsline ~47: Forinfiniteperks, it callscalculatePerkTier(xp, perk.threshold, perk.value). When XP is, say, 500 and threshold is 500 with interval 100, tier = floor((500-500)/100) + 1 = 1. That seems right.The real NaN source: The
activeStatBonusinDisciplineCardis computed as:This looks correct. BUT the
perkBonusTotalfromcomputeTotalPerkBonusForStat(perks, displayXp, statBonus.stat)computes the perk bonus for the same stat key as the discipline's statBonus. For disciplines like "Raw Mana Mastery" withstat: 'maxManaBonus', the perks ALSO havestat: 'maxManaBonus'. So the total isactiveStatBonus + perkBonusTotal. This double-counts ifactiveStatBonusalready includes the base stat bonus scaling.The
/seclabel is wrong for flat bonuses: "Raw Mana Mastery" increases Max Mana by a flat amount, not per second. The UI displays{activeStatBonus.toFixed(2)}/sec on {statBonusLabel}— the/secsuffix is hardcoded but many stats (Max Mana, element capacity) are flat bonuses, not rates.Affected Files
src/components/game/tabs/DisciplinesTab.tsx— the/seclabel and stat bonus displaysrc/components/game/tabs/disciplines-utils.ts—computePerkCurrentEffectandcomputeTotalPerkBonusForStatsrc/lib/game/effects/discipline-effects.ts—computeDisciplineEffectsSteps to Reproduce
statBonus.statis undefined or when the calculation produces NaNExpected Behavior
Suggested Fix Direction
isRateflag tostatBonusor derive it from the stat key name/secfor rate-based statsFix applied for issue #184: Discipline tab NaN display
Root Causes Found:
baseValuewasundefined—DisciplineCarddestructuredbaseValuedirectly fromdefinition, butDisciplineDefinitionhas it atstatBonus.baseValue. This madecalculateStatBonus(undefined, xp, ...)produce NaN, which rendered as "NaN" in the UI./seclabel — The stat bonus and perk displays always appended/seceven for flat bonuses (Max Mana, element capacity, enchant power, etc.).computePerkCurrentEffectalways showed/sec— Even for flat perks like "+25 Max Mana".Changes:
src/components/game/tabs/DisciplinesTab.tsxstatBonus.baseValueinstead of undefinedbaseValueisRateStat()detectionactiveStatBonus,perkBonusTotal,statBonusTotalsrc/components/game/tabs/disciplines-utils.tsisRateStat(statKey)helper with explicit rate/non-rate stat key setsregenBonus,disciplineXpBonus,conversion_*prefixmaxManaBonus,elementCap_*,enchantPower,clickManaBonus,meditationCapBonus,studySpeed,golemCapacity,craftingCostReduction,pactAffinityBonus,guardianBoonMultiplier,clickManaMultiplier,regenMultiplier)computePerkCurrentEffect:/seconly appended for rate stats;onceperks no longer show "(unlocked)" suffixVerification: