Jump to content
  • Advertisement
Sign in to follow this  
SolarMongoose

What to consider for an RPG damage formula?

This topic is 749 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I've come up with a damage formula I might use, and I can't find any reason why it wouldn't work. I can only assume this means I need some outside help to see what's wrong with it.
# The base (at 0 defense) difference between attack and defense needed to add/subtract 50% damage
base_d_factor = 10
    
# Amount added to the base factor for every point of defense over 0
scaled_d_factor = 0.5

# ...(stuff goes here)

dif = attack - defense
if dif:
	sign_dif = sign(dif)
	scale = 1.0 + (-1.0/(sign_dif + dif/(base_d_factor + defense*scaled_d_factor)) + sign_dif)
	return attack * scale
else:  
        # else we'd be dividing by 0
	return attack

Or to summarize, a character's attack value gets multiplied by a number on this curve dependant on how much higher or lower it (the attack value) is than the targets defense.

 

[sharedmedia=gallery:images:7655]

 

Also here's a completely unhelpful visual aid about that curve that I made for no reason.

http://www.gamedev.net/gallery/image/7654-curve/

 

Anyway, the motivations I was working with when I came up with this nonsense are:

  • I wanted the numbers to seem at least a little intuitive. Damage value is always "close" to attack value. If you're fighting an enemy who's roughly the same "level" as you, you'll be doing damage basically equal to your attack value The most damage you'll ever be doing is double what your attack value is.
  • I didn't want a relatively super high defense to completely invalidate any attack. If a character has 40 attack, but an enemy has 120 defense, they'll do around 20 damage. Maybe still not much, but you're never doing just 0 or 1 damage.
  • I wanted it to be easy to balance. Setting an enemies defense indicates a certain range of where the player is expected to be when they fight them and how much damage they will be able to consistently do... In theory.

So... are there any glaring flaws or heinous crimes against decency that anyone's aware of? Have I created some hideous over-complication of what should be some simple... "Bicubic Factorial Curve" or some such? Have I accidentally made an impossible-to-balance Explosive-Feedback-System? Is my code so unreadable that it'll absorb the soul of anyone who reads it too many times? Or just... is there anything else I should consider?

Share this post


Link to post
Share on other sites
Advertisement

What you've got there seems functional.  You'll need to beware the division by zero points, but otherwise it can work.

 

Sigmoids that are similar to that are one of the go-to curves in game development statistics, so you might consider going that route, just make a reusable sigmoid function.

Share this post


Link to post
Share on other sites

I wouldn't sweat it much.  Do test it, since different games need different formulas.

Starcraft (the original), as an example, has very simple methods, but it works for that game.

Share this post


Link to post
Share on other sites

The only way of knowing is by testing.

Damage is something you first consider in your game design:
Is it a fast pace game? or is it slower?

Should the fights be long or short? 

You can tweak damage in all kind of formulas and conditions, and not just by focuing on a single formula. 

But focusing on the design of fights or between fights.

 

For example let's take your rule of "Never 0-1 damage". Meaning any hit that wasn't dodged has implications, which is good for rewarding players on hits and punishing on dodging. However, how do you implement a tank that way? Someone who has more armor is probably less efficient with weapons, therefore giving him more damage because of that rule make no sense.

Yet again, it all depends on your game design and playing style that you want to put in your game. 

Share this post


Link to post
Share on other sites

for things like this, the goal is to model the desired behavior as simply as possible. 

 

if what you have yields the desired behavior, and no simpler model / formula / set of rules does, then this is the best choice. 

 

if it does not yield the desired behavior - its useless.

 

if a simpler model will do, its unnecessary complexity / over-engineering.

 

so you have to start with the definition of the desired behavior.

Share this post


Link to post
Share on other sites

Thanks for all the replies! So I get the impression a big part of it is just testing it out and seeing. Which makes sense. I just wanted to make sure there weren't any obvious foreseeable problems (eg, dividing by 0) or optimizations that I'd missed. Or just any other considerations that might come to mind. Like that it could inhibit the idea of a "tank" character, for example; that's a good observation.

 

I suppose it's probably worth mentioning that it's specifically a ye olde..... fashioned turn-based (j?)rpg... type game. For the most part. While we are trying to keep everything happening smoothly and with as little breaks in the action as we can, I don't think you could call it fast paced, just by virtue of it being turn-based. Also this won't necessarily be the only part of the equation. I can give "modifiers" to any of the numbers, so like if a character is "defending" I could multiply their defense by 1.5, or if something is weak to some element, multiply the final damage by 2. Stuff like that. Maybe if we did want to incorporate a character being a tank or something I could use this in someway. They subtract some value from all damage they receive or something.

 

 

Maybe I need help paring down what the "desired behavior" actually is? It's like...

 

"Compare an 'attack' value to a 'defense' value to determine an amount of 'damage' to be dealt"

  • Given an attack value and defense value, it should be relatively easy to estimate an HP value for a given number-of-hits-needed-to-defeat-someone, or vice-versa.
  • I guess the three things I mentioned in the opening post.

... and uh........... that's all I've got.

 

Well if there's anything else that anyone can think of that I should be considering, let me know. Since it sounds like there's nothing obvious wrong what Ihave, I guess I'll just... use it for a while and see how it works. Thanks again!

Share this post


Link to post
Share on other sites
Seems similar to my approach. :)

Just to throw out my two cents, the fundamental problem with “a ratio of the attacker’s attack stat” is that the stat is multiplied with itself, giving it an unfair advantage. Adding one or two points to attack is much stronger than adding one or two points to defense. It may be helpful to separate the “bonus stats” gained from items from “base stats” gained from levels. I don’t have my exact formula, but I think I have something similar to:

/*
Probably totally incorrect:

STR: Strength (base attack)     ATK: Bonus attack
RES: Resistance (base defense)  DEF: Bonus defense

         A_STR + max(0,A_ATK - B_DEF)
damage = ----------------------------  x  (A_STR+A_ATK)
           A_STR + B_RES + B_DEF
*/

Share this post


Link to post
Share on other sites

One thing that's always bothered me about games with medieval warfare and armor and damage calculations is that they rarely ever actually realistically model the effect and purpose of armor.

 

I remember going to a museum in Finland a few years back and looking at weaponry and armor from 500+ years ago. Knights were covered, head to toe, in steel. Almost nothing could penetrate that. Then they also have a kite shield and sword. A large squad of these guys, slowly marching towards you, was an invincible, inevitable death. The only way you could kill one of these soldiers was to tire them out, lift up their arm, and stab them with a very thin dirk beneath the armor. People didn't wear armor to take LESS damage, they wore it to take NO damage. Even a good scratch or cut could get infected and take months to heal, so people probably spent a lot of effort trying to develop armor which made them impervious to damage and used weaponry specialized against armored opponents. A mere peasant armed with a pitchfork would be minced meat, no matter their martial skill. Armor was expensive though, so not everyone on the battlefield had it. To wear armor was almost a status symbol, and to make it even more of a status symbol, some rich nobles would have their armor inscribed with decorations. One other surprise is in regards to leather armor. Leather armor is HARD. It's not that soft, supple leather which is designed for clothes and couches, it's leather that has been treated differently so that it hardens into a protective shell. It's not as hard as steel, but it will do a very good job of blocking most incoming attacks.

If I ever go and design a game with medieval combat mechanics, I would certainly try to take into account the realism of armor and its functional use. There would be no "Hey, I'm fully armored and yet a single sword swipe cuts me down!" bullshit. What's the point of wearing armor then? Might as walk around the battlefield naked because it's less encumbering and hot. Let's talk about heat and weight a bit too. I don't know about you, but I've had to wear full modern armor before (flak jacket, SAPI plates, kevlar, side SAPI, crotch cover) in the desert. It's bulky. It's uncomfortable. It's HOT. It's like wearing a snow suit in the middle of july. You don't want to move around much because its heavy and tiring. So, designed game mechanics could take advantage of this fact: The temperature, weight and amount of armor contributes to exhaustion, and exhaustion is a function of fighting capability (blocking and delivering blows). A part of battlefield strategy then becomes managing exhaustion, which is what was actually done! Lines would frequently rotate from the front to the back, rest and recover for a bit, move towards the front, and then resume fighting. Gradually, everyone gets really tired and more R&R doesn't help. But then the army which wins is the one which can bring in fresh reserve troops, preferably in a flanking maneuver. The enemy is too tired to fight fresh troops, and they're being flanked, so they either change focus to fight the fresh troops or continue engaging with the tired troops while the flankers mop them up. It's a fascinating mechanic :D

So... damage would be a function of the martial skill, exhaustion, equipped weapon type, sustained injuries, strength. The frequency of attacks would be a function of exhaustion, martial skill, and morale. An incoming attack wouldn't just be subtracted from the armor of the victim. That would be WAY last. First, you'd want to give the defender a chance to dodge, block or parry the attack. This would be a function of their martial skill, morale, exhaustion, equipped weapon type, mental focus, incoming weapon type, and sustained injuries. IF an incoming blow can't be dodged, blocked, or parried, then it is a hit. The hit would be registered somewhere on the body, but the actual damage inflicted would be a function of how armored that body part is and what type of damage we're inflicting (blunt, piercing, slashing, magical, fire, etc). The design goal would to make it so that an armored opponent *could* be near invincible. That's scary, and it should be scary. Nobody fucks with armored guards (see: swiss guard). If you're not prepared to fight an armored opponent, then you lose. Likewise, if nobody is prepared to fight your armored characters, they lose. Game "balance" would be less about balance on the battlefield, and more about access to resources prior to battle, so battlefield victory is partially determined by preparations before battle begins. (man, I want to make this game...)

Share this post


Link to post
Share on other sites

Seems similar to my approach. :)

Just to throw out my two cents, the fundamental problem with “a ratio of the attacker’s attack stat” is that the stat is multiplied with itself, giving it an unfair advantage. Adding one or two points to attack is much stronger than adding one or two points to defense.

I'm not multiplying the stat by itself........ am I? And the greater the difference between attack and defense, the less each point would be "worth", right? So if there's a difference, adding n points to whichever one is lower would have a greater impact than adding n points to the higher one.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!