Skip to content

Commit

Permalink
156 enhancement expect ranged items not have their range set up dismi…
Browse files Browse the repository at this point in the history
…ss autoranged results in that case (#157)

* Handle null item.range values

If !short && !long range, handle as always inRange: 'short'

* changelog.md

* module.json
  • Loading branch information
thatlonelybugbear authored Oct 1, 2024
1 parent c9a0176 commit d27b3a1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
12 changes: 5 additions & 7 deletions scripts/ac5e-helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d27b3a1

Please sign in to comment.