I am trying to build a turn-based RPG where party members and enemies can cast skills and use items. How could I implement a modular list of skills/items/monsters (and maybe character classes, if I get there) so that each PartyMember or Enemy could choose a skill/item from the list and cast it?
My first attempt was this:
public static Dictionary<int, Skill> SkillDictionary = new Dictionary<int, Skill> { {1, new Skill1()}, {2, new Skill2()}, {3, new Skill3()}, }; public abstract class Skill { int skillIndex; public abstract void CastSkill(); } public class Skill1 : Skill { public Skill1(){skillIndex = 1;} public override void CastSkill(){}; } public class Skill2 : Skill { public Skill2(){skillIndex = 2;} public override void CastSkill(){}; } public class Skill3 : Skill { public Skill3(){skillIndex = 3;} public override void CastSkill(){}; } As my code currently stands, each skill is instantiated only once, before Main (due to the dictionary being static). Is there a way to do lazy loading so I won't have to instantiate the skill until called? Is lazy loading favorable to what I have so far? (in case I get to the point where I have LOTS of items, monsters, etc.) Furthermore, suppose I were to make a MonsterDictionary. Then would it be wise to call a Clone method in order to make a new instance of a monster? Perhaps:
public Monster { string name; int otherStats; public Monster(Monster clone) { this.name = clone.name; this.otherStats = clone.otherStats; } } And to create a new instance of the monster in battle, for example:
Enemy e = new Monster(MonsterDictionary["Slime"]); Or - the golden question - is there a better design pattern altogether? Would an Enum be adequate instead of a dictionary in some of these cases? I'm relatively new to C# and game development, so I would like some feedback if possible. I'm curious to see how others organized their game data.