Skip to content

Commit

Permalink
Improve ghost detection
Browse files Browse the repository at this point in the history
  • Loading branch information
dev7355608 committed Apr 1, 2024
1 parent 04ea69d commit 4c36c64
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 14 deletions.
4 changes: 2 additions & 2 deletions scripts/detection-modes/blindsight.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createNameRegExp } from "../utils.js";
import { isGhost } from "./light-perception.mjs";

/**
* The detection mode for Blindsight.
Expand Down Expand Up @@ -60,8 +61,7 @@ export class DetectionModeBlindsight extends DetectionMode {
|| source.document.hasStatusEffect(CONFIG.specialStatusEffects.UNCONSCIOUS)
|| source.document.hasStatusEffect(CONFIG.specialStatusEffects.SLEEP)))
&& !(target instanceof Token && (target.document.hasStatusEffect(CONFIG.specialStatusEffects.BURROW)
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL)
&& !(target.actor?.type === "npc" && target.actor.system.details.type?.value === "undead")
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL) && !isGhost(target.actor)
&& !(source instanceof Token && source.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL))));
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/detection-modes/darkvision.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createNameRegExp } from "../utils.js";
import { isGhost } from "./light-perception.mjs";

/**
* The detection mode for Darkvision.
Expand Down Expand Up @@ -44,8 +45,7 @@ export class DetectionModeDarkvision extends DetectionModeBasicSight {
|| source.document.hasStatusEffect(CONFIG.specialStatusEffects.BURROW)))
&& !(target instanceof Token && (target.document.hasStatusEffect(CONFIG.specialStatusEffects.INVISIBLE)
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.BURROW)
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL)
&& !(target.actor?.type === "npc" && target.actor.system.details.type?.value === "undead")
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL) && !isGhost(target.actor)
&& !(source instanceof Token && source.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL))));
}
}
Expand Down
5 changes: 3 additions & 2 deletions scripts/detection-modes/detect.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isGhost } from "./light-perception.mjs";

/**
* Base class for Detect Magic, Thoughts, etc.
* @abstract
Expand All @@ -24,8 +26,7 @@ export class DetectionModeDetect extends DetectionMode {
|| source.document.hasStatusEffect(CONFIG.specialStatusEffects.SLEEP)
|| source.document.hasStatusEffect(CONFIG.specialStatusEffects.BURROW)))
&& !(target.document.hasStatusEffect(CONFIG.specialStatusEffects.BURROW)
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL)
&& !(target.actor?.type === "npc" && target.actor.system.details.type?.value === "undead")
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL) && !isGhost(target.actor)
&& !(source instanceof Token && source.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL)));
}
}
5 changes: 3 additions & 2 deletions scripts/detection-modes/devils-sight.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { isGhost } from "./light-perception.mjs";

/**
* The detection mode for Devil's Sight.
*/
Expand Down Expand Up @@ -33,8 +35,7 @@ export class DetectionModeDevilsSight extends DetectionMode {
|| source.document.hasStatusEffect(CONFIG.specialStatusEffects.BURROW)))
&& !(target instanceof Token && (target.document.hasStatusEffect(CONFIG.specialStatusEffects.INVISIBLE)
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.BURROW)
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL)
&& !(target.actor?.type === "npc" && target.actor.system.details.type?.value === "undead")
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL) && !isGhost(target.actor)
&& !(source instanceof Token && source.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL))));
}
}
4 changes: 2 additions & 2 deletions scripts/detection-modes/divine-sense.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createNameRegExp } from "../utils.js";
import { isGhost } from "./light-perception.mjs";

/**
* The detection mode for Divine Sense.
Expand Down Expand Up @@ -37,8 +38,7 @@ export class DetectionModeDivineSense extends DetectionMode {
|| source.document.hasStatusEffect(CONFIG.specialStatusEffects.SLEEP)
|| source.document.hasStatusEffect(CONFIG.specialStatusEffects.BURROW)))
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.BURROW)
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL)
&& !(target.actor?.type === "npc" && target.actor.system.details.type?.value === "undead")
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL) && !isGhost(target.actor)
&& !(source instanceof Token && source.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL))) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/detection-modes/ghostly-gaze.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DetectionModeDarkvision } from "./darkvision.mjs";
import { isGhost } from "./light-perception.mjs";

/**
* The detection mode for Ghostly Gaze.
Expand Down Expand Up @@ -28,8 +29,7 @@ export class DetectionModeGhostlyGaze extends DetectionModeDarkvision {
|| source.document.hasStatusEffect(CONFIG.specialStatusEffects.UNCONSCIOUS)
|| source.document.hasStatusEffect(CONFIG.specialStatusEffects.SLEEP)))
&& !(target instanceof Token && (target.document.hasStatusEffect(CONFIG.specialStatusEffects.INVISIBLE)
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL)
&& !(target.actor?.type === "npc" && target.actor.system.details.type?.value === "undead")
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL) && !isGhost(target.actor)
&& !(source instanceof Token && source.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL))));
}
}
34 changes: 32 additions & 2 deletions scripts/detection-modes/light-perception.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createNameRegExp } from "../utils.js";

const detectionModeLightPerceptionClass = ((detectionModeLightPerceptionClass) =>
/**
* The detection mode for Light Perception.
Expand All @@ -21,8 +23,7 @@ const detectionModeLightPerceptionClass = ((detectionModeLightPerceptionClass) =
|| source.document.hasStatusEffect(CONFIG.specialStatusEffects.BURROW)))
&& !(target instanceof Token && (target.document.hasStatusEffect(CONFIG.specialStatusEffects.INVISIBLE)
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.BURROW)
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL)
&& !(target.actor?.type === "npc" && target.actor.system.details.type?.value === "undead")
|| target.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL) && !isGhost(target.actor)
&& !(source instanceof Token && source.document.hasStatusEffect(CONFIG.specialStatusEffects.ETHEREAL))));
}

Expand All @@ -44,3 +45,32 @@ const detectionModeLightPerceptionClass = ((detectionModeLightPerceptionClass) =
)(DetectionModeLightPerception);

export { detectionModeLightPerceptionClass as DetectionModeLightPerception };

export function isGhost(actor) {
if (!(actor && actor.type === "npc" && actor.system.details.type?.value === "undead")) return false;
let hasEtherealness = false;
let hasIncorporealMovement = false;
for (const item of actor.items) {
if (item.type !== "feat") continue;
hasEtherealness ||= ETHEREALNESS_FEAT.test(item.name);
hasIncorporealMovement ||= INCORPOREAL_MOVEMENT_FEAT.test(item.name);
if (hasEtherealness && hasIncorporealMovement) return true;
}
return false;
}

const ETHEREALNESS_FEAT = createNameRegExp({
en: "Etherealness",
de: "Körperlosigkeit",
fr: "Forme éthérée",
es: "Excursion eterea",
"pt-BR": "Forma Etérea",
});

const INCORPOREAL_MOVEMENT_FEAT = createNameRegExp({
en: "Incorporeal Movement",
de: "Körperlose Bewegung",
fr: "Mouvement incorporel",
es: "Movimiento incorpóreo",
"pt-BR": "Movimento Incorpóreo",
});

0 comments on commit 4c36c64

Please sign in to comment.