ID:1862252
 
(See the best response by Kaiochao.)
What is a good way to handle buffs? I don't really like how I handle them now and was planning on reworking them. However before I do I'd like to know of a good way to handle it all.

Currently all buffs have 2 variables, one for the buff multi and another for the current buff multi the player is using.
Then the players stat is calculated with one formula per stat, updating whenever relevant.

So when the player uses the buff, the current buff multi is made equal to the buff multiplier. When its off the current buff multi is 0.

Stat = BaseStat + (BaseStat * Buff1) + (BaseStat * Buff2) ....
*Note that its the way I want to handle how buffs interact with the stat, don't want buffs to be multiplicative.


Any better way to handle buffs?
Best response
In terms of simplifying the math:
Stat = BaseStat * (1 + Buff1 + Buff2 + ... + BuffN)
You can calculate the sum Buff1 + Buff2 + ... + BuffN with a loop through each included buff:
var Buffs[] = list(Buff1, Buff2, ..., BuffN)
var BuffTotal = 0
for(var/Buff in Buffs) BuffTotal += Buff
Stat = BaseStat * (1 + BuffTotal)

Of course, this is just a slightly different way to do exactly what you're already doing.
I'm going to go with the for loop. The reason I didn't like them is because I've got a bunch of variables and was trying to find a way to get rid of them.