Conditional skill accuracy using Yanfly

I'm trying to create status ailment spells that, through Yanfly's Selection control, can hit either a single target or an entire group, either friend or foe. In order to make single-target use a little less useless, I'd like group-target use to reduce the accuracy of the spell. In fact, there are several cases in which I would like a skill to have variable accuracy, including:

Reducing accuracy of status ailment spells when targeting all enemies (as above)
Healing spells that bypass magic evasion, but can still be reflected
Elemental attacks that bypass magic evasion if the target absorbs the element
Instant death spells that never miss undead enemies (which invokes a custom react effect)
Revive spell that has perfect accuracy on KOed targets, but 20% accuracy on undead enemies

To start with the first one, status ailment accuracy, I think it might be possible using a <Pre-Damage Eval> notetag from Yanfly's Skill Core, or something similar. But I'm at a bit of a loss concerning the custom code. In particular, I have no idea how to check whether I've just targeted a group or an individual. If anyone could offer any insight into any of these scenarios, I would be very appreciative.
I managed to get the fourth and fifth ones to work on my own.

Spoiler: like this
I made my Revive skill using Yanfly's damage core and Selection control, along with that DeadOrAliveItem plugin with Cae's compatibility patch, with the following notetags. I'm still struggling with selection, but that's a story for another thread. State 244 is my Undead state, and that state works as outlined in the Yanfly Tips & Tricks for Undead.

Code:
<scope:oneDeadOrAlive>
<Actor or Enemy Select>
<damage formula>
  if (target.isStateAffected(244) && target.isStateAffected(1))
    {target.result().evaded = true;}
  else if (target.isStateAffected(244))
    if(Math.randomInt(10) <= 1) {value = target.mhp;}
    else {target.result().evaded = true;}
  else if (target.isStateAffected(1))
    {value = target.mhp / 5;}
</damage formula>

I made the Death spell just drop an "Instant Death" state, but I might be able to do it without the state. Pretty sure this needs at least Yanfly's States and Buffs Core along with Selection Control.

Code:
<Custom Apply Effect>
  if (user.isStateAffected(244)) {
    target.gainHp(target.mhp);
    target.startAnimation(41);
  } else {
    if (Math.randomInt(10) <= 3)
      {target.gainHp(-target.mhp);}
  }
  target.removeState(245);
</Custom Apply Effect>

I think my first query might just be a matter of finding a script call to find out whether one or all foes have been targetted. I'm not sure about the second one. The third one though, on further thought, might be a little more complicated. If I'm not mistaken, magic evasion is handled entirely before damage is calculated, and wouldn't be able to account for whether the damage is positive or negative. If I could create a skill that bypasses magical evasion while still being considered magical (and susceptible to magic reflection,) perhaps I could work the evasion step right into a custom damage formula.
I managed to get a status ailment spell working as I wanted, but it proved to be a much more difficult ordeal than I'd anticipated.
The check I was looking for is: "if (this._selectedTargetType === 'ALL ENEMIES' || this._selectedTargetType === 'ALL ALLIES')".
However, it seems that this won't evauate during action sequences. Furthermore, the skill's effects always applied the state even when I forced the skill to miss or be evaded. I finally managed to get it working through a custom damage formula:

Code:
<damage formula>
  value = 0;
  if (this._selectedTargetType === 'ALL ENEMIES' || this._selectedTargetType === 'ALL ALLIES') {
    if (Math.random() <= 0.425) {
      target.addState(5);
    }
  } else if (Math.random() <= 0.85) {
    target.addState(5);
  }
</damage formula>

Quite a hassle. I can't help feeling like there was a simpler way that I didn't see. Also, I think this is still bypassing state rates and luck calculation.


As for my second and third queries, they really boil down to this idea: If a skill's final calculated damage is less than zero, that skill should bypass the target's evasion. I had hoped I could accomplish this using the skill phases tags provided by Yanfly's Skill Core, but unfortunately, I think <Before Eval> cannot make use of the damage dealt, and <Pre-Damage Eval> only takes place if the skill has already successfully connected. I'm not sure what else I can try.
I think I've done it, using Yanfly's Hit Accuracy. I changed the accuracy formula to look like this:

Code:
if (this.makeDamageValue(target, false) < 0) {skillHitRate * userHitRate} else {skillHitRate * (userHitRate - targetEvadeRate)}

That means the damage is calculated twice, and the result might not be the same both times, but all that really matters here is whether it's positive or negative, which should be consistent.

I guess all that leaves is incorporating state rates and luck calculation into the status ailment spells above.

Original thread: https://forums.rpgmakerweb.com/threads/conditional-skill-accuracy-using-yanfly.113109/