Magical absorbtion

Trying to work out a mechanic to handle magic absorption.

Basically, a character who is both completely immune to skills tagged as magical and receives MP from it.

I've managed to put together a state which makes a character immune to magical damage and gives a fraction of that damage as MP.

But I'd really like the ability to absorb any magical skill, including non-damaging ones. So the character can be targeted by these effects, negates any effects from them (positive or negative) and grants MP to the character. Amount of MP would ideally be equal to the MP cost of the skill.
Still trying to get this worked out.

For now I've got that damage absorption effect I mentioned, but I'm trying to work out a bit of a bug:
This is the notetag I've got


<Custom React Effect>

if (value > 0 && this.isMagical()){

target.gainMp(.25*value);

target.startAnimation(58);

value=0}

</Custom React Effect>

I'm setting the amount gained to 1/4th damage inflicted because I'd like to avoid every attack immediately refilling MP completely, but apparently that leads to fractional MP gain. Any way to stop that?
Hi, round the value:
Target.gainMp(Math.floor(0.25 * value))
Thanks, seems to have fixed it

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/magical-absorbtion.116789/