Skip to content

Commit

Permalink
v0.3.5
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Stendarpaval committed Aug 16, 2021
1 parent 9203697 commit d8129c1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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"
}
18 changes: 14 additions & 4 deletions scripts/group-initiative/groupInitiative.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

6 changes: 4 additions & 2 deletions scripts/individualRolls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
13 changes: 11 additions & 2 deletions scripts/mobAttackTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/mobRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion templates/mat-msg-individual-rolls.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="dice">
<ol class="dice-rolls">
{{#each this.atkRollData}}
<li class="roll die d20 {{this.color}}" title="{{localize 'Attack Roll'}} (+{{this.finalAttackBonus}} {{localize 'MAT.toHit'}})">{{this.roll}}</li>
<li class="roll die d20 {{this.color}}" title="{{localize 'Attack Roll'}} (+{{this.finalAttackBonus}} {{localize 'MAT.toHit'}}) {{#if ../withAdvantage}}(Advantage){{/if}}{{#if ../withDisadvantage}}(Disadvantage){{/if}}">{{this.roll}}</li>
{{/each}}
</ol>
</div>
Expand Down

0 comments on commit d8129c1

Please sign in to comment.