Skip to content

Commit

Permalink
better dim light handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Eligarf committed Apr 30, 2024
1 parent cb87409 commit f58bc6b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 63 deletions.
5 changes: 4 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# v4.0.2
* dnd5e: If using vision-5e, Hearing doesn't get disadvantage against targets hiding in dim light
* dnd5e: devilsSight gets disadvantage against targets hiding in dim light but not against ones in dark.

# v4.0.1
* Stealthy 4 isn't currently compatible with Perceptive, so I added stealthy.bankPerception and bankStealth to help insulate that module from my internal flag details

Expand All @@ -16,7 +20,6 @@
* Dnd5e: added settings to allow custom skills to substitute for stealth or perception

# v3.18.1
* FINAL V10-compatible version. Only V11+ in the future.
* Update pt-BR.json (thanks Kharmans)

# v3.18.0
Expand Down
12 changes: 6 additions & 6 deletions scripts/doors.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,28 @@ export default class Doors {
if (v10) {
const hiddenDoorBlock = `
<fieldset>
<legend>Stealthy</legend>
<legend><i class="fa-solid fa-piggy-bank"></i> Stealthy</legend>
<div class="form-group">
<label for="stealth">${game.i18n.localize("stealthy.door.stealth")}</label>
<input type="number" name="stealth"/ value="${css.object.flags.stealthy?.stealth}">
<input type="number" name="stealth" value="${css.object.flags.stealthy?.stealth ?? ''}">
</div>
<div class="form-group">
<label for="maxRange">${game.i18n.localize("stealthy.door.maxRange")}</label>
<input type="number" name="maxRange"/ value="${css.object.flags.stealthy?.maxRange}">
<input type="number" name="maxRange" value="${css.object.flags.stealthy?.maxRange ?? ''}">
</div>
</fieldset>`;
html.find(".form-group").last().after(hiddenDoorBlock);
} else {
html.find(`.door-options`).after(`
<fieldset>
<legend>Stealthy</legend>
<legend><i class="fa-solid fa-piggy-bank"></i> Stealthy</legend>
<div class="form-group">
<label>${game.i18n.localize("stealthy.door.stealth")}</label>
<input type="number" name="stealth"/ value="${css.data.flags?.stealthy?.stealth}">
<input type="number" name="stealth" value="${css.data.flags?.stealthy?.stealth ?? ''}">
</div>
<div class="form-group">
<label">${game.i18n.localize("stealthy.door.maxRange")}</label>
<input type="number" name="maxRange"/ value="${css.data.flags?.stealthy?.maxRange}">
<input type="number" name="maxRange" value="${css.data.flags?.stealthy?.maxRange ?? ''}">
</div>
</fieldset>`
);
Expand Down
29 changes: 20 additions & 9 deletions scripts/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ Hooks.on('renderTokenHUD', (tokenHUD, html, app) => {
if (stealthFlag) {
let value = engine.getStealthValue(stealthFlag);
const title = game.i18n.localize("stealthy.hidden.description");
const inputBox = $(
`<input ${editMode}id="ste_hid_inp_box" title="${title}" type="text" name="hidden_value_inp_box" value="${value}"></input>`
);
const inputBox = $(`
<input ${editMode}id="ste_ste_inp_box" title="${title}" type="text" name="ste_inp_box" value="${value}">
</input>
`);
html.find(".right").append(inputBox);
if (game.user.isGM == true) {
inputBox.change(async (inputbox) => {
Expand All @@ -238,9 +239,10 @@ Hooks.on('renderTokenHUD', (tokenHUD, html, app) => {
if (perceptionFlag && !perceptionFlag?.passive) {
let value = engine.getPerceptionValue(perceptionFlag);
const title = game.i18n.localize("stealthy.hidden.description");
const inputBox = $(
`<input ${editMode}id="ste_spt_inp_box" title="${title}" type="text" name="spot_value_inp_box" value="${value}"></input>`
);
const inputBox = $(`
<input ${editMode}id="ste_prc_inp_box" title="${title}" type="text" name="prc_inp_box" value="${value}">
</input>
`);
html.find(".left").append(inputBox);
if (game.user.isGM == true) {
inputBox.change(async (inputbox) => {
Expand Down Expand Up @@ -271,9 +273,18 @@ Hooks.on('getSceneControlButtons', (controls) => {
});

Hooks.on('renderSettingsConfig', (app, html, data) => {
$('<div>').addClass('form-group group-header').html(game.i18n.localize("stealthy.config.general")).insertBefore($('[name="stealthy.stealthToActor"]').parents('div.form-group:first'));
$('<div>').addClass('form-group group-header').html(game.i18n.localize("stealthy.config.advanced")).insertBefore($('[name="stealthy.hiddenLabel"]').parents('div.form-group:first'));
$('<div>').addClass('form-group group-header').html(game.i18n.localize("stealthy.config.debug")).insertBefore($('[name="stealthy.logLevel"]').parents('div.form-group:first'));
const sections = [
{ label: "general", before: "stealthToActor" },
{ label: "advanced", before: "hiddenLabel" },
{ label: "debug", before: "logLevel" },
];
for (const section of sections) {
$('<div>')
.addClass('form-group group-header')
.html(game.i18n.localize(`stealthy.config.${section.label}`))
.insertBefore($(`[name="stealthy.${section.before}"]`)
.parents('div.form-group:first'));
}
});

Hooks.once('ready', async () => {
Expand Down
3 changes: 0 additions & 3 deletions scripts/stealthy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ export class Stealthy {
}

async bankPerception(token, value) {
if (value?.normal === undefined) {
value = { normal: value, disadvantaged: value - 5 };
}
await this.engine.bankPerception(token, value);
}

Expand Down
76 changes: 34 additions & 42 deletions scripts/systems/dnd5e.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class Engine5e extends Engine {
}

const stealthValue = this.getStealthValue(stealthFlag);
Stealthy.logIfDebug('canDetectHidden', { stealthFlag: stealthFlag, stealth: stealthValue, perceptionFlag: perceptionFlag, perception: perceptionValue });
Stealthy.logIfDebug(`${detectionMode} vs '${tgtToken.name}': ${perceptionValue} vs ${stealthValue}`, { stealthFlag, perceptionFlag });
return perceptionValue > stealthValue;
}

Expand Down Expand Up @@ -204,6 +204,17 @@ class Engine5e extends Engine {
}
}

async bankPerception(token, value) {
if (value?.normal === undefined) {
value = { normal: value, disadvantaged: value - 5 };
}
if (stealthy.perceptionToActor) {
await this.updateOrCreateSpotEffect(token.actor, { perception: value });
} else {
await this.bankRollOnToken(token, 'perception', value);
}
}

async rollPerception(actor, roll) {
Stealthy.log('Stealthy5e.rollPerception', { actor, roll });
if (!stealthy.bankingPerception) return;
Expand Down Expand Up @@ -269,53 +280,34 @@ class Engine5e extends Engine {
// check target Token Lighting conditions via effects usage
// look for effects that indicate Dim or Dark condition on the token
adjustForLightingConditions(perceptionPair, visionSource, source, tgtToken, detectionMode) {
let perception;
// Extract the normal perception values from the source
const passivePrc = source?.system?.skills?.[game.settings.get(Stealthy.MODULE_ID, 'perceptionKey')]?.passive ?? -100;
let active = perceptionPair?.normal ?? perceptionPair;
let value = active ?? passivePrc;

// What light band are we told we sit in?
let lightBand = Engine5e.EXPOSURE[this.getLightExposure(tgtToken)];

// Adjust the light band based on conditions
if (detectionMode) {
if (detectionMode === 'basicSight') {
lightBand = lightBand + 1;
}
}
else {
if (visionSource.visionMode?.id === 'darkvision') {
lightBand = lightBand + 1;
}
}

// Extract the normal perception values from the source
let active = perceptionPair?.normal ?? perceptionPair;
let value;
const passivePrc = source?.system?.skills?.[game.settings.get(Stealthy.MODULE_ID, 'perceptionKey')]?.passive ?? -100;
if (active !== undefined) {
value = active;
}
else {
value = passivePrc;
let oldBand = Engine5e.LIGHT_LABELS[lightBand];
switch (detectionMode) {
case 'basicSight':
lightBand += 1;
break;
case 'devilsSight':
if (!lightBand) lightBand = 2;
break;
case 'hearing':
return value;
case undefined:
if (visionSource.visionMode?.id === 'darkvision') lightBand += 1;
break;
}
Stealthy.logIfDebug(`${detectionMode} vs '${tgtToken.name}': ${oldBand}-->${Engine5e.LIGHT_LABELS[lightBand]}`);

// dark = fail, dim = disadvantage, bright = normal
if (lightBand <= 0) {
perception = -100;
}
else if (lightBand === 1) {
let passiveDisadv = Engine5e.GetPassivePerceptionWithDisadvantage(source);
if (active !== undefined) {
value = perceptionPair?.disadvantaged ?? value - 5;
}
else {
value = passiveDisadv;
}
perception = value;
}
else {
perception = value;
}

return perception;
if (lightBand <= 0) return -100;
if (lightBand !== 1) return value;
let passiveDisadv = Engine5e.GetPassivePerceptionWithDisadvantage(source);
return (active !== undefined) ? (perceptionPair?.disadvantaged ?? value - 5) : passiveDisadv;
}

}
Expand Down
4 changes: 2 additions & 2 deletions styles/stealthy.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ste_hid_inp_box {
#ste_ste_inp_box {
width: 50px;
order: 1;
}
#ste_spt_inp_box {
#ste_prc_inp_box {
width: 50px;
order: 1;
}

0 comments on commit f58bc6b

Please sign in to comment.