[Bug] Conflict between MidiQOL.completeItemUse and "Roll a separate attack per target" setting
Just to start thank you for all of the amazing work on this module. I've just started using it and it is incredible.
Foundry: 11.315 DND5e: 3.0.3 Midi: 11.4.10 DAE: 11.3.13
I'm currently working on a macro that overrides the flags.midi-qol.rangeOverride.attack.all
flag (derived from one of the Chris's Premades macros). Specifically in the case where this flag gets set, and the actor is out of range of their target (I'm testing with a single target), and the Workflow > Hits > Roll a separate attack per target
setting is enabled the following error is generated:
itemhandling.js:272 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'aborted')
at Item5e.doItemUse (itemhandling.js:272:17)
doItemUse @ itemhandling.js:272
Promise.then (async)
(anonymous) @ utils.js:1721
completeItemUse @ utils.js:1693
await in completeItemUse (async)
eval @ VM35799:33
await in eval (async)
#executeScript @ foundry.js:22928
execute @ foundry.js:22876
callMacro @ workflow.js:2307
callMacros @ workflow.js:2175
WorkflowState_RollFinished @ workflow.js:1440
await in WorkflowState_RollFinished (async)
performState @ workflow.js:476
await in performState (async)
unSuspend @ workflow.js:419
doItemUse @ itemhandling.js:633
await in doItemUse (async)
🎁call_wrapper @ libWrapper-wrapper.js:616
🎁CONFIG.Item.documentClass.prototype.use#0 @ libWrapper-wrapper.js:189
_onAction @ inventory.mjs:377
await in _onAction (async)
(anonymous) @ inventory.mjs:35
This check for the aborted
property specifically occurs in the multiple rolls branch. My guess though is that the issue is the inner call to completeItemUse
resolves to null
in the case of a range check failure:
// itemhandling.js
const result = await completeItemUse(this, config, newOptions);
if (result.aborted) break;
// util.js
item.use(config, options).then(result => { if (!result) resolve(result) });
// itemhandling.js
if (checkMechanic("checkRange") !== "none" && !isAoETargeting && !isRangeTargeting && !AoO && speaker.token) {
if (tokenToUse && targetsToUse.size > 0) {
if (rangeDetails.result === "fail")
return null;
else tokenToUse = rangeDetails.attackingToken;
}
}
I don't know nearly enough to know how it would impact the rest of the midi-qol, but it seems in this case there should be a
if (result === null) continue;
branch prior to the break check.
Let me know if there is something I'm misconfiguring here or if any additional details would be helpful. Below is the macro I'm testing with and two troubleshooter exports (one with the setting off (does not trigger the error) and one with the setting one (triggers the error)).
Macro:
let features = workflow.actor.items.filter(i => i.system.actionType === 'mwak' && (i.type === 'weapon' ? i.system.equipped : true))
let feature
if (!features.length) {
ui.notifications.info('You have no equipped weapons to attack with!')
return
} else {
feature = features[0]
}
let effectData = {
'icon': workflow.item.img,
'origin': workflow.item.uuid,
'duration': {
'seconds': 1
},
'name': 'Override Range Check',
'changes': [
{
'key': 'flags.midi-qol.rangeOverride.attack.all',
'mode': 0,
'value': '1',
'priority': 20
}
]
}
let effect = await createEffect(workflow.actor, effectData)
let options = {
'targetUuids': [workflow.targets.first().document.uuid]
}
await warpgate.wait(100)
await MidiQOL.completeItemUse(feature, {}, options)
await effect.delete()
async function createEffect(actor, effectData) {
let effects = await actor.createEmbeddedDocuments('ActiveEffect', [effectData])
return effects[0]
}