Calculation of damage with debuffs

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,305
Reaction score
11,731
First Language
English
Primarily Uses
RMVXA
My understanding is that debuffs, like states, are applied after damage has been calculated. However, I'm now wondering if that is actually true.

I have a skill where the actor is healed by the enemy's ATK x 2. It also applies an ATK debuff. For the healing to be worth it, that debuff must happen after the actor gets the heal. However, it doesn't seem to be quite like that.

I have an enemy with an ATK of 30. Healing should, if I am correct, be 60. It never is. With variance set to zero, it is 46, which looks like it's being calculated after the debuff has been applied.

Here is my damage formula:
Code:
a.hp += b.atk*2; b.add_debuff(2,2,); b.atk*2

As you can see, the damage part of the formula is at the end, after the debuff, but that is because the formula has to end with a number. If I end it with the debuff, I get zero damage.

Can anyone enlighten me as to what's going on here?
Thank you.
 

kirbwarrior

Veteran
Veteran
Joined
Nov 13, 2014
Messages
814
Reaction score
536
First Language
English
Primarily Uses
N/A
My understanding is that debuffs, like states, are applied after damage has been calculated.
I didn't know that. I know common events happen after damage, but I thought buffs and states applied right when they were received.

Code:
a.hp += b.atk*2; b.add_debuff(2,2,); b.atk*2
And as such, you're applying the debuff before the damage but after the healing. You could set a temporary variable first;

Code:
c = b.atk*2; a.hp += c; b.add_debuff(2,2,); c

"c" is set up to be the target's attack. In order, it then heals the user for c, applies a debuff, then damages for c.

Mind, that last part makes me pause. It sounds like what you want is to only heal and debuff, not do damage. If that's true, I'd actually make this two different skills;

A - This skill targets the enemy. It gives an invisible state (for simplicity, you can call this state Target and use it for other skills).. It then calls a common event that stores the target's attack into a variable (using Target to 'find' the right enemy), then forces skill B.
B - The user heals equal to the variable, then gives the Target'd enemy a debuff and removes Target. This might need a second common event.

That's without plugins, I'm certain it's much easier with plugins.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,370
Reaction score
1,779
First Language
EN
Primarily Uses
RMMZ
Since the debuff is being added to the target and seems to have fixed duration, I wonder if it might be easier to just add it as a skill effect?
 

Magnus0808

Software Developer
Veteran
Joined
Feb 2, 2019
Messages
165
Reaction score
191
First Language
Danish
Primarily Uses
RMMV
Hmm I just tried to replicate the issue, but when using a skill with your damage formula against an enemy with 30 ATK I did heal for 60 as expected. :rswt
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,305
Reaction score
11,731
First Language
English
Primarily Uses
RMVXA
@Magnus0808 That confirms my logic, so thank you for the test. I'm not at all sure what is causing the difference at my end.

@kirbwarrior I tried your damage formula and that appears to have sorted it out, so thank you very much.

@caethyril I'll keep that in mind for other skills where I want to do something like this. Thank you.
 

kirbwarrior

Veteran
Veteran
Joined
Nov 13, 2014
Messages
814
Reaction score
536
First Language
English
Primarily Uses
N/A
Since the debuff is being added to the target and seems to have fixed duration, I wonder if it might be easier to just add it as a skill effect?
This actually sounds way easier. Since the attack heals the user and damages the target, it could just be a drain spell that does "b.atk * 2" damage, then adds the debuff with effects instead of the damage formula, which should come after the damage.
 
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,305
Reaction score
11,731
First Language
English
Primarily Uses
RMVXA
@kirbwarrior That does indeed sound much more straightforward. I was simply overthinking it. That's what I get for being away from game making for a few months.
Thank you.
 

Magnus0808

Software Developer
Veteran
Joined
Feb 2, 2019
Messages
165
Reaction score
191
First Language
Danish
Primarily Uses
RMMV
Maybe I misunderstod what the skill was supposed to do. I thought it was on purpose that you deal less damage than you heal.
So what your damage formular does is (when the target has 30 ATK):
Heal for 2 * target ATK (60)
Apply ATK debuf to target for 2 rounds (reduces ATK to around 22)
Deal 2 * target ATK (44)

The reason this happens is because the damage formular gets evaluated (basically run as code) where the last statement is returned as the damage value. So the first two statements (Lines before ; ) gets run first in order.
 

gstv87

Veteran
Veteran
Joined
Oct 20, 2015
Messages
2,342
Reaction score
1,366
First Language
Spanish
Primarily Uses
RMVXA
in terms of objects, "b" is always the same object.
if you apply a modifier to "b", and then reference "b", you're referencing "b" + modifier, not "b, the object that is stated in the database"

if there's no separation of references, the program doesn't know that you want to keep them separated.
 

Latest Threads

Latest Profile Posts

I managed to review my previous lessons on Learn MV and fixed a lot of things. Yay! :kaopride:
I've decided "Attack on Equestria" should be released first... hence this new ARG channel! https://www.youtube.com/channel/UClKiUI8xOVx9dsF4kRXUmxw
Check it out, and subscribe! The ARG will lead up to the video game. It's not a creepy game, but I just thought it should follow ARG standards.
For anyone interested in my project M - i finally made a gamethread about it :D

Forum statistics

Threads
110,409
Messages
1,053,089
Members
143,474
Latest member
Arsyloth
Top