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
That's the code that determines a Physical "Attack" damage:
atk = [attacker.atk - self.pdef / 2, 0].max
self.damage = atk * (20 + attacker.str) / 20
What this means is that your initial "attack value" is your attack, minus half your targets PDEF, or zero, whichever value is higher. The actual DAMAGE you cause is that "attack value" * (20 + your characters strength) all divided by 20.
So...
A weapon with 100 Attack, and a character with 10 STR versus a monster with 50 PDEF will cause:
100 - (50/2) = 75
75 * (20 + 10) / 20 =
105 damage totalThe rest of the lines consider in Elemental reductions/additions, and evasion.
You could just go in there and CHANGE the formulas too, you can find that code in the "Game Battler 3" section in the scripting page.
if hit_result == true
# Calculate power
power = skill.power + user.atk * skill.atk_f / 100
if power > 0
power -= self.pdef * skill.pdef_f / 200
power -= self.mdef * skill.mdef_f / 200
power = [power, 0].max
end
# Calculate rate
rate = 20
rate += (user.str * skill.str_f / 100)
rate += (user.dex * skill.dex_f / 100)
rate += (user.agi * skill.agi_f / 100)
rate += (user.int * skill.int_f / 100)
# Calculate basic damage
self.damage = power * rate / 20
# Element correction
self.damage *= elements_correct(skill.element_set)
self.damage /= 100
# If damage value is strictly positive
if self.damage > 0
# Guard correction
if self.guarding?
self.damage /= 2
end
end
This is damage for a regular SKILL (magic spell, or skill, etc): (It's a bit more complicated)
power = skill.power + user.atk * skill.atk_f / 100
if power > 0
power -= self.pdef * skill.pdef_f / 200
power -= self.mdef * skill.mdef_f / 200
power = [power, 0].max
end
So first it determines the base "power" of the skill, which is done by taking the skill's Power value (We will assume 100 for this hypothetical skill), then it adds the (user.atk * skill.atk_f /100) value, let me clarify quickly:
skill.X_f is the value on the skill screen which says how much that value influences total damage; in this case, if you the skill had an ATK_F of 50, that would mean 50% of the users's atk value (from weapon) is calculated into the damage. 200 ATK * (50 / 100) => 200 ATK * 50% = 100 ATK.
So using those stats, right now the "Power" is 100 for the skill's power + 100 from the users ATK value to equal 200.
NOW it does that same % thing and applies it to the PDEF_F and MDEF_F values of the skill, for example an MDEF of 50 on this skill and a PDEF of 10 on this skill would do this: (We will assume that the monster you are attacking has 50 PDEF and 50 MDEF)
Monsters PDEF of 50 * (skills PDEF modifer of 10 / 100) = 5
Monsters MDEF of 50 * (skills MDEF modifer of 50 / 100) = 25
So after those two lines your "Power" is:
200 - 5 - 25 =
170 damageAfter it does that, it takes either that number or zero, whichever is higher. (This ensures no negative damage!)
rate = 20
rate += (user.str * skill.str_f / 100)
rate += (user.dex * skill.dex_f / 100)
rate += (user.agi * skill.agi_f / 100)
rate += (user.int * skill.int_f / 100)
...
self.damage = power * rate / 20
THESE lines are VERY important. These are where those other _F values on the Database page come into play. It's JUST like the one I showed above, it takes the _f value and turns it into a %, then applies that to the user's value and creates a "rate". The "rate" is basically a multiplier which, after it's calculated, will change that "power" we calculated above.
Let's assume the skill has a STR-F of 20, and an INT-F of 90, the rest are zero, your character has 50 STR and 60 INT, and a DEX of 20 and an AGI of 10.
Rate starts at
20.
Caster STR of 50 * (Skill STR-F of 20 / 100) = 50 * 20% = 10
Rate is now 20 + 10 =
30Caster DEX of 20 * (Skill DEX-F of 0 / 100) = 20 * 0% = 0
Rate is now 30 + 0 =
30Caster AGI of 10 * (Skill DEX-F of 0 / 100) = 10 * 0% = 0
Rate is now 30 + 0 =
30Caster INT of 60 * (Skill INT-F of 90 / 100) = 60 * 90% = 54
Rate is now 30 + 54 =
84Now we take the last line, self.damage = power * rate / 20
Power of
170 * Rate of
84 / 20 =
714 damageThe self.damage = power * (rate/20) will determine the almost final damage received by the monsters. Once that's calculated it will (as the rest of the lines show) do other things like apply elemental weaknesses/resists. Once that's done another script takes that damage and displays/applies it to the monster for real, possibly killing it.
Make sure you note how in the example the skill totally snowballed out of control thanks to that rate created, and also thanks to the high weapon ATK. These values can get out of control if you don't have a VERY careful mathematical idea of what and how you're doing the whole game!
I will stress that if you play with those numbers in a test project for a while, you will find ways to "tweak" your combat system to something you like, I took out all those static values and make STR, etc, all % based too, makes it REALLY easy to do math, since damage is basically your weapon's Attack value * STR/100, etc.
That makes it really easy to determine attack values and damage/armor values later in the game as well!