Beispiel #1
0
        public List <FarmAnimalForPurchase> GetFarmAnimalsForPurchase(Farm farm)
        {
            List <FarmAnimalForPurchase> purchaseAnimalStock   = new List <FarmAnimalForPurchase>();
            FarmAnimalsData             farmAnimalsData        = new FarmAnimalsData();
            Dictionary <string, string> farmAnimalsDataEntries = farmAnimalsData.GetEntries();

            foreach (KeyValuePair <string, ConfigFarmAnimal> entry in this.FarmAnimals)
            {
                if (!entry.Value.CanBePurchased())
                {
                    continue;
                }

                string        name             = entry.Value.Category;
                string        displayName      = entry.Value.AnimalShop.Name;
                string        description      = entry.Value.AnimalShop.Description;
                int           price            = Convert.ToInt32(entry.Value.AnimalShop.Price) / 2; // Divide by two because of the weird functionality in Object.salePrice()
                List <string> farmAnimalTypes  = this.GetFarmAnimalTypes(name);
                List <string> buildingsILiveIn = new List <string>(entry.Value.Buildings);

                FarmAnimalForPurchase farmAnimalForPurchase = new FarmAnimalForPurchase(name, displayName, description, price, buildingsILiveIn, farmAnimalTypes);

                purchaseAnimalStock.Add(farmAnimalForPurchase);
            }

            return(purchaseAnimalStock);
        }
        private void FixSave(string saveFolder)
        {
            string saveFile = Path.Combine(saveFolder, Path.GetFileName(saveFolder));

            if (!File.Exists(saveFile))
            {
                this.Monitor.Log($"{saveFile} does not exist", LogLevel.Error);
                return;
            }

            // Baseline
            FarmAnimalsData data = new FarmAnimalsData();

            WhiteVariation whiteVariation        = new WhiteVariation();
            string         coopDwellerSubstitute = whiteVariation.ApplyPrefix(Paritee.StardewValleyAPI.FarmAnimals.Type.Base.Chicken.ToString());
            string         barnDwellerSubstitute = whiteVariation.ApplyPrefix(Paritee.StardewValleyAPI.FarmAnimals.Type.Base.Cow.ToString());

            this.Monitor.Log($"Searching {saveFolder} for problematic farm animal types", LogLevel.Trace);

            // Replace barn animals with White Cows and coop animals with White Chickens
            XmlDocument doc = new XmlDocument();

            // Track the types to be substituted
            List <string> typesToBeSubstituted = new List <string>();

            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(doc.NameTable);

            namespaceManager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

            // Load the xml
            doc.Load(saveFile);

            XmlNodeList buildings = doc.SelectNodes("//GameLocation[@xsi:type='Farm']/buildings/Building[@xsi:type='Barn' or @xsi:type='Coop']", namespaceManager);

            this.Monitor.Log($"- Checking {buildings.Count} buildings", LogLevel.Trace);

            // Go through each building
            for (int i = 0; i < buildings.Count; i++)
            {
                XmlNode building = buildings[i];

                bool isCoop = building.Attributes["xsi:type"].Value.Equals("Coop");

                // Grab only the animal types
                XmlNodeList types = building.SelectNodes(".//FarmAnimal/type");

                for (int k = 0; k < types.Count; k++)
                {
                    XmlNode type = types[k];

                    // If the type can't be found in the data entries
                    // then substitute it with an appropriate basic animal
                    if (!data.GetEntries().ContainsKey(type.InnerText))
                    {
                        typesToBeSubstituted.Add(type.InnerText);

                        type.InnerText = isCoop ? coopDwellerSubstitute : barnDwellerSubstitute;
                    }
                }
            }

            if (typesToBeSubstituted.Count > 0)
            {
                // save the XmlDocument back to disk
                doc.Save(saveFile);

                this.Monitor.Log($"- Converted {typesToBeSubstituted.Count} farm animals to White Cows or White Chickens: {String.Join(", ", typesToBeSubstituted.Distinct())}", LogLevel.Trace);
            }
            else
            {
                this.Monitor.Log($"- No problematic farm animals found", LogLevel.Trace);
            }
        }