Hello, I’m making an arpg where one of the characters can steal buffs from enemies. The concept is that a meter fills up as you steal buffs. You can use that meter to gain buffs and heal some damage. The amount healed and buffs gained depends on the type of enemy you are fighting. I am done with coding the heal mechanic.
Buffs can range from Attack+10%, moveSpeed boosts to poison immunity/ temporary invincibility. Most of it will involve stats of some sort. My stat class is similar to the one brackey used in a tutorial. The stat class has base value,current value, max value etc and it can recalculate values when a buff is applied or removed.
Additionally enemies should also be able to apply debuffs like stat penalties and poison/ DoT effects.
The problem I’m facing is how to tie all these together. For example, I was thinking to keep a list of buffs I have stolen from the enemy and apply them when the player hits a button. Problem is, the player can steal buffs repeatedly. So I’d be adding the same buff to the list repeatedly. Then I thought of having having a amount variable in the buffs that I can increase when I get the same buff again… Even then I’d need some way to determine if I already have a buff. Should I use a strig variable for identifying buffs?
Also, I need to make sure that buffs like poison immunity interact properly with the poison debuff.
I’m sure I’m making things much more convoluted than they need to be but The more I think the complex it gets. Hopefully you guys can help me sort this out.
If you have something like an abstract class for the buff and then inheriting classes like AttackBuff, MoveSpeedBuff etc. and if you reference the current status effect/buff with this abstract class, you can do something like:
Buff currentBuff;
if (currentBuff != null) {
// dome something if the player already has a buff
}
if (currentBuff is AttackBuff) {
// do some attack buff stuff
}
List<Type> allBuffs = new List<Type>(); // using System; at the top!
allBuffs.Add(typeof(AttackBuff));
allBuffs.Add(typeof(MoveSpeedBuff));
The abstract buff class should have everything that every buff has. So probably an effect duration variable, a method Apply() or Use() or however you want to call it that is called when a player uses a buff and other things I can’t think of right now.
I didn’t know there was typeof() in c#. If I’m reading this correctly,I need to make seperate derived classes for each buff type and store their types, right?