Merge branch 'develop' of https://github.com/ThaumRystra/DiceCloud into develop
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import evaluateCalculation from '../../utility/evaluateCalculation.js';
|
||||
|
||||
export default function computeCalculation(computation, node){
|
||||
export default function computeCalculation(computation, node) {
|
||||
const calcObj = node.data;
|
||||
evaluateCalculation(calcObj, computation.scope);
|
||||
aggregateCalculationEffects(node, computation);
|
||||
aggregateCalculationProficiencies(node, computation);
|
||||
}
|
||||
|
||||
export function aggregateCalculationEffects(node, computation){
|
||||
function aggregateCalculationEffects(node, computation) {
|
||||
const calcObj = node.data;
|
||||
delete calcObj.effects;
|
||||
computation.dependencyGraph.forEachLinkedNode(
|
||||
@@ -34,15 +35,60 @@ export function aggregateCalculationEffects(node, computation){
|
||||
},
|
||||
true // enumerate only outbound links
|
||||
);
|
||||
if (calcObj.effects && typeof calcObj.value === 'number'){
|
||||
if (calcObj.effects && typeof calcObj.value === 'number') {
|
||||
calcObj.baseValue = calcObj.value;
|
||||
calcObj.effects.forEach(effect => {
|
||||
if (
|
||||
effect.operation === 'add' &&
|
||||
effect.amount && typeof effect.amount.value === 'number'
|
||||
){
|
||||
) {
|
||||
calcObj.value += effect.amount.value
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function aggregateCalculationProficiencies(node, computation) {
|
||||
const calcObj = node.data;
|
||||
delete calcObj.proficiencies;
|
||||
delete calcObj.proficiency;
|
||||
computation.dependencyGraph.forEachLinkedNode(
|
||||
node.id,
|
||||
(linkedNode, link) => {
|
||||
// Only proficiency links
|
||||
if (link.data !== 'proficiency') return;
|
||||
// That have data
|
||||
if (!linkedNode.data) return;
|
||||
// Ignore inactive props
|
||||
if (linkedNode.data.inactive) return;
|
||||
|
||||
// Collate effects
|
||||
calcObj.proficiencies = calcObj.proficiencies || [];
|
||||
calcObj.proficiencies.push({
|
||||
_id: linkedNode.data._id,
|
||||
name: linkedNode.data.name,
|
||||
value: linkedNode.data.value,
|
||||
});
|
||||
},
|
||||
true // enumerate only outbound links
|
||||
);
|
||||
if (calcObj.proficiencies) {
|
||||
calcObj.proficiency = 0;
|
||||
calcObj.proficiencies.forEach(prof => {
|
||||
if (prof.value > calcObj.proficiency) {
|
||||
calcObj.proficiency = prof.value;
|
||||
}
|
||||
});
|
||||
// Get the character's proficiency bonus to apply
|
||||
let profBonus = computation.scope['proficiencyBonus']?.value || 0;
|
||||
|
||||
// Multiply the proficiency bonus by the actual proficiency
|
||||
if (calcObj.proficiency === 0.49) {
|
||||
// Round down proficiency bonus in the special case
|
||||
calcObj.proficiencyBonus = Math.floor(profBonus * 0.5);
|
||||
} else {
|
||||
calcObj.proficiencyBonus = Math.ceil(profBonus * calcObj.proficiency);
|
||||
}
|
||||
calcObj.value += calcObj.proficiencyBonus;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user