# Browser RPG fight calculation formula

I am making a simple browser rpg game, similar to battleknight. To keep the game simple, I have just Strength, Constitution, and Luck. But as luck is random based, I'm struggling with fight calculations. I need some kind of formula to calculate attacks.

Preview from battleknight

UPDATE I was thinking about this model:

Strength - base dmg.

speed - chance of attack avoidance

toughness - increase HP

luck - crit. hit chance

defence - chance of attack blocking.

As I expect, there will be fight between high and lower ranked players so I want to calculate attack differently. My idea is sum of stronger player stats(this will be cap). So random based attributes will be divided by this sum. Example:

cap = sumOfStrongerPlayerAttributes
player1Luck = player1.luck / cap
player2Luck = player2.luck / cap
// also luck can be devided for ensure that crit hits will not be so often


Also crit. hit dmg. will be calculated from based dmg. like:

critHitDmg = player.strength * someKindOfConst


This model will prevent from too often crits. And player who will spend all his resources to level up luck, will have low stamina, defence or base dmg (which is also important for crit. hit dmg)

• You're struggling how? – Alexandre Vaillancourt Mar 2 '18 at 14:33
• Yeah, but what are Strength and Constitution for? What's your intended gameplay? Assuming that we know what battleknight is about makes this question very unclear. – Alexandre Vaillancourt Mar 2 '18 at 14:38
• When asking for help designing a formula, it's important to include (in the question itself - don't tack it on in the comments) constraints or examples of what kinds of outcomes of the formula would be considered "good" for your application and what outcomes would be considered "bad." For instance, you want characters with more strength to do more damage (good), you want characters with more luck to get more critical hits (good), you don't want critical hit chance to go as high as 110% (bad) - is it only 110 that's bad? Or do you want a lower cap? What are the ranges of your stats? – DMGregory Mar 2 '18 at 14:46
• @TomP Asking for good literature advice is off-topic for this site. You might want to discuss ideas about this in chat. We have not edited this out yet because we're trying to figure out what you're after exactly :) – Alexandre Vaillancourt Mar 2 '18 at 14:52
• You may want to have a look at Design Patterns of Successful Role Playing Games, which I found a very informative book on the subject of the kinds of calculations to use for this kind of thing. – Jules Mar 2 '18 at 19:50

## 4 Answers

Your question can be summarized as "I got a Luck stat in my combat system, please tell me why".

Ask yourself: What game-design goal does the Luck stat fulfill? Do you have an immediate answer? If you don't then I would recommend you to just throw it out.

Now you are just down to two stats: Strength and Constitution. This doesn't seem like much. But you should ask yourself if you actually need more than this. Adding complexity just for complexity sake doesn't make a game more interesting, just more confusing. As you develop your game from there, you might discover design problems where these two stats are insufficient and you might consider a solution which adds a 3rd or 4th stat. But then you will know what problem you actually want to solve, so the formulas will come naturally to you.

To be honest, I played many games which had some kind of "Luck" stat in one way or another, and it almost always turned out to be a game design flaw. It usually doesn't make you "feel" any more lucky, because it usually doesn't affect the really important random number rolls. And neither does it affect any events in the game story where your character is particularly lucky or unlucky for plot reasons ("Your princess is in another castle? How can that be? I got 120 Luck, how is it possible that I picked the wrong castle?!?"). Instead it is usually a stat with a very vaguely defined role. Is there actually any situation your character could be in where "being lucky" is not of an advantage somehow? So what does "luck" actually mean? Is it an offensive stat? A defensive stat? An utility stat? Is it more or less important than other stats? Who knows? You usually need to dive deep into the metagame to understand what it actually does and in which situations it gives you a benefit. When a game mechanic isn't intuitive, then it is usually not a good mechanic.

• Indeed, if as the question text suggests the primary role of the Luck stat is to increase the chances of critical hits, perhaps some kind of "precision" or "weapon mastery" stat might be a better choice. – Jules Mar 2 '18 at 19:52
• As I am a little new in this sector, so I kinda had no idea how to make this equation. Luck is critical hit chance ... Chance will be calculated like ( Luck / sum_of_stronger_player_stats ). That should work with cases where player with higher rank is fighting lower ranked player ... and when fighting same ranked player, chances are more balanced – TomP Mar 2 '18 at 21:21

You essentially want your crit to scale from 0% to 100% with diminishing returns. Here is a formula that is 0% at luck=0 and approaches 100% as luck goes to infinity.

f = 2.71; // you can mess with this factor to change how quickly it diminishes
crit = Math.random() > Math.pow(f, -luck); // assuming random is in the range [0.0, 1.0]


Then use a multiplier if there was a crit

mult = 2; // set for a multiplier of 2


Then calculate the base power of the attack. I just set it to strength + 10

base_power = strength + 10;


Then just use the multiplier if crit was true

damage = base_power * (crit ? mult : 1);


Let me know if you need something different, and I can update my answer.

• Crit chance should be called "crit chance" (or some variant of that), not "luck". – NotThatGuy Mar 3 '18 at 14:18

## What does Luck mean?

Luck could increase the chance of some combination of:

• Hitting
• Evading
• Blocking
• Crit-ing (also potentially crit damage)
• Getting an item (if there are items)
• Having that item be a good item
• Success of any action you attempt
• Any random (unambiguously) good thing happening
• Any random (unambiguously) bad thing not happening

I'd suggest not using Luck for the first few in favour of having dedicated stats for those with less ambiguous name (e.g. accuracy / chance to hit, evasion / dodge, crit chance, block chance, drop rate, drop quality - dexterity has also been known to cover some combination of the first 4).

## How do you calculate with Luck?

There are a few ways Luck can work: (can apply to other stats as well)

• Gives a chance of something happening (that wasn't possible before)
• Increases the chance of something happening (which is also be dependent on other stats)
• Make some non-percentage number bigger (e.g. crit damage)

The last one can simply be a multiplier (e.g. 1 Luck → x *= 1.01, 2 Luck → x *= 1.02 - it doesn't have to be 0.01 per 1 Luck).

For the first two you'll need to convert your Luck stat into a percentage (0%-100%) (there isn't a "correct" way to do this, you'll need to take into account the points mentioned below).

The second one is probably the most complicated, as you'll need to decide what exactly luck will change - I might suggest having it decrease the chance of failure: e.g. a 60% chance to hit with 50% luck gives you a (1-0.6)*0.5 = 20% chance of missing (i.e. 80% chance to hit).

For any of them you'll need to consider a few things:

• What kind of scaling do you want? In many games, stats use diminishing returns (grows fast at the beginning at then slows down) - this can make the game more balanced or easier to balance, as the stat bonuses are impactful at first, but don't get out of control.

Note that some linear increases may already give you diminishing returns - e.g. if your chance to hit increases from 25% to 50%, that's a 100% damage increase (you're hitting twice as often), but from 50% to 75% would only be a 50% damage increase. If you want to use a linear increase and the stat is unbounded, you'll need to figure out what will happen when you get to 100%.

• What's the maximum value for the stat? Is there a maximum?

• How much of a bonus would it provide at any point, especially compared to the same investment into other stats?

You may want to strive to have any given point provide a comparable benefit no matter which stat you throw it into at which point (with different stats changing your playstyle), or you could have some be significantly better (not one stat as a whole be better than another, but rather the m-th point of one be better than the n-th point of another), to allow for some min-maxing.

## Should you include Luck?

Luck: (especially if it affects many things)

• Adds to the perceived complexity of the game by giving the player more things to put points into, which may be good or bad (this can be good if players can run out of others things to put points into, but this can be addressed in other ways)
• Can make the game harder to balance, unless Luck is mostly useless, in which case you should probably just remove it
• Can be hard for players to see the effects of, making players feel like getting more of it is a waste
• Probably wouldn't clearly and quantifiably explain what it does, making players less likely to want to invest in it
• Generally doesn't really affect a player's playstyle. As mentioned above, different stats could be used to allow the player to change their playstyle, but having one stat just sort of helping all over and not really have a clear focus goes against this.

Overall I'd say: no, you shouldn't include it, but you can possibly include more specific stats (as mentioned above).

Building on Kyy13's answer, if you have a hard cap for stats (max value) then it can become a more simple, linear equation where you want f(x)=min_crit_percentage when x=stat_min and f(x)=max_crit_percentage when x=stat_cap, so you end up with:

crit_percentage = x * (max_crit_percentage / stat_cap)

and you'll use instead

crit = Math.random()*100 > luck*(max_crit/stat_cap);


When making formulae for attack results and such you'll want to decide the kind of relationship between the actual stat and the effect in battle; a linear relationship like this one will make every point count, while one with diminishing returns will make it less worth it to spend points on luck when you're close to the cap. Make sure the player knows about this if it's not linear (maybe display the crit percentage or how much they will get by spending an extra point) so they can make an educated choice and don't feel like they're being tricked or they wasted points when they're closer to the cap.