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