MV Reflection state still applies on-hit effects

Hello Makers!
I've been trying to make a Magic Reflection state for a while now, as I'm not the biggest fan of reflecting 100% of the original damage back. And it does work to an extent. There are just a few things I'm missing.
  1. After taking the damage, the effects of the skill (e.g. add state) can still be applied to the target.
  2. I also haven't figured out how to make those effects have a chance of being applied back to the attacker.
Below is the code I put in the state's note box. I used Yanfly's Buffs & States Core for that. Is there a way to make it work somehow?

<Custom Apply Effect> var stacks = target.getStateCounter(stateId) || 0; stacks += 1; stacks = stacks.clamp(0, 1); target.setStateCounter(stateId, stacks); </Custom Apply Effect> <Custom React Effect> if (this.isPhysical() && value > 0) { var reflect = Math.round(value * 0.25); user.startAnimation(7); user.gainHp(-1 * reflect); if (user.isDead()) { user.performCollapse(); } target.startAnimation(2); value = 0; var stacks = target.getStateCounter(stateId) || 0; stacks -= 1; stacks = stacks.clamp(0, 1); if (stacks < 1) { target.removeState(stateId); } } </Custom React Effect>
You would have to either
- Take the effects off the skill and put them into a Post-Damage Eval that looks for your reflect state and does the stuff; you'd have to do that for each skill
or
- Get/make/commission a new plugin to do this. Nothing in the notetags for Skills or Buffs can circumvent the regular applying of Effects on the skill.
I'm not sure why the effects wouldn't be applied to the target, the <react> tag is just a hook for running your code, it won't cancel the skill unless you add code for it.

As for reflecting back the effects it's a little more complicated but it should be possible to just apply the effects of the skill to the attacker instead
That code is normally
JavaScript:
this.item().effects.forEach(function(effect) {
     this.applyItemEffect(target, effect);
}, this);

(See rpgobjects.js in the game_action section)
So you could just copy this and change target to be user
I'm not sure why the effects wouldn't be applied to the target
I also found the OP confusing, but my best understanding is they don't want the effects to be applied when their fake reflect status is triggered. There's nothing in Yanfly notetags that can affect that.
Oh, well that's a fairly easy change too, simply add a property to the action and check that action in the action apply code.

In the react block where the reflection applies just do something like

this._ignoreEffects = true;

Either search for `Game_Action.prototype.apply` in rpg_objects, or the code I posted in my previous post, and wrap it with a check for that boolean. IE

JavaScript:
if(!this._ignoreEffects) {
    this.item().effects.forEach(function(effect) {
       this.applyItemEffect(target, effect);
    }, this);
}

As usual when making changes to the core files, double check that the function isnt being overwritten by a plugin
@contentdeleted's code should help you, but please note it's bad practice to make any changes to the core files.

You should always put your changes in a plugin (which would involve copying the entire Game_Action.prototype.apply function into a new file and making the change there).

Also, as you're using Yanfly's plugins, it's a given fact that they do overwrite that function. So you would need to find the Yanfly plugin farthest down on the plugin manager list with the function, copy that version, add the modification, and put your plugin underneath that.
You should always put your changes in a plugin (which would involve copying the entire Game_Action.prototype.apply function into a new file and making the change there).
That really depends, while it's usually a good idea to avoid making changes directly to the core files to avoid conflicts with other plugins, if you can confirm that your change does not conflict it's best to avoid making a new plugin for it (if the change is very minor and relies on modifying code rather than overwriting or wrapping it) and calling the existing prototype as it lengthens the function stack unnecessarily which has (extremely minor) performance impacts and more importantly can make it more difficult to understand the flow of your code.

In this case you'd actually want to avoid this, because each of Yanflys plugins relies on wrapping the core function, not overwriting it.

Example:
1708018482888.png


If you still want to make a separate plugin for this in-order to avoid changing the core files at any cost just make sure it is placed in your functions list in the editor at the top and is loaded before the yanfly plugins and do not copy out any of their code.
it's best to avoid making a new plugin for it...as it lengthens the function stack unnecessarily which has (extremely minor) performance impacts
I would say the length of the function stack makes such a nonexistent difference for any modern processor that it's not worth a non-coder trying to differentiate between when they should or shouldn't edit a core file 😉

But you are absolutely correct that the Yanfly plugins alias the apply() method and any user changes should load above them. I withdraw the objection 🙂
I would say the length of the function stack makes such a nonexistent difference for any modern processor that it's not worth a non-coder trying to differentiate between when they should or shouldn't edit a core file
Right, it's basically not worth mentioning but it sure lends an air of importance to my argument 😛

Based on the user's code snippets I'm comfortable saying they at least have some javascript fundamentals (unless it was all copied from somewhere), and are probably going to be fine making a one line change like this.

You're right to advise caution though, its very easy to cause unintended effects along the stack of plugins if you've imported a sizeable chunk of community code
I put my changes always in their own plugin, even if it is a single line, simply so it is documented that I changed something there.
Thanks for the insides you all~ I followed @ATT_Turan's suggestion and used the Post-Damage Eval for it (I'm always looking past the easiest solutions, sorry), and reworked the state in question a bit. I don't want to change anything inside the plugins cause I don't know how to do it properly. My Java knowledge is very limited. Once again, thanks. :>

This topic can be closed.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/reflection-state-still-applies-on-hit-effects.165788/