# How to develop RPG Damage Formulas?

I'm developing a classical 2d RPG (in a similar vein to final fantasy) and I was wondering if anyone had some advice on how to do damage formulas/links to resources/examples? I'll explain my current setup. Hopefully I'm not overdoing it with this question, and I apologize if my questions is too large/broad

My Characters stats are composed of the following:

``````enum Stat
{
HP = 0,
MP = 1,
SP = 2,
Strength = 3,
Vitality = 4,
Magic = 5,
Spirit = 6,
Skill = 7,
Speed = 8, //Speed/Agility are the same thing
Agility = 8,
Evasion = 9,
MgEvasion = 10,
Accuracy = 11,
Luck = 12,
};
``````

Vitality is basically defense to physical attacks and spirit is defense to magic attacks.

All stats have fixed maximums (9999 for HP, 999 for MP/SP and 255 for the rest). With abilities, the maximums can be increased (99999 for HP, 9999 for HP/SP, 999 for the rest) with typical values (at level 100) before/after abilities+equipment+etc will be 8000/20,000 for HP, 800/2000 for SP/MP, 180/350 for other stats

Late game Enemy HP will typically be in the lower millions (with a super boss having the maximum of ~12 million).

I was wondering how do people actually develop proper damage formulas that scale correctly? For instance, based on this data, using the damage formulas for Final Fantasy X as a base looked very promising. A full reference here http://www.gamefaqs.com/ps2/197344-final-fantasy-x/faqs/31381 but as a quick example: Str = 127, 'Attack' command used, enemy Def = 34.

``````1. Physical Damage Calculation:
Step 1 ------------------------------------- [{(Stat^3 ÷ 32) + 32} x DmCon ÷16]
Step 2 ---------------------------------------- [{(127^3 ÷ 32) + 32} x 16 ÷ 16]
Step 3 -------------------------------------- [{(2048383 ÷ 32) + 32} x 16 ÷ 16]
Step 4 --------------------------------------------------- [{(64011) + 32} x 1]
Step 5 -------------------------------------------------------- [{(64043 x 1)}]
Step 6 ---------------------------------------------------- Base Damage = 64043
Step 7 ----------------------------------------- [{(Def - 280.4)^2} ÷ 110] + 16
Step 8 ------------------------------------------ [{(34 - 280.4)^2} ÷ 110] + 16
Step 9 ------------------------------------------------- [(-246)^2) ÷ 110] + 16
Step 10 ---------------------------------------------------- [60516 ÷ 110] + 16
Step 11 ------------------------------------------------------------ [550] + 16
Step 12 ---------------------------------------------------------- DefNum = 566
Step 13 ---------------------------------------------- [BaseDmg * DefNum ÷ 730]
Step 14 --------------------------------------------------- [64043 * 566 ÷ 730]
Step 15 ------------------------------------------------------ [36248338 ÷ 730]
Step 16 ------------------------------------------------- Base Damage 2 = 49655
Step 17 ------------ Base Damage 2 * {730 - (Def * 51 - Def^2 ÷ 11) ÷ 10} ÷ 730
Step 18 ---------------------- 49655 * {730 - (34 * 51 - 34^2 ÷ 11) ÷ 10} ÷ 730
Step 19 ------------------------- 49655 * {730 - (1734 - 1156 ÷ 11) ÷ 10} ÷ 730
Step 20 ------------------------------- 49655 * {730 - (1734 - 105) ÷ 10} ÷ 730
Step 21 ------------------------------------- 49655 * {730 - (1629) ÷ 10} ÷ 730
Step 22 --------------------------------------------- 49655 * {730 - 162} ÷ 730
Step 23 ----------------------------------------------------- 49655 * 568 ÷ 730
Step 24 -------------------------------------------------- Final Damage = 38635
``````

I simply modified the dividers to include the attack rating of weapons and the armor rating of armor.

Magic Damage is calculated as follows: Mag = 255, Ultima is used, enemy MDef = 1

``````Step 1 ----------------------------------- [DmCon * ([Stat^2 ÷ 6] + DmCon) ÷ 4]
Step 2 ------------------------------------------ [70 * ([255^2 ÷ 6] + 70) ÷ 4]
Step 3 ------------------------------------------ [70 * ([65025 ÷ 6] + 70) ÷ 4]
Step 4 ------------------------------------------------ [70 * (10837 + 70) ÷ 4]
Step 5 ----------------------------------------------------- [70 * (10907) ÷ 4]
Step 6 ------------------------------------ Base Damage = 190872 [cut to 99999]
Step 7 ---------------------------------------- [{(MDef - 280.4)^2} ÷ 110] + 16
Step 8 ------------------------------------------- [{(1 - 280.4)^2} ÷ 110] + 16
Step 9 ---------------------------------------------- [{(-279.4)^2} ÷ 110] + 16
Step 10 -------------------------------------------------- [(78064) ÷ 110] + 16
Step 11 ------------------------------------------------------------ [709] + 16
Step 12 --------------------------------------------------------- MDefNum = 725
Step 13 --------------------------------------------- [BaseDmg * MDefNum ÷ 730]
Step 14 --------------------------------------------------- [99999 * 725 ÷ 730]
Step 15 ------------------------------------------------- Base Damage 2 = 99314
Step 16 ---------- Base Damage 2 * {730 - (MDef * 51 - MDef^2 ÷ 11) ÷ 10} ÷ 730
Step 17 ------------------------ 99314 * {730 - (1 * 51 - 1^2 ÷ 11) ÷ 10} ÷ 730
Step 18 ------------------------------ 99314 * {730 - (51 - 1 ÷ 11) ÷ 10} ÷ 730
Step 19 --------------------------------------- 99314 * {730 - (49) ÷ 10} ÷ 730
Step 20 ----------------------------------------------------- 99314 * 725 ÷ 730
Step 21 -------------------------------------------------- Final Damage = 98633
``````

The problem is that the formulas completely fall apart once stats start going above 255. In particular Defense values over 300 or so start generating really strange behavior. High Strength + Defense stats lead to massive negative values for instance. While I might be able to modify the formulas to work correctly for my use case, it'd probably be easier just to use a completely new formula. How do people actually develop damage formulas? I was considering opening excel and trying to build the formula that way (mapping Attack Stats vs. Defense Stats for instance) but I was wondering if there's an easier way? While I can't convey the full game mechanics of my game here, might someone be able to suggest a good starting place for building a damage formula?

Thanks

-
I think you've done the right thing in first setting what kind of stats, HP etc you want. This is part of the player experience and the math should fit 'around' these values. With so many stats though, the player should intuitively know what stats will affect his magical, physical attacks, etc. So the first big question is what stats correspond to an attack, and what stats defend against these stats (For ex PhDef defends only against PhAtk). – Jonathan Connell Jun 30 '11 at 9:02
The huge thing is balance, it would probably be a good idea to create an interactive program (say in C# or something quick) where you can change stats and see what kind of results you get. If you can change the formulae at run time, that would also help :) – Jonathan Connell Jun 30 '11 at 9:14
Consider using Excel to do this. Seems well suited to the task and you wouldn't have to write a line of code. – Alex Schearer Jun 30 '11 at 23:22
The most important question is: Which formula gives players the most fun? (searched the page for "fun" and non of the answers mentioned it :P) If it stats or damage go up too fast players get insensitized, if it goes up to slowly they get bored. Players need to feel happy when they gain a level, so they need to feel like they put work into it and also that it will have some noticeable effect on their game performance. (that's my 2 pence) – Annan May 26 '12 at 21:06

Creating formulas like this requires knowledge of elementary mathematical functions - the things you learned about in Algebra and Pre-calculus class.

Once you have those mastered, just ask yourself (replace "value" with "damage," or "health," or "speed" or whatever):

Then just tweak it (add/multiply stuff, change the base-value, etc) until it feels right. A graphing calculator will help you visualize how changes to the parameters will affect the function.

By the way, the problems you are experiencing are due to integer overflows.

Use variable-types that are large enough to hold the numbers you're working with. Sizes differ by platform in C++, but using the 32-bit Visual Studio compiler, `unsigned int` is 32-bit, while `unsigned __int64` (MS-specific) is 64-bit. Also consider using a `double`.

Additionally, try to reorganize your operations so that you don't encounter such large numbers in the first place (for example, rather than `MDef * MDef / 110`, do `(int)((float)MDef / 110 * MDef)`).

-
If you're running into integer overflows, conversion to float - which only reliably supports 24 bits of integer part - is going to have a different set of accuracy problems. – Joe Wreschnig Jun 29 '11 at 21:16
@Joe: I've rolled back your edit; I specifically chose `__int64` over `uint64_t` because `stdint.h` is not available on Visual Studio 2008 and below, and I didn't want to confuse the poor boy any more than he already is. – BlueRaja - Danny Pflughoeft Jun 29 '11 at 21:32
@BlueRaja: I don't see any evidence the asker is using Visual Studio, and it's present in every other standard toolchain (including Visual Studio 2010). – Joe Wreschnig Jun 29 '11 at 22:07
You left out one important variant as well, I think: If you want the damage to have an upper bound which you can get close to, but never quite reach, you can use a sigmoid function. – Martin Sojka Jun 30 '11 at 5:41
@Martin: read again, I didn't leave that out :) – BlueRaja - Danny Pflughoeft Jun 30 '11 at 5:43

Your formulas seem pretty complicated. I'm not sure how professional RPG developers handle this, but I'd recommend on focusing on simplicity. Try to find the simplest possible formula you can that still incorporates the range of stats you want to use. For instance, could you have stats modify each other prior to damage calculation, rather than modifying the damage during the calculation? Once you've got a formula in mind, I'd try graphing it for a wide range of possible values to see how it will behave as players level up. Obviously the fewer variables you have, them more feasible this will be.

Additionally, BlueRaja provided an important explanation of why you might be seeing unexpected values at higher stat levels. Using unsigned types and checking for overflows will be important.

-
+1 for simple. Anyone can make rigorously complicated stuff, that doesn't make a good game though. – eBusiness Jun 29 '11 at 22:27
@Randolf unless you're running on an Apple 2 or something, it's highly doubtful that removing a multiply or a divide here and there is going to affect performance in any measurable way. – Tetrad Jun 30 '11 at 6:34
@Randolf A big battle in an RPG might mean something like 10 damage calculations per second, a modern CPU can do several billion operations per second. You can safely assume that the performance impact of any such "visible" maths is negligible. Simple in this case is for the sake of those who design and those who play the game, not for our computers. – eBusiness Jun 30 '11 at 9:36
@Randolf Richardson: I just think you might be missing the target a bit in this case. For an MMO a good fast no-fat protocol is paramount, and heavy tasks like physics need to be designed with performance in mind. But damage calculation is core gameplay, it should be designed with gameplay in mind, if you bring performance concerns into such a question you risk compromising the gameplay part. Talk about performance when it matters, you risk giving the impression that this is an important area to optimise, thus stealing the attention from the real performance sinners. – eBusiness Jun 30 '11 at 22:21
@Randolf: I'm implying nothing; I'm saying that optimizing something that isn't a bottleneck is a waste of time. – Nicol Bolas Jul 1 '11 at 17:17

My Characters stats are composed of the following:

There's your real problem: you defined your stats before defining what those stats actually mean. You're putting the cart before the horse.

Look at how D&D (tabletop) works. "Strength" doesn't mean anything by itself; it only means something because there's a rule that says, "Add your strength bonus to your melee attack." That rule is part of D&D's combat rules. Without the combat rules, "Strength" is generally a meaningless quantity.

The first question you need to ask yourself is this: how much differentiation do I want between characters? Again, look at D&D. There, they have 6 basic stats. These stats define different dimensions of play for characters. A character with a high Dexterity will have different options from a character with low Dexterity.

But the reason for even that difference all comes back to rules. A high Dexterity means bonuses to ranged attacks; you can hit more often with ranged attacks. So just between Strength and Dexterity, you have two dimensions of play: ranged vs. melee.

Intelligence and Wisdom also form something of a pairing, but these interact more with specific classes. Int makes Wizards and other arcane spellcasters better (or possible under some rulesets), Wisdom is vital for Clerics and other divine spellcasters. Because divine and arcane spells have different spell lists, these two stats are involved in different dimensions of play.

You need to define the basic rules around stats before you can define growth progression functions and the like. You don't need specifics; you don't need to say that "each point of strength is added into the random roll to determine if a melee attack hits." What you need are meta-rules like "dexterity makes ranged attackers better." You can figure out exactly how it makes them better later on.

There are different ways to progress characters. A common old-school Final Fantasy trick was to simply use the character's level as part of their damage computations. This could be simply multiplying the level by the appropriate stat, or it could mean applying a function to the character's level. Say, a quadratic progression, so that the rate of a character's damage would increase per level.

However you want your combat functions to work, they need to take into account progression. Your functions need hooks for progression.

D&D has a funny way of progression. It is part class-based; every time you go up in level, you get new class features and a flat bonus to your to-hit, based on your character class. However, some class features got better by themselves. Spells in D&D would have progression built into them. A spell might do 1d4 damage per 2 levels of a spellcaster above the first. So every other wizard level makes that spell better.

D&D also used item-based progression heavily. Until 4th edition, item-based progression was mainly for fighting characters, but even in older editions, spellcasters had items that gave them stat buffs or other adjustments (or flat out gave them spells).

So items are another thing your combat functions need to take into account. Do items just buff one or more stats while equipped, or do they do other things as well? D&D was a bit odd, in that stats rarely changed; weapons simply did XdY damage, possibly with a bonus based on one of your stats. And that was that. So your only way to do more damage in battle was to find a better weapon. In many videogame RPGs, they take level into account in addition to a weapon.

-
"There's your real problem: you defined your stats before defining what those stats actually mean. You're putting the cart before the horse.". I strongly disagree; the numbers in themselves are just a way to inform the player of his power, etc. it is part of the game design. If you proceed the other way round, you could end up with an end boss with 147hp... who wants that really? – Jonathan Connell Jul 1 '11 at 9:13
Well, Sarevok (in Baldurs Gate) only had 135 HP ... – Martin Sojka Jul 1 '11 at 9:51
@3nixios: What does it matter if the end boss has 147Hp? What matters is whether the last boss is challenging, interesting, and above all rewarding to defeat. A boss with a lot of Hp isn't interesting; it's a waste of time. A boss that can mess with your party, that requires special tactics that change from moment to moment, that requires that you must to use every ability you have to its maximum potential, that is what makes for a great final boss. I'll take the interesting 147Hp boss over the boring block of Hp any day. – Nicol Bolas Jul 1 '11 at 9:53
@Nicol Bolas I totally agree with you, I was trying to support why I believe that the starting point has to be from the stats. The stats a player starts with are the primary indication and gameplay that the player plays with during the game. I agree that huge HP bars for bosses aren't necessary, it gives the player a better indication of what is the best setup against the boss, what stats weapons etc. are more effective. The amount of course is irrelevant to the way you calculate it, because you can just divide or multiple your final calculations by a constant c and be done with it. – Jonathan Connell Jul 1 '11 at 10:22
@3nixios: But that's part of my point. Dexterity in D&D exists to allow a differentiation between melee specialist characters and ranged specialists. If there were no concept of melee and ranged attacks (and in many FF games for example, there isn't), then this distinction would not need to exist. You could get away with 5 stats instead of 6. Defining a Hp range is one thing, but defining what basic stats you have is another. Stats require rules before you can make sense of them, and you have to know what you intend a stat to do before you can say that having that stat is a good idea. – Nicol Bolas Jul 1 '11 at 10:27

I think you make the mistake that you want to create a formula without having a proper design in mind.

Try to implement "types" of enemies, e.g. "armored" => a player attack if it is of type physical is reduced by 50%. Do not make a battle flow to abstract, think about what is relevant and what is not.

If your design says "armored enemies" are weak against magic but strong against physical damage, represent that in code. But remember that you have do a lot of testing, because the values won't work magically the first time you write the code. Try to create a design, put the logic into code, always check whether this the technical representation of what you had in mind and if it isn't change the values until it is.

-
 I was already encompassing that sort of thing - armor rating scales down physical attack damage unless the attack is flagged as armor piercing or uses a % based damage formula – user127817 Jul 1 '11 at 19:38

Late game Enemy HP will typically be in the lower millions (with a super boss having the maximum of ~12 million).

This I have a problem with. You should build your bosses around what you think your players should be able to handle. You're building your players and combat formula around what you want your bosses to be like.

Once you get your combat mechanics and roles built, then you can decide on how you want to design your bosses as it should be a good balance between the damage the players can deal/absorb vs what the boss can deal/absorb.

-

all games in the final fantasy series have had a stat cap of 255 because of the problem you are encountering. at level 100 stats would be 255.

you say about increasing stats with abilities and equipment and I remember seeing this in the games but the way this is done is in the formula. there is an extra step that checks for ability and equipment modifiers and applies them after the stats have been used.

in your case it would be step 21: apply ability modifiers step 22: apply equipment modifiers step23: final damage.

if you are interested google for final fantasy formulas, they are out there. I have copys of the actual battle mechanics including AI for final fantasy 4, 6, 7 and 9. people cracked them from the original games when they were creating roms for emulators. There not that hard to find if you look hard enough.

the biggest thing for creating formulas is testing. set up a script to run your battle wit ai on both side and run several hundred battles. vary the monsters and the stats and see if it works or if lv 40 kills everything, it is entirely possible that a boss is actually impossible to kill lol. a tip would be to turn off all animation as it is impressive how fast AI's can battle when no one is watching.

-

I was wondering how do people actually develop proper damage formulas that scale correctly?

The first 2 things are:

• decide what you mean by 'correctly' - what is your idea of 'correct damage'?
• decide what you mean by 'scale' - what values are going to change, and what effect do you want those changes to have?

Once you know that, you have enough information to use the mathematical formulas that BlueRaja mentioned in his answer. Just remember there is no such thing as a 'proper' damage formula - just one that matches your design for the type of experience you want your players to have.

-

Those numbers you quoted are likely derived from a just tweaking a simulation, over thousands of runs.

So you should write a simulation create a level 20 character, and see how he fares through 200 battles or so against the enemy types he's supposed to be fighting at that point. Do it again for a level 30 character (in presumably the next section of the world).

It'll take a while to get right, but writing automated simulations will definitely make this much easier than just guessing and manually playing it out.

-