Пример #1
0
        public void Edit <T>(IAssetData asset)
        {
            ModEntry.RecipesAdded.Clear();
            IDictionary <string, string> BaseData = asset.AsDictionary <string, string>().Data;

            KnownRecipes = GetRecipesFromAsset(asset);
            int AddedRecipes = 0;

            Dictionary <int, int> AllIngredients = new Dictionary <int, int>();

            foreach (CookingRecipe testRecipe in KnownRecipes)
            {
                AllIngredients.Clear();

                AllIngredients = GetAllIngredientsFromChildren(testRecipe.OutputID);

                bool isNew = !testRecipe.Ingredients.ContentEquals(AllIngredients);

                if (isNew)
                {
                    CookingRecipe newRecipe = new CookingRecipe()
                    {
                        Name        = testRecipe.Name,
                        Source      = "null",// testRecipe.Source,
                        MysteryText = testRecipe.MysteryText,
                        OutputID    = testRecipe.OutputID,
                        Ingredients = AllIngredients
                    };

                    string NameToAdd = newRecipe.GetKey();

                    if (ModEntry.RecipesAdded.TryGetValue(newRecipe.GetKey(), out List <string> SecondaryRecipes))
                    {
                        //We have already created a list
                        if (SecondaryRecipes.Count == 0)
                        {
                            NameToAdd = $"Alt: {NameToAdd}";
                        }
                        else
                        {
                            NameToAdd = $"Alt {SecondaryRecipes.Count + 1}: {NameToAdd}";
                        }

                        SecondaryRecipes.Add(NameToAdd);
                        Logger.LogDebug($"{newRecipe.GetKey()}: {string.Join(", ", SecondaryRecipes)}");
                    }
                    else
                    {
                        NameToAdd = $"Alt: {NameToAdd}";
                        ModEntry.RecipesAdded.Add(newRecipe.GetKey(), new List <string>()
                        {
                            $"{NameToAdd}"
                        });
                    }

                    BaseData[NameToAdd] = newRecipe.GetValue();
                    AddedRecipes++;
                }
            }
            Logger.LogInfo($"Added {AddedRecipes} recipes!");
        }
Пример #2
0
        private void InternalSetup()
        {
            craftingResults.Clear();
            RecipesAdded.Clear();

            string[]      recipeData;
            string[]      ingredientPairs;
            CookingRecipe recipe;

            //Construct a list of recipes for our internal use
            foreach (KeyValuePair <string, string> kvp in CraftingRecipe.cookingRecipes)
            {
                recipeData      = kvp.Value.Split('/');
                ingredientPairs = recipeData[0].Split(' ');

                recipe = new CookingRecipe
                {
                    Name        = kvp.Key,
                    Source      = recipeData[3],
                    MysteryText = recipeData[1]
                };

                if (Regex.IsMatch(recipeData[2], "[0-9]+ [0-9]+"))
                {
                    recipe.OutputID = int.Parse(recipeData[2].Split(' ')[0]);
                    recipe.Amount   = int.Parse(recipeData[2].Split(' ')[1]);
                }
                else
                {
                    recipe.OutputID = int.Parse(recipeData[2]);
                }

                for (int i = 0; i < ingredientPairs.Length; i = i + 2)
                {
                    int ingredientId     = int.Parse(ingredientPairs[i]);
                    int ingredientAmount = int.Parse(ingredientPairs[i + 1]);

                    recipe.AddIngredient(ingredientId, ingredientAmount);
                }

                craftingResults.Add(recipe);
            }

            int AddedRecipes = 0;

            Dictionary <int, int> AllIngredients = new Dictionary <int, int>();

            foreach (CookingRecipe testRecipe in craftingResults)
            {
                AllIngredients.Clear();

                AllIngredients = GetAllIngredientsFromChildren(testRecipe.OutputID);

                bool isNew = !testRecipe.Ingredients.ContentEquals(AllIngredients);

                if (isNew)
                {
                    CookingRecipe newRecipe = new CookingRecipe()
                    {
                        Name        = testRecipe.Name,
                        Source      = "null",// testRecipe.Source,
                        MysteryText = testRecipe.MysteryText,
                        OutputID    = testRecipe.OutputID,
                        Ingredients = AllIngredients
                    };



                    string NameToAdd = newRecipe.GetKey() + " ";

                    if (RecipesAdded.TryGetValue(newRecipe.GetKey(), out List <string> SecondaryRecipes))
                    {
                        //We have already created a list

                        for (int i = 0; i < SecondaryRecipes.Count; i++)
                        {
                            NameToAdd = NameToAdd + " "; //Pad that shit to avoid dupes
                        }

                        SecondaryRecipes.Add(NameToAdd);
                    }
                    else
                    {
                        RecipesAdded.Add(newRecipe.GetKey(), new List <string>()
                        {
                            NameToAdd
                        });
                    }

                    CraftingRecipe.cookingRecipes.Add(NameToAdd, newRecipe.GetValue());
                    AddedRecipes++;
                }
            }
            Monitor.Log($"Added {AddedRecipes} recipes!", LogLevel.Info);
        }