mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 14:36:13 +01:00
Fix tooltip reporting very close for adjacent diagonal tokens
This commit is contained in:
parent
c0451ee023
commit
75a9e7900a
2 changed files with 8 additions and 14 deletions
|
|
@ -420,10 +420,7 @@ const updateActorsRangeDependentEffects = async token => {
|
|||
// Get required distance and special case 5 feet to test adjacency
|
||||
const required = rangeMeasurement[range];
|
||||
const reverse = type === CONFIG.DH.GENERAL.rangeInclusion.outsideRange.id;
|
||||
const inRange =
|
||||
required === 5
|
||||
? userTarget.isAdjacentWith(token.object)
|
||||
: userTarget.distanceTo(token.object) <= required;
|
||||
const inRange = userTarget.distanceTo(token.object) <= required;
|
||||
if (reverse ? inRange : !inRange) {
|
||||
enabledEffect = false;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
|
|||
const targetPoint = target.center;
|
||||
const thisBounds = this.bounds;
|
||||
const targetBounds = target.bounds;
|
||||
const adjacencyBuffer = canvas.grid.distance * 1.75; // handles diagonals with one square elevation difference
|
||||
|
||||
// Figure out the elevation difference.
|
||||
// This intends to return "grid distance" for adjacent ones, so we add that number if not overlapping.
|
||||
|
|
@ -77,11 +78,12 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
|
|||
const boundsCorrection = canvas.grid.distance / canvas.grid.size;
|
||||
const originRadius = (thisBounds.width * boundsCorrection) / 2;
|
||||
const targetRadius = (targetBounds.width * boundsCorrection) / 2;
|
||||
const distance = canvas.grid.measurePath([
|
||||
const measuredDistance = canvas.grid.measurePath([
|
||||
{ ...originPoint, elevation: 0 },
|
||||
{ ...targetPoint, elevation }
|
||||
]).distance;
|
||||
return Math.floor(distance - originRadius - targetRadius + canvas.grid.distance);
|
||||
const distance = Math.floor(measuredDistance - originRadius - targetRadius + canvas.grid.distance);
|
||||
return Math.min(distance, distance > adjacencyBuffer ? Infinity : canvas.grid.distance);
|
||||
}
|
||||
|
||||
// Compute what the closest grid space of each token is, then compute that distance
|
||||
|
|
@ -99,10 +101,11 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
|
|||
y: targetEdge.y + Math.sign(targetPoint.y - targetEdge.y)
|
||||
})
|
||||
: targetPoint;
|
||||
return canvas.grid.measurePath([
|
||||
const distance = canvas.grid.measurePath([
|
||||
{ ...adjustedOriginPoint, elevation: 0 },
|
||||
{ ...adjustDestinationPoint, elevation }
|
||||
]).distance;
|
||||
return Math.min(distance, distance > adjacencyBuffer ? Infinity : canvas.grid.distance);
|
||||
}
|
||||
|
||||
_onHoverIn(event, options) {
|
||||
|
|
@ -128,8 +131,7 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
|
|||
|
||||
// Determine the actual range
|
||||
const ranges = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.variantRules).rangeMeasurement;
|
||||
const distanceNum = originToken.distanceTo(this);
|
||||
const distanceResult = DhMeasuredTemplate.getRangeLabels(distanceNum, ranges);
|
||||
const distanceResult = DhMeasuredTemplate.getRangeLabels(originToken.distanceTo(this), ranges);
|
||||
const distanceLabel = `${distanceResult.distance} ${distanceResult.units}`.trim();
|
||||
|
||||
// Create the element
|
||||
|
|
@ -181,11 +183,6 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
|
|||
return null;
|
||||
}
|
||||
|
||||
/** Tests if the token is at least adjacent with another, with some leeway for diagonals */
|
||||
isAdjacentWith(token) {
|
||||
return this.distanceTo(token) <= canvas.grid.distance * 1.5;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
_drawBar(number, bar, data) {
|
||||
const val = Number(data.value);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue