public static XmlWarrior ToXml(this IWarrior warrior) { XmlWarrior xmlWarrior = new XmlWarrior() { TypeOfWarrior = warrior.TypeName, Name = warrior.Name }; xmlWarrior.EquipmentList.AddRange(warrior.Equipment.Select(x => x.Name).ToList()); if (warrior is IHenchMen) { IHenchMen henchMan = warrior as IHenchMen; xmlWarrior.AmountInGroup = henchMan.AmountInGroup; } else if (warrior is IHero) { IHero hero = warrior as IHero; xmlWarrior.SkillList.AddRange(hero.Skills.Select(x => x.SkillName).ToList()); } if (warrior is IWizard) { IWizard wizard = warrior as IWizard; xmlWarrior.SpellList.AddRange(wizard.DrawnSpells.Select(x => x.SpellName).ToList()); } return(xmlWarrior); }
public static IWarrior FromXml(this IWarbandRoster warbandRoster, XmlWarrior xmlWarrior) { IWarrior warrior = warbandRoster.WarBand.GetWarrior(xmlWarrior.TypeOfWarrior); warrior = warbandRoster.AddWarrior(warrior); foreach (string item in xmlWarrior.EquipmentList) { warrior.AddEquipment(item); } if (warrior is IHenchMen) { IHenchMen henchMan = warrior as IHenchMen; for (int i = 1; i < xmlWarrior.AmountInGroup; i++) { henchMan.IncreaseGroupByOne(); } } else if (warrior is IHero) { IHero hero = warrior as IHero; foreach (string skill in xmlWarrior.SkillList) { hero.AddSkill(skill); } } if (warrior is IWizard) { IWizard wizard = warrior as IWizard; foreach (string item in xmlWarrior.SpellList) { wizard.AddSpell(item); } } return(warrior); }