Skip to content

Commit

Permalink
fix: prevent errors due to missing critical object
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosFdez committed Oct 10, 2021
1 parent 4d7a5b6 commit 1c3b8c4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions betterrolls5e/scripts/migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export async function migrate() {
if (!brFlags) return;

const critRange = brFlags.critRange?.value;
if (critRange && !item.data.data.critical.threshold) {
if (critRange && !item.data.data.critical?.threshold) {
updates["data.critical.threshold"] = Number(critRange) || null;
}

const critDamage = brFlags.critDamage?.value;
if (critDamage && !item.data.data.critical.critDamage) {
if (critDamage && !item.data.data.critical?.critDamage) {
updates["data.critical.damage"] = item.data.data.damage.parts[critDamage]?.[0];
}

Expand Down
2 changes: 1 addition & 1 deletion betterrolls5e/scripts/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export class ItemUtils {
if (!item) return null;

// Get item crit, favoring the smaller between it and the actor's crit threshold
let itemCrit = item.data.data.critical.threshold || 20;
let itemCrit = item.data.data.critical?.threshold || 20;
const characterCrit = ActorUtils.getCritThreshold(item.actor, item.data.type);
return Math.min(20, characterCrit, itemCrit);
}
Expand Down

0 comments on commit 1c3b8c4

Please sign in to comment.