From 2d5091877fbdbf9c840bd39caca1aed1c91f44c0 Mon Sep 17 00:00:00 2001 From: Werner Date: Mon, 23 Jan 2023 17:58:11 +0100 Subject: [PATCH] change options for roll to for dnd to work new way. add some midi checks --- src/lmrtfy.js | 9 ++++- src/roller.js | 98 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 66 insertions(+), 41 deletions(-) diff --git a/src/lmrtfy.js b/src/lmrtfy.js index 872babf..765f833 100644 --- a/src/lmrtfy.js +++ b/src/lmrtfy.js @@ -207,6 +207,13 @@ class LMRTFY { } + // overwrite for the dnd5e system, unsure if other 5e systems does this too + if (game.system.id === "dnd5e") { + LMRTFY.normalRollEvent = { fastForward: true }; + LMRTFY.advantageRollEvent = { advantage: true, fastForward: true }; + LMRTFY.disadvantageRollEvent = { disadvantage: true, fastForward: true }; + } + LMRTFY.d20Svg = '' + '' + @@ -225,7 +232,7 @@ class LMRTFY { ''; // for now we don't allow can fails until midi-qol has update patching.js - if (game.modules.get('midi-qol')) { + if (game.modules.getName("midi-qol")?.active && !isNewerVersion(game.modules.getName("midi-qol")?.version, "10.0.26")) { LMRTFY.canFailChecks = false; } diff --git a/src/roller.js b/src/roller.js index 51421d7..292de88 100644 --- a/src/roller.js +++ b/src/roller.js @@ -29,6 +29,9 @@ class LMRTFYRoller extends Application { PERCEPTION: "perception", } + this.hasMidi = game.modules.getName("midi-qol")?.active; + this.midiUseNewRoller = isNewerVersion(game.modules.getName("midi-qol")?.version, "10.0.26"); + Handlebars.registerHelper('canFailAbilityChecks', function (name, ability) { if (LMRTFY.canFailChecks) { return `
` + @@ -225,23 +228,33 @@ class LMRTFYRoller extends Application { } } - async _makeRoll(event, rollMethod, failRoll, ...args) { - let fakeEvent = {} + _getRollOptions(event, failRoll) { + let options; switch(this.advantage) { case -1: - fakeEvent = LMRTFY.disadvantageRollEvent; + options = {... LMRTFY.disadvantageRollEvent }; break; case 0: - fakeEvent = LMRTFY.normalRollEvent; + options = {... LMRTFY.normalRollEvent }; break; case 1: - fakeEvent = LMRTFY.advantageRollEvent; + options = {... LMRTFY.advantageRollEvent }; break; case 2: - fakeEvent = event; + options = event; break; } + if (failRoll) { + options["parts"] = [-100]; + } + + return options; + } + + async _makeRoll(event, rollMethod, failRoll, ...args) { + let options = this._getRollOptions(event, failRoll); + // 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); @@ -302,17 +315,10 @@ class LMRTFYRoller extends Application { } actor[rollMethod](game.i18n.localize(label), formula, target); - break; } default: { - const options = { - event: fakeEvent, - } - if (failRoll) { - options["parts"] = [-100]; - } await actor[rollMethod].call(actor, ...args, options); } } @@ -472,11 +478,13 @@ class LMRTFYRoller extends Application { const ability = event.currentTarget.dataset.ability; if (game.system.id === 'pf2e') this.pf2Roll = this.pf2eRollFor.ABILITY; - // for now we don't allow can fails until midi-qol has update patching.js - if (game.modules.get('midi-qol')) { - this._makeRoll(event, LMRTFY.abilityRollMethod, ability); - } else { + // until patching has been removed + if (!this.hasMidi) { + this._makeRoll(event, LMRTFY.abilityRollMethod, false, ability); + } else if (this.midiUseNewRoller) { this._makeRoll(event, LMRTFY.abilityRollMethod, false, ability); + } else { + this._makeRoll(event, LMRTFY.abilityRollMethod, ability); } } @@ -485,12 +493,14 @@ class LMRTFYRoller extends Application { const ability = event.currentTarget.dataset.ability; if (game.system.id === 'pf2e') this.pf2Roll = this.pf2eRollFor.ABILITY; - // for now we don't allow can fails until midi-qol has update patching.js - if (game.modules.get('midi-qol')) { - this._makeRoll(event, LMRTFY.abilityRollMethod, ability); - } else { + // until patching has been removed + if (!this.hasMidi) { + this._makeRoll(event, LMRTFY.abilityRollMethod, true, ability); + } else if (this.midiUseNewRoller) { this._makeRoll(event, LMRTFY.abilityRollMethod, true, ability); - } + } else { + this._makeRoll(event, LMRTFY.abilityRollMethod, ability); + } } _onAbilitySave(event) { @@ -498,13 +508,15 @@ class LMRTFYRoller extends Application { const saves = event.currentTarget.dataset.ability; if (game.system.id === 'pf2e') this.pf2Roll = this.pf2eRollFor.SAVE; this._makeRoll(event, LMRTFY.saveRollMethod, false, saves); - - // for now we don't allow can fails until midi-qol has update patching.js - if (game.modules.get('midi-qol')) { - this._makeRoll(event, LMRTFY.saveRollMethod, saves); - } else { + + // until patching has been removed + if (!this.hasMidi) { + this._makeRoll(event, LMRTFY.saveRollMethod, false, saves); + } else if (this.midiUseNewRoller) { this._makeRoll(event, LMRTFY.saveRollMethod, false, saves); - } + } else { + this._makeRoll(event, LMRTFY.saveRollMethod, saves); + } } _onFailAbilitySave(event) { @@ -512,11 +524,13 @@ class LMRTFYRoller extends Application { const saves = event.currentTarget.dataset.ability; if (game.system.id === 'pf2e') this.pf2Roll = this.pf2eRollFor.SAVE; - // for now we don't allow can fails until midi-qol has update patching.js - if (game.modules.get('midi-qol')) { - this._makeRoll(event, LMRTFY.saveRollMethod, saves); - } else { + // until patching has been removed + if (!this.hasMidi) { + this._makeRoll(event, LMRTFY.saveRollMethod, true, saves); + } else if (this.midiUseNewRoller) { this._makeRoll(event, LMRTFY.saveRollMethod, true, saves); + } else { + this._makeRoll(event, LMRTFY.saveRollMethod, saves); } } @@ -525,11 +539,13 @@ class LMRTFYRoller extends Application { const skill = event.currentTarget.dataset.skill; if (game.system.id === 'pf2e') this.pf2Roll = this.pf2eRollFor.SKILL; - // for now we don't allow can fails until midi-qol has update patching.js - if (game.modules.get('midi-qol')) { - this._makeRoll(event, LMRTFY.skillRollMethod, skill); - } else { + // until patching has been removed + if (!this.hasMidi) { this._makeRoll(event, LMRTFY.skillRollMethod, false, skill); + } else if (this.midiUseNewRoller) { + this._makeRoll(event, LMRTFY.skillRollMethod, false, skill); + } else { + this._makeRoll(event, LMRTFY.skillRollMethod, skill); } } @@ -538,11 +554,13 @@ class LMRTFYRoller extends Application { const skill = event.currentTarget.dataset.skill; if (game.system.id === 'pf2e') this.pf2Roll = this.pf2eRollFor.SKILL; - // for now we don't allow can fails until midi-qol has update patching.js - if (game.modules.get('midi-qol')) { - this._makeRoll(event, LMRTFY.skillRollMethod, skill); - } else { + // until patching has been removed + if (!this.hasMidi) { + this._makeRoll(event, LMRTFY.skillRollMethod, true, skill); + } else if (this.midiUseNewRoller) { this._makeRoll(event, LMRTFY.skillRollMethod, true, skill); + } else { + this._makeRoll(event, LMRTFY.skillRollMethod, skill); } }