From 2c9995393086ea14287af8e8bfb925a14f22e115 Mon Sep 17 00:00:00 2001 From: Kyle Kemp Date: Mon, 27 Mar 2023 12:15:35 -0500 Subject: [PATCH] fix(stats): character stat gain incorrectly did not work for non-total-level scaling --- src/app/helpers/stats.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/app/helpers/stats.ts b/src/app/helpers/stats.ts index 7aeb1906..7212a3fa 100644 --- a/src/app/helpers/stats.ts +++ b/src/app/helpers/stats.ts @@ -50,7 +50,7 @@ export function getStat(stats: Record = defaultStatsZero(), stat: export function calculateStatFromState(state: any, character: IPlayerCharacter, stat: Stat): number { const statGains: IStatGain[] = state.game.statGains?.[stat] ?? []; - return statGains.reduce((total, statGain) => { + const retVal = statGains.reduce((total, statGain) => { const { levelStat, divisor } = statGain; let value = 0; @@ -58,11 +58,13 @@ export function calculateStatFromState(state: any, character: IPlayerCharacter, if(levelStat === 'lastTotalLevel') { value = character.lastTotalLevel; } else { - value = get(character, `skills.${levelStat}.level`, 0); + value = get(state, `${levelStat}.level`, 0); } return total + Math.floor(value / divisor); }, 0); + + return retVal; } export function calculateStat(equipment: Partial>, stat: Stat): number { @@ -70,12 +72,14 @@ export function calculateStat(equipment: Partial>, s } export function calculateHealthFromState(state: any, character: IPlayerCharacter): number { - return calculateStatFromState(state, character, Stat.HealthBonus) + return 10 + + calculateStatFromState(state, character, Stat.HealthBonus) + calculateStat(character.equipment, Stat.HealthBonus); } export function calculateEnergyFromState(state: any, character: IPlayerCharacter): number { - return calculateStatFromState(state, character, Stat.EnergyBonus) + return 5 + + calculateStatFromState(state, character, Stat.EnergyBonus) + calculateStat(character.equipment, Stat.EnergyBonus); }