Skip to content

Commit

Permalink
localize chat scraping for Dnd4e/PF2e
Browse files Browse the repository at this point in the history
  • Loading branch information
Eligarf committed Sep 19, 2023
1 parent 5fc92c3 commit d4990f2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v3.13.1
* PF2e/Dnd4e: Localize the chat scraping functions

# v3.13.0
* PF2e: Update chat parsing to match changed text in hide and seek actions
* PF2e: Add an error notification if PF2e Workbench is missing
Expand Down
12 changes: 6 additions & 6 deletions scripts/systems/dnd4e.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Stealthy } from '../stealthy.js';
import Engine from '../engine.js';

// This mechanically works, but I don't know how one is supposed to get rid
// of the Hidden effect once it is placed given the PF1 UI doesn't seem to show
// active effects.

class Engine4e extends Engine {

constructor() {
super();

const usesStealth = `uses ${game.i18n.localize('DND4EBETA.SkillStl')}.`
const usesPerception = `uses ${game.i18n.localize('DND4EBETA.SkillPrc')}.`
Stealthy.log('Localized Chat Tags', { usesStealth, usesPerception });

Hooks.on('createChatMessage', async (message, options, id) => {
if (message.flavor.endsWith('uses Stealth.')) {
if (message.flavor.endsWith(usesStealth)) {
await this.rollStealth(message, options, id);
}
else if (message.flavor.endsWith('uses Perception.')) {
else if (message.flavor.endsWith(usesPerception)) {
await this.rollPerception(message, options, id);
}
});
Expand Down
19 changes: 14 additions & 5 deletions scripts/systems/pf2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,29 @@ export class EnginePF2e extends Engine {
super();

const workbench = game.modules.get('xdy-pf2e-workbench')?.active;
Stealthy.log('workbench', workbench);
if (!workbench) {
Hooks.once('ready', async () => {
ui.notifications.error(`${game.i18n.localize('stealthy.pf2e.dependency')}`);
});
}

// There is probably a better practice for figuring out skill checks in PF2E, but this "works"
const stealthTags = [
`>${game.i18n.localize('xdy-pf2e-workbench.macros.basicActionMacros.actions.Hide')} - ${game.i18n.localize('PF2E.StealthLabel')} ${game.i18n.localize('PF2E.Check.Label')}<`,
`>${game.i18n.format("PF2E.InitiativeWithSkill", { skillName: game.i18n.localize('PF2E.StealthLabel') }) }<`,
];
const perceptionTags = [
`>${game.i18n.localize('xdy-pf2e-workbench.macros.basicActionMacros.actions.Seek')} - ${game.i18n.localize('PF2E.PerceptionCheck')}<`,
`>${game.i18n.format("PF2E.InitiativeWithSkill", { skillName: game.i18n.localize('PF2E.PerceptionLabel') })}<`,
];
Stealthy.log('Localized Chat Tags', { stealthTags, perceptionTags });

Hooks.on('createChatMessage', async (message, options, id) => {
// Stealthy.log("createChatMessage", message);
if (['>Initiative: Stealth<', '>(Stealth Check)<', 'Hide - Stealth Check'].some(t => message.flavor.includes(t))) {
if (stealthTags.some(t => message.flavor.includes(t))) {
await this.rollStealth(message, options, id);
}
else if (['>(Perception Check)<', 'Seek - Perception Check', '>Initiative: Perception<'].some(t => message.flavor.includes(t))) {
else if (perceptionTags.some(t => message.flavor.includes(t))) {
await this.rollPerception(message, options, id);
}
});
Expand All @@ -40,7 +49,7 @@ export class EnginePF2e extends Engine {
const stealth = hiddenEffect?.flags?.stealthy?.hidden ?? (10 + target.actor.system.skills.ste.value);
const source = visionSource.object?.actor;
let seeking = this.findSpotEffect(source);
const perception = seeking?.flags?.stealthy?.spot ?? 10 + source.system.attributes.perception.value;
const perception = seeking?.flags?.stealthy?.spot ?? 10 + source.system.attributes.perception?.value;

if (perception < stealth) {
Stealthy.log(`${visionSource.object.name}'s ${perception} can't see ${target.name}'s ${stealth}`);
Expand Down Expand Up @@ -134,7 +143,7 @@ export class EnginePF2e extends Engine {
}

getSpotFlagAndValue(actor, effect) {
const value = effect?.flags.stealthy.spot ?? (10 + actor.system.attributes.perception.value);
const value = effect?.flags.stealthy.spot ?? (10 + actor.system.attributes.perception?.value);
return { flag: { spot: value }, value };
}

Expand Down

0 comments on commit d4990f2

Please sign in to comment.