From d27b3a1808d91763c03d7afac69d1cc062cff4c7 Mon Sep 17 00:00:00 2001 From: Themis Date: Tue, 1 Oct 2024 14:50:45 +0100 Subject: [PATCH] 156 enhancement expect ranged items not have their range set up dismiss autoranged results in that case (#157) * Handle null item.range values If !short && !long range, handle as always inRange: 'short' * changelog.md * module.json --- Changelog.md | 3 +++ module.json | 4 ++-- scripts/ac5e-helpers.mjs | 12 +++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Changelog.md b/Changelog.md index 2ebbfd2..cd1f335 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,6 @@ +## v11.315331.3 +- Handle items without short and long range set more gracefully. Closes [#156](https://github.com/thatlonelybugbear/automated-conditions-5e/issues/156) +- ## v11.315331.2 - Added French translation, with [#154](https://github.com/thatlonelybugbear/automated-conditions-5e/pull/154) thanks to @CaosFR diff --git a/module.json b/module.json index 9c5f61d..a143ba7 100644 --- a/module.json +++ b/module.json @@ -2,7 +2,7 @@ "id": "automated-conditions-5e", "title": "Automated Conditions 5e", "description": "A small module for Foundry VTT that tries to automate some rolling aspects of the common 5e Conditions.", - "version": "11.315331.2", + "version": "11.315331.3", "authors": [ { "name": "thatlonelybugbear", @@ -68,6 +68,6 @@ "url": "https://github.com/thatlonelybugbear/automated-conditions-5e", "license": "https://raw.githubusercontent.com/thatlonelybugbear/automated-conditions-5e/main/LICENSE", "manifest": "https://github.com/thatlonelybugbear/automated-conditions-5e/releases/latest/download/module.json", - "download": "https://github.com/thatlonelybugbear/automated-conditions-5e/releases/download/v11.315331.2/module.zip", + "download": "https://github.com/thatlonelybugbear/automated-conditions-5e/releases/download/v11.315331.3/module.zip", "changelog": "https://raw.githubusercontent.com/thatlonelybugbear/automated-conditions-5e/main/Changelog.md" } diff --git a/scripts/ac5e-helpers.mjs b/scripts/ac5e-helpers.mjs index 14f2b92..a0fbc61 100644 --- a/scripts/ac5e-helpers.mjs +++ b/scripts/ac5e-helpers.mjs @@ -214,22 +214,20 @@ export function _autoRanged(item, token, target) { range: { value: short, long }, } = item.system; const flags = token.actor?.flags?.[Constants.MODULE_ID]; - const sharpShooter = - flags?.sharpShooter || _hasItem(item.actor, 'sharpshooter'); + const sharpShooter = flags?.sharpShooter || _hasItem(item.actor, 'sharpshooter'); if (sharpShooter && long && actionType == 'rwak') short = long; - const crossbowExpert = - flags?.crossbowExpert || _hasItem(item.actor, 'crossbow expert'); + const crossbowExpert = flags?.crossbowExpert || _hasItem(item.actor, 'crossbow expert'); const distance = target ? _getDistance(token, target) : undefined; const nearbyFoe = settings.autoRangedNearbyFoe && ['rwak', 'rsak'].includes(actionType) && - _findNearby(token, 'opposite', 5, 1) && //hostile vs friendly disposition only + _findNearby(token, 'opposite', 5, 1) && //hostile vs friendly disposition only !crossbowExpert; - const inRange = - distance <= short ? 'short' : distance <= long ? 'long' : false; + const inRange = (!short && !long) || distance <= short ? 'short' : distance <= long ? 'long' : false; //expect short and long being null for some items, and handle these cases as in short range. return { inRange: !!inRange, range: inRange, distance, nearbyFoe }; } + export function _hasItem(actor, itemName) { return actor?.items.some((item) => item?.name