/// <summary> /// Generate a combatant based on a predefined template /// </summary> /// <param name="template">Template to be used to generate a combatant</param> /// <param name="level">Experience level to be applied to this combatant's skills</param> /// <returns>A combatant generated from the template, modified to be at the specified level.</returns> public static Combatant FromTemplate(Microsoft.Xna.Framework.Game game, string template) { var combatant = new Combatant(game); var templateType = template.Split('/')[0]; var templateName = template.Split('/')[1]; string settingString = String.Join("\r\n", File.ReadAllLines("Content/Battle/Combatants/" + templateType + ".js")); var nodeList = JObject.Parse(settingString); if (nodeList[templateName].SelectToken("name") != null) { combatant.Name = nodeList[templateName]["name"].ToString(); } combatant.Class = nodeList[templateName]["class"].ToString(); combatant.Avatar = Avatar.GenerateAvatar(game, null, nodeList[templateName]["avatar"].ToString()); if (nodeList[templateName].SelectToken("icon") != null) { combatant.Avatar.Icon = (nodeList[templateName]["icon"]).ToString(); } combatant.CurrentHealth = (int)(nodeList[templateName]["health"]); combatant.MaxHealth = (int)(nodeList[templateName]["health"]); combatant.CurrentMana = (int)(nodeList[templateName]["mana"]); combatant.MaxMana = (int)(nodeList[templateName]["mana"]); combatant.ArmorTypes = Item.StringToItemType(nodeList[templateName]["armortype"].ToString()); combatant.WeaponTypes = Item.StringToItemType(nodeList[templateName]["weapontype"].ToString()); combatant.Inventory = nodeList[templateName]["inventory"].Select(item => Item.Factory(game, item.ToString())).ToList(); combatant.Stats = new Dictionary <Stat, int> { { Stat.Health, 0 }, { Stat.Mana, 0 }, { Stat.Defense, (int)(nodeList[templateName]["stats"]["defense"]) }, { Stat.Attack, (int)(nodeList[templateName]["stats"]["attack"]) }, { Stat.Wisdom, (int)(nodeList[templateName]["stats"]["wisdom"]) }, { Stat.Intelligence, (int)(nodeList[templateName]["stats"]["intelligence"]) }, { Stat.Speed, (int)(nodeList[templateName]["stats"]["speed"]) }, { Stat.Hit, (int)(nodeList[templateName]["stats"]["hit"]) }, }; combatant.AbilityExperienceLevels = nodeList[templateName]["abilities"].ToDictionary( ability => Ability.Factory(game, ability["name"].ToString()), ability => (int)ability["experience"] ); return(combatant); }
public static Ability Factory(Microsoft.Xna.Framework.Game game, string name) { // todo : there has to be a less tedious way to do this... switch (name.ToLower()) { case "lunge": return(new Lunge(game)); case "cleave": return(new Cleave(game)); // todo : 3rd sword ability case "headshot": return(new Headshot(game)); case "drill": return(new Drill(game)); // todo : 3rd gun ability case "healing": return(new Healing(game)); case "protect": return(new Protect(game)); case "revive": return(new Revive(game)); case "fire": return(new Fire(game)); case "lightning": return(new Lightning(game)); case "quake": return(new Quake(game)); case "cobra punch": return(new CobraPunch(game)); case "flying knee": return(new FlyingKnee(game)); case "whip kick": return(new WhipKick(game)); case "target": return(new Target(game)); case "focus": return(new Focus(game)); case "serenity": return(new Serenity(game)); case "sprint": return(new Sprint(game)); case "untouchable": return(new Untouchable(game)); case "blur": return(new Blur(game)); case "awareness": return(new Awareness(game)); case "vengeance": return(new Vengeance(game)); case "deflection": return(new Deflection(game)); case "steel wall": return(new SteelWall(game)); case "move": return(new Move(game)); case "attack": return(new Attack(game)); case "drink potion": return(new DrinkPotion(game)); default: throw new Exception(string.Format("Unknown ability {0}", name)); } }