Found in : Game_Battler 3
Method name : attack_effect
Calculation : We use the following code:
#--------------------------------------------------------------------------
# * Applying Normal Attack Effects
# attacker : battler
#--------------------------------------------------------------------------
def attack_effect(attacker)
# Clear critical flag
self.critical = false
# First hit detection
hit_result = (rand(100) < attacker.hit)
# If hit occurs
if hit_result == true
# Calculate basic damage
atk = [attacker.atk - self.pdef / 2, 0].max
self.damage = atk * (20 + attacker.str) / 20
# Element correction
self.damage *= elements_correct(attacker.element_set)
self.damage /= 100
# If damage value is strictly positive
if self.damage > 0
# Critical correction
if rand(100) < 4 * attacker.dex / self.agi
self.damage *= 2
self.critical = true
end
# Guard correction
if self.guarding?
self.damage /= 2
end
end
# Dispersion
if self.damage.abs > 0
amp = [self.damage.abs * 15 / 100, 1].max
self.damage += rand(amp+1) + rand(amp+1) - amp
end
# Second hit detection
eva = 8 * self.agi / attacker.dex + self.eva
hit = self.damage < 0 ? 100 : 100 - eva
hit = self.cant_evade? ? 100 : hit
hit_result = (rand(100) < hit)
end
# If hit occurs
if hit_result == true
# State Removed by Shock
remove_states_shock
# Substract damage from HP
self.hp -= self.damage
# State change
@state_changed = false
states_plus(attacker.plus_state_set)
states_minus(attacker.minus_state_set)
# When missing
else
# Set damage to "Miss"
self.damage = "Miss"
# Clear critical flag
self.critical = false
end
# End Method
return true
end
In this formula, self is the person being attacked and attacker is the person doing the attacking.
From the beginning, we clear the critical flag (responsible for showing "Critical" when damage is being displayed). After this, we determine whether an attack will be successful or not, by picking a random number between 0 and 100. If this number is less than our attackers hit rate, we set a hit_result flag to true, otherwise false.
If our hit_result is true, we start with a atk value determined by the attackers atk value, minus the defenders physical defense divided by 2. We then make this value at least 0. We take this value and multiple it by 20 plus our attacker's strength value. Then divide by 20. We set this value to our defenders damage value.
We multiple our damage by our elemental correction value of our attackers attack element set. Then divide our damage by 100.
If our damage is greater than 0, we will attempt to make this a critical hit or not. If a random number between 0 and 100 is less than the attacker's dexterity, divided by our defenders agility multipled by 4, a critical hit occurs. The damage is multipled by 2 and we set our critical flag to true.
If our defender is defending, our damage is divided by 2.
After this, we randomize our damage value a little bit, but only if the damage is not equal to 0. We start, by taking the absolute value of our damage value, multiple it by 15 and divide it by 100. We then make sure this value is at least equal to 1. We will call this new value amp. We add a random number between 0 and our (amp + 1) twice and then subtract our amp value.
Now, we will try to see if our defender cannot evade the attack. We will take 8 times the defenders agi value and divide it by our attackers dex value, then add our defenders evasion value. We set this value to eva. Now if our damage is less than 0, we set a hit value to 100, otherwise, we set a hit value to 100 minus our eva value. If our defender can't evade, we then set our hit value to 100. Then we pick another random number between 0 and 100, and if it is less than our hit value, we set another hit_result value to true, otherwise false.
If hit_result is true again, we remove states that are removed when our defender is hit. We then subtract our damage value from the defenders hp and add our attackers attack element set and subtract our attackers minus element set.
If hit_result is false, we set our damage to "Miss" and clear or critical flag again.