I am trying to build a turn-based RPG where party members and enemies can cast skills.
I want to have PartyMembers and Enemies cast skills on each other. For example: Heal has a caster and a target, WarCry(attack up) has a caster and all members of the party (either all PartyMembers or all Enemies, depending on who is doing the casting). Each skill should have an SP cost, and if the player or enemy does not have enough SP they should not be able to cast ituse 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?
public static Dictionary<int, Skill> SkillDictionary = new Dictionary<int, Skill>
{
{1, new Skill1()}, // I don't want to new anything up though!
{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(){};
}
HoweverAs my code currently stands, this isn't ideal. I don't wanteach skill is instantiated only once, before Main (due to new anything upthe dictionary being static). Does that meanIs there a way to do lazy loading so I would needwon't have to implement a singleton design for allinstantiate the skillsskill until called? Is lazy loading favorable to what I have so far? (I'm not too experienced with programmingin case I get to the point where I have LOTS of items, but is theremonsters, etc.) Furthermore, suppose I were to make a wayMonsterDictionary. Then would it be wise to do that using genericscall a Clone method in the abstract Skill classorder 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 enumEnum be adequate instead of a dictionary in some of these cases? (Forgive my programming skillsI'm relatively new to C# and game development, so I just learned about enums today)would like some feedback if possible. I'm curious to see how others organized their game data.