mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 06:26: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
|
// Get required distance and special case 5 feet to test adjacency
|
||||||
const required = rangeMeasurement[range];
|
const required = rangeMeasurement[range];
|
||||||
const reverse = type === CONFIG.DH.GENERAL.rangeInclusion.outsideRange.id;
|
const reverse = type === CONFIG.DH.GENERAL.rangeInclusion.outsideRange.id;
|
||||||
const inRange =
|
const inRange = userTarget.distanceTo(token.object) <= required;
|
||||||
required === 5
|
|
||||||
? userTarget.isAdjacentWith(token.object)
|
|
||||||
: userTarget.distanceTo(token.object) <= required;
|
|
||||||
if (reverse ? inRange : !inRange) {
|
if (reverse ? inRange : !inRange) {
|
||||||
enabledEffect = false;
|
enabledEffect = false;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
|
||||||
const targetPoint = target.center;
|
const targetPoint = target.center;
|
||||||
const thisBounds = this.bounds;
|
const thisBounds = this.bounds;
|
||||||
const targetBounds = target.bounds;
|
const targetBounds = target.bounds;
|
||||||
|
const adjacencyBuffer = canvas.grid.distance * 1.75; // handles diagonals with one square elevation difference
|
||||||
|
|
||||||
// Figure out the elevation difference.
|
// Figure out the elevation difference.
|
||||||
// This intends to return "grid distance" for adjacent ones, so we add that number if not overlapping.
|
// 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 boundsCorrection = canvas.grid.distance / canvas.grid.size;
|
||||||
const originRadius = (thisBounds.width * boundsCorrection) / 2;
|
const originRadius = (thisBounds.width * boundsCorrection) / 2;
|
||||||
const targetRadius = (targetBounds.width * boundsCorrection) / 2;
|
const targetRadius = (targetBounds.width * boundsCorrection) / 2;
|
||||||
const distance = canvas.grid.measurePath([
|
const measuredDistance = canvas.grid.measurePath([
|
||||||
{ ...originPoint, elevation: 0 },
|
{ ...originPoint, elevation: 0 },
|
||||||
{ ...targetPoint, elevation }
|
{ ...targetPoint, elevation }
|
||||||
]).distance;
|
]).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
|
// 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)
|
y: targetEdge.y + Math.sign(targetPoint.y - targetEdge.y)
|
||||||
})
|
})
|
||||||
: targetPoint;
|
: targetPoint;
|
||||||
return canvas.grid.measurePath([
|
const distance = canvas.grid.measurePath([
|
||||||
{ ...adjustedOriginPoint, elevation: 0 },
|
{ ...adjustedOriginPoint, elevation: 0 },
|
||||||
{ ...adjustDestinationPoint, elevation }
|
{ ...adjustDestinationPoint, elevation }
|
||||||
]).distance;
|
]).distance;
|
||||||
|
return Math.min(distance, distance > adjacencyBuffer ? Infinity : canvas.grid.distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onHoverIn(event, options) {
|
_onHoverIn(event, options) {
|
||||||
|
|
@ -128,8 +131,7 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
|
||||||
|
|
||||||
// Determine the actual range
|
// Determine the actual range
|
||||||
const ranges = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.variantRules).rangeMeasurement;
|
const ranges = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.variantRules).rangeMeasurement;
|
||||||
const distanceNum = originToken.distanceTo(this);
|
const distanceResult = DhMeasuredTemplate.getRangeLabels(originToken.distanceTo(this), ranges);
|
||||||
const distanceResult = DhMeasuredTemplate.getRangeLabels(distanceNum, ranges);
|
|
||||||
const distanceLabel = `${distanceResult.distance} ${distanceResult.units}`.trim();
|
const distanceLabel = `${distanceResult.distance} ${distanceResult.units}`.trim();
|
||||||
|
|
||||||
// Create the element
|
// Create the element
|
||||||
|
|
@ -181,11 +183,6 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
|
||||||
return null;
|
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 */
|
/** @inheritDoc */
|
||||||
_drawBar(number, bar, data) {
|
_drawBar(number, bar, data) {
|
||||||
const val = Number(data.value);
|
const val = Number(data.value);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue