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);
        }
        /// <summary>Add at least one animal type to a category when the 'bfav_fa_addtypes' command is invoked.</summary>
        /// <param name="command">The name of the command invoked.</param>
        /// <param name="args">The arguments received by the command. Each word after the command name is a separate argument.</param>ary>
        private void AddTypes(string command, string[] args)
        {
            if (Game1.hasLoadedGame)
            {
                this.Monitor.Log($"this cannot be done after loading a save");
                return;
            }

            if (args.Length > 2)
            {
                this.Monitor.Log($"use quotation marks (\") around your text if you are using spaces", LogLevel.Error);
                return;
            }

            if (args.Length < 1)
            {
                this.Monitor.Log($"category is required", LogLevel.Error);
                return;
            }

            string category = args[0].Trim();

            if (!this.Config.FarmAnimals.ContainsKey(category))
            {
                this.Monitor.Log($"{category} is not a category in config.json", LogLevel.Error);
                return;
            }

            if (args.Length < 2)
            {
                this.Monitor.Log($"type is required", LogLevel.Error);
                return;
            }

            List <string>   types           = new List <string>(this.Config.FarmAnimals[category].Types);
            List <string>   newTypes        = args[1].Split(',').Select(i => i.Trim()).ToList();
            FarmAnimalsData farmAnimalsData = new FarmAnimalsData();

            // Check if these new types are valid
            foreach (string newType in newTypes)
            {
                if (!farmAnimalsData.Exists(newType))
                {
                    this.Monitor.Log($"{newType} does not exist in Data/FarmAnimals", LogLevel.Error);
                    return;
                }
            }

            this.Config.FarmAnimals[category].Types = types.Concat(newTypes).Distinct().ToArray();

            this.HandleUpdatedConfig();

            string output = this.DescribeFarmAnimalCategory(new KeyValuePair <string, ConfigFarmAnimal>(category, this.Config.FarmAnimals[category]));

            this.Monitor.Log(output, LogLevel.Info);
        }
Beispiel #3
0
 public BreedFarmAnimal(Player farmer, BreedFarmAnimalConfig breedFarmAnimalConfig)
 {
     this.Farmer = farmer;
     this.AvailableFarmAnimals           = breedFarmAnimalConfig.AvailableFarmAnimals;
     this.BlueFarmAnimals                = breedFarmAnimalConfig.BlueFarmAnimals;
     this.FarmAnimalsData                = breedFarmAnimalConfig.FarmAnimalsData;
     this.RandomizeNewbornFromCategory   = breedFarmAnimalConfig.RandomizeNewbornFromCategory;
     this.RandomizeHatchlingFromCategory = breedFarmAnimalConfig.RandomizeHatchlingFromCategory;
     this.IgnoreParentProduceCheck       = breedFarmAnimalConfig.IgnoreParentProduceCheck;
 }
        public BreedFarmAnimalConfig(Dictionary <string, List <string> > availableFarmAnimals, BlueVariation blueFarmAnimals, bool randomizeNewbornFromCategory = false, bool randomizeHatchlingFromCategory = false, bool ignoreParentProduceCheck = false)
        {
            this.AvailableFarmAnimals = availableFarmAnimals;
            this.BlueFarmAnimals      = blueFarmAnimals;
            this.FarmAnimalsData      = new FarmAnimalsData();

            // Default these to false for backwards compatibility
            this.RandomizeNewbornFromCategory   = randomizeNewbornFromCategory;
            this.RandomizeHatchlingFromCategory = randomizeHatchlingFromCategory;
            this.IgnoreParentProduceCheck       = ignoreParentProduceCheck;
        }
        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);
            }
        }
        /// <summary>Add a unique category when the 'bfav_fa_addcategory' command is invoked.</summary>
        /// <param name="command">The name of the command invoked.</param>
        /// <param name="args">The arguments received by the command. Each word after the command name is a separate argument.</param>
        private void AddCategory(string command, string[] args)
        {
            if (Game1.hasLoadedGame)
            {
                this.Monitor.Log($"this cannot be done after loading a save");
                return;
            }

            if (args.Length > 4)
            {
                this.Monitor.Log($"use quotation marks (\") around your text if you are using spaces", LogLevel.Error);
                return;
            }

            if (args.Length < 1)
            {
                this.Monitor.Log($"category is required", LogLevel.Error);
                return;
            }

            string category = args[0].Trim();

            if (this.Config.FarmAnimals.ContainsKey(category))
            {
                this.Monitor.Log($"{category} already exists in config.json", LogLevel.Error);
                return;
            }

            if (args.Length < 2)
            {
                this.Monitor.Log($"type is required", LogLevel.Error);
                return;
            }

            List <string>   types           = args[1].Split(',').Select(i => i.Trim()).ToList();
            FarmAnimalsData farmAnimalsData = new FarmAnimalsData();

            // Check if these new types are valid
            foreach (string key in types)
            {
                if (!farmAnimalsData.Exists(key))
                {
                    this.Monitor.Log($"{key} does not exist in Data/FarmAnimals", LogLevel.Error);
                    return;
                }
            }

            string        building  = args.Length < 3 ? Barn.BARN : args[2].Trim();
            List <string> buildings = new List <string>();

            if (building.ToLower().Equals(Coop.COOP.ToLower()))
            {
                foreach (PariteeAnimalHouse.Size size in Enum.GetValues(typeof(Coop.Size)))
                {
                    buildings.Add(PariteeAnimalHouse.FormatBuilding(Coop.COOP, size));
                }
            }
            else if (building.ToLower().Equals(Barn.BARN.ToLower()))
            {
                foreach (PariteeAnimalHouse.Size size in Enum.GetValues(typeof(Barn.Size)))
                {
                    buildings.Add(PariteeAnimalHouse.FormatBuilding(Barn.BARN, size));
                }
            }
            else
            {
                buildings = building.Split(',').Select(i => i.Trim()).ToList();

                BlueprintsData blueprintsData = new BlueprintsData();

                // Check if these new types are valid
                foreach (string key in buildings)
                {
                    if (!blueprintsData.Exists(key))
                    {
                        this.Monitor.Log($"{key} does not exist in Data/Blueprints", LogLevel.Error);
                        return;
                    }
                }
            }

            string animalShop = args.Length < 4 ? FarmAnimalsCommands.ANIMAL_SHOP_UNAVAILABLE : args[3].Trim().ToLower();

            if (!animalShop.Equals(FarmAnimalsCommands.ANIMAL_SHOP_AVAILABLE) && !animalShop.Equals(FarmAnimalsCommands.ANIMAL_SHOP_UNAVAILABLE))
            {
                this.Monitor.Log($"animalshop must be yes or no", LogLevel.Error);
                return;
            }

            ConfigFarmAnimalAnimalShop configFarmAnimalAnimalShop;

            try
            {
                configFarmAnimalAnimalShop = this.GetAnimalShopConfig(category, animalShop);
            }
            catch
            {
                // Messaging handled in function
                return;
            }

            this.Config.FarmAnimals.Add(category, new ConfigFarmAnimal());

            this.Config.FarmAnimals[category].Category   = category;
            this.Config.FarmAnimals[category].Types      = types.Distinct().ToArray();
            this.Config.FarmAnimals[category].Buildings  = buildings.ToArray();
            this.Config.FarmAnimals[category].AnimalShop = configFarmAnimalAnimalShop;

            this.HandleUpdatedConfig();

            string output = this.DescribeFarmAnimalCategory(new KeyValuePair <string, ConfigFarmAnimal>(category, this.Config.FarmAnimals[category]));

            this.Monitor.Log(output, LogLevel.Info);
        }