Skip to content

Commit

Permalink
Disable flanking for GM-hidden tokens (#13472)
Browse files Browse the repository at this point in the history
  • Loading branch information
stwlam authored Feb 2, 2024
1 parent 7b01ad1 commit 680aaac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ interface GamePF2e
TextEditor: typeof TextEditorPF2e;
/** Cached values of frequently-checked settings */
settings: {
automation: {
/** Flanking detection */
flanking: boolean;
};
/** Campaign feat slots */
campaign: {
enabled: boolean;
Expand Down
8 changes: 5 additions & 3 deletions src/module/canvas/token/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ class TokenPF2e<TDocument extends TokenDocumentPF2e = TokenDocumentPF2e> extends
* @param context.reach An optional reach distance specific to this measurement
* @param context.ignoreFlankable Optionally ignore flankable (for flanking highlight) */
canFlank(flankee: TokenPF2e, context: { reach?: number; ignoreFlankable?: boolean } = {}): boolean {
if (this === flankee || !game.settings.get("pf2e", "automation.flankingDetection")) {
const settingDisabled = !game.pf2e.settings.automation.flanking;
const oneIsGMHidden = this.document.hidden || flankee.document.hidden;
if (settingDisabled || oneIsGMHidden || this === flankee) {
return false;
}

Expand Down Expand Up @@ -195,9 +197,9 @@ class TokenPF2e<TDocument extends TokenDocumentPF2e = TokenDocumentPF2e> extends
* @param context.ignoreFlankable Optionally ignore flankable (for flanking position indicator) */
buddiesFlanking(flankee: TokenPF2e, context: { reach?: number; ignoreFlankable?: boolean } = {}): TokenPF2e[] {
if (!this.canFlank(flankee, context)) return [];

const ignoreFlankable = !!context.ignoreFlankable;
return canvas.tokens.placeables
.filter((t) => t !== this && t.canFlank(flankee, R.pick(context, ["ignoreFlankable"])))
.filter((t) => t !== this && t.canFlank(flankee, { ignoreFlankable }))
.filter((b) => this.onOppositeSides(this, b, flankee));
}

Expand Down
3 changes: 3 additions & 0 deletions src/scripts/set-game-pf2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ export const SetGamePF2e = {
game.pf2e = fu.mergeObject(game.pf2e ?? {}, initSafe);
game.pf2e.ConditionManager.initialize();
game.pf2e.settings = {
automation: {
flanking: game.settings.get("pf2e", "automation.flankingDetection"),
},
campaign: {
enabled: game.settings.get("pf2e", "campaignFeats"),
sections: game.settings.get("pf2e", "campaignFeatSections"),
Expand Down

0 comments on commit 680aaac

Please sign in to comment.