diff --git a/scripts/minion.js b/scripts/minion.js index 577d17b..4d65f04 100644 --- a/scripts/minion.js +++ b/scripts/minion.js @@ -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(); } diff --git a/scripts/plugins/vanilla.js b/scripts/plugins/vanilla.js index 1bcaad7..c9bcc2d 100644 --- a/scripts/plugins/vanilla.js +++ b/scripts/plugins/vanilla.js @@ -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; @@ -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: ` +

${game.i18n.localize("MINIONMANAGER.Dialogs.MinionAttack.Label")}

+

+ `, + 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; + + } });