I’m setting up the functionality to apply damage to characters. I’m going to want the function to include some kind of variable for a damage type so that I can have things like elemental damage that some creatures will take more/less damage from.
In my last project I believe I set this up as an enumerator, and every time I had a particular type of damage I needed to check for, I just added another value to the enumerator for it.
Having grown a bit since then, I am aware that I have other options to achieve this result. For example, I could use a class. I could create a damageType class and send a whole class over to my damage function to enable more complex effects. (I recall back when I used Unreal I saw they did this, although I didn’t understand what was going on back then.)
So should I use a class for my damage type? Or rather: at what point does it make more sense to use a class than an enum? (And what other options are worth considering?)
Like if I only had a basic four or five elements, I’d stick to an enum, sure.
But with a class I could do things like have a whole list of attributes: physical versus magical, element attributes, specific types of physical damage (piercing, slashing, bludgeoning,) or make a damage type deal +5 against ogres.
Wow, sign me up! Except… Well, I don’t think I’m going to have THAT complicated of a battle system in my game.
So, at what point is it more reasonable to make a damage type class versus just checking against an enum, and/or adding another value to my “TakeDamage” function, and/or just writing a special override to the “TakeDamage” function in the particular enemy class?
I apologize for such an open-ended question, but the idea of using a class like this is still new to me. I’m not really sure how much extra work this would require versus what kind of work it could save.
Honestly I still can’t wrap my head around the idea of using a class like a variable because I still see a class as a whole program; it sounds like injecting someone with a person to fight a disease.