Ejemplo n.º 1
0
        public static void NewSeeds(int id)
        {
            //ModEntry.GetMonitor().Log("checking key in cropseeds...");
            if (CropSeeds.ContainsKey(id))
            {
                CropSeeds[id] += 1;
            }
            else
            {
                CropSeeds.Add(id, 1);
            }

            //ModEntry.GetMonitor().Log("checking if max is reached...");
            if (CropSeeds[id] >= config.processed_crops_for_cultivation_level)
            {
                if (!CropTraits.ContainsKey(id))
                {
                    CropTraits.Add(id, new List <CropTrait>());
                }

                CropSeeds[id] = 0;

                List <CropTrait> traits;
                CropTraits.TryGetValue(id, out traits);

                if (traits.Count >= Enum.GetValues(typeof(CropTrait)).Length)
                {
                    ModEntry.GetMonitor().Log($"tried to add trait to {CropSeedsDisplayName(id)}, but traits are maxed", LogLevel.Trace);
                    return;
                }

                AddTrait(GetNewRandomTrait(traits), traits, id);
            }
        }
Ejemplo n.º 2
0
        public static void Save()
        {
            SaveData dat = new SaveData()
            {
                InfestedCrops = pests.Select((pest) => pest.GetPos()).ToList()
            };

            ModEntry.GetHelper().Data.WriteSaveData <SaveData>(SaveData._InfestedCrops, dat);
            ModEntry.GetMonitor().Log("Pests.Save() executed", LogLevel.Trace);
        }
Ejemplo n.º 3
0
        public static void Load()
        {
            Dictionary <int, List <CropTrait> > loadedCropTraits = ModEntry.GetHelper().Data.ReadSaveData <SaveData>(SaveData._CropTraits)?.CropTraits;

            if (loadedCropTraits != null)
            {
                CropTraits = loadedCropTraits;
            }

            Dictionary <int, int> loadedCropSeeds = ModEntry.GetHelper().Data.ReadSaveData <SaveData>(SaveData._CropSeeds)?.CropSeeds;

            if (loadedCropSeeds != null)
            {
                CropSeeds = loadedCropSeeds;
            }

            List <Vector2> loadedTempQualityFertilizer = ModEntry.GetHelper().Data.ReadSaveData <SaveData>(SaveData._TempQualityFertilizer)?.TempQualityFertilizer;

            if (loadedTempQualityFertilizer != null)
            {
                TempQualityFertilizer = loadedTempQualityFertilizer;
            }

            List <Vector2> loadedTempQualityIIFertilizer = ModEntry.GetHelper().Data.ReadSaveData <SaveData>(SaveData._TempQualityIIFertilizer)?.TempQualityIIFertilizer;

            if (loadedTempQualityIIFertilizer != null)
            {
                TempQualityIIFertilizer = loadedTempQualityIIFertilizer;
            }

            List <Vector2> loadedTempWaterStop = ModEntry.GetHelper().Data.ReadSaveData <SaveData>(SaveData._TempWaterStop)?.TempWaterStop;

            if (loadedTempWaterStop != null)
            {
                TempWaterStop = loadedTempWaterStop;
            }

            List <Vector2> loadedTempWaterOneDay = ModEntry.GetHelper().Data.ReadSaveData <SaveData>(SaveData._TempWaterOneDay)?.TempWaterOneDay;

            if (loadedTempWaterOneDay != null)
            {
                TempWaterOneDay = loadedTempWaterOneDay;
            }

            List <Vector2> loadedTempWaterTwoDays = ModEntry.GetHelper().Data.ReadSaveData <SaveData>(SaveData._TempWaterTwoDays)?.TempWaterTwoDays;

            if (loadedTempWaterTwoDays != null)
            {
                TempWaterTwoDays = loadedTempWaterTwoDays;
            }

            ModEntry.GetMonitor().Log("Cultivation.Load() executed", LogLevel.Trace);
            ModEntry.GetMonitor().Log($"loaded {CropTraits.Count} crop traits and {CropSeeds.Count} crop seeds", LogLevel.Trace);
        }
Ejemplo n.º 4
0
        public static void AddTrait(CropTrait trait, List <CropTrait> traits, int id)
        {
            ITranslationHelper trans = ModEntry.GetHelper().Translation;

            string gettraitdescr()
            {
                switch (trait)
                {
                case CropTrait.PestResistanceI:
                case CropTrait.PestResistanceII:
                    return(trans.Get("cult.msg_traitdesc_pestres"));

                case CropTrait.QualityI:
                case CropTrait.QualityII:
                    return(trans.Get("cult.msg_traitdesc_quality"));

                case CropTrait.WaterI:
                case CropTrait.WaterII:
                    return(trans.Get("cult.msg_traitdesc_water"));

                case CropTrait.SpeedI:
                case CropTrait.SpeedII:
                    return(trans.Get("cult.msg_traitdesc_speed"));

                default:
                    return("ERROR gettraitdescr");
                }
            }

            string gettraitname()
            {
                switch (trait)
                {
                case CropTrait.PestResistanceI:
                    return(trans.Get("cult.msg_trait_pestresI"));

                case CropTrait.PestResistanceII:
                    return(trans.Get("cult.msg_trait_pestresII"));

                case CropTrait.QualityI:
                    return(trans.Get("cult.msg_trait_qualityI"));

                case CropTrait.QualityII:
                    return(trans.Get("cult.msg_trait_qualityII"));

                case CropTrait.WaterI:
                    return(trans.Get("cult.msg_trait_waterI"));

                case CropTrait.WaterII:
                    return(trans.Get("cult.msg_trait_waterII"));

                case CropTrait.SpeedI:
                    return(trans.Get("cult.msg_trait_speedI"));

                case CropTrait.SpeedII:
                    return(trans.Get("cult.msg_trait_speedII"));

                default:
                    return("ERROR gettraitname");
                }
            }

            void add()
            {
                ModEntry.GetMonitor().Log($"Added {trait} to {CropSeedsName(id)}", LogLevel.Trace);
                Game1.showGlobalMessage(trans.Get("cult.msg_traitinc", new { traitdesc = gettraitdescr(), seed = CropSeedsName(id), trait = gettraitname() }));
                traits.Add(trait);
                CropTraits[id] = traits;
            }

            bool alreadyContains() => traits.Contains(trait);

            CropTrait newTrait = GetNewRandomTrait(traits);

            if (traits.Contains(newTrait))
            {
                ModEntry.GetMonitor().Log("Bug: tried to find new trait with full list or returned wrong trait", LogLevel.Error);
                return;
            }

            if (alreadyContains())
            {
                switch (trait)
                {
                case CropTrait.PestResistanceI:
                    AddTrait(CropTrait.PestResistanceII, traits, id);
                    break;

                case CropTrait.WaterI:
                    AddTrait(CropTrait.WaterII, traits, id);
                    break;

                case CropTrait.QualityI:
                    AddTrait(CropTrait.QualityII, traits, id);
                    break;

                case CropTrait.SpeedI:
                    AddTrait(CropTrait.SpeedII, traits, id);
                    break;

                default:
                    AddTrait(newTrait, traits, id);
                    break;
                }
            }
            else
            {
                switch (trait)
                {
                case CropTrait.PestResistanceII:
                    if (traits.Contains(CropTrait.PestResistanceI))
                    {
                        add();
                    }
                    else
                    {
                        trait = CropTrait.PestResistanceI;
                        add();
                    }
                    break;

                case CropTrait.WaterII:
                    if (traits.Contains(CropTrait.WaterI))
                    {
                        add();
                    }
                    else
                    {
                        trait = CropTrait.WaterI;
                        add();
                    }

                    break;

                case CropTrait.QualityII:
                    if (traits.Contains(CropTrait.QualityI))
                    {
                        add();
                    }
                    else
                    {
                        trait = CropTrait.QualityI;
                        add();
                    }

                    break;

                case CropTrait.SpeedII:
                    if (traits.Contains(CropTrait.SpeedI))
                    {
                        add();
                    }
                    else
                    {
                        trait = CropTrait.SpeedI;
                        add();
                    }
                    break;

                default:
                    add();
                    break;
                }
            }
        }