示例#1
0
        /**
         * <summary>Checks if a collection of inventory item instances has all the items necessary to craft this recipe's item.</summary>
         * <param name="invCollection">The collection of inventory item instances to check</param>
         * <returns>True if the collection has all the items necessary to craft the recipe's item</returns>
         */
        public bool CanBeCrafted(InvCollection invCollection)
        {
            if (HasInvalidItems(invCollection))
            {
                return(false);
            }

            if (useSpecificSlots)
            {
                int maxSlot = invCollection.InvInstances.Count - 1;
                foreach (Ingredient ingredient in ingredients)
                {
                    if (maxSlot < ingredient.CraftingIndex)
                    {
                        maxSlot = ingredient.CraftingIndex;
                    }
                }

                if (maxSlot < 0)
                {
                    return(false);
                }

                for (int i = 0; i <= maxSlot; i++)
                {
                    Ingredient  ingredient  = GetIngredientForIndex(i);
                    InvInstance invInstance = invCollection.GetInstanceAtIndex(i);

                    if (InvInstance.IsValid(invInstance))
                    {
                        // Item in slot

                        if (ingredient == null)
                        {
                            return(false);
                        }

                        if (ingredient.ItemID != invInstance.ItemID)
                        {
                            return(false);
                        }

                        if (ingredient.Amount > invInstance.Count)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        // Slot is empty

                        if (ingredient != null)
                        {
                            return(false);
                        }
                    }
                }
            }
            else
            {
                // Indices don't matter, just check counts are correct

                foreach (Ingredient ingredient in ingredients)
                {
                    int ingredientCount = invCollection.GetCount(ingredient.ItemID);
                    if (ingredientCount < ingredient.Amount)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }