diff --git a/scripts/initiative.js b/scripts/initiative.js index 15a4367..0d01681 100644 --- a/scripts/initiative.js +++ b/scripts/initiative.js @@ -40,7 +40,7 @@ export function refreshInitiativeGroupGraphics(t) { background.width = diameter; background.height = diameter; background.beginFill(0xFFFFFF) - .drawCircle((diameter / 2), (diameter / 2), Math.max(1, (diameter-2)/2)) + .drawCircle((diameter / 2), (diameter / 2), Math.max(1, (diameter - 2) / 2)) .endFill(); sprite._background = background; diff --git a/scripts/lib.js b/scripts/lib.js index 3d780ad..635165f 100644 --- a/scripts/lib.js +++ b/scripts/lib.js @@ -38,7 +38,7 @@ export function isValidOverkillItem(item) { } -export function getActiveGM(){ +export function getActiveGM() { return game.users .filter(u => u.active && u.isGM) .sort((a, b) => a.isGM && !b.isGM ? -1 : 1)?.[0]; diff --git a/scripts/plugins/midiqol.js b/scripts/plugins/midiqol.js index 1094260..92f696d 100644 --- a/scripts/plugins/midiqol.js +++ b/scripts/plugins/midiqol.js @@ -1,7 +1,6 @@ import * as lib from "../lib.js"; import CONSTANTS from "../constants.js"; import * as api from "../api.js"; -import { isValidOverkillItem } from "../lib.js"; export default { @@ -36,7 +35,6 @@ export default { const attackHookId = Hooks.on("dnd5e.preRollAttack", (rolledItem, rollConfig) => { if (rolledItem !== workflow.item) return true; - rollConfig.fastForward = true; rollConfig.parts.push(numMinionsAttacked); Hooks.off("dnd5e.preRollAttack", attackHookId); return true; @@ -50,19 +48,22 @@ export default { if (!minionAttacks?.[workflow.id]) return true; if (workflow.item.system?.damage?.parts?.length < 1) return true; - const numMinionsAttacked = minionAttacks[workflow.id]; - delete minionAttacks[workflow.id]; - const firstDamage = workflow.item.system.damage.parts[0][0]; - const newFormula = isNaN(Number(firstDamage)) - ? firstDamage + " * " + numMinionsAttacked - : Number(firstDamage) * numMinionsAttacked; + const newDamageParts = []; + + for (let index = 0; index < workflow.item.system.damage.parts.length; index++) { + const firstDamage = workflow.item.system.damage.parts[index][0]; + const newFormula = isNaN(Number(firstDamage)) + ? "(" + firstDamage.toString() + " * " + minionAttacks[workflow.id].toString() + ")" + : Number(firstDamage) * minionAttacks[workflow.id]; + const damageType = workflow.item.system.damage.parts[index][1]; + newDamageParts.push(`${newFormula}${damageType ? `[${damageType}]` : ""}`); + } - const damageType = workflow.item.system.damage.parts[0][1]; + delete minionAttacks[workflow.id]; const damageHookId = Hooks.on("dnd5e.preRollDamage", (rolledItem, rollConfig) => { if (rolledItem !== workflow.item) return true; - rollConfig.fastForward = true; - rollConfig.parts[0] = [`${newFormula}${damageType ? `[${damageType}]` : ""}`]; + rollConfig.parts = newDamageParts; Hooks.off("dnd5e.preRollDamage", damageHookId); return true; }); @@ -81,7 +82,7 @@ export default { Hooks.on("midi-qol.preDamageRollComplete", async (workflow) => { const validAttack = lib.isValidOverkillItem(workflow.item); - if(!validAttack) return true; + if (!validAttack) return true; if (!workflow.hitTargets.size) return true; const hitTarget = Array.from(workflow.hitTargets)[0] @@ -155,7 +156,7 @@ export default { workflow.item ); - if(lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_OVERKILL_MESSAGE)) { + if (lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_OVERKILL_MESSAGE)) { ChatMessage.create({ content: `
${label1}
` }); diff --git a/scripts/plugins/vanilla.js b/scripts/plugins/vanilla.js index d74fb8f..b8cedb3 100644 --- a/scripts/plugins/vanilla.js +++ b/scripts/plugins/vanilla.js @@ -1,7 +1,6 @@ import * as lib from "../lib.js"; import CONSTANTS from "../constants.js"; import * as api from "../api.js"; -import { getActiveGM } from "../lib.js"; export default { @@ -64,16 +63,21 @@ export default { 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; + for (let index = 0; index < item.system.damage.parts.length; index++) { + + const firstDamage = item.system.damage.parts[index][0]; + const newFormula = isNaN(Number(firstDamage)) + ? "(" + firstDamage.toString() + " * " + minionOnlyDamages[item.parent.uuid].numMinionsAttacked.toString() + ")" + : Number(firstDamage) * minionOnlyDamages[item.parent.uuid].numMinionsAttacked; - const damageType = item.system.damage.parts[0][1]; + const damageType = item.system.damage.parts[index][1]; + + if (lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_GROUP_ATTACK_BONUS)) { + rollConfig.parts[index] = [`${newFormula}${damageType ? `[${damageType}]` : ""}`]; + } + } - rollConfig.parts[0] = [`${newFormula}${damageType ? `[${damageType}]` : ""}`]; + delete minionAttacks[item.parent.uuid]; return true; @@ -81,19 +85,23 @@ export default { // 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; - delete minionOnlyDamages[item.parent.uuid]; + for (let index = 0; index < item.system.damage.parts.length; index++) { - const damageType = item.system.damage.parts[0][1]; + const firstDamage = item.system.damage.parts[index][0]; + const newFormula = isNaN(Number(firstDamage)) + ? "(" + firstDamage.toString() + " * " + minionOnlyDamages[item.parent.uuid].numMinionsAttacked.toString() + ")" + : Number(firstDamage) * minionOnlyDamages[item.parent.uuid].numMinionsAttacked; - if (lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_GROUP_ATTACK_BONUS)) { - rollConfig.parts[0] = [`${newFormula}${damageType ? `[${damageType}]` : ""}`]; + const damageType = item.system.damage.parts[index][1]; + + if (lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_GROUP_ATTACK_BONUS)) { + rollConfig.parts[index] = [`${newFormula}${damageType ? `[${damageType}]` : ""}`]; + } } + delete minionOnlyDamages[item.parent.uuid]; + return true; } @@ -128,11 +136,11 @@ export default { Hooks.on("dnd5e.rollDamage", async (item, damageRoll) => { const validAttack = lib.isValidOverkillItem(item); - if(!validAttack) return true; + if (!validAttack) return true; const hitTargets = Array.from(game.user.targets) - if(!hitTargets.length) return true; + if (!hitTargets.length) return true; const hitTarget = hitTargets[0]; @@ -155,7 +163,7 @@ export default { name: hitTarget.actor.name }); - if(lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_OVERKILL_MESSAGE)) { + if (lib.getSetting(CONSTANTS.SETTING_KEYS.ENABLE_OVERKILL_MESSAGE)) { ChatMessage.create({ content: `${label1}
` });