Example #1
0
        private List <CookingRecipe> GetRecipesFromAsset(IAssetData asset)
        {
            List <CookingRecipe>        toReturn    = new List <CookingRecipe>();
            Dictionary <string, string> BaseRecipes = (Dictionary <string, string>)asset.Data;

            CookingRecipe cr;

            foreach (KeyValuePair <string, string> recipe in BaseRecipes)
            {
                cr = new CookingRecipe();
                string[] recipeLine = recipe.Value.Split('/');
                cr.Name   = recipe.Key;
                cr.Source = recipeLine[3];

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

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

                    cr.AddIngredient(ingredientId, ingredientAmount);
                }

                toReturn.Add(cr);
            }
            return(toReturn);
        }
        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);
        }