Hey so I what I've been trying to accomplish is when anyone is physically attacked in combat the damage is initially mitigated by defense, and then applied to health, but I wanted the amount of mitigated damage to still be applied to their MP gauge(which I've repurposed as stamina and is used as basically a second more short term HP gauge). So I've came up with the following to use as the damage formula:
var wd = Math.randomInt(a.atk)+1; //Weapon Damage
var dm = Math.randomInt(b.def)+1; //Damage Mitigation
dm > wd ? b.gainMp(-wd): b.gainMp(-dm); //lose stamina based off of mitigated damage or weapon damage if value is lower
b.result().critical ? wd : Math.max(1, (wd - dm)) //criticals bypass defense
And it works, but one of the problems with the above is using b.gainMp in the damage formula step doesn't account for resistances to damage types, which I'd still like to be considered, or anything else that is applied after the formula I suppose. I'm learning this as I go, so it might be super simple, but I've tried using my var dm later in the action phase (with VisuStella Battle Core, <JS Post-Damage as User> , but that doesn't seem to work the way I've tried it. which was something like:
<JS Post-Damage>
dm > wd ? b.gainMp(-wd * this.calcElementRate(target)): b.gainMp(-dm * this.calcElementRate(target))
</JS Post-Damage>
But the console says dm is undefined at that point. So really what I want is the amount of damage that was mitigated by defense to be applied to their MP gauge but also affected by the modifiers that come after the damage formula is calculated. Maybe this can all be done a completely different way than I've been trying.
I'd really appreciate the help, thank you.
var wd = Math.randomInt(a.atk)+1; //Weapon Damage
var dm = Math.randomInt(b.def)+1; //Damage Mitigation
dm > wd ? b.gainMp(-wd): b.gainMp(-dm); //lose stamina based off of mitigated damage or weapon damage if value is lower
b.result().critical ? wd : Math.max(1, (wd - dm)) //criticals bypass defense
And it works, but one of the problems with the above is using b.gainMp in the damage formula step doesn't account for resistances to damage types, which I'd still like to be considered, or anything else that is applied after the formula I suppose. I'm learning this as I go, so it might be super simple, but I've tried using my var dm later in the action phase (with VisuStella Battle Core, <JS Post-Damage as User> , but that doesn't seem to work the way I've tried it. which was something like:
<JS Post-Damage>
dm > wd ? b.gainMp(-wd * this.calcElementRate(target)): b.gainMp(-dm * this.calcElementRate(target))
</JS Post-Damage>
But the console says dm is undefined at that point. So really what I want is the amount of damage that was mitigated by defense to be applied to their MP gauge but also affected by the modifiers that come after the damage formula is calculated. Maybe this can all be done a completely different way than I've been trying.
I'd really appreciate the help, thank you.