Esempio n. 1
0
        private static void UpdateCurrentCookables()
        {
            oldIngredients = ingredients.ToArray();
            Dictionary <string, int> dict = new Dictionary <string, int>();

            if (Game1.activeClickableMenu is not CraftingPage)
            {
                currentCookables = dict;
                return;
            }
            List <Item> tempIngredients = new List <Item>();

            foreach (var item in ingredients)
            {
                if (item == null)
                {
                    tempIngredients.Add(null);
                    continue;
                }
                Item clone = item.getOne();
                clone.Stack = item.Stack;
                tempIngredients.Add(clone);
            }
            while (true)
            {
                bool keepCooking = false;
                foreach (var name in CraftingRecipe.cookingRecipes.Keys)
                {
                    if (!Config.AllowUnknownRecipes && !Game1.player.cookingRecipes.ContainsKey(name))
                    {
                        continue;
                    }
                    CraftingRecipe recipe  = new CraftingRecipe(name, true);
                    Item           crafted = recipe.createItem();
                    if (crafted == null)
                    {
                        continue;
                    }
                    foreach (var key in recipe.recipeList.Keys)
                    {
                        int need = recipe.recipeList[key];
                        for (int i = 0; i < tempIngredients.Count; i++)
                        {
                            if (IsCorrectIngredient(tempIngredients[i], key))
                            {
                                int consume = Math.Min(need, tempIngredients[i].Stack);
                                need -= consume;
                            }
                            if (need <= 0)
                            {
                                break;
                            }
                        }

                        if (need > 0)
                        {
                            goto next;
                        }
                    }
                    if (dict.ContainsKey(name))
                    {
                        dict[name]++;
                    }
                    else
                    {
                        dict[name] = 1;
                    }
                    keepCooking = true;
                    foreach (var key in recipe.recipeList.Keys)
                    {
                        int need = recipe.recipeList[key];
                        for (int i = 0; i < tempIngredients.Count; i++)
                        {
                            if (IsCorrectIngredient(tempIngredients[i], key))
                            {
                                int consume = Math.Min(need, tempIngredients[i].Stack);
                                tempIngredients[i].Stack -= consume;
                                if (tempIngredients[i].Stack <= 0)
                                {
                                    tempIngredients[i] = null;
                                }
                                need -= consume;
                            }
                            if (need <= 0)
                            {
                                break;
                            }
                        }
                    }
next:
                    continue;
                }
                if (!keepCooking)
                {
                    break;
                }
            }
            currentCookables = dict;
        }