Mana Return Based on Damage Dealt

Hello,

I am using RPG Maker MV.

I am trying to make a state that causes the battler to do 50% of their normal damage and to gain MP based on say 10% of the damage they deal each round they have the state.

I figure that Yanfly's BuffStatesCore is the best way to do this.
http://yanfly.moe/2015/12/25/yep-50-buffs-states-core/

I think the damage portion should work similar to a crtical hit, but check for the state instead of critical. applyStateId(x)

Game_Action.prototype.applyCritical = function(damage) {
return damage * 3;
};

I think using the following lunatic mode

<Custom Initiate Effect>

And then something along the lines of changing the above applyCritical to check for a state?

applyStateId(x)

isStateAffected(stateId: number) // I am not sure what 'number' here is supposed to represent

and then changing the 3 to a 0.5 or whatever I want to change it to.

<Custom Initiate Effect>



Any help here would be appreciated.


I think that the mana gain porion will work with one of the follow lunatic mode choices (I'm sure I can figure out which one if I have a working code)
<Custom Action End Effect>
<Custom Turn End Effect>
<Custom Establish Effect>


But my problem lies in what code goes between. I do not know how to call upon the damage done by the battler in that round.

it would be something along of the lines of

user.gainMp(user.thisDamageValue*0.1)

or maybe user.evalDamageValue

Game_ActionResult_this.hpDamage()*0.1

Game_Battler_this._result.hpDamage
After some testing, none of this works. I have no idea if I am even close with any of these and they just need slightly tweaking. but, it is beyond my knowledge at the moment.

I have, however, figured out a workaround. I can just add the following the every skill. I haven't tested it so I'm not sure it works as is, but a little tweaking and it should work.

if (a.isStateAffected(staeID)) { a.gainMp(dmg*0.1); dmg*0.5; } else {dmg}


Doing it this way is much easier, as it is relatively easy to reference the damage inside the skill itself.
However, I would still prefer to do it in the state itself, because I intend to use more states like this such as a vampiric state that drains HP when the state is applied, and others that I intend to use.

I don't even know if it's possible, but my question is does anyone know the script to call upon a character's damage outside of the skill?
So I figured out a way with Yanfly's Buff and States Core
http://yanfly.moe/2015/12/25/yep-50-buffs-states-core/

By using this notetag for a state

<Custom Confirm Effect>
Math.floor(value*=0.5)
user.gainMp(value*0.1)
</Custom Confirm Effect>

However, I ran into another problem that maybe someone could help with, if possible. That the damage dealt now contains decimals. I have the tried the following 2 options, and cannot think of any others..

Math.floor(value*=0.5) //damage isn't rounded
value*=Math.floor(0.5) //deals no damage

Original thread: https://forums.rpgmakerweb.com/threads/mana-return-based-on-damage-dealt.87209/