dnd5e icon indicating copy to clipboard operation
dnd5e copied to clipboard

Feature request actor.calcluateDamage

Open tposney opened this issue 10 months ago • 4 comments

After the call to dnd5e.preCalculateDamage, damage.active is force set to {} / {active: "Immunity", multiplier: 0). In midi-qol I have occasion to want to configure some of the actives during the preCalculateDamage hook, so that multipliers can be applied prior to damage modification.

Would it be possible to have damage.active initialised to {} prior to the call to dnd5e.preCalculateDamage?

tposney avatar Apr 13 '24 00:04 tposney

Hmm, what is your intention here exactly? Do you want us to not squash any changes made to active during preCalculateDamage? If you set active.multiplier to 2 during preCalculateDamage, are you thinking we'll then modify that value (so if you doubled during pre-calc and then halved during our modification it would end up as 1)?

arbron avatar Apr 17 '24 19:04 arbron

The exact change I would like is that if in calculateDamage, damage.active is already defined don't initialise it to {}. And yes, I'd expect that you base other calculations off the multiplier that was set in preCalc, so in you example the changes made in preCalc would be do double the damage.value and set the multiplier. If the calculateDamage has a half damage the damage.value would end up as the original value and the multiplier would end up being 1.

Which would entail changing

      let damageMultiplier = multiplier;

to

        let damageMultiplier = (damage.active?.multiplier ?? 1) * multiplier;

The specific example I have is computing damage when the target has saved. According to at least one rules interpretation the correct order of damage calc should be saves -> modifications -> resistance/immunity. Currently if I pass options.multiplier the order will be modifications/resistance/saves.

There is also an interpretation that says what is currently being done is correct, so I also have the case of simply setting the multiplier in options during precalculate damage (thanks for the change to make that possible by the way).

So I'm looking to implement the changes due to saves in the preCalculateDamage hook.

I have code to set the multiplier/active/actual damage for each damage item according to the save, but the multiplier per damage item get overwritten (and the active.saved that I set), however the calculated damage is correct.

tposney avatar Apr 18 '24 06:04 tposney

@tposney Let me know if this does what you need: https://github.com/foundryvtt/dnd5e/pull/3491

arbron avatar Apr 24 '24 17:04 arbron

Looks like exactly what I wanted - many thanks.

tposney avatar Apr 25 '24 13:04 tposney