Search Unity

RPG Math

Discussion in 'Game Design' started by Not_Sure, Nov 25, 2014.

  1. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    Hey, does anyone know where I could find some references for RPG math?

    You know, like how to calculate damage, armor, or critical hits...

    I'm interested in reading up on how other games do things, but the source material is sparce.
     
  2. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    There is a thread covering some of this here in the game design forum. May need to check out some of the RPG threads.

    Really there is no set formula for it. Each game's designers will come up with the system based on how they want stats and such to impact their game play. For example, some games may place more weight on gear while others place more weight on skills or even character level.
     
    Kinos141 and AndrewGrayGames like this.
  3. Jimmy-P

    Jimmy-P

    Joined:
    Jul 10, 2014
    Posts:
    59
    I think it depends completely on how you want the game to play. I've made an RPG combat system where every action is tied to one of the player's skills, which range from 0-100. When a skill is used, I make a random number from 1-100 and compare it with the skill number, making the likelihood of success it a simple % chance, where the % is equal to the player's skill. I have no levels and no equipment to deal with, using powerups in place of equipment. If I were designing it to be like traditional RPG with XP and levels, I would probably set up the math quite differently.
     
  4. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    Much of your statement is true, the bold part isn't. Additionally, where the stats come from is irrelevant for a mathematical discussion. It only matters that said stats have a value.

    The basic mathematical premise for an RPG comes down to this: who falls over first? In other words, does it take the players longer to defeat an enemy than it does the enemy to defeat the players?

    We can mathematically model this.

    TTDd = HPd / DPTa

    Where: TTD is 'Time to Defeat', HP is 'Hit Points', DPT is 'Damage per Unit Time'. Stats suffixed with 'd' refer to the defender; stats suffixed with 'a' refer to the attacker.

    DPT (known in MMORPGs as 'DPS') is easily derivable:

    DPTa = DMGa / FRQa

    Where: DMG is Raw damage, FRQ is damage frequency. Suffix rules still apply.

    ...Thus, the 'true' form of the damage equation looks like this:

    TTDd = HPd / (DMGa / FRQa)

    To design an encounter, you need to derive this for both the enemy party and the player party. The player's numbers should always be bigger; the point of enemies is to lose in a compelling way. To that end, something I favor doing is instituting some margin for a 'easy' and 'hard' fight. If TTDpc - TTDe > MARGe, the fight is 'easy'; if TTDpc < MARGh, the fight is 'hard'. Some fights need to be excessively easy (or hard.) Only playtesting will reveal which fights need to be what.

    New suffix rules! 'pc' refers to the player character/player party. 'e' refers to the enemy/enemy party.

    Now, let's get into armor. There's a few ways you can do it, but ultimately the point of instituting armor is to provide finer control over the TTD equation above. There's a few ways you can do it:

    TTDd = HPd / (DMGa * ((ARMhardcap - ARMd) / ARMhardcap)) / FRQa)
    TTDd = HPd / (DMGa - (ARMd * 0.5) / FRQa)

    Where: ARM is Armor. The 'hardcap' suffix refers to a maximum value that a given stat can never exceed.

    The first system is a coefficient system, where we're taking the DPS and modifying it by a percentage; at a certain point, due to the way datatypes work, damage received will become either scratch damage (1 point of damage), or a functional miss (between 0 and 1 point of damage, which due to integer truncation, works out to zero damage.)

    The second system is an additive system, where we're taking the raw damage and mitigating some of it due to armor. One important thing to remember in this case is that we need a mathematical constraint that armor mitigation cannot exceed damage; the least amount of damage an attack should be able to do is either zero (a functional miss) or one damage (a flesh wound), otherwise, hitting someone's armor will heal them. Such a setup is batshit ridiculous and will shatter your player's suspension of disbelief.

    Since you're interested in other stats, 'armor penetration', known in some works as 'elemental weakness' in a magic/ability-based context, works similarly, if in the opposite way, to armor. As an exercise in your own creativity, reason out where an armor penetration stat go on our damage equation. How would you make it a scaling stat? How would you make it operate based on some fixed value?

    Finally, critical hits. Mathematically, Critical Hits are random downward spikes in battle duration, so be careful with them. Also, while crits have a 'stat', that stat is often a raw probability (e.g., in World of Warcraft every character has a base 5% crit chance.) This probability requires tuning, but so does the 'modifier' to the effect (some systems have crits that do +50% effect. Other have +100% effect. Some systems allow for variable additional effects on crits, which is usually another crit-related stat altogether.) This is something that can be modeled, but ultimately it would be better to have warm bodies playtest (you could alternatively write a battle simulator, which might help your iteration times a little.)

    In any event, those are only examples. As @GarBenjamin said, beyond the base equation, how you implement other stats becomes a matter of creativity, and what a particular permutation buys for your game.

    Note to UnityTech: I think this forum is a good use case to add LaTEX support. Notating equations in plain text is a royal pain in the backside.
     
    Last edited: Nov 25, 2014
  5. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    Lol I see what you are saying. In reality though to me this is confirmation that what I said is correct. It is just a matter of how a person views things.

    Yes generically it is DPS and AC and HP etc. damage per second, armor class and hit points.

    But how each of those elements is determined can vary greatly. So in my view it there is no set formula for it. Because DPS, AC and HP and yada yada are open for interpretation based on implementation.

    DPS can be calculated. Does no good if attacks are blocked or miss. AC, distance, dodging ability come into play. HP is irrelevant if no hit. HP is updated otherwise. Etc. Etc. To me it is just each system is a customization process of how you want it to behave so is best to approach it that way from the start.
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    WOW has endless formulas from the community. They call it Theorycrafting, and there's excel sheets, calculators for damage, mob scaling formulas and more. It's hardly sparse, it's commonplace, need to search theorycrafting as a term.

    Generally this boils down to a curve, so you can pretty much skip the formulas and evaluate normalized curves from unity (public AnimationCurve damageScale) etc...

    Then plug in your normalized level or whatever.

    Asvarduil has some great advice there if you want complex relationships.
     
    AndrewGrayGames likes this.
  7. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    Since this is mathematics, I can prove and counter your point at the same time. There's some logical problems in what you've just said, even though there is truth in it too.

    Funny enough, most of what you just said are not open to interpretation. If your HP reaches zero, you die. DPS actually means "Damage Per Second" (though that itself is an implemention, thus why I went with "Damage Per Unit Time" in my examples above; that applies to turn-based and real-time systems alike, and thus is a better abstraction for speaking about RPG math in general.) The point is, DPS is outright telling you that you're dividing damage by a unit of time, there is no interpretation to be had in that.

    Now, I can throw you a bone on the last one, though. Armor, Armor Rating, Armor Class are all names for the same thing. And, how you implement armor can vary.

    That said, I feel that claiming that armor class justifies your position that 'there is no true equation for RPG combat' (which, there's a lengthy post above you disproving), is because armor is a secondary stat that is itself a customization on the core 'Time to Defeat' equation. The fact of the matter is, is that there is a core equation that conventional RPG combat is based upon, it exists, and not just as a matter of faith.

    Remember, the essence of combat in a conventional RPG is, 'who falls over first?' Who falls over first is a function of A) HP, B) how often you're hurting the other thingy, and C) how much you're hurting the other thingy. Those three variables are the things that hold true, 100% of the time, period. If you can find a widely-accepted work that is considered a conventional RPG that disproves that assertion, I will send you funds to buy you a cup of coffee. Good coffee.

    Miss is pretty self-explanatory, regardless of the cause - 0 damage for a turn. That has a mathematical impact on your opponent's TTD, that one isn't open to interpretation (I hope; if it misses...well, it missed. No effect. Enemy gains your attack frequency towards their current TTD. End of story.)

    However, blocking is often implemented in different ways. In The Elder Scrolls V: Skyrim, Blocking is an action that can be triggered at any time if you have Stamina, that mitigates damage you would receive, with a scaling modifier based on your block skill. In Final Fantasy V, blocking with a shield is rolled upon being targeted for an attack, and if the roll succeeds, completely mitigates an attack, just as if it were a full-out miss. Again, though, this is a customization on the core 'hit the other thing until it falls over' situation. The presence of blocking does not disprove that you have to hit the other thing until it falls over.
     
    hippocoder likes this.
  8. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    Is it important for you to prove and counter my points? Lol

    I can see what you are saying. It is just a difference in views about the conclusions we arrive at. For DPS yes we know it is damage per second. But how is it arrived at? Is every game implementing DPS with the same formula? I highly doubt it. Some will just use some base damage (and likely range) for the weapon. Others will take into account an attack speed. Some may literally fix a DPS for the weapon which itself will include the attack speed. Some will look at items that increase the player's attack speed. So to me there is no set in stone formula for DPS. It is just my view of it.
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I think it is important to get the definitions down when working with numbers yeah :p Damage Per Second is an important distinction to make, since your DPS can rely on several factors while your damage scaling and damage from a weapon is generally a single factor.

    To calculate DPS as a statistic from this, you would feed it through the system and measure the end result.

    DPS is just damage over a period of time, and is the end result of various scaling formulas. DPS is present in every game where you deal with damage.

    Ideally you want DPS to be a statistic rather than a formula, since you'll be able to excel sheet this, and predict how long a given encounter might take place.
     
    GarBenjamin and AndrewGrayGames like this.
  10. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    Yes, very. It's in the super geek handbook, Chapter 7, Section 53, Paragraph 11, Guide point #2.

     
  11. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    Lol it is some good fun to debate things sometimes. My mind is quickly heading toward images of turkey, potatoes and other fine foods. A great feast. So with that in mind I feel I really cannot be held accountable for any of my posts til sometime next week.
     
    AndrewGrayGames likes this.
  12. RJ-MacReady

    RJ-MacReady

    Joined:
    Jun 14, 2013
    Posts:
    1,718
    I like elements. Like banana elemental is weak to Monkey type monsters. Fork elemental is strong against Food type monsters.

    Also creative associations. Like dexterity helps you reload your gun faster, mind strength improves your resistance to falling prey to magic tricks.
     
  13. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    Thank you everyone for your suggestions.

    @Asvarduil - I completely agree that it is important to think of the combat in terms of who falls down first, but I think that randomness and skill need to play their own part in that to keep tension high. You formulas are a good starting point to think of them.

    In terms of what I have in mind I'm looking more for a Diablo type system, over an MMO type system. I'm also thinking that I want a bit of a paper/rock/scissor mechanic that weighs different build types as Misterselmo suggested. Only in my case I'm looking at high Agility beat armored, high strength beats crowds, and high attack speed beats high health.

    I should mention this is something I've been working at for a long time and in no way comes before my other project that I haven't had the chance to work on. But what I'm looking at is this:

    Steps
    1) Compare Attack Classes
    2) Determine Type of Hit
    3) Roll for Damage
    4) Reduce Damage for Block
    5) Reduce Damage for Armor
    6) Reduce Damage for Resistances
    7) Deal Damage
    8) Reduce Defender's and Attacker's Attack Class

    Types of Hit
    Critical miss - The attacker falls over.
    Miss - The attacker swings at air.
    Parry - The defender hits the attacker's attack, both lose time.
    Block - The defender has a shield reduce the damage before their armor reduces it a second time.
    Hit - The defender takes raw damage.
    Direct Hit - The defender takes damage that ignores armor.
    Critical Hit - The defender takes strong damage.
    Brutal Hit - The defender takes strong damage that ignores armor.


    Then the variables would come from:

    Attacker's Stats Used
    Strength
    Agility
    Will Power
    Intelligence

    Attack Class

    Weapon Base Damage
    Weapon Attack Speed
    Weapon Multiplier for Strength, Agility, Will Power, and Intelligence

    Defender’s Stats Used
    Attack Class
    Armor
    Resistance for Physical, Poison, Magic, Fire, Ice, and Lightning Damage

    And Finally I should note that how you hold your weapon would have its own effect:

    Stances
    Two Handed - 150% Strength
    Duel Weilding - 75% Attack Time, alternating between weapons
    One Handed - 150% Attack Class
    Shielded - Chance to block
    Unarmed - 75% Attack Time and 150% Attack Class
     
  14. gallenwolf

    gallenwolf

    Joined:
    Mar 11, 2012
    Posts:
    118
  15. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,835
    I dont know what the question is since you seem to have figured it the formula you want for it.
     
    AndrewGrayGames likes this.
  16. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    Yeah, precisely. Sure, it's easy to say that it all comes down to DPS, HP, etc, but "DPS" is itself a derived value. It's commonly derived from "attacks per second * damage per attack", but that's not the only way you might figure it out, and each of those might in turn be derived statistics...
     
    GarBenjamin likes this.
  17. Kinos141

    Kinos141

    Joined:
    Jun 22, 2011
    Posts:
    969
    It's the same for all games.
    I realized that after player MUGEN when I learned all attacks had a numeric value.
    It goes attack value(10) subtracted from defense(5) equals the remainder subtracted from life-points(100).
    So it's 10-5 = 5, then 100-5 = 95hp left.

    This goes for all games, even shooters.

    You have to figure out damage, HP, how MP works. Do MP has effects, like poison, burning, draining, which all just subtracts life over time.
    Does MP effects affect enemy performance, like how freezing slows them down, etc.
     
  18. jepriddy

    jepriddy

    Joined:
    Dec 9, 2014
    Posts:
    4
    I'd also like to point out how D&D uses armor... which is that basically armor makes it harder to hit you. This makes sense if we define a "hit" as any contact that actually results in bodily injury... IE: armor reduces odds of injury. In fact, decent armor usually doesn't protect you from a fraction of damage... it's either effective or it isn't, which depends on where and how you're struck, force used, weapon type vs armor type, etc. It may seem over-simplified on the surface of it, but realistically speaking it isn't far off from the truth. Also worth mentioning is commonplace usage of an "evasion" stat or ability which just makes you harder to hit.

    As for the math, it's actually both complex and simple at the same time. First you define the constraints in an ambiguous manner, then attempt to find a mathematical solution that fits the profile. I'll provide an example. I'm working on a city-builder/4x/sim type of game, and one of the concepts I was recently working on was a factory. I first defined my constraints as such: productivity is proportional to resources supplied, resources needed will vary (but labor will always be a factor), productivity is inversely proportional to the damage done to the factory building. The last point ended up being mathematically the most interesting because, in my estimation, the majority of damage to productivity is done with the initial damage. (IE: the first shells/bombs can destroy shelves, products, wiring, machinery... etc... while the very last shells/bombs are really only finishing the job of taking the walls down [long after productivity has crashed]) This implies that the amount that productivity changes by should change depending on how much damage has been dealt.

    I came up with something like productivity = (percentage of max materials present*percentage of max workers present)/(damage factor)^2 where damage factor is a number between 1 and 2. (higher=more damage) [the reason for this is to avoid divide-by-zero errors.] so damage factor = (1-percentage of hitpoints remaining)+1

    But the same process can be applied to anything really. I personally prefer to use functions that are continuous over the range intended to be used rather than choosing from a handful of discrete values. It seems to add a lot of depth and feeling to gameplay for little added complexity... and you can still use modifiers to great effect.

    Another thing used a lot in RPG math is randomization. A lot of gamers-turned-programmers tend to stay away from it because all the games that you tend to notice randomness in tend to be infuriating for that reason. Of course most great games incorporate some randomness, the difference is that it isn't as noticeable because the devs choose not to use randomness by itself to determine things (like dice in Risk). Many games utilize a "base damage" and then incorporate a random amount of damage for attack damage. Say 50 + random(-5,5). Which should average out to be about 50, but you cannot say for certain that you can kill an enemy with 100 hitpoints in two hits, or that it would be impossible to kill an enemy with 105 hitpoints with two hits.

    This randomness accounts for variables that devs can't really keep track of. Adding random components also gives you an opportunity to create subtle differences between weapons that reflects (somewhat) the way in which they work... for example, 50 + rand(-5,5) is much different than 50 + rand(-25,25). While both (in the long term) will average toward 50, one will be much more predictable than the other. That could be advantageous for a player with a high luck stat which might bias randomized numbers, or it might just make someone feel good that they could hit 75 with one weapon whereas the other only has a max damage of 55. I also like to think about how the weapon functions (as I noted above), for example... when swinging a sword you're pretty much going to cause the same amount of damage if you use the same force with only a few exceptions, however... something like an arrow could cause massive trauma, or lighter damage depending on where exactly it hits (which can be affected by a lot of variables not directly tied to the attacker or target)... so the larger random component reflects this.

    Now that I've written a book I'm going to stop writing. Just some food for thought.
     
    Jimmy-P and AndrewGrayGames like this.
  19. AndrewGrayGames

    AndrewGrayGames

    Joined:
    Nov 19, 2009
    Posts:
    3,821
    No, that was actually pretty good. So far I'm the only game designer I know who hasn't actually played D&D, despite having a DM's guide and player book.
     
  20. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    Actually, I'm in the same boat. I read the hell out of a DM's guide but never actually managed to get involved in a campaign.
     
  21. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    Sorry for the long pause between posts, it's been a crazy week.

    @jepriddy - I think I'm on the same page, but not doing a good job conveying it.

    I'm looking at passing through 3 steps of damage reduction where the reduction is compound between block, armor, and resistance.

    The formula for the reduction is:
    Armor / (Damage + Armor) = Percent Damage Reduced.

    At that rate 100 armor getting 100 damage equals 50 damage. While 50 Armor to 100 damage be 67 damage (66.6% of 100 damage).

    Then it gets interesting when done in stages:

    100 Damage
    100 Shield Blocks 50% leaving 50 Damage.
    100 Armor Blocks 66.6% leaving 16.5 Damage.
    100 Physical Resistance blocks 85% leaving 3 Damage.

    But lets say that same character doesn't block and they'd get 17 points.

    Or if the attacker get a direct hit and ignores armor and only physical resistance would count, making it 50 points.

    I think it works well.
     
  22. BeefSupreme

    BeefSupreme

    Joined:
    Aug 11, 2014
    Posts:
    279
    Haha, same here. A few years ago I finally got rid of a big stack of books from RPGs that I never played. I just like reading different rule sets, which is probably weird...
     
  23. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,315
    here is the method i use on a RPG, there is no level, only equipment and passive skills. Im not sure it will scale well with player progression
    Code (CSharp):
    1. public virtual void Damage(DamageInfo info)
    2.     {
    3.         //check if this attack can evaded
    4.         if (info.CanEvade)
    5.         {
    6.             if(Check_Evasion)
    7.                 return; //we evaded
    8.         }
    9.  
    10.         //mitigate resistance
    11.         switch (info.Type)
    12.         {
    13.         case DamageType.Is.Antimatter:
    14.             mitigatedDamage = info.Damage - (info.Damage * _Stats.Mitigation.Antimatter / 100);
    15.             break;
    16.         case DamageType.Is.Energy:
    17.             mitigatedDamage = info.Damage - (info.Damage * _Stats.Mitigation.Energy / 100);
    18.             break;
    19.         case DamageType.Is.Kinetic:
    20.             mitigatedDamage = info.Damage - (info.Damage * _Stats.Mitigation.Kinetic / 100);
    21.             break;
    22.         }
    23.  
    24.         //mitigate armor
    25.         mitigatedDamage = Mathf.Clamp ((mitigatedDamage - (_Stats.Defense / 5)),1,Mathf.Infinity);
    26.         //apply damage
    27.         DecreaseHealth ((int)mitigatedDamage);
    28.         OnReceiveDamage (info);
    29.     }
     
  24. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    It could be good.
    It wouldn't work for what I'm interested in doing though.

    Also, I was interested in a combat system for a hack-n-slash ARPG.

    I need to figure out how to balance out different aspects of combat mathmatically, while at the same time making them polarizing in their effects and in the character building so their's a point in different builds.

    And one major hang up I have is factoring in attack class from the attacker and defender to get the type of hit, damage spread, and so on.