From d8129c1a18cff21b243ce663be31d4ed2c03ac29 Mon Sep 17 00:00:00 2001 From: Stendarpaval Date: Mon, 16 Aug 2021 23:31:25 +0200 Subject: [PATCH] v0.3.5 - Fixes a bug that caused exported macros to only work for GMs when the "Enable Dice so Nice rolls" setting was disabled. - Exported macros that aren't specifically exported to roll with advantage or disadvantage, will now be rolled with advantage if the alt key is held down and with disadvantage if the Command key (MacOS) and presumably the Ctrl key (Windows) is held down. Didn't test on Windows, I'm afraid. - Added "(Advantage)" and "(Disadvantage)" strings to the attack roll tooltip that appears when you hover over the attack roll results in the Mob Attack Results chat message. --- module.json | 4 ++-- scripts/group-initiative/groupInitiative.js | 18 ++++++++++++++---- scripts/individualRolls.js | 6 ++++-- scripts/mobAttackTool.js | 13 +++++++++++-- scripts/mobRules.js | 4 ++-- templates/mat-msg-individual-rolls.html | 2 +- 6 files changed, 34 insertions(+), 13 deletions(-) diff --git a/module.json b/module.json index 5018dad..f70f989 100644 --- a/module.json +++ b/module.json @@ -16,7 +16,7 @@ } ], "url": "https://github.com/Stendarpaval/mob-attack-tool", - "version": "0.3.4", + "version": "0.3.5", "minimumCoreVersion": "0.8.8", "compatibleCoreVersion": "0.8.8", "system": ["dnd5e"], @@ -27,5 +27,5 @@ "styles/mob-attack-tool.css" ], "manifest": "https://raw.githubusercontent.com/Stendarpaval/mob-attack-tool/main/module.json", - "download": "https://github.com/Stendarpaval/mob-attack-tool/releases/download/0.3.4/module.zip" + "download": "https://github.com/Stendarpaval/mob-attack-tool/releases/download/0.3.5/module.zip" } diff --git a/scripts/group-initiative/groupInitiative.js b/scripts/group-initiative/groupInitiative.js index c75ab8e..2f448a0 100644 --- a/scripts/group-initiative/groupInitiative.js +++ b/scripts/group-initiative/groupInitiative.js @@ -191,14 +191,14 @@ export async function rollGroupInitiative(creatures) { let groups = formInitiativeGroups(creatures); // get first combatant id for each group - const ids = Object.keys(groups).map(key => groups[key][0]); + const leaderIDs = Object.keys(groups).map(key => groups[key][0]); const messageOptions = { flavor: "Rolling for initiative! (grouped)" }; // roll initiative for group leaders only - await this.rollInitiative(ids, {messageOptions}); + await this.rollInitiative(leaderIDs, {messageOptions}); // prepare others in the group let groupUpdates; @@ -221,13 +221,23 @@ export async function rollGroupInitiative(creatures) { if (group.length <= 1 || initiative) return updates; // get initiative from leader of group - initiative = this.combatants.get(group[0]).initiative; + if (leaderIDs.includes(group[0]) && this.combatants.get(group[0])?.initiative) { + initiative = this.combatants.get(group[0]).initiative; + } else { + for (let leaderID of leaderIDs) { + if (this.combatants.get(leaderID).actor.data._id === actor.data._id && this.combatants.get(leaderID)?.initiative) { + initiative = this.combatants.get(leaderID).initiative; + break; + } + } + } + if (!initiative) console.error(`Mob Attack Tool | There was a problem obtaining the initiative score of the group leader of ${actor.name}.`); updates.push({_id: id, initiative}); return updates; }, []); // batch update all other combatants - this.updateEmbeddedDocuments('Combatant', groupUpdates); + await this.updateEmbeddedDocuments('Combatant', groupUpdates); } diff --git a/scripts/individualRolls.js b/scripts/individualRolls.js index f3a0174..aa565d3 100644 --- a/scripts/individualRolls.js +++ b/scripts/individualRolls.js @@ -4,7 +4,7 @@ import { endGroupedMobTurn, getDamageFormulaAndType, sendChatMessage, getAttackB export async function rollMobAttackIndividually(data) { // Temporarily disable DSN 3d dice from rolling, per settings - if (!game.settings.get(moduleName, "enableDiceSoNice")) { + if (!game.settings.get(moduleName, "enableDiceSoNice") && game.user.isGM) { await game.settings.set(moduleName, "hiddenDSNactiveFlag", false); } @@ -120,6 +120,8 @@ export async function rollMobAttackIndividually(data) { pluralOrNot: pluralOrNot, critMsg: critMsg, endOfMsg: `!`, + withAdvantage: data.withAdvantage, + withDisadvantage: data.withDisadvantage, atkRollData: atkRollData, showIndividualAttackRolls: (atkRollData.length === 0) ? false : game.user.getFlag(moduleName,"showIndividualAttackRolls") ?? game.settings.get(moduleName,"showIndividualAttackRolls"), displayTarget: data.targets.length !== 0, @@ -420,5 +422,5 @@ export async function processIndividualDamageRolls(data, weaponData, finalAttack } } // Allow DSN 3d dice to be rolled again - await game.settings.set(moduleName, "hiddenDSNactiveFlag", true); + if (game.user.isGM) await game.settings.set(moduleName, "hiddenDSNactiveFlag", true); } \ No newline at end of file diff --git a/scripts/mobAttackTool.js b/scripts/mobAttackTool.js index 89756c9..555d85b 100644 --- a/scripts/mobAttackTool.js +++ b/scripts/mobAttackTool.js @@ -762,10 +762,19 @@ export class MobAttackDialog extends FormApplication { mobAttackData.numSelected = mobList[Object.keys(mobList)[0]].numSelected; } + // if macro not exported explicitly with advantage/disadvantage, + // make the macro respond to alt (option on MacOS) and ctrl (Command on MacOS) for advantage/disadvantage. + let advKeyEvent = mobAttackData.withAdvantage; + let disadvKeyEvent = mobAttackData.withDisadvantage; + if (!mobAttackData.withAdvantage && !mobAttackData.withDisadvantage) { + advKeyEvent = `event.altKey`; + disadvKeyEvent = `event.metaKey`; + } + let macroData = { type: "script", name: selectedName, - command: `MobAttacks.quickRoll({numSelected: ${mobAttackData.numSelected}, weaponLocators: ${JSON.stringify(mobAttackData.weaponLocators)}, attacks: ${JSON.stringify(mobAttackData.attacks)}, withAdvantage: ${mobAttackData.withAdvantage}, withDisadvantage: ${mobAttackData.withDisadvantage}, rollTypeValue: ${mobAttackData.rollTypeValue}, rollTypeMessage: "${mobAttackData.rollTypeMessage}", endMobTurn: ${mobAttackData.endMobTurn}, monsters: ${JSON.stringify(mobAttackData.monsters)}})`, + command: `MobAttacks.quickRoll({numSelected: ${mobAttackData.numSelected}, weaponLocators: ${JSON.stringify(mobAttackData.weaponLocators)}, attacks: ${JSON.stringify(mobAttackData.attacks)}, withAdvantage: ${advKeyEvent}, withDisadvantage: ${disadvKeyEvent}, rollTypeValue: ${mobAttackData.rollTypeValue}, rollTypeMessage: "${mobAttackData.rollTypeMessage}", endMobTurn: ${mobAttackData.endMobTurn}, monsters: ${JSON.stringify(mobAttackData.monsters)}})`, img: mobAttackData.weapons[key].img }; @@ -837,7 +846,7 @@ export function MobAttacks() { }) data["weapons"] = weapons; - data["attacks"] = attacks; + if (targets.length) data["attacks"] = attacks; (async () => { if (game.settings.get(moduleName, "mobRules") === 0) { diff --git a/scripts/mobRules.js b/scripts/mobRules.js index a2dc7d9..7baa1b0 100644 --- a/scripts/mobRules.js +++ b/scripts/mobRules.js @@ -4,7 +4,7 @@ import { endGroupedMobTurn, getDamageFormulaAndType, calcD20Needed, calcAttacker export async function rollMobAttack(data) { // Temporarily disable DSN 3d dice from rolling, per settings - if (!game.settings.get(moduleName, "enableDiceSoNice")) { + if (!game.settings.get(moduleName, "enableDiceSoNice") && game.user.isGM) { await game.settings.set(moduleName, "hiddenDSNactiveFlag", false); } @@ -284,5 +284,5 @@ export async function processMobRulesDamageRolls(data, weaponData, numHitAttacks } } // Allow DSN 3d dice to be rolled again - await game.settings.set(moduleName, "hiddenDSNactiveFlag", true); + if (game.user.isGM) await game.settings.set(moduleName, "hiddenDSNactiveFlag", true); } \ No newline at end of file diff --git a/templates/mat-msg-individual-rolls.html b/templates/mat-msg-individual-rolls.html index ec6d2bb..49e6d89 100644 --- a/templates/mat-msg-individual-rolls.html +++ b/templates/mat-msg-individual-rolls.html @@ -18,7 +18,7 @@
    {{#each this.atkRollData}} -
  1. {{this.roll}}
  2. +
  3. {{this.roll}}
  4. {{/each}}