Esempio n. 1
0
 /// <summary>Get an ingredient needed for a recipe.</summary>
 /// <param name="pipes">The pipes to search.</param>
 /// <param name="id">The item or category ID.</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 static bool TryGetIngredient(this IPipe[] pipes, int id, int count, out Consumable consumable)
 {
     return(pipes.TryGetIngredient(item => item.Sample.parentSheetIndex == id || item.Sample.category == id, count, out consumable));
 }
Esempio n. 2
0
        /****
        ** TryGetIngredient
        ****/
        /// <summary>Get an ingredient needed for a recipe.</summary>
        /// <param name="pipes">The pipes to search.</param>
        /// <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 static bool TryGetIngredient(this IPipe[] pipes, Func <ITrackedStack, bool> predicate, int count, out Consumable consumable)
        {
            int countMissing = count;

            ITrackedStack[] consumables = pipes.GetItems().Where(predicate)
                                          .TakeWhile(chestItem =>
            {
                if (countMissing <= 0)
                {
                    return(false);
                }

                countMissing -= chestItem.Count;
                return(true);
            })
                                          .ToArray();

            consumable = new Consumable(new TrackedItemCollection(consumables), count);
            return(consumable.IsMet);
        }