Skip to content

Commit

Permalink
Fixed saving throw type actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Oct 5, 2023
1 parent b7c8254 commit 28e39d9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 14 deletions.
4 changes: 2 additions & 2 deletions scripts/minion.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import vanilla from "./plugins/vanilla.js";

export function initializeMinions() {

if(CONSTANTS.MODULES.MIDI){
if (CONSTANTS.MODULES.MIDI) {
midiqol.initializeMinions();
}else{
} else {
vanilla.initializeMinions();
}

Expand Down
74 changes: 62 additions & 12 deletions scripts/plugins/vanilla.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
if (!api.isMinion(item.parent) || !isGroupAttack) return true;

// If we've already prompted the user, and the attack hasn't gone through, then we continue the original attack
if(minionAttacks[item.parent.uuid] && !minionAttacks[item.parent.uuid].attacked) {
if (minionAttacks[item.parent.uuid] && !minionAttacks[item.parent.uuid].attacked) {
rollConfig.parts = minionAttacks[item.parent.uuid].rollConfig.parts;
minionAttacks[item.parent.uuid].attacked = true;
return true;
Expand Down Expand Up @@ -52,24 +52,74 @@ export default {

});

const minionOnlyDamages = {};

Hooks.on("dnd5e.preRollDamage", (item, rollConfig) => {

if (!minionAttacks?.[item.parent.uuid]) return true;
if (item.system?.damage?.parts?.length < 1) return true;
if (!lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_GROUP_ATTACKS)) return true;
const isGroupAttack = getProperty(item, CONSTANTS.FLAGS.MIDI_GROUP_ATTACK) ?? false;
if (!api.isMinion(item.parent) || !isGroupAttack) return true;

if (minionAttacks?.[item.parent.uuid]) {

const numMinionsAttacked = minionAttacks[item.parent.uuid].numMinionsAttacked;
delete minionAttacks[item.parent.uuid];
const firstDamage = item.system.damage.parts[0][0];
const newFormula = isNaN(Number(firstDamage))
? firstDamage + " * " + numMinionsAttacked
: Number(firstDamage) * numMinionsAttacked;

const damageType = item.system.damage.parts[0][1];

rollConfig.parts[0] = [`${newFormula}${damageType ? `[${damageType}]` : ""}`];

return true;

} else {

// If we've already prompted the user, and the attack hasn't gone through, then we continue the original attack
if (minionOnlyDamages[item.parent.uuid] && !minionOnlyDamages[item.parent.uuid].attacked) {
const firstDamage = item.system.damage.parts[0][0];
const newFormula = isNaN(Number(firstDamage))
? firstDamage + " * " + minionOnlyDamages[item.parent.uuid].numMinionsAttacked
: Number(firstDamage) * minionOnlyDamages[item.parent.uuid].numMinionsAttacked;

const numMinionsAttacked = minionAttacks[item.parent.uuid].numMinionsAttacked;
delete minionAttacks[item.parent.uuid];
const firstDamage = item.system.damage.parts[0][0];
const newFormula = isNaN(Number(firstDamage))
? firstDamage + " * " + numMinionsAttacked
: Number(firstDamage) * numMinionsAttacked;
delete minionOnlyDamages[item.parent.uuid];

const damageType = item.system.damage.parts[0][1];
const damageType = item.system.damage.parts[0][1];

rollConfig.fastForward = true;
rollConfig.parts[0] = [`${newFormula}${damageType ? `[${damageType}]` : ""}`];
if (lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_GROUP_ATTACK_BONUS)) {
rollConfig.parts[0] = [`${newFormula}${damageType ? `[${damageType}]` : ""}`];
}

return true;
return true;
}

Dialog.confirm({
title: game.i18n.localize("MINIONMANAGER.Dialogs.MinionAttack.Title"),
content: `
<p>${game.i18n.localize("MINIONMANAGER.Dialogs.MinionAttack.Label")}</p>
<p><input name="numberOfAttacks" type="number" value="1"></p>
`,
yes: (html) => {
return html.find('input[name="numberOfAttacks"]').val()
},
options: { height: "100%" }
}).then(result => {

const numMinionsAttacked = Number(result) || 1;

minionOnlyDamages[item.parent.uuid] = { numMinionsAttacked, rollConfig, attacked: false };

// Roll the damage with the existing config, which just includes the minion bonus
item.rollDamage(rollConfig);

});

return false;

}

});

Expand Down

0 comments on commit 28e39d9

Please sign in to comment.