Skip to content

Commit

Permalink
Update ma5e.js
Browse files Browse the repository at this point in the history
fixed item usage/ammo bug
  • Loading branch information
jessev14 committed May 11, 2022
1 parent 3e84452 commit 9f43677
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions scripts/ma5e.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class Multiattack5e {
// Before making prime roll, prepare to intercept chat message creation and prevent it
Hooks.once("preCreateChatMessage", (chatMessage, chatMessageData, options, userID) => {
(async () => {
await new Promise(resolve => setTimeout(() => resolve(), 100)); // Short delay to allow prime roll to complete usage/ammo updates

// Gather roll, actor, and item information from chat message data
const primeRoll = chatMessage.roll;
const tokenID = chatMessage.data.speaker.token;
Expand All @@ -158,17 +160,15 @@ class Multiattack5e {
const rollType = chatMessage.getFlag("dnd5e", "roll.type");
const itemID = chatMessage.getFlag("dnd5e", "roll.itemId");
const item = actor.items.get(itemID);
let rollMethod, rollOptions;
let rollOptions;
if (rollType === "attack") {
rollMethod = CONFIG.Item.documentClass.prototype.rollAttack;
rollOptions = {
fastForward: true,
chatMessage: false,
advantage: vantage === "advantage",
disadvantage: vantage === "disadvantage"
};
} else {
rollMethod = CONFIG.Item.documentClass.prototype.rollDamage;
rollOptions = {
critical: primeRoll.isCritical,
options: {
Expand All @@ -180,8 +180,11 @@ class Multiattack5e {

const rollArray = [primeRoll];
for (let i = 1; i < numberOfRolls; i++) {
const itemRoll = await rollMethod.call(item, rollOptions);
const itemRoll = rollType === "attack"
? await item.rollAttack(rollOptions)
: await item.rollDamage(rollOptions);
if (!itemRoll) break;

rollArray.push(itemRoll);
}
const dsnSetting = game.settings.get(moduleName, "extraAttackDSN");
Expand Down Expand Up @@ -244,7 +247,7 @@ class Multiattack5e {
let vantageMode;
if (rollType === "attack") vantageMode = CONFIG.Dice.D20Roll.ADV_MODE[vantage];
else vantageMode = vantage === "critical";
ogCallback(html, vantageMode);
return ogCallback(html, vantageMode);
}
}
});
Expand Down

0 comments on commit 9f43677

Please sign in to comment.