/// <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="requirement">The ingredient requirement with 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 Requirement requirement)
        {
            int countMissing = count;

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

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

            requirement = new Requirement(new TrackedItemCollection(consumables), count);
            return(requirement.IsMet);
        }
Esempio n. 2
0
        /// <summary>Get an ingredient needed for a given recipe.</summary>
        /// <param name="chests">The chests 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="requirement">The ingredient requirement with matching consumables.</param>
        /// <returns>Returns whether the requirement is met.</returns>
        public static bool TryGetIngredient(this Chest[] chests, Func <Item, bool> predicate, int count, out Requirement requirement)
        {
            int countMissing = count;

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

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

            requirement = new Requirement(consumables, count);
            return(requirement.IsMet);
        }
 /// <summary>Get an ingredient needed for a recipe.</summary>
 /// <param name="pipes">The pipes to search.</param>
 /// <param name="itemID">The item ID.</param>
 /// <param name="count">The number of items to find.</param>
 /// <param name="requirement">The ingredient requirement with matching consumables.</param>
 /// <returns>Returns whether the requirement is met.</returns>
 public static bool TryGetIngredient(this IPipe[] pipes, int itemID, int count, out Requirement requirement)
 {
     return(pipes.TryGetIngredient(item => item.Sample.parentSheetIndex == itemID, count, out requirement));
 }
Esempio n. 4
0
 /// <summary>Get an ingredient needed for a given recipe.</summary>
 /// <param name="chests">The chests to search.</param>
 /// <param name="itemID">The item ID.</param>
 /// <param name="count">The number of items to find.</param>
 /// <param name="requirement">The ingredient requirement with matching consumables.</param>
 /// <returns>Returns whether the requirement is met.</returns>
 public static bool TryGetIngredient(this Chest[] chests, int itemID, int count, out Requirement requirement)
 {
     return(chests.TryGetIngredient(item => item.parentSheetIndex == itemID, count, out requirement));
 }