Esempio n. 1
0
        public static void OnNewDay()
        {
            ModEntry.GetMonitor().Log($"There are currently {pests.Count} infested crops", LogLevel.Trace);

            //pests eat crops
            //ModEntry.GetMonitor().Log("nom", LogLevel.Trace);
            List <Pest> copy = new List <Pest>(pests);

            foreach (Pest pest in copy)
            {
                //ModEntry.GetMonitor().Log("nom on pest", LogLevel.Trace);
                if (pest.NomNom())
                {
                    pests.Remove(pest);
                }
            }

            //infest adjacent crops
            //ModEntry.GetMonitor().Log("adjacent", LogLevel.Trace);
            copy = new List <Pest>(pests);
            foreach (Pest pest in copy)
            {
                pests.AddRange(pest.InfestAdjacent(config.adjacent_infestation_chance));
            }

            //infest new crops
            //ModEntry.GetMonitor().Log("infest new", LogLevel.Trace);
            foreach (KeyValuePair <Vector2, TerrainFeature> kv in Game1.getFarm().terrainFeatures.Pairs)
            {
                if (kv.Key is Vector2 vec && kv.Value is HoeDirt hd)
                {
                    //ModEntry.GetMonitor().Log("found hoedirt", LogLevel.Trace);
                    if (CheckChance(config.pest_infestation_chance))
                    {
                        Pest pest = TryInfestCrop(vec, hd);
                        if (pest != null)
                        {
                            ModEntry.GetMonitor().Log("Infested crop at " + vec, LogLevel.Trace);
                            pests.Add(pest);
                        }
                    }
                }
            }

            ModEntry.GetMonitor().Log($"Now there are {pests.Count} infested crops", LogLevel.Trace);
        }
Esempio n. 2
0
        public List <Pest> InfestAdjacent(double chance)
        {
            List <Pest> pests = new List <Pest>();

            foreach (KeyValuePair <Vector2, TerrainFeature> pair in GetAdjacentCrops())
            {
                if (pair.Key is Vector2 vec && pair.Value is HoeDirt hd && Pests.CheckChance(chance))
                {
                    Pest pest = Pests.TryInfestCrop(vec, hd);
                    if (pest != null)
                    {
                        ModEntry.GetMonitor().Log("Infested adjacent crop at " + vec, LogLevel.Trace);
                        pests.Add(pest);
                    }
                }
            }
            return(pests);
        }
Esempio n. 3
0
        public static Pest TryInfestCrop(Vector2 pos, HoeDirt hd)
        {
            if (hd == null || hd != null && hd.crop == null || hd.crop.dead.Value || hd.crop.isWildSeedCrop() || pests.Exists((Pest p) => p.HasPosition(pos)))
            {
                return(null);
            }

            List <CropTrait> traits = Cultivation.GetTraits(hd.crop);

            switch (Cultivation.GetPestRes(pos, traits, false))
            {
            case 0:
                break;

            case 1:
                if (CheckChance(config.pest_resistance_i_chance))
                {
                    return(null);
                }
                break;

            case 2:
                if (CheckChance(config.pest_resistance_ii_chance))
                {
                    return(null);
                }
                break;

            default:
                ModEntry.GetMonitor().Log("Bug: GetPestRes returned wrong value", LogLevel.Error);
                break;
            }

            Pest pest = new Pest(pos, hd);

            return(pest);
        }