Exemplo n.º 1
0
        public void Sample_AddedRecipes_Ok()
        {
            var aRecipes = new AddedRecipeList();

            string sample = File.ReadAllText(SampleFileDirectory + "AddedRecipes_Samples.txt");

            bool result = aRecipes.FromString(sample);

            Assert.IsTrue(result);
        }
Exemplo n.º 2
0
        public void Deserialize_AddedRecipesList_FullDetails()
        {
            const string serialized = "AddedRecipes:" + "\r\n" +
                                      "(" + "\r\n" +
                                      "    ItemID:Aerogel;" + "\r\n" +
                                      "    AmountCrafted:1;" + "\r\n" +
                                      "    Ingredients:" + "\r\n" +
                                      "        (" + "\r\n" +
                                      "            ItemID:Titanium;" + "\r\n" +
                                      "            Required:2;" + "\r\n" +
                                      "        )," + "\r\n" +
                                      "        (" + "\r\n" +
                                      "            ItemID:Copper;" + "\r\n" +
                                      "            Required:3;" + "\r\n" +
                                      "        );" + "\r\n" +
                                      "    LinkedItemIDs:Silver,Gold;" + "\r\n" +
                                      "    Path:Fabricator/Resources/BasicMaterials;" +
                                      ")," + "\r\n" +
                                      "(" + "\r\n" +
                                      "    ItemID:Aerogel;" + "\r\n" +
                                      "    AmountCrafted:1;" + "\r\n" +
                                      "    Ingredients:" + "\r\n" +
                                      "        (" + "\r\n" +
                                      "            ItemID:Titanium;" + "\r\n" +
                                      "            Required:2;" + "\r\n" +
                                      "        )," + "\r\n" +
                                      "        (" + "\r\n" +
                                      "            ItemID:Copper;" + "\r\n" +
                                      "            Required:3;" + "\r\n" +
                                      "        );" + "\r\n" +
                                      "    LinkedItemIDs:Silver,Gold;" + "\r\n" +
                                      "    Path:Fabricator/Resources/BasicMaterials;" +
                                      ");" + "\r\n";


            var recipe = new AddedRecipeList();

            recipe.FromString(serialized);

            Assert.AreEqual(TechType.Aerogel, recipe[0].ItemID);
            Assert.AreEqual(1, recipe[0].AmountCrafted);

            Assert.AreEqual(2, recipe[0].SmlIngredients.Count);
            Assert.AreEqual(TechType.Titanium, recipe[0].SmlIngredients[0].techType);
            Assert.AreEqual(2, recipe[0].SmlIngredients[0].amount);
            Assert.AreEqual(TechType.Copper, recipe[0].SmlIngredients[1].techType);
            Assert.AreEqual(3, recipe[0].SmlIngredients[1].amount);

            Assert.AreEqual(2, recipe[0].LinkedItems.Count);
            Assert.AreEqual(TechType.Silver, recipe[0].LinkedItems[0]);
            Assert.AreEqual(TechType.Gold, recipe[0].LinkedItems[1]);

            Assert.AreEqual("Fabricator/Resources/BasicMaterials", recipe[0].Path);
        }
        public void Deserialize_AddedRecipesList_NoAmounts_Defaults()
        {
            const string serialized = "AddedRecipes:" + "\r\n" +
                                      "(" + "\r\n" +
                                      "    ItemID:Aerogel;" + "\r\n" +
                                      "    Ingredients:" + "\r\n" +
                                      "        (" + "\r\n" +
                                      "            ItemID:Titanium;" + "\r\n" +
                                      "        )," + "\r\n" +
                                      "        (" + "\r\n" +
                                      "            ItemID:Copper;" + "\r\n" +
                                      "        );" + "\r\n" +
                                      "    Path:Fabricator/Resources/BasicMaterials;" +
                                      "    ForceUnlockAtStart: NO;" +
                                      ")," + "\r\n" +
                                      "(" + "\r\n" +
                                      "    ItemID:Aerogel;" + "\r\n" +
                                      "    Ingredients:" + "\r\n" +
                                      "        (" + "\r\n" +
                                      "            ItemID:Titanium;" + "\r\n" +
                                      "        )," + "\r\n" +
                                      "        (" + "\r\n" +
                                      "            ItemID:Copper;" + "\r\n" +
                                      "        );" + "\r\n" +
                                      "    Path:Fabricator/Resources/BasicMaterials;" +
                                      ");" + "\r\n";


            var recipe = new AddedRecipeList();

            recipe.FromString(serialized);

            Assert.AreEqual(TechType.Aerogel.ToString(), recipe[0].ItemID);
            Assert.AreEqual(false, recipe[0].AmountCrafted.HasValue);

            Assert.AreEqual(2, recipe[0].Ingredients.Count);

            var item0 = recipe[0].Ingredients[0];

            Assert.AreEqual(TechType.Titanium.ToString(), item0.ItemID);
            Assert.AreEqual(1, item0.Required);

            var item1 = recipe[0].Ingredients[1];

            Assert.AreEqual(TechType.Copper.ToString(), item1.ItemID);
            Assert.AreEqual(1, item1.Required);

            Assert.AreEqual(false, recipe[0].LinkedItemIDs.Count > 0);
            Assert.AreEqual(false, recipe[0].ForceUnlockAtStart);

            Assert.AreEqual("Fabricator/Resources/BasicMaterials", recipe[0].Path);
        }
Exemplo n.º 4
0
        public void Deserialize_AddedRecipesList_NoAmounts_DefaultTo1()
        {
            const string serialized = "AddedRecipes:" + "\r\n" +
                                      "(" + "\r\n" +
                                      "    ItemID:Aerogel;" + "\r\n" +
                                      "    Ingredients:" + "\r\n" +
                                      "        (" + "\r\n" +
                                      "            ItemID:Titanium;" + "\r\n" +
                                      "        )," + "\r\n" +
                                      "        (" + "\r\n" +
                                      "            ItemID:Copper;" + "\r\n" +
                                      "        );" + "\r\n" +
                                      "    Path:Fabricator/Resources/BasicMaterials;" +
                                      ")," + "\r\n" +
                                      "(" + "\r\n" +
                                      "    ItemID:Aerogel;" + "\r\n" +
                                      "    Ingredients:" + "\r\n" +
                                      "        (" + "\r\n" +
                                      "            ItemID:Titanium;" + "\r\n" +
                                      "        )," + "\r\n" +
                                      "        (" + "\r\n" +
                                      "            ItemID:Copper;" + "\r\n" +
                                      "        );" + "\r\n" +
                                      "    Path:Fabricator/Resources/BasicMaterials;" +
                                      ");" + "\r\n";


            var recipe = new AddedRecipeList();

            recipe.FromString(serialized);

            Assert.AreEqual(TechType.Aerogel, recipe[0].ItemID);
            Assert.AreEqual(1, recipe[0].AmountCrafted);

            Assert.AreEqual(2, recipe[0].SmlIngredients.Count);
            Assert.AreEqual(TechType.Titanium, recipe[0].SmlIngredients[0].techType);
            Assert.AreEqual(1, recipe[0].SmlIngredients[0].amount);
            Assert.AreEqual(TechType.Copper, recipe[0].SmlIngredients[1].techType);
            Assert.AreEqual(1, recipe[0].SmlIngredients[1].amount);

            Assert.AreEqual(0, recipe[0].LinkedItems.Count);

            Assert.AreEqual("Fabricator/Resources/BasicMaterials", recipe[0].Path);
        }
Exemplo n.º 5
0
        private static void PatchAddedRecipes()
        {
            addedRecipeList = new AddedRecipeList();
            if (File.Exists(AddedRecipiesFile))
            {
                string serializedData = File.ReadAllText(AddedRecipiesFile);
                if (!string.IsNullOrEmpty(serializedData) && addedRecipeList.Deserialize(serializedData) && addedRecipeList.Count > 0)
                {
                    foreach (IAddedRecipe item in addedRecipeList)
                    {
                        try
                        {
                            CustomCraft.AddRecipe(item.ItemID, item.SmlHelperRecipe(), new CraftingPath(item.Path));
                        }
                        catch
                        {
                            Logger.Log($"Error on AddRecipe{Environment.NewLine}" +
                                       $"Entry with error:{Environment.NewLine}" +
                                       $"{item}");
                        }
                    }

                    Logger.Log($"AddedRecipies loaded. File reformatted.");
                    File.WriteAllText(AddedRecipiesFile, addedRecipeList.PrintyPrint());
                }
                else
                {
                    Logger.Log($"No AddedRecipes were loaded. File was empty or malformed.");
                }
            }
            else
            {
                File.WriteAllText(AddedRecipiesFile, $"# Added Recipes #{Environment.NewLine}" +
                                  $"# Check the AddedRecipes_Samples.txt file in the SampleFiles folder for details on how to add recipes for items normally not craftable #{Environment.NewLine}");
                Logger.Log($"{AddedRecipiesFile} file not found. Empty file created.");
            }
        }
        public void Deserialize_AddedRecipesList_AllLowerCaseIDs()
        {
            const string serialized = "AddedRecipes:                                            " +
                                      "(                                                        " +
                                      "    ItemID:stalkertooth;                                 " +
                                      "    AmountCrafted: 1;                                    " +
                                      "    Ingredients:                                         " +
                                      "        ( ItemID:quartz; Required:1; );                  " +
                                      "    Path:Fabricator/Resources/BasicMaterials;            " +
                                      "),                                                       " +
                                      "(                                                        " +
                                      "    ItemID:coralchunk;                                   " +
                                      "    AmountCrafted: 2;                                    " +
                                      "    Ingredients:                                         " +
                                      "        ( ItemID:crashpowder; Required:2; );             " +
                                      "    Path:Fabricator/Resources/BasicMaterials;            " +
                                      "),                                                       " +
                                      "(                                                        " +
                                      "    ItemID:nutrientblock;                                " +
                                      "    AmountCrafted: 2;                                    " +
                                      "    Ingredients:                                         " +
                                      "        ( ItemID:salt; Required:2; ),                    " +
                                      "        ( ItemID:purplerattlespore; Required:1; ),       " +
                                      "        ( ItemID:purplevaseplantseed; Required:1; ),     " +
                                      "        ( ItemID:orangepetalsplantseed; Required:1; ),   " +
                                      "        ( ItemID:orangemushroomspore; Required:1; ),     " +
                                      "        ( ItemID:pinkmushroomspore; Required:1; );       " +
                                      "    Path:Fabricator/Survival/CuredFood;                  " +
                                      ");                                                       ";

            var recipeList = new AddedRecipeList();

            bool success = recipeList.FromString(serialized);

            Assert.IsTrue(success);
            Assert.AreEqual(3, recipeList.Count);
        }
Exemplo n.º 7
0
        public void CreateFromClases_ThenTest_SampleAddRecipes()
        {
            var nutrientBlockRecipe = new AddedRecipe()
            {
                ItemID             = TechType.NutrientBlock.ToString(),
                AmountCrafted      = 1,
                ForceUnlockAtStart = false,
                Path        = PathHelper.Fabricator.Sustenance.CuredFood.CuredFoodTab.GetCraftingPath.ToString(),
                Ingredients =
                {
                    new EmIngredient(TechType.CuredReginald,   1),
                    new EmIngredient(TechType.PurpleVegetable, 1),
                    new EmIngredient(TechType.HangingFruit,    1),
                }
            };

            var bigFilterWaterRecipe = new AddedRecipe()
            {
                ItemID             = TechType.BigFilteredWater.ToString(),
                AmountCrafted      = 1,
                Path               = PathHelper.Fabricator.Sustenance.Water.WaterTab.GetCraftingPath.ToString(),
                ForceUnlockAtStart = false,
                Ingredients        =
                {
                    new EmIngredient(TechType.FilteredWater, 2)
                }
            };

            var origRecipeList = new AddedRecipeList
            {
                nutrientBlockRecipe,
                bigFilterWaterRecipe
            };

            string serialized = origRecipeList.PrettyPrint();

            string samples2File = SampleFileDirectory + "AddedRecipes_Samples2.txt";

            File.WriteAllText(samples2File, serialized);

            var readingRecipeList = new AddedRecipeList();

            string reserialized = File.ReadAllText(samples2File);

            bool success = readingRecipeList.FromString(reserialized);

            Assert.IsTrue(success);

            Assert.AreEqual(origRecipeList.Count, readingRecipeList.Count);

            // nutrientBlockRecipe
            AddedRecipe nutrientBlock = origRecipeList[0];

            Assert.AreEqual(nutrientBlock.ItemID, nutrientBlockRecipe.ItemID);
            Assert.AreEqual(nutrientBlock.AmountCrafted, nutrientBlockRecipe.AmountCrafted);
            Assert.AreEqual(nutrientBlock.Path, nutrientBlockRecipe.Path);
            Assert.AreEqual(nutrientBlock.Ingredients.Count, nutrientBlockRecipe.Ingredients.Count);
            Assert.AreEqual(nutrientBlock.Ingredients[0].ItemID, nutrientBlockRecipe.Ingredients[0].ItemID);
            Assert.AreEqual(nutrientBlock.Ingredients[1].ItemID, nutrientBlockRecipe.Ingredients[1].ItemID);
            Assert.AreEqual(nutrientBlock.Ingredients[2].ItemID, nutrientBlockRecipe.Ingredients[2].ItemID);
            Assert.AreEqual(nutrientBlock.Ingredients[0].Required, nutrientBlockRecipe.Ingredients[0].Required);
            Assert.AreEqual(nutrientBlock.Ingredients[1].Required, nutrientBlockRecipe.Ingredients[1].Required);
            Assert.AreEqual(nutrientBlock.Ingredients[2].Required, nutrientBlockRecipe.Ingredients[2].Required);
            Assert.AreEqual(nutrientBlock.Unlocks.Count, nutrientBlockRecipe.Unlocks.Count);
            Assert.AreEqual(nutrientBlock.ForceUnlockAtStart, nutrientBlockRecipe.ForceUnlockAtStart);
            Assert.AreEqual("Fabricator/Survival/CuredFood", nutrientBlockRecipe.Path);

            // bigFilterWaterRecipe
            AddedRecipe bigFilteredWater = origRecipeList[1];

            Assert.AreEqual(bigFilteredWater.ItemID, bigFilterWaterRecipe.ItemID);
            Assert.AreEqual(bigFilteredWater.AmountCrafted, bigFilterWaterRecipe.AmountCrafted);
            Assert.AreEqual(bigFilteredWater.Path, bigFilterWaterRecipe.Path);
            Assert.AreEqual(bigFilteredWater.Ingredients.Count, bigFilterWaterRecipe.Ingredients.Count);
            Assert.AreEqual(bigFilteredWater.Ingredients[0].ItemID, bigFilterWaterRecipe.Ingredients[0].ItemID);
            Assert.AreEqual(bigFilteredWater.Ingredients[0].Required, bigFilterWaterRecipe.Ingredients[0].Required);
            Assert.AreEqual(bigFilteredWater.Unlocks.Count, bigFilterWaterRecipe.Unlocks.Count);
            Assert.AreEqual(bigFilteredWater.ForceUnlockAtStart, bigFilterWaterRecipe.ForceUnlockAtStart);
        }
        public void CreateFromClases_ThenTest_SampleAddRecipes()
        {
            var nutrientBlockRecipe = new AddedRecipe()
            {
                ItemID        = TechType.NutrientBlock,
                AmountCrafted = 1,
                Path          = PathHelper.Fabricator.Sustenance.CuredFood.GetThisNode.ToString()
            };

            nutrientBlockRecipe.AddIngredient(TechType.CuredReginald, 1);
            nutrientBlockRecipe.AddIngredient(TechType.PurpleVegetable, 1);
            nutrientBlockRecipe.AddIngredient(TechType.HangingFruit, 1);

            var bigFilterWaterRecipe = new AddedRecipe()
            {
                ItemID        = TechType.BigFilteredWater,
                AmountCrafted = 1,
                Path          = PathHelper.Fabricator.Sustenance.Water.GetThisNode.ToString()
            };

            bigFilterWaterRecipe.AddIngredient(TechType.FilteredWater, 2);

            var origRecipeList = new AddedRecipeList();

            origRecipeList.Collections.Add(nutrientBlockRecipe);
            origRecipeList.Collections.Add(bigFilterWaterRecipe);

            string serialized = origRecipeList.PrintyPrint();

            string samples2File = SampleFileDirectory + "AddedRecipes_Samples2.txt";

            File.WriteAllText(samples2File, serialized);

            var readingRecipeList = new AddedRecipeList();

            string reserialized = File.ReadAllText(samples2File);

            bool success = readingRecipeList.FromString(reserialized);

            Assert.IsTrue(success);

            Assert.AreEqual(origRecipeList.Count, readingRecipeList.Count);

            // nutrientBlockRecipe
            Assert.AreEqual(origRecipeList[0].ItemID, nutrientBlockRecipe.ItemID);
            Assert.AreEqual(origRecipeList[0].AmountCrafted, nutrientBlockRecipe.AmountCrafted);
            Assert.AreEqual(origRecipeList[0].Path, nutrientBlockRecipe.Path);
            Assert.AreEqual(origRecipeList[0].SmlIngredients.Count, nutrientBlockRecipe.SmlIngredients.Count);
            Assert.AreEqual(origRecipeList[0].SmlIngredients[0].techType, nutrientBlockRecipe.SmlIngredients[0].techType);
            Assert.AreEqual(origRecipeList[0].SmlIngredients[1].techType, nutrientBlockRecipe.SmlIngredients[1].techType);
            Assert.AreEqual(origRecipeList[0].SmlIngredients[2].techType, nutrientBlockRecipe.SmlIngredients[2].techType);
            Assert.AreEqual(origRecipeList[0].SmlIngredients[0].amount, nutrientBlockRecipe.SmlIngredients[0].amount);
            Assert.AreEqual(origRecipeList[0].SmlIngredients[1].amount, nutrientBlockRecipe.SmlIngredients[1].amount);
            Assert.AreEqual(origRecipeList[0].SmlIngredients[2].amount, nutrientBlockRecipe.SmlIngredients[2].amount);

            // bigFilterWaterRecipe
            Assert.AreEqual(origRecipeList[1].ItemID, bigFilterWaterRecipe.ItemID);
            Assert.AreEqual(origRecipeList[1].AmountCrafted, bigFilterWaterRecipe.AmountCrafted);
            Assert.AreEqual(origRecipeList[1].Path, bigFilterWaterRecipe.Path);
            Assert.AreEqual(origRecipeList[1].SmlIngredients.Count, bigFilterWaterRecipe.SmlIngredients.Count);
            Assert.AreEqual(origRecipeList[1].SmlIngredients[0].techType, bigFilterWaterRecipe.SmlIngredients[0].techType);
            Assert.AreEqual(origRecipeList[1].SmlIngredients[0].amount, bigFilterWaterRecipe.SmlIngredients[0].amount);
        }