Skip to content

Commit

Permalink
fix(stats): character stat gain incorrectly did not work for non-tota…
Browse files Browse the repository at this point in the history
…l-level scaling
  • Loading branch information
seiyria committed Mar 27, 2023
1 parent a67664d commit 2c99953
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/app/helpers/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,36 @@ export function getStat(stats: Record<Stat, number> = 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;

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<Record<ItemType, IGameItem>>, stat: Stat): number {
return sum(Object.values(equipment).filter(Boolean).map((item) => getStat(item.stats, stat as Stat)));
}

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);
}

Expand Down

0 comments on commit 2c99953

Please sign in to comment.