Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for wall collision when determining flanking buddies in TokenPF2e#isFlanking #16984

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/module/canvas/token/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,27 @@ class TokenPF2e<TDocument extends TokenDocumentPF2e = TokenDocumentPF2e> extends
return this._canControl(user, event);
}

/** Determine wether this token can see another token on the canvas. */
canSee(token: TokenPF2e): boolean {
if (!token.isVisible) return false;
// Shrink bounds by 5 pixels to avoid clipping walls
const tokenBounds = token.mechanicalBounds.pad(-5);
const tokenCenter = token.center;
const tokenPoints = [
tokenCenter,
{ x: tokenBounds.left, y: tokenBounds.top },
{ x: tokenBounds.right, y: tokenBounds.top },
{ x: tokenBounds.right, y: tokenBounds.bottom },
{ x: tokenBounds.left, y: tokenBounds.bottom },
];
const pointSource = new foundry.canvas.sources.PointVisionSource({ object: this });
const polygon = CONFIG.Canvas.polygonBackends.sight.create(this.center, {
source: pointSource,
type: "sight",
});
return tokenPoints.some((p) => polygon.contains(p.x, p.y));
}

/**
* Determine whether this token can flank another—given that they have a flanking buddy on the opposite side
* @param flankee The potentially flanked token
Expand Down Expand Up @@ -211,7 +232,8 @@ class TokenPF2e<TDocument extends TokenDocumentPF2e = TokenDocumentPF2e> extends
(t) =>
(t.actor?.isAllyOf(thisActor) ||
(this.document.isLinked && t.actor === thisActor && t.id !== this.id)) &&
t.canFlank(flankee, R.pick(context, ["ignoreFlankable"])),
t.canFlank(flankee, R.pick(context, ["ignoreFlankable"])) &&
t.canSee(flankee),
);
if (flankingBuddies.length === 0) return false;

Expand Down
Loading