/// <summary>Get an ingredient needed for a recipe.</summary> /// <param name="recipes">The items to match.</param> /// <param name="consumable">The matching consumables.</param> /// <param name="recipe">The matched requisition.</param> /// <returns>Returns whether the requirement is met.</returns> public bool TryGetIngredient(IRecipe[] recipes, out IConsumable consumable, out IRecipe recipe) { IDictionary <IRecipe, StackAccumulator> accumulator = recipes.ToDictionary(req => req, req => new StackAccumulator()); foreach (ITrackedStack input in this.GetItems()) { foreach (var entry in accumulator) { recipe = entry.Key; StackAccumulator stacks = entry.Value; if (recipe.AcceptsInput(input)) { ITrackedStack stack = stacks.Add(input); if (stack.Count >= recipe.InputCount) { consumable = new Consumable(stack, entry.Key.InputCount); return(true); } } } } consumable = null; recipe = null; return(false); }
/**** ** TryGetIngredient ****/ /// <summary>Get an ingredient needed for a recipe.</summary> /// <param name="predicate">Returns whether an item should be matched.</param> /// <param name="count">The number of items to find.</param> /// <param name="consumable">The matching consumables.</param> /// <returns>Returns whether the requirement is met.</returns> public bool TryGetIngredient(Func <ITrackedStack, bool> predicate, int count, out IConsumable consumable) { StackAccumulator stacks = new StackAccumulator(); foreach (ITrackedStack input in this.GetItems().Where(predicate)) { TrackedItemCollection stack = stacks.Add(input); if (stack.Count >= count) { consumable = new Consumable(stack, count); return(consumable.IsMet); } } consumable = null; return(false); }