From 66f66d1d85546013b569a2b9bc03143708f5ede6 Mon Sep 17 00:00:00 2001 From: Forien Date: Sun, 10 Dec 2023 13:46:49 +0100 Subject: [PATCH] fixed `ammoRange` typo and added graceful fallback to not block opening Actor Sheet --- modules/item/item-wfrp4e.js | 21 +++++++++++++-------- static/lang/en.json | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/modules/item/item-wfrp4e.js b/modules/item/item-wfrp4e.js index 18185d66e..c2e9166c2 100644 --- a/modules/item/item-wfrp4e.js +++ b/modules/item/item-wfrp4e.js @@ -1207,14 +1207,19 @@ export default class ItemWfrp4e extends Item { value *= 2; else // If the range modification is a formula (supports +X -X /X *X) { - try // Works for + and - - { - ammoValue = (0, eval)(ammoValue); - value = Math.floor((0, eval)(value + ammoValue)); - } - catch // if *X and /X - { // eval (50 + "/5") = eval(50/5) = 10 - value = Math.floor((0, eval)(value + ammoRange)); + try { + try // Works for + and - + { + ammoValue = (0, eval)(ammoValue); + value = Math.floor((0, eval)(value + ammoValue)); + } + catch // if *X and /X + { // eval (50 + "/5") = eval(50/5) = 10 + value = Math.floor((0, eval)(value + ammoValue)); + } + } catch (error) { + ui.notifications.error(game.i18n.format("ERROR.AMMO_MODS", {type})); + console.error(error, {value, type, item: this, ammo: this.ammo}); } } return value diff --git a/static/lang/en.json b/static/lang/en.json index 31b946864..6066fa052 100644 --- a/static/lang/en.json +++ b/static/lang/en.json @@ -1373,6 +1373,7 @@ "APPLYREQUESTOWNER": "Apply Effect command sent to owner", "EFFECT.Applied" : "{name} applied to", "ERROR.EFFECT": "Error when running effect {effect}, please see the console (F12)", + "ERROR.AMMO_MODS": "Ammunition '{type}' value could not be resolved, aborting. Check console (F12) for details`", "SinReduced": "Sin reduced by 1", "TargetingCancelled": "Targeting canceled: Already opposing a test", "ERROR.Property": "WFRP4e Rolls must specify the item property",