1
\$\begingroup\$

I have a issue I am unsure the best way to go about solving. Developing a game I store all the "percentage boosts" a character could get either from skills, equipment, quest items or whatnot as decimals (lowest being 0.0001 all the way to 1.0+).

This might not be the proper way in relation to my question but, without radically changing a game that's already live (web game), it's the way I have to work with.

What I normally do is look at all your equipment, boons, skills and so on that affect this stat and add them all together:

loop
    equipmentBonus += slot->bonus // where equipBonus = 0.0 to start.

Do the same things for boons, skills and so on.

Now we have this number, lets say its 1.87 (187% to this stat) One might think:

Stat * Bonus // (10 * 1.87 = 18.7)

Seems straight forward. But what if that total bonus is a flat 1.0; now it's just 10. In my mind it should double it, so:

Stat * (1 + Bonus) // (10 * 2.87 = 28.7)

Ok so now if their bonus is above 1 we double it.

New issue: Bonus is now 3.6 (+1 = 4.6)

This is where I am having issues, because in my mind 3.6 (360%) (same base stat of 10) is now 36, where as 4.6 (1 + Bonus) = 46.

The only solution I could think of was to stop the addition of 1 once we reach higher then 2, but again that poses issues because 1 is now 2, 2 is now 3, 3 is now 3 ... (hundred percent).

Can some one help me understand the best way to apply these stat bonuses? Would it be as simple as:

Stat + (Stat * Bonus)// But what if the bonus is higher then 1?

Thoughts?

I am not looking for code, but a better understanding oh how to handle percentages both above and below 100%, without fundamentally changing how they are stored (i.e., 0.0001 -> 1.0) in a way where they stack in an additive way (I believe is above) as opposed to multiplicative way)

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to the Game Dev Stack Exchange. In general, it's considered good form on the Stack Exchange sites to wait a while before accepting an answer - it gives more time & thus encourages more users to answer, potentially resulting in better & more diverse responses. \$\endgroup\$
    – Pikalek
    Aug 3, 2021 at 20:45
  • 1
    \$\begingroup\$ For future question, keep in mind that there's rarely a "best" solution to most game design problems - usually it's a matter of trade offs. Questions tend to do better when they address a particular concern or when you help the community understand what your idea of best means in the context of the post. \$\endgroup\$
    – Pikalek
    Aug 3, 2021 at 20:48

1 Answer 1

3
\$\begingroup\$

I think you have two concepts mixed up: A percentage multiplier and a percentage bonus.

A percentage multiplier can decrease your stats below their original value. If you have a debuff that says "attack stat reduced to 20%", then that means you'll have stat*0.2 afterwards. If, on the other hand, you have a buff that says "attack stat tripled", then you'll have stat*3.

However, if you have percentage bonuses, it adds to the stats you already have. Before bonuses you have 100% of your base stats. After a +10% bonus you'll have 110% of your base stats. This is true regardless of how big the bonus is. Maybe this makes it more intuitive: If you have a "+200% bonus", this means you gain 2x your stats on top of your existing stats. Meaning that you'll have 3x your original stats in the end.

The two formulas you came up with intuitively are actually identical. Quick mathematical proof:

finalStat = stat * (1 + bonus); //Multiply it out
finalStat = stat * 1 + stat * bonus; //*1 is trivial, get rid of it
finalStat = stat + stat * bonus; //Here we are!

As long as you add all percentage numbers together before calculating the final stats, the bonuses will be additive, not multiplicative. You can achieve this easily by ensuring that you only do the finalStat = stat + stat * bonus calculation exactly once in your code.

Also, be careful that you don't have different systems in your game with bonuses that stack by multiplication (unless intended). Players are very efficient at finding and exploiting these to push their stats to the moon.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .