# RPG Formula - Attack and defense

I'm making a game and I'm struggling with the formula to calculate the real damage the player does. I have skills which can do for example 10 hits of 20% weapon damage each of a total of 200% damage. Or another skill does 200% damage 1 hit.

However the formula I have right now is something like this

( 2 * Attack - Defense ) * 0.5


As you can see with an equal defense, the attack that does 1 hit 200% weapon damage will actually do more damage than the skill that does 10 hits 20% weapon damage each, because the reduction is greater when dealing low amounts of damage.

Or another case is a weapon does 200 physical damage and 50 fire damage. With this formula a enemy with 100 defense receives 150 physical (ok) and 0 fire damage (negative, not ok)

Can anyone help me get a formula (not too complex)? I don't know what to try. What I want to achieve is to get the same real damage (1 hit @ 200% or 10 hits @ 20%) and make the defense matter, what I mean by that is that it affects the attack.

• With your current formula, you'll only do the listed attack damage if your target has no defense (in all other cases you'll do less), and will do no damage at all if defense is at least double the attack. Is that a rule you want to preserve, or do you want attacks to always do at least some damage/have the potential to do more than the listed amount? – DMGregory Sep 1 '16 at 22:32
• I feel this question to be too broad. It depends, a lot, on all the circumstances. If you want 1 hit @ 200% or 10 hits @ 20% to be equals then you need to apply defense to the total damage, and not to each step. – DH. Sep 1 '16 at 22:32
• I'm making a game as well and really like the original answer. One note that I had for the OP was; Wouldn't you want the 10 attacks of 20% damage to be a weak attack vs high defense enemies. I would assume a high defense enemy would require large, slow attacks to effectively take it down. At least that's how I remember most games working. Like you might use a fast, small damage weapon to take down low armor enemies, but it's not so effective vs large enemies (unless you have crit chance or something). – AndrewSteinheiser Sep 16 '18 at 17:50

When you want one hit with 200% attack to be exactly equal to 20 hits with 10% attack, then your only option is to make defense a percent value.

When the defender has 55% defense vs. physical damage, then the total amount of physical damage they receive is reduced to 45%, no matter how large or small the portions in which it gets dished out.

However, percentual defense has its pitfalls, especially in RPGs where you have a continuous progression. You can never allow to go above 100%, because then you have total invulnerability. Even getting very close to 100% is a balancing nightmare. The difference between 97% and 99% means the character can withstand three times as many hits, so an inconspicuous 2% defense buff can turn out to be a game-breaker. On the other hand, there is not much practical difference between having a total of 1% or 3% defense, so it is hard to still have a meaningful progression on lower levels.

A different formula used to calculate damage which you see quite often is:

damage = att * att / (att + def)


Also, you need to be aware that you get a result of NaN (or a division by zero error with integer arithmetic) when both attack and defense is 0, so you should not forget to handle that situation separately. You also get weird results when you insert negative values, so your character system should not allow negative attack or defense (when you want healing magic which uses the same formula, invert the sign afterwards).
• Solid answer, and I like that formula. :) But I do take issue with this line: "your only option is to make defense a percent value." The requested behaviour only requires that damage reduction obeys a distributive property, and there are many ways to do this. We could adapt your formula for instance and make it.... damage = skill_attack * (base_attack/(base_attack + defense)) - this way defense isn't capped, but the damage reduction multiplier is still consistent across skills with the same weapon, and so distributes as desired. – DMGregory Sep 2 '16 at 1:33
• Using the examples from the question: "I have skills which can do for example 10 hits of 20% weapon damage each of a total of 200% damage" here skill_attack = base_attack * 0.2, while "another skill does 200% damage 1 hit" would have skill_attack = base_attack * 2 exactly as you say. – DMGregory Sep 2 '16 at 11:13