Fixed negative base values being ignored

This commit is contained in:
Stefan Zermatten
2021-07-12 14:12:20 +02:00
parent 2ecb0e2671
commit 0d21ab758e
2 changed files with 17 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
export default class EffectAggregator{
constructor(){
this.base = 0;
this.base = undefined;
this.add = 0;
this.mul = 1;
this.min = Number.NEGATIVE_INFINITY;
@@ -20,7 +20,11 @@ export default class EffectAggregator{
switch(effect.operation){
case 'base':
// Take the largest base value
this.base = result > this.base ? result : this.base;
if(Number.isFinite(this.base)){
this.base = Math.max(this.base, result);
} else {
this.base = result;
}
break;
case 'add':
// Add all adds together

View File

@@ -14,7 +14,14 @@ export default function combineStat(stat, aggregator, memo){
}
function getAggregatorResult(stat, aggregator){
let base = Math.max(aggregator.base, stat.baseValue || 0);
let base;
if (!Number.isFinite(aggregator.base)){
base = stat.baseValue || 0;
} else if (!Number.isFinite(stat.baseValue)){
base = aggregator.base || 0;
} else {
base = Math.max(aggregator.base, stat.baseValue);
}
let result = (base + aggregator.add) * aggregator.mul;
if (result < aggregator.min) {
result = aggregator.min;
@@ -28,6 +35,7 @@ function getAggregatorResult(stat, aggregator){
if (!stat.decimal && Number.isFinite(result)){
result = Math.floor(result);
}
console.log({result, agg: aggregator.base, statBase: stat.baseValue, base, name: stat.name, stat});
return result;
}
@@ -137,7 +145,8 @@ function combineSkill(stat, aggregator, memo){
}
// Combine everything to get the final result
let result = (aggregator.base + stat.abilityMod + profBonus + aggregator.add) * aggregator.mul;
let base = aggregator.base || 0;
let result = (base + stat.abilityMod + profBonus + aggregator.add) * aggregator.mul;
if (result < aggregator.min) result = aggregator.min;
if (result > aggregator.max) result = aggregator.max;
if (aggregator.set !== undefined) {