# How to design a damage formula in an RPG which keeps weapons with different attack speeds balanced?

I'm making a mobile rpg game, an infinite one where there is a loot system like Diablo 3. Weapons have attack and speed, armor pieces have a resistance value (not percentage).

The formula I'm using is:

float realDamage = SkillDmg * BaseDamage / ( BaseDamage + Defense )


The results are good, the damage gets bigger if the defense gets lower and it doesn't exponentially go up because of the division between ( BaseDamage + Defense ).

Lets say I have a sword with 1.0 attack speed that deals 50 damage. Thats 50 dps, and I have a dagger that I want it to attack faster, but of course deal less damage, to maintain the dps the logic says that if the daggers attack speed is doubled, the damage needs to be halfed (2.0 speed with 25 dmg ). But using the formula above you'll see that the actual real damage DPS is lower than the sword.

Iv'e solved this by making the dagger not do 25 damage but a bit more, doing some calculations I can make the real dps be the same to balance things. In this case the dagger at 2.0 speed would need to deal 32 damage to be the same real damage dps as the sword.

However, I want to display the DPS number on weapons. If I just display the daggers DPS as 32 dmg * 2 attackspeed it's going to be 64 dps, compared to the sword 50 dps, one will clearly say that the dagger is better, but of course it's not.

Possible solutions? Change the initial damage formula? If so to which one? Lets assume I don't change the formula, is there any solution? I really don't like having to trick the dagger to deal more damage than half to make it even...

I'd really wish I'd know the damage formula for diablo 3. I know that diablo 3 weapons DPS it's simply base damage * attack speed.

Edit:

Lets assume defense = 50 and normal attack (skillDmg = baseDmg)

Sword 1.0 attack speed dealing 50 dmg -> real damage hit=  50 * 50 / ( 50 + 50 ) = **25 dmg** = 25 dps

Dagger 2.0 attack speed dealing 32 dmg -> real damage hit = 32 * 32 / ( 32 + 50 ) = **12.5 dmg** = 25 dps

Sword item, lets display the actual sword dps, 50 * 1.0 = **50 dps**
Dagger item, lets display the dagger dps, 32 * 2.0 = **64 dps** (SHOULD BE THE SAME)

• In your edit you have the formula I posted in my answer (damage * damage / ( damage + defense)), just without taking skill damage into account. The reason for the difference in DPS is because you are using the same defense. The reason why you get different results is because with that formula, slow but strong weapons are better against high-def enemies while fast but weak weapons are better against low-def enemies (which seems plausible). You assumed a high-def enemy and balanced both weapons against it, which means you made the dagger overpowered. The DPS calculation shows that overpower. Sep 29, 2017 at 12:35

The problems you have with calculating DPS from that formula are because what you call BaseDamage doesn't actually seem to be that.

Assuming that all numbers are positive, BaseDamage / ( BaseDamage + Defense ) will always resolve to a floating point number somewhere between 1 and 0. It doesn't matter if you have 10 BaseDamage, 1,000 BaseDamage or 1,000,000 BaseDamage, you will always be in that range. Where in that range depends on how the BaseDamage of the weapon compares to the Defense of the target. That means what actually affects the order of magnitude of the realDamage of an attack is mostly the SkillDmg multiplier.

Looking at these mathematical properties, I would not really call this weapon property BaseDamage but rather DefensePenetration, because it describes the ability of the weapon to overcome the enemy defense and still do most of its damage. This might actually be an interesting mechanic to have (or not... it's something you need to testplay), but it does not say much about the power level of a weapon.

So how do we solve this problem?

Well, there is no right solution to this problem. But a change which might do what you want to do (twice as powerful weapon = about twice as much damage) is to add the BaseDamage as another multiplicative factor:

float realDamage = SkillDmg * BaseDamage * BaseDamage / (BaseDamage + Defense)


If you like the defense penetration mechanic you accidentally discovered, this is how it would look with Penetration as a separate weapon stat:

float realDamage = SkillDmg * BaseDamage * Penetration / (Penetration + Defense)


• Even when the defense is pathetic compared to the attack value, there is never more damage than attack. This gives you an upper limit on how much damage a character can inflict, which makes balancing far easier.
• On the other extreme, no matter how high the defense gets, it can never completely mitigate damage (except through rounding errors), so there is always room for improvement for the defender and there is never a completely pointless attack.
• When Defense and BaseDamage (and Penetration when you want it) are roughly the same, there is roughly half as much realDamage as BaseDamage. This is true no matter how large the values are. This is also what you can base your DPS estimation on. Simply assume that the enemy has as much defense as the weapon has attack/penetration, which means your DPS formula becomes AttackFrequency * BaseDamage / 2

Edit: Here are some tables with example values:

 Damage by Defense for single attack

Defense
|     0 |   35  | 50   | 100
---+-------+------+-------+-------
35 |    35 | 17.5  | 14.4 |  9.1
Attack 50 |    50 | 29.4  | 25.0 | 16.6
100 |   100 | 74.0  | 66.7 | 50.0

Dps assuming HitFrequency = 100 / Attack

Defense
|     0 |   35  | 50   | 100
---+-------+-------+------+-------
35 |   100 | 50.0  | 41.1 | 25.9
Attack 50 |   100 | 58.8  | 50.0 | 33.3
100 |   100 | 74.0  | 66.7 | 50.0


As you can see from these numbers, high-damage-low-speed weapons are still nominally more powerful against the same enemy than low-damage-high-speed weapons if they have the same DPS according to AttackFrequency * BaseDamage / 2. But the effect is more visible on high-def enemies than on low-def enemies. Both are equally good on 0-def enemies. That means fast-attack weapons are less bad on low-def enemies than on high-def enemies.

This might be balanced by the fact that high-speed weapons give the player more flexibility regarding damage distribution and thus allows them to avoid wasting DPS on overkills. When the player faces a very large number of very weak enemies which all die with one hit, then a 5 attacks per second weapon can kill 5 enemies per second while a 1 attacks per second weapon can only kill 1 enemy per second. Another possible advantage appears when you add randomness to attacks. Due to the law of large numbers, many weak attacks will do a smoother and more reliable damage output than few strong ones. Players usually benefit from reliability. But when such considerations are irrelevant due to your game mechanics and/or encounter design, you will have to make your faster weapons a bit more powerful than they should be to compensate.

One way to give high-speed weapons a boost could be the introduction of effects which trigger with an x%chance per hit and do not depend on damage. These would be much more powerful with a fast-attack weapon because they would trigger far more frequently.

• Thanks @Philipp, I think that will solve it. The damage will be too high at the moment but I'll tweak it. Sep 29, 2017 at 11:25
• @marcg11 What exactly is your range for SkillDmg? I assumed it to be a multiplicative factor. So a basic attack has 1.0 and a double-damage special attack would have 2.0. If you would rather want these to be integers, you might want to add it to BaseDamage instead of multiplying it. Sep 29, 2017 at 11:27
• I've realised that the formula you gave is exactly the same as mine if I establish skillDamage as a multiplier. So I still cannot half the damage of the dagger if I double the attack speed to maintain damage. Sep 29, 2017 at 12:00
• @marcg11 No, it's not the same. The main difference is that I multiply with BaseDamage squared (BaseDamage * BaseDamage), you are only multiplying by BaseDamage once (which means BaseDamage gets reduced away in the formula). Sep 29, 2017 at 12:17
• But my skillDmg was never a percent, a normal attack skillDmg is the same as baseDmg, so it's the same. Sep 29, 2017 at 12:21

If you intend weapons of equal "power" to result in equal DPS, an easy solution would be to assign DPS directly and calculate damage per hit from that, e.g.

float realDamage = (SkillDmg * DPS / ( DPS + Defense )) / AttackSpeed


In this example, your sword would have 50 DPS and 1.0 attack speed and the dagger would have 50 DPS and 2.0 attack speed. If you want to display damage per hit, that's simply DPS divided by attack speed (i.e. 50 for the sword and 25 for the dagger).

Note that this gets rid of the "slower weapons are better vs high defense" mechanic, which I assume is what you want.

• Yes that's more or less the idea, but instead of DPS I'm using a value which is the same for all weapons of level x Oct 6, 2017 at 14:31