Skip to content

Commit

Permalink
130 feature request modify assuption for passive perception (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eligarf authored May 21, 2024
1 parent 6d8212f commit 69310fe
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 82 deletions.
7 changes: 4 additions & 3 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# v4.0.8
* look for midi-qol flag to determine if perception disadvantage is already present before adding a -5 penalty to passive perception in dim light
# v4.1.0
* dnd5e: look for midi-qol flag to determine if perception disadvantage is already present before adding a -5 penalty to passive perception in dim light
* pf1: allow GMs to specify a value other than 10 for take-10 passive spot option

# v4.0.7
* v12 compatability
* v12 compatibility

# v4.0.6
* Handle tokens without skills (like vehicles)
Expand Down
6 changes: 3 additions & 3 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@
},
"pf1": {
"name": "Pathfinder",
"spotTake10": {
"name": "Perception take-10",
"hint": "If no banked perception roll is available, assume the Perception take-10 result for the visibility test. If disabled, Hidden tokens will not be seen without a banked perception roll."
"passiveSpotOffset": {
"name": "Assumed roll for passive spotting",
"hint": "If no banked perception roll is available, assume this value for the d20 in the visibility test. Typically, -99 to auto-fail or 10 for a take-10 result."
}
},
"pf2e": {
Expand Down
6 changes: 3 additions & 3 deletions languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@
},
"pf1": {
"name": "Pathfinder",
"spotTake10": {
"name": "Test de perception-10",
"hint": "If no banked perception roll is available, assume the Perception take-10 result for the visibility test. If disabled, Hidden tokens will not be seen without a banked perception roll."
"passiveSpotOffset": {
"name": "Assumed roll for passive spotting",
"hint": "If no banked perception roll is available, assume this value for the d20 in the visibility test. Typically, -99 to auto-fail or 10 for a take-10 result."
}
},
"pf2e": {
Expand Down
6 changes: 3 additions & 3 deletions languages/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@
},
"pf1": {
"name": "Pathfinder",
"spotTake10": {
"name": "Percepção pegue-10",
"hint": "Se nenhum efeito Percebendo estiver ativo, assuma o resultado de Percepção - 10 para o teste de visibilidade. Se desativado, os tokens Escondidos não serão vistos sem um efeito Percebendo ativo."
"passiveSpotOffset": {
"name": "Assumed roll for passive spotting",
"hint": "If no banked perception roll is available, assume this value for the d20 in the visibility test. Typically, -99 to auto-fail or 10 for a take-10 result."
}
},
"pf2e": {
Expand Down
30 changes: 20 additions & 10 deletions scripts/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function migrate(moduleVersion, oldVersion) {
return moduleVersion;
}

Hooks.once('setup', () => {
Hooks.once('init', () => {
const module = game.modules.get(Stealthy.MODULE_ID);
const moduleVersion = module.version;

Expand All @@ -21,7 +21,6 @@ Hooks.once('setup', () => {
stealthy.stealthToActor = value;
}
});
stealthy.stealthToActor = game.settings.get(Stealthy.MODULE_ID, 'stealthToActor');

game.settings.register(Stealthy.MODULE_ID, 'perceptionToActor', {
name: game.i18n.localize("stealthy.perceptionToActor.name"),
Expand All @@ -34,7 +33,6 @@ Hooks.once('setup', () => {
stealthy.perceptionToActor = value;
}
});
stealthy.perceptionToActor = game.settings.get(Stealthy.MODULE_ID, 'perceptionToActor');

game.settings.register(Stealthy.MODULE_ID, 'friendlyStealth', {
name: game.i18n.localize("stealthy.friendlyStealth.name"),
Expand Down Expand Up @@ -177,24 +175,36 @@ Hooks.once('setup', () => {
}
}
});
const schemaVersion = game.settings.get(Stealthy.MODULE_ID, 'schema');
if (schemaVersion !== moduleVersion) {
Hooks.once('ready', () => {
game.settings.set(Stealthy.MODULE_ID, 'schema', migrate(moduleVersion, schemaVersion));
});
}

game.settings.register(Stealthy.MODULE_ID, 'activeSpot', {
scope: 'world',
config: false,
type: Boolean,
default: true,
});
stealthy.bankingPerception = game.settings.get(Stealthy.MODULE_ID, 'activeSpot');

Stealthy.log(`Initialized ${moduleVersion}`);
});

Hooks.once('setup', () => {
const module = game.modules.get(Stealthy.MODULE_ID);
const moduleVersion = module.version;

stealthy.stealthToActor = game.settings.get(Stealthy.MODULE_ID, 'stealthToActor');
stealthy.perceptionToActor = game.settings.get(Stealthy.MODULE_ID, 'perceptionToActor');

const schemaVersion = game.settings.get(Stealthy.MODULE_ID, 'schema');
if (schemaVersion !== moduleVersion) {
Hooks.once('ready', () => {
game.settings.set(Stealthy.MODULE_ID, 'schema', migrate(moduleVersion, schemaVersion));
});
}

stealthy.bankingPerception = game.settings.get(Stealthy.MODULE_ID, 'activeSpot');

Stealthy.log(`Setup ${moduleVersion}`);
});

const LIGHT_ICONS = {
bright: '<i class="fa-solid fa-circle"></i>',
dim: '<i class="fa-solid fa-circle-half-stroke"></i>',
Expand Down
96 changes: 47 additions & 49 deletions scripts/systems/dnd5e.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,55 +31,53 @@ class Engine5e extends Engine {
}
});

Hooks.once('setup', () => {
game.settings.register(Stealthy.MODULE_ID, 'perceptionDisadvantage', {
name: game.i18n.localize("stealthy.dnd5e.perceptionDisadvantage.name"),
hint: game.i18n.localize("stealthy.dnd5e.perceptionDisadvantage.hint"),
scope: 'world',
config: true,
type: Boolean,
default: true,
});

game.settings.register(Stealthy.MODULE_ID, 'stealthKey', {
name: game.i18n.localize("stealthy.dnd5e.stealthKey.name"),
hint: game.i18n.localize("stealthy.dnd5e.stealthKey.hint"),
scope: 'world',
config: true,
type: String,
default: 'ste'
});

game.settings.register(Stealthy.MODULE_ID, 'perceptionKey', {
name: game.i18n.localize("stealthy.dnd5e.perceptionKey.name"),
hint: game.i18n.localize("stealthy.dnd5e.perceptionKey.hint"),
scope: 'world',
config: true,
type: String,
default: 'prc'
});

game.settings.register(Stealthy.MODULE_ID, 'ignorePassiveFloor', {
name: game.i18n.localize("stealthy.dnd5e.ignorePassiveFloor.name"),
hint: game.i18n.localize("stealthy.dnd5e.ignorePassiveFloor.hint"),
scope: 'world',
config: true,
type: Boolean,
default: false,
});

game.settings.register(Stealthy.MODULE_ID, 'friendlyUmbralSight', {
name: game.i18n.localize("stealthy.dnd5e.friendlyUmbralSight.name"),
scope: 'world',
config: false,
type: String,
choices: {
'allow': game.i18n.localize("stealthy.dnd5e.friendlyUmbralSight.allow"),
'inCombat': game.i18n.localize("stealthy.dnd5e.friendlyUmbralSight.inCombat"),
'ignore': game.i18n.localize("stealthy.dnd5e.friendlyUmbralSight.ignore")
},
default: 'inCombat'
});
game.settings.register(Stealthy.MODULE_ID, 'perceptionDisadvantage', {
name: game.i18n.localize("stealthy.dnd5e.perceptionDisadvantage.name"),
hint: game.i18n.localize("stealthy.dnd5e.perceptionDisadvantage.hint"),
scope: 'world',
config: true,
type: Boolean,
default: true,
});

game.settings.register(Stealthy.MODULE_ID, 'stealthKey', {
name: game.i18n.localize("stealthy.dnd5e.stealthKey.name"),
hint: game.i18n.localize("stealthy.dnd5e.stealthKey.hint"),
scope: 'world',
config: true,
type: String,
default: 'ste'
});

game.settings.register(Stealthy.MODULE_ID, 'perceptionKey', {
name: game.i18n.localize("stealthy.dnd5e.perceptionKey.name"),
hint: game.i18n.localize("stealthy.dnd5e.perceptionKey.hint"),
scope: 'world',
config: true,
type: String,
default: 'prc'
});

game.settings.register(Stealthy.MODULE_ID, 'ignorePassiveFloor', {
name: game.i18n.localize("stealthy.dnd5e.ignorePassiveFloor.name"),
hint: game.i18n.localize("stealthy.dnd5e.ignorePassiveFloor.hint"),
scope: 'world',
config: true,
type: Boolean,
default: false,
});

game.settings.register(Stealthy.MODULE_ID, 'friendlyUmbralSight', {
name: game.i18n.localize("stealthy.dnd5e.friendlyUmbralSight.name"),
scope: 'world',
config: false,
type: String,
choices: {
'allow': game.i18n.localize("stealthy.dnd5e.friendlyUmbralSight.allow"),
'inCombat': game.i18n.localize("stealthy.dnd5e.friendlyUmbralSight.inCombat"),
'ignore': game.i18n.localize("stealthy.dnd5e.friendlyUmbralSight.ignore")
},
default: 'inCombat'
});

Hooks.on('dnd5e.rollSkill', async (actor, roll, skill) => {
Expand Down
37 changes: 26 additions & 11 deletions scripts/systems/pf1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,31 @@ export class EnginePF1 extends Engine {

constructor() {
super();
game.settings.register(Stealthy.MODULE_ID, 'spotTake10', {
scope: 'world',
config: false,
type: Boolean,
default: false,
});

game.settings.register(Stealthy.MODULE_ID, 'passiveSpotOffset', {
name: game.i18n.localize("stealthy.pf1.passiveSpotOffset.name"),
hint: game.i18n.localize("stealthy.pf1.passiveSpotOffset.hint"),
scope: 'world',
config: true,
type: Number,
default: -999,
});

Hooks.once('setup', () => {
game.settings.register(Stealthy.MODULE_ID, 'spotTake10', {
name: game.i18n.localize("stealthy.pf1.spotTake10.name"),
hint: game.i18n.localize("stealthy.pf1.spotTake10.hint"),
scope: 'world',
config: true,
type: Boolean,
default: false,
});
Hooks.once('ready', () => {
const offset = game.settings.get(Stealthy.MODULE_ID, 'passiveSpotOffset');
if (offset === -999) {
game.settings.set(
Stealthy.MODULE_ID,
'passiveSpotOffset',
game.settings.get(Stealthy.MODULE_ID, 'spotTake10') ? 10 : -99
)
}
});

Hooks.on('pf1ActorRollSkill', async (actor, message, skill) => {
Expand Down Expand Up @@ -54,11 +69,11 @@ export class EnginePF1 extends Engine {
getPerceptionFlag(token) {
const flag = super.getPerceptionFlag(token);
if (flag) return flag;
if (!game.settings.get(Stealthy.MODULE_ID, 'spotTake10')) return undefined;
const offset = game.settings.get(Stealthy.MODULE_ID, 'passiveSpotOffset');
return {
token,
passive: true,
perception: 10 + token.actor.system?.skills?.per?.mod ?? -110
perception: offset + (token.actor.system?.skills?.per?.mod ?? 0)
};
}

Expand Down

0 comments on commit 69310fe

Please sign in to comment.