diff --git a/ChangeLog.md b/ChangeLog.md index 095e7cf..c2d2237 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,6 @@ # v3.14.2 -* Dnd5e: Temporary workaround for vision-5e hooks while I work on properly hooking up Stealthy to it. -* Dnd5e: Updated pt-BR translations (Thanks Kharmans) +* Dnd5e: If vision-5e is enabled, add perception vs stealth checks to the following detection modes: `devilsSight`, `etherealSight`, `hearing`, `lightPerception`, `seeAll`, `seeInvisibility`, and `witchSight` +* Dnd5e: Updated pt-BR translations (thanks Kharmans) * Dnd5e: Added both name and label fields to the language .json files for Dim/Dark * PF1: Disabled Stealthy until I can figure out a better way to capture skill rolls * Dnd4e: Disabled Stealthy until I can figure out a better way to capture skill rolls diff --git a/scripts/engine.js b/scripts/engine.js index fccd0a6..5d72014 100644 --- a/scripts/engine.js +++ b/scripts/engine.js @@ -24,7 +24,6 @@ export default class Engine { patchFoundry() { // Generic Detection mode patching - Stealthy.log('Engine.patchFoundry'); libWrapper.register( Stealthy.MODULE_ID, 'DetectionMode.prototype._canDetect', @@ -51,9 +50,10 @@ export default class Engine { } isHidden(visionSource, tgtToken) { - const friendlyStealth = game.settings.get(Stealthy.MODULE_ID, 'friendlyStealth'); - const ignoreFriendlyStealth = friendlyStealth === 'ignore' || !game.combat && friendlyStealth === 'inCombat'; - if (ignoreFriendlyStealth && tgtToken?.disposition === visionSource.object.document?.disposition) return false; + if (tgtToken?.disposition === visionSource.object.document?.disposition) { + const friendlyStealth = game.settings.get(Stealthy.MODULE_ID, 'friendlyStealth'); + if (friendlyStealth === 'ignore' || !game.combat && friendlyStealth === 'inCombat') return false; + } const hiddenEffect = this.findHiddenEffect(tgtToken?.actor); if (!hiddenEffect) return false; diff --git a/scripts/systems/dnd5e.js b/scripts/systems/dnd5e.js index c18be9d..e9f41db 100644 --- a/scripts/systems/dnd5e.js +++ b/scripts/systems/dnd5e.js @@ -64,7 +64,7 @@ class Engine5e extends Engine { type: Boolean, default: false, }); - + game.settings.register(Stealthy.MODULE_ID, 'friendlyUmbralSight', { name: game.i18n.localize("stealthy.dnd5e.friendlyUmbralSight.name"), scope: 'world', @@ -101,19 +101,49 @@ class Engine5e extends Engine { } patchFoundry() { + // If vision-5e isn't active, just keep the default behavior if (!game.modules.get("vision-5e")?.active) { super.patchFoundry(); return; } - Stealthy.log('Dnd5e.patchFoundry'); - // Detection mode patching + // Pick the sight modes in vision-5e that we want Stealthy to affect + let sightModes = [ + 'CONFIG.Canvas.detectionModes.devilsSight._canDetect', + 'CONFIG.Canvas.detectionModes.etherealSight._canDetect', + 'CONFIG.Canvas.detectionModes.lightPerception._canDetect', + 'CONFIG.Canvas.detectionModes.seeAll._canDetect', + 'CONFIG.Canvas.detectionModes.seeInvisibility._canDetect', + 'CONFIG.Canvas.detectionModes.witchSight._canDetect', + ]; + for (const mode of sightModes) { + libWrapper.register( + Stealthy.MODULE_ID, + mode, + function (wrapped, visionSource, target) { + switch (this.type) { + case DetectionMode.DETECTION_TYPES.SIGHT: + const srcToken = visionSource.object.document; + if (!(srcToken instanceof TokenDocument)) break; + const tgtToken = target?.document; + if (!(tgtToken instanceof TokenDocument)) break; + const engine = stealthy.engine; + if (engine.isHidden(visionSource, tgtToken)) return false; + } + return wrapped(visionSource, target); + }, + libWrapper.MIXED, + { perf_mode: libWrapper.PERF_FAST } + ); + } + + // Lastly, give Stealthy access to the hearing checks libWrapper.register( Stealthy.MODULE_ID, - 'CONFIG.Canvas.detectionModes.basicSight._canDetect', + 'CONFIG.Canvas.detectionModes.hearing._canDetect', function (wrapped, visionSource, target) { switch (this.type) { - case DetectionMode.DETECTION_TYPES.SIGHT: + case DetectionMode.DETECTION_TYPES.SOUND: const srcToken = visionSource.object.document; if (!(srcToken instanceof TokenDocument)) break; const tgtToken = target?.document;