Skip to content

Commit

Permalink
change options for roll to for dnd to work new way. add some midi checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Werner committed Jan 23, 2023
1 parent 76a0876 commit 2d50918
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 41 deletions.
9 changes: 8 additions & 1 deletion src/lmrtfy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<svg class="lmrtfy-dice-svg-normal" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"' +
'viewBox="0 0 64 64" style="enable-background:new 0 0 64 64;" xml:space="preserve">' +
'<g transform="translate(-246.69456,-375.66745)">' +
Expand All @@ -225,7 +232,7 @@ class LMRTFY {
'</svg>';

// 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;
}

Expand Down
98 changes: 58 additions & 40 deletions src/roller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<div>` +
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -485,38 +493,44 @@ 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) {
event.preventDefault();
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) {
event.preventDefault();
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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down

0 comments on commit 2d50918

Please sign in to comment.