Hello! I’m still pretty new to C#, coming from C++. I’m working on a spell casting game demo, where the user can craft their own spell. The player can choose from a list on how their spell will function, such as what kind of spell it is (fire, water, etc.), what kind of path it’ll take, and the spell’s hitbox.
The way I decided to balance it was make each factor affect the overall spell’s functionality with multipliers. Right now, I’ve decided on it affecting the damage, speed, and mana cost. How I decided to define those multipliers? Right now, I just have a file with 3 static arrays which define those multiplier values for damage, speed, and mana cost for each factor of the spell, and just pull from it when I need it. I guess this is a lookup table.
It’s like such
public class SpellConstants
{
public static readonly float[] MediumMultipliers =
{
//Could use a struct here instead but I'm fine working with this.
//Damage //Speed //ManaCost
0.0f, 0.0f, 0.0f, //NONE
1.0f, 1.0f, 1.0f, //Fire
0.8f, 1.2f, 1.0f, //Water
...
And this is how I would assign the stats to a spell
public void setStats()
{
//mediums, means, and mod are enums defined above.
int mediumIndex = (int)components.medium;
int meansIndex = (int)components.means;
int modIndex = (int)components.mod;
damage = 8.0f
* SpellConstants.MediumMultipliers[3*mediumIndex]
* SpellConstants.MeansMultipliers [3*meansIndex]
* SpellConstants.ModMultipliers[3*modIndex];
speed = 8.0f
* SpellConstants.MediumMultipliers[3*mediumIndex + 1]
* SpellConstants.MeansMultipliers [3*meansIndex + 1]
* SpellConstants.ModMultipliers[3*modIndex + 1];
manacost = 8.0f
* SpellConstants.MediumMultipliers[3*mediumIndex + 2]
* SpellConstants.MeansMultipliers [3*meansIndex + 2]
* SpellConstants.ModMultipliers[3*modIndex + 2];
}
This spell (Not a component just a class) is passed to a GameObject with a CastedSpell component, which handles moving the projectile, collision, and passing the damage, etc.
This works really well for me with floats. The path it takes is also an array, but of child classes of a base class, which affects how a spell will move, which functions as expected.
public static readonly SpellMeans[] SpellMeansObjects =
{
null, // NONE,
new SpellMeans_Normal(), // Standard,
new SpellMeans_Arched(), // Arced,
…
And this is passed to the GameObject similarly.
However, now I’m trying to make the game look nice with materials and shaders. The “medium” (again fire, water) would most likely be the only thing determining what material to assign to the spell. However, doing what I did above with the array, but with materials, just sounds bad and messy to me. Ideally, I’d like to assign these in the inspector (and possibly all these arrays), while keeping the easy way of grabbing these values.
How could I go about restructuring how this is done to get the functionality I want from it? I’m really overthinking this and just need a push in the right direction.
Thank you!