コード例 #1
0
ファイル: ModEntry.cs プロジェクト: AndyCrocker/StardewMods
        /// <summary>Gets the existing crop config values from a specified <see cref="CropMod"/>, <paramref name="season"/>, and <paramref name="cropName"/>.</summary>
        /// <param name="cropMod">The crop mod to get the config values from.</param>
        /// <param name="season">The season to get the values from.</param>
        /// <param name="cropName">The name of the crop.</param>
        /// <param name="enabled">The enabled config value of the crop.</param>
        /// <param name="dropChance">The drop chance config value of the crop.</param>
        private void GetExistingCropConfigValues(CropMod cropMod, string season, string cropName, out bool enabled, out float dropChance)
        {
            // setup default values
            enabled    = true;
            dropChance = 1;

            // validate
            if (cropMod == null)
            {
                // set the default enabled value for cactus fruit to be false, this is because they die when planted outside (it'll be just disabled instead of removed because some mods such as Seeds Are Rare may rely on this mod being able to drop cactus fruit, even if it requires users to change their configuration)
                if (cropName.ToLower() == "cactus fruit")
                {
                    enabled = false;
                }

                // set the default enabled value for qi fruit to be false, this is a quest item so it's rather unbalanced to have this enabled by default
                if (cropName.ToLower() == "qi fruit")
                {
                    enabled = false;
                }

                return;
            }

            // get Crop object
            var crop = cropMod.GetSeasonByName(season)?.Crops?.FirstOrDefault(c => c.Name.ToLower() == cropName.ToLower());

            if (crop == null)
            {
                return;
            }

            enabled    = crop.Enabled;
            dropChance = crop.DropChance;
        }
コード例 #2
0
ファイル: ModEntry.cs プロジェクト: AndyCrocker/StardewMods
        /// <summary>Creates a <see cref="CropMod"/> from a collection of <see cref="Seed"/>s.</summary>
        /// <param name="seeds">The seeds to convert.</param>
        /// <param name="oldCropMod">The old <see cref="CropMod"/> object to copy config options from.</param>
        /// <returns>The created crop mod object.</returns>
        private CropMod CreateCropModFromSeeds(IEnumerable <Seed> seeds, CropMod oldCropMod = null)
        {
            // sort all crop ids into seasons
            var springCrops = new List <Crop>();
            var summerCrops = new List <Crop>();
            var fallCrops   = new List <Crop>();
            var winterCrops = new List <Crop>();

            foreach (var seed in seeds)
            {
                if (seed.Season.ToLower() == "spring")
                {
                    GetExistingCropConfigValues(oldCropMod, "spring", seed.CropName, out var enabled, out var dropChance);
                    springCrops.Add(new Crop(seed.CropName, enabled, dropChance));
                }
                else if (seed.Season.ToLower() == "summer")
                {
                    GetExistingCropConfigValues(oldCropMod, "summer", seed.CropName, out var enabled, out var dropChance);
                    summerCrops.Add(new Crop(seed.CropName, enabled, dropChance));
                }
                else if (seed.Season.ToLower() == "fall")
                {
                    GetExistingCropConfigValues(oldCropMod, "fall", seed.CropName, out var enabled, out var dropChance);
                    fallCrops.Add(new Crop(seed.CropName, enabled, dropChance));
                }
                else if (seed.Season.ToLower() == "winter")
                {
                    GetExistingCropConfigValues(oldCropMod, "winter", seed.CropName, out var enabled, out var dropChance);
                    winterCrops.Add(new Crop(seed.CropName, enabled, dropChance));
                }
            }

            // return converted object
            return(new CropMod(new Season(springCrops), new Season(summerCrops), new Season(fallCrops), new Season(winterCrops), oldCropMod?.Enabled ?? true));;
        }
コード例 #3
0
ファイル: ModEntry.cs プロジェクト: MadAbs/smapi-mod-dump
        /// <summary>The method for finding which seeds are currently enabled in the specified mod.</summary>
        /// <param name="modName">The internal mod name that will be used for getting the list of seeds.</param>
        /// <returns>A list of enabled seeds.</returns>
        private List <Seed> CheckModForEnabledCrops(string modName)
        {
            List <Seed> seedNames = new List <Seed>();

            // Get the CropMod object for the current mod from config
            PropertyInfo configInfo = ModConfig.GetType().GetProperty(modName);
            CropMod      mod        = (CropMod)configInfo.GetValue(ModConfig);

            // Get the 4 season properties for the current CropMod
            PropertyInfo[] modSeasonsInfo = mod.GetType().GetProperties();

            // Get the seed index for finding seed names for the crops
            PropertyInfo seedIndexInfo            = SeedIndex.GetType().GetProperty(modName);
            Dictionary <string, string> seedIndex = (Dictionary <string, string>)seedIndexInfo.GetValue(SeedIndex);

            for (int i = 0; i < 4; i++)
            {
                PropertyInfo modSeasonInfo = modSeasonsInfo[i];
                Season       season        = (Season)modSeasonInfo.GetValue(mod);
                string       seasonName    = modSeasonInfo.Name.ToLower();

                if (season == null)
                {
                    continue;
                }

                foreach (Crop crop in season.Crops)
                {
                    if (crop.Enabled)
                    {
                        string seedName = seedIndex
                                          .Where(seed => seed.Key == crop.Name)
                                          .Select(seed => seed.Value)
                                          .FirstOrDefault();

                        if (string.IsNullOrEmpty(seedName))
                        {
                            MMonitor.Log($"Seed name for {crop.Name} couldn't be found", LogLevel.Error);
                            continue;
                        }

                        // If the seed is already in the dictionary, add the season to the array
                        if (seedNames.Where(seed => seed.Name == seedName).Any())
                        {
                            // Add the season to all instances of the seed
                            seedNames
                            .Where(seed => seed.Name == seedName)
                            .Select(seed => seed.Seasons.Add(seasonName));
                        }
                        else
                        {
                            // Add the to the list [Chance] number of times, so it has an effect on the final result
                            for (int j = 0; j < crop.Chance; j++)
                            {
                                seedNames.Add(new Seed(0, seedName, new string[1] {
                                    seasonName
                                }));
                            }

                            MMonitor.Log($"{seedName} has been added to the seed list");
                        }
                    }
                }
            }

            return(seedNames);
        }
コード例 #4
0
        /// <summary>The method for finding which seeds are currently enabled in the specified mod.</summary>
        /// <param name="modName">The internal mod name that will be used for getting the list of seeds.</param>
        /// <returns>A list of enabled seeds.</returns>
        private List <Seed> CheckModForEnabledCrops(string modName)
        {
            List <Seed> seedNames = new List <Seed>();

            // get the CropMod object for the current mod from config
            PropertyInfo configInfo = typeof(ModConfig).GetProperty(modName);
            CropMod      mod        = (CropMod)configInfo.GetValue(ModConfig);

            // get the 4 season properties for the current CropMod
            PropertyInfo[] modSeasonsInfo = typeof(CropMod).GetProperties();

            // get the seed index for finding seed names for the crops
            PropertyInfo    seedIndexInfo = typeof(CropModData).GetProperty(modName);
            List <SeedData> seedIndex     = (List <SeedData>)seedIndexInfo.GetValue(null);

            foreach (var modSeasonInfo in modSeasonsInfo)
            {
                Season season     = (Season)modSeasonInfo.GetValue(mod);
                string seasonName = modSeasonInfo.Name.ToLower();

                if (season == null)
                {
                    continue;
                }

                foreach (Crop crop in season.Crops)
                {
                    if (!crop.Enabled || crop.Chance == 0)
                    {
                        continue;
                    }

                    SeedData seedData = seedIndex
                                        .Where(seed => seed.CropName == crop.Name)
                                        .FirstOrDefault();

                    // check both name and id as a seed could have either populated, depending if its a SDV crop, or JA crop
                    if (string.IsNullOrEmpty(seedData.SeedName) && seedData.SeedId == -1)
                    {
                        ModMonitor.Log($"Seed name for {crop.Name} couldn't be found", LogLevel.Error);
                        continue;
                    }

                    if (ModEntry.ModConfig.UseCropYearRequirement && Game1.year < seedData.YearRequirement)
                    {
                        ModMonitor.Log($"Skipped {crop.Name} as year requirement was not met");
                        continue;
                    }

                    // if the seed is already in the dictionary, add the season to the array
                    if (seedNames.Where(seed => seed.Name == seedData.SeedName).Any())
                    {
                        seedNames
                        .Where(seed => seed.Name == seedData.SeedName)
                        .Select(seed => seed.Seasons.Add(seasonName));
                    }
                    else
                    {
                        // add the to the list [Chance] number of times, so it has an effect on the final result
                        for (int j = 0; j < crop.Chance; j++)
                        {
                            // if the seed name is null, load the seed id instead. this is only the case for base game seeds. this is so the code that handles converting ja names to ids doesn't run the base game crops
                            string seedName = seedData.SeedName;
                            if (seedData.SeedName == null)
                            {
                                seedName = seedData.SeedId.ToString();
                            }

                            seedNames.Add(new Seed(0, seedName, new string[1] {
                                seasonName
                            }));
                        }

                        ModMonitor.Log($"{seedData.CropName} has been added to the seed list");
                    }
                }
            }

            return(seedNames);
        }