Skip to content

Commit

Permalink
Add noticed as a filter to unhiding things
Browse files Browse the repository at this point in the history
  • Loading branch information
Eligarf committed May 20, 2024
1 parent cad485e commit b41e2c9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# v1.3.0
* V12 compatibility
* Add option to remove GM hidden state on combatants at combat start.
* Add option to remove GM hidden state on noticed combatants at combat start.

# v1.2.3
* Fix failed stealth to follow Sneak rules
Expand Down
25 changes: 18 additions & 7 deletions esmodules/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,17 @@ Hooks.once('init', () => {
const computeCover = game.settings.get(MODULE_ID, 'computeCover');

const stealthers = encounter.combatants.contents.filter((c) => c.flags.pf2e.initiativeStatistic === 'stealth');
const gmHiddenIds = encounter.combatants.contents
.map((c) => c.token instanceof Token ? c.token.document : c.token)
.filter((t) => t.hidden)
.map((t) => t.id);
let perceptionChanges = {};
let revealedIds = encounter.combatants.contents
.filter((c) => c.flags.pf2e.initiativeStatistic !== 'stealth')
.map((c) => c.token instanceof Token ? c.token.document : c.token)
.filter((t) => t.hidden)
.map((t) => t.id);

for (const stealther of stealthers) {
// log('stealther', stealther);

Expand Down Expand Up @@ -189,6 +199,10 @@ Hooks.once('init', () => {
otherUpdate[`flags.${PERCEPTION_ID}.data.${other.token.id}.visibility`] = visibility;
}

if (target?.result !== 'unnoticed' && gmHiddenIds.includes(stealtherTokenDoc.id) && !revealedIds.includes(stealtherTokenDoc.id)) {
revealedIds.push(stealtherTokenDoc.id);
}

// Add a new category if necessary, and put this other token's result in the message data
if (!(target.result in messageData)) {
messageData[target.result] = {
Expand Down Expand Up @@ -262,18 +276,15 @@ Hooks.once('init', () => {
}
}

// Un-GM-hide any combatants
// Un-GM-hide any noticed combatants
if (removeGmHidden) {
const gmHidden = encounter.combatants.contents
.map((c) => c.token instanceof Token ? c.token.document : c.token)
.filter((t) => t.hidden);
for (const t of gmHidden) {
let update = updates.find((u) => u._id === t.id);
for (const t of revealedIds) {
let update = updates.find((u) => u._id === t);
if (update) {
update.hidden = false;
}
else {
updates.push({ _id: t.id, hidden: false });
updates.push({ _id: t, hidden: false });
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"hint": "Use 'Unnoticed' rather than 'Undetected' when the stealth initiative check beats the target's perception DC and initiative"
},
"removeGmHidden": {
"name": "Remove GM Hidden Flags at Combat Start",
"name": "Reveal noticed tokens with GM Hidden Flags at Combat Start",
"hint": "Combatant tokens which have been manually hidden by toggling their visibility state to off will be changed to on at combat start, allowing perception/stealth results to affect visibility as normal"
},
"override": {
Expand Down

0 comments on commit b41e2c9

Please sign in to comment.