I'm modding a game and I want to create a list of weapons with different statistics. What I have in mind is this: I would like to create a lot of variables for different stats and have them somewhere in one place in my code so I can easily modify them later if need be. E.g. I would do this:
ironSword_AttackSpeed = 1.5f;
ironSword_Damage = 15;
ironAxe_AttackSpeed = 1.2f;
ironAxe_Damage = 20;
etc.
Then, I will create lots of variables which will represent weapons (instances of the class SL_Weapons which contains fields such as AttackSpeed, Damage, etc.) and add them to a list. Those variables will be named: ironSword, ironAxe, etc. And finally I want to assign each of those weapons its corresponding stats. What I want to avoid is assigning each value 'individually' like this:
ironSword.AttackSpeed = ironSword_AttackSpeed;
ironAxe.AttackSpeed = ironAxe_AttackSpeed;
etc.
I would like to do sth like this instead:
foreach (SL_Weapon weapon in weapons)
{
((SL_WeaponStats)weapon.StatsHolder).AttackSpeed = VARIABLENAME_AttackSpeed;
}
Is something like that even possible? I mean the compiler would somehow have to know the name of each SL_Weapon variable in foreach loop (like ironSword, ironAxe, etc.) and then take this variable as a string and then assign to this weapon's AttackSpeed field another variable that is called the same + _AttackSpeed. I want to change around 150 weapons in my mod and each of them has at least 5 fields to change so if I have to do it manually, there is at least 750 lines of code for those changes alone. And all those lines are repeatable in some sense, so I hope there is a way to do it more efficiently :)