From 33fd2c85adea65cd2daa2a2be69e4b8e0d7bfe31 Mon Sep 17 00:00:00 2001 From: Javier Jacobo Date: Wed, 22 May 2024 07:23:12 -0700 Subject: [PATCH] update compatibility for pf2e 5.13.6 --- module.json | 2 +- src/lmrtfy.js | 13 +++++++------ src/roller.js | 51 +++++++++++++++++++++++++++------------------------ 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/module.json b/module.json index 343353c..027adeb 100644 --- a/module.json +++ b/module.json @@ -114,7 +114,7 @@ "type": "system", "manifest": "https://github.com/foundryvtt/pf2e/releases/download/3.13.6/system.json", "compatibility": { - "verified": "3.13.6" + "verified": "5.13.6" } }, { diff --git a/src/lmrtfy.js b/src/lmrtfy.js index 178ff76..e81f317 100644 --- a/src/lmrtfy.js +++ b/src/lmrtfy.js @@ -388,15 +388,16 @@ class LMRTFY { static buildAbilityModifier(actor, ability) { const modifiers = []; - - const mod = game.pf2e.AbilityModifier.fromScore(ability, actor.data.data.abilities[ability].value); + const attribute = actor.system.abilities[ability]; + const attributeLabel = game.i18n.localize(attribute.label); + const mod = new game.pf2e.Modifier(attributeLabel, attribute.mod, 'ability', true); modifiers.push(mod); - [`${ability}-based`, 'ability-check', 'all'].forEach((key) => { - (actor.synthetics.statisticsModifier[key] || []).forEach((m) => modifiers.push(m.clone())); + (actor.synthetics.modifierAdjustments[key] || []).forEach((m) => modifiers.push(m.clone())); }); - - return new game.pf2e.StatisticModifier(`${game.i18n.localize('LMRTFY.AbilityCheck')} ${game.i18n.localize(mod.label)}`, modifiers); + const slug = `${game.i18n.localize('LMRTFY.AbilityCheck')}${attributeLabel}`; + const statisticModifier = new game.pf2e.StatisticModifier(slug, modifiers); + return statisticModifier; } static async hideBlind(app, html, msg) { diff --git a/src/roller.js b/src/roller.js index 375955e..8fb55fe 100644 --- a/src/roller.js +++ b/src/roller.js @@ -284,11 +284,12 @@ class LMRTFYRoller extends Application { case this.pf2eRollFor.SKILL: // system specific roll handling - const skill = actor.system.skills[args[0]]; + const skillSlug = actor.system.skills[args[0]].slug; + const skill = actor.skills[skillSlug]; // roll lore skills only for actors who have them ... if (!skill) continue; - const skillOptions = actor.getRollOptions(['all', `${skill.ability ?? 'int'}-based`, 'skill-check', skill.name]); + const skillOptions = actor.getRollOptions(['all', `${skill.ability ?? 'int'}-based`, 'skill-check', skillSlug]); skill.roll({ event, skillOptions, dc: this.dc }); break; @@ -361,27 +362,9 @@ class LMRTFYRoller extends Application { } _makePF2EInitiativeRoll(event) { - // save the current roll mode to reset it after this roll - const rollMode = game.settings.get("core", "rollMode"); - game.settings.set("core", "rollMode", this.mode || CONST.DICE_ROLL_MODES); - - for (let actor of this.actors) { - const initiative = actor.data.data.attributes.initiative; - const rollNames = ['all', 'initiative']; - if (initiative.ability === 'perception') { - rollNames.push('wis-based'); - rollNames.push('perception'); - } else { - const skill = actor.data.data.skills[initiative.ability]; - rollNames.push(`${skill.ability}-based`); - rollNames.push(skill.name); - } - const options = actor.getRollOptions(rollNames); - initiative.roll({ event, options }); + for (const actor of this.actors) { + actor.initiative.roll(); } - - game.settings.set("core", "rollMode", rollMode); - event.currentTarget.disabled = true; this._checkClose(); } @@ -651,7 +634,17 @@ class LMRTFYRoller extends Application { this._checkClose(); } else if (game.system.id == "pf2e") { for (let actor of this.actors) { - actor.rollRecovery(); + actor.rollRecovery().then(rollResult => { + if (!rollResult) return; + const adjustDyingCounterFn = rollResult.degreeOfSuccess >= 2 ? () => actor.decreaseCondition('dying') : () => actor.increaseCondition('dying', { max: actor.system.attributes.dying.max ?? 4 }); + const dosToNumberOfCalls = { 0: 2, 1: 1, 2: 1, 3: 2 }; + const adjustDyingCounterCalls = Array.from({ length: dosToNumberOfCalls[rollResult.degreeOfSuccess] }, () => adjustDyingCounterFn()); + Promise.all(adjustDyingCounterCalls).then(() => { + if (actor.system.attributes.dying.value === 0) { + actor.increaseCondition('wounded', { max: actor.system.attributes.wounded.max ?? 3 }); + } + }); + }); } event.currentTarget.disabled = true; this._checkClose(); @@ -662,7 +655,17 @@ class LMRTFYRoller extends Application { _onPerception(event) { event.preventDefault(); - this._makeDiceRoll(event, `1d20 + @attributes.perception.totalModifier`, game.i18n.localize("LMRTFY.PerceptionRollMessage")); + + if (game.system.id !== 'pf2e') { + return this._makeDiceRoll(event, `1d20 + @attributes.perception.totalModifier`, game.i18n.localize("LMRTFY.PerceptionRollMessage")); + } + + const ability = event.currentTarget.dataset.ability; + this.pf2Roll = this.pf2eRollFor.PERCEPTION; + if (!this.hasMidi || this.midiUseNewRoller) { + return this._makeRoll(event, LMRTFY.abilityRollMethod, false, ability); + } + this._makeRoll(event, LMRTFY.abilityRollMethod, ability); } _onRollTable(event) {