public override string Execute() { string heroName = InputArgs.ElementAt(1); IHero heroFound = container.Heroes.FirstOrDefault(x => x.Name == heroName); if (heroFound is null) { throw new ArgumentException(string.Format(Constants.HeroUnfoundNameError, heroName)); } string recipeName = InputArgs.ElementAt(0); var strengthBonus = long.Parse(InputArgs.ElementAt(2)); var agilityBonus = long.Parse(InputArgs.ElementAt(3)); var intelligenceBonus = long.Parse(InputArgs.ElementAt(4)); var hitpointsBonus = long.Parse(InputArgs.ElementAt(5)); var damageBonus = long.Parse(InputArgs.ElementAt(6)); string[] itemsRequiredNames = InputArgs.Skip(7).ToArray(); IRecipe newRecipe = new Recipe(recipeName, strengthBonus, agilityBonus, intelligenceBonus, hitpointsBonus, damageBonus, itemsRequiredNames); heroFound.AddRecipe(newRecipe); string resultMessage = string.Format(Constants.RecipeCreatedMessage, recipeName, heroName); return(resultMessage); }
public override string Execute() { try { string heroName = args[1]; IHero hero = this.manager.heroes[heroName]; string itemName = args[0]; int strengthBonus = int.Parse(args[2]); int agilityBonus = int.Parse(args[3]); int intelligenceBonus = int.Parse(args[4]); int hitPointsBonus = int.Parse(args[5]); int damageBonus = int.Parse(args[6]); List <string> neededList = args.Skip(7).ToList(); IRecipe recipeItem = new RecipeItem(itemName, strengthBonus, agilityBonus, intelligenceBonus, hitPointsBonus, damageBonus, neededList); hero.AddRecipe(recipeItem); return(string.Format(Constants.RecipeCreatedMessage, itemName, heroName)); } catch (Exception e) { return(e.Message); } }
public string AddRecipeToHero(IList <string> arguments) { string name = arguments[0]; string heroName = arguments[1]; int strengthBonus = int.Parse(arguments[2]); int agilityBonus = int.Parse(arguments[3]); int intelligenceBonus = int.Parse(arguments[4]); int hitpointsBonus = int.Parse(arguments[5]); int damageBonus = int.Parse(arguments[6]); string[] requiredItems = arguments.Skip(7).ToArray(); IRecipe recipe = new RecipeItem(name, strengthBonus, agilityBonus, intelligenceBonus, hitpointsBonus, damageBonus, requiredItems); IHero hero = this.GetHero(heroName); return(hero.AddRecipe(recipe)); }
public string AddRecipeToHero(List <String> arguments, IHero hero) { string result = null; string itemName = arguments[0]; string heroName = arguments[1]; int strengthBonus = int.Parse(arguments[2]); int agilityBonus = int.Parse(arguments[3]); int intelligenceBonus = int.Parse(arguments[4]); int hitPointsBonus = int.Parse(arguments[5]); int damageBonus = int.Parse(arguments[6]); string[] recipeItems = arguments.Skip(7).ToArray(); RecipeItem newItem = new RecipeItem(itemName, strengthBonus, agilityBonus, intelligenceBonus, hitPointsBonus, damageBonus, recipeItems); hero.AddRecipe(newItem); result = string.Format(Constants.RecipeCreatedMessage, newItem.Name, heroName); return(result); }