MV [SOLVED][YEP Buffs and States Core] A state which causes skill damage/healing to be calculated based on a different stat

I want to have a character whose passive state causes any healing skills they use to scale off of Atk instead of Mat. I've figured out enough to check which skill the character has selected, check if the damage type is HP Recovery, and I've even been able to store the damage formula in a variable, then use replace() to change "a.mat" to "a.atk" in the string if it exists, but I don't know how to feed that formula back in to be used for damage calculation. I obviously can't just replace the formula in the skill itself, as that would cause it to scale off of Atk for other characters as well.

Is this even something that can be done with the Buffs and States Core, or would I need to use something like Damage Core? I've never looked into the latter so I don't know if it can even be used with states or how to do so.

Edit: For more context, this is what the state tag currently looks like:
Spoiler: State Tag Contents
JavaScript:
<Custom Confirm Effect>
 // Get the current skill
 var skill = this.item();
 // Checks if the skill type is "HP Recover"
 if (skill && skill.damage.type === 3) {
  // Store the contents of "formula" as a variable
  var formula = skill.damage.formula;
  // Checks if the formula uses M.Attack
  let usesMat = formula.includes("a.mat");
  if (usesMat == true) {
   // Creates a new formula string with "a.mat" replaced by "a.atk"
   let newFormula = formula.replace("a.mat", "a.atk");
  }
 }
</Custom Confirm Effect>
There's no need to put any of this into notetags or use a plugin at all. See:

(You'd need a plugin to have a passive state, but the healing calculation has nothing to do with it)

You don't show what your actual formula is, but let's say you're healing for MAT+50. You'd make your damage formula:
Code:
a.isStateAffected(X) ? a.atk+50 : a.mat+50
where X is the ID of your passive state.
There's no need to put any of this into notetags or use a plugin at all. See:

(You'd need a plugin to have a passive state, but the healing calculation has nothing to do with it)

You don't show what your actual formula is, but let's say you're healing for MAT+50. You'd make your damage formula:
Code:
a.isStateAffected(X) ? a.atk+50 : a.mat+50
where X is the ID of your passive state.
I was hoping to avoid having to edit the damage formulas for the skills directly, as I was told it's bad practice to do it just to accommodate one circumstance (plus I was hoping to avoid having to do it individually for every healing skill) but if that's the only option then I guess it's what I'll have to do.

And I didn't mention it originally since it didn't seem relevant to my question, but yes, I am already using a plugin to give this passive state to the character.
I was hoping to avoid having to edit the damage formulas for the skills directly, as I was told it's bad practice to do it just to accommodate one circumstance
I don't understand why that would be true. It's your game: it's not like there's any reason your skill formulae should be generically functional, they can accommodate whatever circumstances your project needs 🙂

(plus I was hoping to avoid having to do it individually for every healing skill) but if that's the only option then I guess it's what I'll have to do.
I don't know how many healing skills you have, but it should be a pretty fast copy/paste process to modify them with the conditional I provided above. The Damage Core plugin isn't useful to you because its notetags go into the skill to replace the damage formula - there's nothing you can do there that you can't do in the formula, it's just more readable.

You could use your original approach with a notetag that takes place earlier than confirm, but that's
1 - more complicated, because you'd have to put passive states on everyone to change the formula back and forth, and
2 - actually bad practice, in my opinion, to modify the skill's formula 😉

You could use a state to entirely recalculate the damage.
Code:
<Custom Confirm Effect>
if (this.isRecover() && this.isSkill())
{
    switch (this.item().id)
        // These are all IDs of healing skills
        case 14:
            // Recalulate the damage. For example, ATK+50 with a 20% variance
            value=(user.atk+50)*.8 + (Math.random()*(user.atk+50)*.4);
            break;
        case 72:
            value=user.atk*3;
            break;
}
</Custom Confirm Effect>
but I don't see how that's easier than putting it into the formula, since you still need to accommodate each individual skill there. If nothing else, it's more keystrokes and probably more time to figure out the math.

So that's not your only option, but it's definitely what I'd do.

And I didn't mention it originally since it didn't seem relevant to my question, but yes, I am already using a plugin to give this passive state to the character.
I know, I just wanted to clarify from my statement "there's no need to use a plugin at all."
it's not like there's any reason your skill formulae should be generically functional, they can accommodate whatever circumstances your project needs
I guess the reason why I want to avoid making them specialized is because that's what I personally feel more comfortable with. I'd rather do the grunt work now to make this one case work dynamically from the state itself if possible than having to go back and make little changes for any future specialized cases. Maybe that's counterproductive, since playtesting is nothing but making little changes, but if I can do anything to avoid over-complicating my individual skill formulas I'd prefer that approach.

Either way, you've given me some good insight, and I'll definitely look into the options you've presented.
I don't understand why that would be true. It's your game: it's not like there's any reason your skill formulae should be generically functional, they can accommodate whatever circumstances your project needs 🙂
I know Yanfly had put out an article once that recommended against it. Thing is, as long as you don't intend to use autobattle for anything, it shouldn't be an issue. If you are using autobattle, then it's best to avoid doing funny stuff in the damage formula.
I know Yanfly had put out an article once that recommended against it. Thing is, as long as you don't intend to use autobattle for anything, it shouldn't be an issue. If you are using autobattle, then it's best to avoid doing funny stuff in the damage formula.
There is the autobattle portion - it also runs through those routines when the enemy battlers are evaluating what to do on their turn.

The thing is, that article gets slightly misrepresented. There are certain things (which change the state of the battlefield) which should be avoided in damage formulae because those functions will get called whether or not it's calculating a damage value.

So, for example, calling the function to add a state to the target should be avoided in the damage formula, because that can happen at times when you're not actually performing the skill.

Something like this, where you're checking for a state, is irrelevant.
There is the autobattle portion - it also runs through those routines when the enemy battlers are evaluating what to do on their turn.

The thing is, that article gets slightly misrepresented. There are certain things (which change the state of the battlefield) which should be avoided in damage formulae because those functions will get called whether or not it's calculating a damage value.

So, for example, calling the function to add a state to the target should be avoided in the damage formula, because that can happen at times when you're not actually performing the skill.

Something like this, where you're checking for a state, is irrelevant.
I really think this should be posted somewhere for all to see, because that article isn't really clear on that. It had me worried once, and then I slapped myself and noted that I'm not doing anything particularly troublesome in my formulas, outside of the one that did add a state, which I promptly fixed.
For anyone who finds this thread later, here is the solution I ended up going with. It replaces the damage formula before healing, then reverts it within the same action after healing to make sure the regular formula is used in any other situation. It should work with any HP Recover skill that includes "a.mat" in the formula.
Spoiler: State Notetag
JavaScript:
<Custom Confirm Effect>
 // Get the current skill
 var skill = this.item();
 // Checks if the skill type is "HP Recover"
 if (skill && skill.damage.type === 3) {
  // Store the contents of "formula" as a variable
  var formula = skill.damage.formula;
  // Checks if the formula uses M.Attack
  let usesMat = formula.includes("a.mat");
  if (usesMat == true) {
   // Creates a new formula string with "a.mat" replaced by "a.atk"
   let newFormula = formula.replace("a.mat", "a.atk");
   // Creates a private variable and stores the original formula in it.
   user._storedFormula = user._storedFormula || null;
   if (user._storedFormula == null) {
    user._storedFormula = skill.damage.formula;
    // Replaces the formula in the skill with the new formula
    skill.damage.formula = newFormula;
   }
  }
 }
</Custom Confirm Effect>

<Custom Conclude Effect>
 // Checks if the stored formula exists
 user._storedFormula = user._storedFormula || null;
 if (user._storedFormula !== null) {
  // Accesses the skill and replaces the altered formula with the stored formula
  var skill = this.item();
  if (skill && skill.damage.type === 3) {
   skill.damage.formula = user._storedFormula;
   // Clears the stored formula
   user._storedFormula = null;
  }
 }
</Custom Conclude Effect>

Original thread: https://forums.rpgmakerweb.com/threads/solved-yep-buffs-and-states-core-a-state-which-causes-skill-damage-healing-to-be-calculated-based-on-a-different-stat.153674/