예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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, List <ITrackedStack> > accumulator = recipes.ToDictionary(req => req, req => new List <ITrackedStack>());

            foreach (ITrackedStack stack in this.GetItems())
            {
                foreach (var entry in accumulator)
                {
                    recipe = entry.Key;
                    List <ITrackedStack> found = entry.Value;

                    if (recipe.AcceptsInput(stack))
                    {
                        found.Add(stack);
                        if (found.Sum(p => p.Count) >= recipe.InputCount)
                        {
                            consumable = new Consumable(new TrackedItemCollection(found), entry.Key.InputCount);
                            return(true);
                        }
                    }
                }
            }

            consumable = null;
            recipe     = null;
            return(false);
        }