tposney / midi-qol

Other
5 stars 0 forks source link

workflow.advantage undefined at phases before AttackRollComplete. #1182

Open tposney opened 1 year ago

tposney commented 1 year ago

In GitLab by @thatlonelybugbear on Mar 3, 2023, 23:18

This is just an issue to track the message from the discord MidiQOL thread: https://discord.com/channels/170995199584108546/1010273821401555087/1080536611558789150

It seems that when you make an attack with (dis/)advantage, the workflow is updated to indicate workflow.advantage/workflow.disadvantage on AttackRollComplete.

I was trying to add a situational attackBonus to the workflow (https://discord.com/channels/170995199584108546/1010273821401555087/1080518536415412265), by either a

if (!!workflow.advantage) workflow.setAttackRoll(await new Roll(workflow.attackRoll.formula.concat(" +2").evaluate()))

during the preCheckHits (hooking on preCheckHits) or

if (!!workflow.advantage) Hooks.once("dnd5e.preRollAttack", (item,config) => {config.parts.push("2")})

during preAttackRoll (hooking on preAttackRoll), but both ways failed cause the workflow.advantage was still undefined by these points.

Any way around it?

tposney commented 1 year ago

workflow.checkAdvantage is called before calling item.rollAttack is called so should be correctly inside dnd5e.preRollAttack.

Unfortunately there are a variety of sources for advantage and key based advantage (i.e. holding alt) won't be reflected in workflow.advantage at that point. This means I really need to clean this up (I've been holding off cause it's a nightmare).

However, inside dnd5e.preRollAttack, rollConfig should correctly reflect midi's view of advantage. So just hooking dnd5e.preRollAttack and doing

Hooks.once("dnd5e.preRollAttack", (item, rollConfig) => {
    if (rollConfig.advatnage) {
        // do some stuff
    }
}

should work fine. You can set the Hooks.once in the mdi-qol.preItemUse hook or do a Hooks.on and check the item is the right item - have a look at the metamagic items in the midi sample items for one way to do that - so that spurious item rolls don't break the effect.