Fixed crash where null ability broke skills

This commit is contained in:
Stefan Zermatten
2023-03-31 12:19:15 +02:00
parent 2b7851ab32
commit 76a0918a78

View File

@@ -1,12 +1,12 @@
import aggregate from './aggregate/index.js';
export default function computeVariableAsSkill(computation, node, prop){
export default function computeVariableAsSkill(computation, node, prop) {
// Skills are based on some ability Modifier
let ability = computation.scope[prop.ability];
prop.abilityMod = ability?.modifier || 0;
// Inherit the ability's skill effects and proficiencies if skill is not a save
if (prop.skillType !== 'save' && ability){
if (prop.skillType !== 'save' && ability) {
aggregateAbilityEffects({
computation,
skillNode: node,
@@ -21,7 +21,7 @@ export default function computeVariableAsSkill(computation, node, prop){
let profBonus = computation.scope['proficiencyBonus']?.value || 0;
// Multiply the proficiency bonus by the actual proficiency
if(prop.proficiency === 0.49){
if (prop.proficiency === 0.49) {
// Round down proficiency bonus in the special case
profBonus = Math.floor(profBonus * 0.5);
} else {
@@ -37,7 +37,7 @@ export default function computeVariableAsSkill(computation, node, prop){
prop.effects = node.data.effects;
// If there is no aggregator, determine if the prop can hide, then exit
if (!aggregator){
if (!aggregator) {
prop.hide = statBase === undefined &&
prop.proficiency == 0 ||
undefined;
@@ -52,14 +52,14 @@ export default function computeVariableAsSkill(computation, node, prop){
if (aggregator.set !== undefined) {
result = aggregator.set;
}
if (Number.isFinite(result)){
if (Number.isFinite(result)) {
result = Math.floor(result);
}
prop.value = result;
// Advantage/disadvantage
if (aggregator.advantage && !aggregator.disadvantage){
if (aggregator.advantage && !aggregator.disadvantage) {
prop.advantage = 1;
} else if (aggregator.disadvantage && !aggregator.advantage){
} else if (aggregator.disadvantage && !aggregator.advantage) {
prop.advantage = -1;
} else {
prop.advantage = 0;
@@ -76,7 +76,8 @@ export default function computeVariableAsSkill(computation, node, prop){
prop.rollBonuses = aggregator.rollBonus;
}
function aggregateAbilityEffects({computation, skillNode, abilityNode}){
function aggregateAbilityEffects({ computation, skillNode, abilityNode }) {
if (!abilityNode?.id) return;
computation.dependencyGraph.forEachLinkedNode(
abilityNode.id,
(linkedNode, link) => {
@@ -85,15 +86,15 @@ function aggregateAbilityEffects({computation, skillNode, abilityNode}){
if (linkedNode.data.inactive) return;
// Check that the link is a valid effect/proficiency to pass on
// to a skill from its ability
if (link.data === 'effect'){
if (link.data === 'effect') {
if (![
'advantage', 'disadvantage', 'passiveAdd', 'fail', 'conditional'
].includes(linkedNode.data.operation)){
].includes(linkedNode.data.operation)) {
return;
}
}
// Apply the aggregations
let arg = {node: skillNode, linkedNode, link};
let arg = { node: skillNode, linkedNode, link };
aggregate.effect(arg);
aggregate.proficiency(arg);
},