I'm currently working on a Magic system for a game I'm building and I feel like the references to the exact statistic are a bit complicated. I got a Vital class:
public int baseValue;
public int currValue;
public string statName;
For reference to the vitals used in the game, I have an enum:
public enum VitalName { Health, Mana}
I also have a Spell class:
public string spellName;
public MagicEffect magicEffect ;
with a derived BlackMagic class:
public int BaseDamage;
The MagicEffect Base Class has nothing but VitalModifier is derived from it:
public int vitalToAdjustIndex;
and finally, a LivingBeing class with this:
public Vital[] vitals = new Vital[Enum.GetValues(typeof(VitalName)).Length];
private void SetupVitals()
{
for(int i = 0; i < vitals.Length; i++)
{
vitals[i] = new Vital
{
statName = ((VitalName)i).ToString()
};
}
}
Now, what's happening is that the LivingBeing.CastSpell() function has what I think is a rather long reference to find the exact vital to modify:
public void CastSpell(LivingBeing target, BlackMagic spellToCast)
{
target.vitals[((VitalModifier)spellToCast.magicEffect).vitalToAdjustIndex].currValue -= spellToCast.BaseDamage;
}
It might just be me but using that rather long line seems like it's not needed. The reason I have to cast spellToCast.MagicEffect to a VitalModifier is because the MagicEffect property of a spell doesn't have a VitalToAdjustIndex property...
I realize that casting is a major issue in my code since I have to use 4 overload for the LivingBeing.CastSpell() because the Spell doesn't have a baseDamage property... so I end up having one overload for each type of spell (White, Special, Ailment and Effect).
I don't really know if there's another way to do it, but if there is a way to avoid multiple overloads or the need for all that casting, I'd be thankful
Also, should I put all the code in the same "box" when I ask a question or separate it like I did?