# Formula for stacking percentages to keep them from getting out of control

I have a game that has a mechanic, where a specific class can stack what are called "life stealing enchantments" to steal greater amounts of health from the enemy depending on the type of life stealing enchant they have equipped.

A player can have 14 of these equipped at any time. Lets use an example of two of them:

• Sharp Fang 10% of enemies health
• Deprived Blood Lust 25% of enemies health

Right now, for this specific class, if you have 14 Deprived Blood Lust enchants equipped that's simply 14 * .025 = 325% which is way out of control.

Other classes, will not stack their life stealing affixes, instead we would just take the best one you have equipped. This particular issue is around the class where these can stack.

Now to mitigate some of the "high excessive number", which is well over 100% of the enemies health making you essentially able to kill anything, I attempted to create a formula:

1 - 0.25 * ((13 * 0.25) / 2) // 59%

essentially for each additional Deprived Blood Lust, we divide it by 2, so each additional one would do half the damage.

This would do 59% of the enemies health in damage, much more manageable. Except for the issue that Sharp Fang (10%) is much better then Deprived Blood Lust at:

1 - 0.10 * ((13 * 0.10) / 2) // 93%

Now we have one Sharp Fang at full strength and the rest are divided by 2.

So in other words, cheaper, weaker Sharp Fang is better then more expensive Deprived Blood Lust.

What I am looking for is help in creating some kind of formula where you can do full strength for the first enchantment and then for each additional enchantment you would do less, however higher percentages should end up with higher damage.

This same concept should work with mixing and matching these two in any amount that is less then or equal to 14. Assuming this is possible

So 14 25% enchantments should be better then 14 10% enchantments, even if 13 of the 25% are not firing at full strength.

Thoughts?

• Can the enemy have a resistance as well against your life stealing? Is your stealing based on hit or once per encounter? Is it meant for healing yourself? (In that case it is more like a life leech based on your damage dealt). Your dimish return formula looks a bit off as well, usually there is a division in the line of 1 - 0.25 / (0.25 * 13). (the formula is just a simple example) Oct 19, 2021 at 17:03
• You could make some enemies partly or fully immune to this, forcing the player to not put all their eggs in one basket. Alternatively, "deal x% of enemy's health" seems very powerful, perhaps it shouldn't stack at all? Oct 20, 2021 at 1:11

One simple way to approach this is to say that subsequent items in the stack apply to the percentage that's left after the earlier items in the stack took their bite.

• So the first buff in the stack takes 25% of 100% = 25%

• The second buff in the stack takes 25% of the remaining 75% = 18.75%

• The third buff in the stack takes 25% of the remaining 56.25% = 14.06%...

We can compute this as:

float GetTotalValueOfStack(float baseValue, int stackSize) {
return 1.0f - Power(1.0f - baseValue, stackSize);
}


Here's how that compares with stacks of 0-14 items, each taking either a 10% or 25% nibble out of what's left after the earlier items in the stack take their piece.

Number in Stack Total Value with 10% Base Total Value with 25% Base
0 0.0% 0.0%
1 10.0% 25.0%
2 19.0% 43.8%
3 27.1% 57.8%
4 34.4% 68.4%
5 41.0% 76.3%
6 46.9% 82.2%
7 52.2% 86.7%
8 57.0% 90.0%
9 61.3% 92.5%
10 65.1% 94.4%
11 68.6% 95.8%
12 71.8% 96.8%
13 74.6% 97.6%
14 77.1% 98.2%

By construction, this will never exceed 100%, so you never go too far out of control.

You can even use a variant on this to combine the effects of different enchantments without the total exceeding 100%:

float GetTotalValueOfMixedStack(List<PercentageBuff> buffs) {
// Sort our buffs from strongest to weakest.
buffs.Sort((a, b) => { return b.percent.CompareTo(a.percent); });

// Accumulate each stacked buff into a running total.
float runningTotal = 0f;
foreach (var buff in buffs) {
float subStack = GetTotalValueOfStack(buff.percent, buff.stackSize);
// Each new stack nibbles from the portion left after the stack so far.
runningTotal += (1.0f - runningTotal) * subStack;
}

return runningTotal;
}


One option would be to make certain enchantments only attachable to certain items. For example any % based attacks can only be on weapons and rings. So then you limit how many of these can appear on a whole character. Other items could add a fixed value boost rather than percentage. This inherently limits the huge percentage stacking.