Difference between revisions of "Stop Putting Mechanics in Damage Formulas"

From Yanfly.moe Wiki
Jump to navigation Jump to search
Line 6: Line 6:
 
== Introduction ==
 
== Introduction ==
  
Every other RPG Maker MV/MZ user has seen [https://forums.rpgmakerweb.com/index.php?threads/damage-formulas-101.81905/ this article on RPG Maker Web]. It teaches you how to manipulate the damage formula to add in more complexity to skills and items. While most of what the article teaches is okay, the parts where it teaches you how to add mechanics to it aren't because they can conflict heavily with how your game is supposed to operate when the time comes.
+
Every other RPG Maker MV/MZ user has seen [https://forums.rpgmakerweb.com/index.php?threads/damage-formulas-101.81905/ this article on RPG Maker Web]. It teaches you how to manipulate the damage formula to add in more complexity to skills and items. While most of what the article teaches is okay, the parts where it teaches you how to add mechanics to it aren't because they can conflict heavily with how your game is supposed to operate when the time comes. Don't worry, even I fell prey to this early on in the RPG Maker MV lifecycle.
  
 
{{Article by Yanfly}}
 
{{Article by Yanfly}}
Line 13: Line 13:
  
 
That's because the damage formulas should be reserved for damage calculations only. While damage calculations typically occur during battle and/or processing of the effects, they also occur when a skill or item is being evaluated by the A.I. to determine if it's the right skill to use, too. Let's take a look at what happens when mechanics are placed in damage formulas.
 
That's because the damage formulas should be reserved for damage calculations only. While damage calculations typically occur during battle and/or processing of the effects, they also occur when a skill or item is being evaluated by the A.I. to determine if it's the right skill to use, too. Let's take a look at what happens when mechanics are placed in damage formulas.
 +
 +
  
 
== A Brand New Project ==
 
== A Brand New Project ==
Line 21: Line 23:
  
 
The above screenshot is to show you that there are no plugins installed. This is to prove that there is no outside plugin influence to cause some of the problems occurring in what will be shown below.
 
The above screenshot is to show you that there are no plugins installed. This is to prove that there is no outside plugin influence to cause some of the problems occurring in what will be shown below.
 +
 +
  
 
=== Special Skills ===
 
=== Special Skills ===
Line 75: Line 79:
  
 
<hr>
 
<hr>
 +
 +
  
 
=== The Berserker ===
 
=== The Berserker ===
Line 89: Line 95:
  
 
He seems fitting for the Berserker type, right?
 
He seems fitting for the Berserker type, right?
 +
 +
Now that everything is ready, it's time to go over and do a battle test!
 +
 +
 +
 +
== Witnessing the Problem ==
 +
 +
[[File:MechanicsInsideDamageFormulas_Troops.png|600px]]
 +
 +
Let's head over to the Troops tab in the Database. Pick any of them. I'm picking the first one since it's the most convenient.
 +
 +
Note that in the screenshot above, there are no Troop events to cause anything special from happening.
 +
 +
With that in mind, let's hit the '''Battle Test''' button and start a playtest.
 +
 +
=== Turn 1 ===
 +
 +
[[File:MechanicsInsideDamageFormulas_Turn1.png|600px]]
 +
 +
On turn one, without anything that has happened in battle you'll see that Harold's HP is at 25%, has his ATK buffed TWICE, has his DEF debuffed TWICE, and MP at 0.
 +
 +
Just what on earth happened?
 +
 +
 +
 +
=== Explanation ===
 +
 +
[[File:MechanicsInsideDamageFormulas_Evaluate.png]]
 +
 +
The above two functions are the "culprit" to why this happens. I say "culprit" in quotes because it's not really a culprit. It's doing what it's supposed to be doing: its job of calculating the damage formula. It's not at fault that we, the game devs, decided to put game mechanics inside the damage formulas.
 +
 +
But why did it calculate without the actions being performed though?
 +
 +
That's because for some cases, like the A.I. for Auto Battle, all of a battler's available actions have to be evaluated in order to determine the optimal action to perform for battle. RPG Maker's A.I. is simplistic, find the largest number, go with the skill that produces the largest number. However, because we put mechanics in them, each time the calculations are made, the mechanics are also being performed.
 +
 +
Why did it happen TWICE though? Let's look back at the troops page:
 +
 +
[[File:MechanicsInsideDamageFormulas_Troops.png|600px]]
 +
 +
There are two enemies there.
 +
 +
The A.I. would evaluate each available skill for each available enemy. This means if there are two enemies, the skills are evaluated twice each. And this will happen each turn. If there are 8 enemies, the skills will be evaluated 8 times each. This means that the self-HP halving skill would occur 8 times over had there been a full enemy party.
  
 
|}
 
|}

Revision as of 20:16, 25 January 2021

Welcome to the wiki! This is where you can find resources from Yanfly.moe, Ækashics.moe,
VisuStella, Caz Wolf, Fallen Angel Olivia, Atelier Irina, and other affiliated content creators.


Introduction

Every other RPG Maker MV/MZ user has seen this article on RPG Maker Web. It teaches you how to manipulate the damage formula to add in more complexity to skills and items. While most of what the article teaches is okay, the parts where it teaches you how to add mechanics to it aren't because they can conflict heavily with how your game is supposed to operate when the time comes. Don't worry, even I fell prey to this early on in the RPG Maker MV lifecycle.

Yanfly.png This is an article written by Yanfly.

Why do I say that?

That's because the damage formulas should be reserved for damage calculations only. While damage calculations typically occur during battle and/or processing of the effects, they also occur when a skill or item is being evaluated by the A.I. to determine if it's the right skill to use, too. Let's take a look at what happens when mechanics are placed in damage formulas.


A Brand New Project

Let's create a brand new project to show off the controlled aspects of this problem.

MechanicsInsideDamageFormulas BlankProject.png

The above screenshot is to show you that there are no plugins installed. This is to prove that there is no outside plugin influence to cause some of the problems occurring in what will be shown below.


Special Skills

Using the examples found in the article above, we'll have the following effects made for 4 different skills:


Power Strike:

MechanicsInsideDamageFormulas Example1.png

a.addBuff(2, 5); a.atk * 4 - b.def * 2

This is a skill that gives the user an ATK buff for 5 turns.


Risk Taker:

MechanicsInsideDamageFormulas Example2.png

a.addDebuff(3, 5); a.atk * 4 - b.def * 2

This is a skill that gives the user an DEF debuff for 5 turns.


Bodyslam:

MechanicsInsideDamageFormulas Example3.png

a.gainHp(Math.round(-a.hp * 0.5)); a.atk * 4 - b.def * 2

This is a skill that causes the user to lose 50% of their HP upon usage.


Desperation:

MechanicsInsideDamageFormulas Example4.png

a.setMp(0); a.atk * 4 - b.def * 2

This is a skill that causes the user to lose all MP (brings it to 0) upon usage.



The Berserker

MechanicsInsideDamageFormulas Berserker.png

Now, let's create a Berserker class! The Berserker class will be a standard class. It will have the four skills we've just made. It also has the trait: Auto Battle.

Why are we using Auto Battle? It's because it's one of the few ways RPG Maker utilizes the evaluation function for damage formulas.

Let's also assign the class to Harold.

MechanicsInsideDamageFormulas Harold.png

He seems fitting for the Berserker type, right?

Now that everything is ready, it's time to go over and do a battle test!


Witnessing the Problem

MechanicsInsideDamageFormulas Troops.png

Let's head over to the Troops tab in the Database. Pick any of them. I'm picking the first one since it's the most convenient.

Note that in the screenshot above, there are no Troop events to cause anything special from happening.

With that in mind, let's hit the Battle Test button and start a playtest.

Turn 1

MechanicsInsideDamageFormulas Turn1.png

On turn one, without anything that has happened in battle you'll see that Harold's HP is at 25%, has his ATK buffed TWICE, has his DEF debuffed TWICE, and MP at 0.

Just what on earth happened?


Explanation

MechanicsInsideDamageFormulas Evaluate.png

The above two functions are the "culprit" to why this happens. I say "culprit" in quotes because it's not really a culprit. It's doing what it's supposed to be doing: its job of calculating the damage formula. It's not at fault that we, the game devs, decided to put game mechanics inside the damage formulas.

But why did it calculate without the actions being performed though?

That's because for some cases, like the A.I. for Auto Battle, all of a battler's available actions have to be evaluated in order to determine the optimal action to perform for battle. RPG Maker's A.I. is simplistic, find the largest number, go with the skill that produces the largest number. However, because we put mechanics in them, each time the calculations are made, the mechanics are also being performed.

Why did it happen TWICE though? Let's look back at the troops page:

MechanicsInsideDamageFormulas Troops.png

There are two enemies there.

The A.I. would evaluate each available skill for each available enemy. This means if there are two enemies, the skills are evaluated twice each. And this will happen each turn. If there are 8 enemies, the skills will be evaluated 8 times each. This means that the self-HP halving skill would occur 8 times over had there been a full enemy party.