Skip to content

Commit

Permalink
0.3.14
Browse files Browse the repository at this point in the history
- Fixed bug that could freeze browser when combined with CTG module thanks to @arcanistzed's suggestion in issue #40.
- Took some additional measures (via a sneaky workaround) to ensure that few conflicts arise from CTG, Group Initiative and Mob Attack Tool each overriding Foundry's core initiative rolling functions.
  • Loading branch information
Stendarpaval committed Dec 30, 2021
1 parent 25f1b96 commit ef982b3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 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.13",
"version": "0.3.14",
"minimumCoreVersion": "0.8.8",
"compatibleCoreVersion": "9",
"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.13/module.zip"
"download": "https://github.com/Stendarpaval/mob-attack-tool/releases/download/0.3.14/module.zip"
}
8 changes: 5 additions & 3 deletions scripts/group-initiative/groupInitiative.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export async function matRollInitiative(ids, {formula=null, updateTurn=true, mes

// Produce an initiative roll for the Combatant
const roll = combatant.getInitiativeRoll(formula);
// Check for V9+
if (String(game.version).startsWith("9.")) await roll.evaluate({async: true});
updates.push({_id: id, initiative: roll.total});

// Construct chat message data
Expand All @@ -59,7 +61,7 @@ export async function matRollInitiative(ids, {formula=null, updateTurn=true, mes
}, messageOptions);
const chatData = await roll.toMessage(messageData, {
create: false,
rollMode: combatant.hidden && (rollMode === "roll") ? "gmroll" : rollMode
rollMode: combatant.hidden && (["roll", "publicroll"].includes(rollMode)) ? "gmroll" : rollMode
});
// Play 1 sound for the whole rolled set
if ( i > 0 ) chatData.sound = null;
Expand Down Expand Up @@ -118,7 +120,7 @@ export async function matRollInitiative(ids, {formula=null, updateTurn=true, mes
}

// Ensure the turn order remains with the same combatant
if ( updateTurn ) {
if ( updateTurn && currentId ) {
await this.update({turn: this.turns.findIndex(t => t.id === currentId)});
}

Expand Down Expand Up @@ -198,7 +200,7 @@ export async function rollGroupInitiative(creatures) {
};

// roll initiative for group leaders only
await this.rollInitiative(leaderIDs, {messageOptions});
await this.matRollInitiative(leaderIDs, {messageOptions});

// prepare others in the group
let groupUpdates;
Expand Down
24 changes: 14 additions & 10 deletions scripts/mobAttack.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,28 @@ Hooks.on('diceSoNiceRollStart', (messageId, context) => {
Hooks.on("renderCombatTracker", async ( app, html, options ) => {
let combat = options.combat;
if (!combat) return;
if (!combat.originalRollNPC) {
combat.originalRollNPC = combat.rollNPC;

if (!combat.matRollInitiative) {
combat.matRollInitiative = matRollInitiative.bind(combat);
}
if (!combat.originalRollAll) {
combat.originalRollAll = combat.rollAll;

if (!combat.MAToriginalRollNPC) {
combat.MAToriginalRollNPC = combat.rollNPC;
}
if (!combat.MAToriginalRollAll) {
combat.MAToriginalRollAll = combat.rollAll;
}

if (game.settings.get(moduleName, "enableMobInitiative")) {
combat.rollNPC = rollNPC.bind(combat);
combat.rollAll = rollAll.bind(combat);
} else {
// reset the methods
if (combat.originalRollNPC) {
combat.rollNPC = combat.originalRollNPC;
if (combat.MAToriginalRollNPC) {
combat.rollNPC = combat.MAToriginalRollNPC;
}
if (combat.originalRollAll) {
combat.rollAll = combat.originalRollAll;
if (combat.MAToriginalRollAll) {
combat.rollAll = combat.MAToriginalRollAll;
}
}
});
});
4 changes: 3 additions & 1 deletion scripts/mobAttackTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,8 @@ export class MobAttackDialog extends FormApplication {
},
default: "yes"
}).render(true);
}
}
ui.combat?.render(true);
})

// select a previously saved mob and optionally delete one or reset all mobs
Expand Down Expand Up @@ -603,6 +604,7 @@ export class MobAttackDialog extends FormApplication {
await game.settings.set(moduleName,'hiddenMobName',mobSelected);
}
if (game.combat) await game.combat.update();
ui.combat?.render(true);
resolve(mobSelected);
}
}
Expand Down

0 comments on commit ef982b3

Please sign in to comment.