Skip to content

Commit

Permalink
Proper hookups into vision-5e
Browse files Browse the repository at this point in the history
  • Loading branch information
Eligarf committed Apr 4, 2024
1 parent fb919eb commit a0baf7f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
4 changes: 2 additions & 2 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions scripts/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
Expand Down
40 changes: 35 additions & 5 deletions scripts/systems/dnd5e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a0baf7f

Please sign in to comment.