Fixed proficiency bonus not applying in actions
This commit is contained in:
@@ -2,9 +2,8 @@ import operator from '/imports/parser/parseTree/operator.js';
|
||||
import { parse } from '/imports/parser/parser.js';
|
||||
import logErrors from './logErrors.js';
|
||||
|
||||
export default function applyEffectsToCalculationParseNode(calcObj, actionContext){
|
||||
if (!calcObj.effects) return;
|
||||
calcObj.effects.forEach(effect => {
|
||||
export default function applyEffectsToCalculationParseNode(calcObj, actionContext) {
|
||||
calcObj.effects?.forEach(effect => {
|
||||
if (effect.operation !== 'add') return;
|
||||
if (!effect.amount) return;
|
||||
if (effect.amount.value === null) return;
|
||||
@@ -17,8 +16,31 @@ export default function applyEffectsToCalculationParseNode(calcObj, actionContex
|
||||
operator: '+',
|
||||
fn: 'add'
|
||||
});
|
||||
} catch (e){
|
||||
} catch (e) {
|
||||
logErrors([e], actionContext)
|
||||
}
|
||||
});
|
||||
// Add the highest proficiency as well
|
||||
let highestProficiency;
|
||||
calcObj.proficiencies?.forEach(proficiency => {
|
||||
if (
|
||||
proficiency.value > highestProficiency
|
||||
|| (highestProficiency === undefined && Number.isFinite(proficiency.value))
|
||||
) {
|
||||
highestProficiency = proficiency.value;
|
||||
}
|
||||
});
|
||||
if (highestProficiency) {
|
||||
try {
|
||||
let profParseNode = parse(highestProficiency.toString());
|
||||
calcObj.parseNode = operator.create({
|
||||
left: calcObj.parseNode,
|
||||
right: profParseNode,
|
||||
operator: '+',
|
||||
fn: 'add'
|
||||
});
|
||||
} catch (e) {
|
||||
logErrors([e], actionContext)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import evaluateCalculation from '/imports/api/engine/computation/utility/evaluat
|
||||
import applyEffectsToCalculationParseNode from '/imports/api/engine/actions/applyPropertyByType/shared/applyEffectsToCalculationParseNode.js';
|
||||
import logErrors from './logErrors.js';
|
||||
|
||||
export default function recalculateCalculation(calc, actionContext, context){
|
||||
export default function recalculateCalculation(calc, actionContext, context) {
|
||||
if (!calc?.parseNode) return;
|
||||
calc._parseLevel = 'reduce';
|
||||
applyEffectsToCalculationParseNode(calc, actionContext);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import resolve, { toString } from '/imports/parser/resolve.js';
|
||||
|
||||
export default function evaluateCalculation(calculation, scope, givenContext){
|
||||
export default function evaluateCalculation(calculation, scope, givenContext) {
|
||||
const parseNode = calculation.parseNode;
|
||||
const fn = calculation._parseLevel;
|
||||
const calculationScope = {...calculation._localScope, ...scope};
|
||||
const {result: resultNode, context} = resolve(fn, parseNode, calculationScope, givenContext);
|
||||
const calculationScope = { ...calculation._localScope, ...scope };
|
||||
const { result: resultNode, context } = resolve(fn, parseNode, calculationScope, givenContext);
|
||||
calculation.errors = context.errors;
|
||||
if (resultNode?.parseType === 'constant'){
|
||||
if (resultNode?.parseType === 'constant') {
|
||||
calculation.value = resultNode.value;
|
||||
} else if (resultNode?.parseType === 'error'){
|
||||
} else if (resultNode?.parseType === 'error') {
|
||||
calculation.value = null;
|
||||
} else {
|
||||
calculation.value = toString(resultNode);
|
||||
|
||||
Reference in New Issue
Block a user