/// <summary> /// This function handles the end of the day. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnEndOfDay(object sender, EventArgs e) { if (Conditions.HasWeather(CurrentWeather.Frost) && WeatherOpt.AllowCropDeath) { Farm f = Game1.getFarm(); int count = 0, maxCrops = (int)Math.Floor(SDVUtilities.CropCountInFarm(f) * WeatherOpt.DeadCropPercentage); foreach (KeyValuePair <Vector2, TerrainFeature> tf in f.terrainFeatures) { if (count >= maxCrops) { break; } if (tf.Value is HoeDirt curr && curr.crop != null) { if (Dice.NextDouble() > WeatherOpt.CropResistance) { CropList.Add(tf.Key); count++; } } } if (count > 0) { foreach (Vector2 v in CropList) { HoeDirt hd = (HoeDirt)f.terrainFeatures[v]; hd.crop.dead = true; } queuedMsg = new HUDMessage(Helper.Translation.Get("hud-text.desc_frost_killed", new { deadCrops = count }), Color.SeaGreen, 5250f, true) { whatType = 2 }; } } if (IsEclipse) { IsEclipse = false; } //moon works after frost does OurMoon.HandleMoonAtSleep(Game1.getFarm(), Helper.Translation); }
internal static HUDMessage HandleOnSaving(WeatherConditions Conditions, MersenneTwister Dice) { if (Conditions.HasWeather(CurrentWeather.Frost) && ClimatesOfFerngill.WeatherOpt.AllowCropDeath) { Farm f = Game1.getFarm(); int count = 0, maxCrops = (int)Math.Floor(SDVUtilities.CropCountInFarm(f) * ClimatesOfFerngill.WeatherOpt.DeadCropPercentage); foreach (KeyValuePair <Vector2, TerrainFeature> tf in f.terrainFeatures.Pairs) { if (count >= maxCrops) { break; } if (tf.Value is HoeDirt curr && curr.crop != null) { Crop test = new Crop(curr.crop.indexOfHarvest.Value, 0, 0); if (Dice.NextDouble() > ClimatesOfFerngill.WeatherOpt.CropResistance && (!test.seasonsToGrowIn.Contains("winter") || !SDVUtilities.IsWinterForageable(test.indexOfHarvest.Value))) { CropList.Add(tf.Key); count++; } } } if (count > 0) { foreach (Vector2 v in CropList) { HoeDirt hd = (HoeDirt)f.terrainFeatures[v]; hd.crop.dead.Value = true; } return(new HUDMessage( ClimatesOfFerngill.Translator.Get("hud-text.desc_frost_killed", new { deadCrops = count }), Color.SeaGreen, 5250f, true) { whatType = 2 }); } } return(null); }
/// <summary>Raised before the game begins writes data to the save file (except the initial save creation).</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void OnSaving(object sender, SavingEventArgs e) { if (!Context.IsMainPlayer) { return; } if (Conditions.HasWeather(CurrentWeather.Frost) && WeatherOpt.AllowCropDeath) { Farm f = Game1.getFarm(); int count = 0, maxCrops = (int)Math.Floor(SDVUtilities.CropCountInFarm(f) * WeatherOpt.DeadCropPercentage); foreach (KeyValuePair <Vector2, TerrainFeature> tf in f.terrainFeatures.Pairs) { if (count >= maxCrops) { break; } if (tf.Value is HoeDirt curr && curr.crop != null) { if (Dice.NextDouble() > WeatherOpt.CropResistance) { CropList.Add(tf.Key); count++; } } } if (count > 0) { foreach (Vector2 v in CropList) { HoeDirt hd = (HoeDirt)f.terrainFeatures[v]; hd.crop.dead.Value = true; } queuedMsg = new HUDMessage( Helper.Translation.Get("hud-text.desc_frost_killed", new { deadCrops = count }), Color.SeaGreen, 5250f, true) { whatType = 2 }; } } }
internal static void ProcessHazardousCropWeather(WeatherConditions curr, int timeOfDay, MersenneTwister Dice) { //frost works at night, heatwave works during the day if (timeOfDay == 1700) { if (curr.HasWeather(CurrentWeather.Heatwave) || curr.HasWeather(CurrentWeather.Sandstorm)) { ClimatesOfFerngill.Logger.Log("Beginning Heatwave code"); ExpireTime = 2000; Farm f = Game1.getFarm(); int count = 0, maxCrops = (int)Math.Floor(SDVUtilities.CropCountInFarm(f) * ClimatesOfFerngill.WeatherOpt.DeadCropPercentage); foreach (KeyValuePair <Vector2, TerrainFeature> tf in f.terrainFeatures.Pairs) { if (count >= maxCrops) { break; } if (tf.Value is HoeDirt dirt && dirt.crop != null) { if (Dice.NextDouble() <= ClimatesOfFerngill.WeatherOpt.CropResistance) { if (ClimatesOfFerngill.WeatherOpt.Verbose) { ClimatesOfFerngill.Logger.Log($"Dewatering crop at {tf.Key}. Crop is {dirt.crop.indexOfHarvest}"); } CropList.Add(tf.Key); dirt.state.Value = HoeDirt.dry; count++; } } } if (CropList.Count > 0) { if (ClimatesOfFerngill.WeatherOpt.AllowCropDeath) { if (curr.HasWeather(CurrentWeather.Heatwave) && !curr.HasWeather(CurrentWeather.Sandstorm)) { SDVUtilities.ShowMessage(ClimatesOfFerngill.Translator.Get("hud-text.desc_heatwave_kill", new { crops = count }), 3); } if (curr.HasWeather(CurrentWeather.Sandstorm)) { SDVUtilities.ShowMessage(ClimatesOfFerngill.Translator.Get("hud-text.desc_sandstorm_kill", new { crops = count }), 3); } } else { if (curr.HasWeather(CurrentWeather.Heatwave) && !curr.HasWeather(CurrentWeather.Sandstorm)) { SDVUtilities.ShowMessage(ClimatesOfFerngill.Translator.Get("hud-text.desc_heatwave_dry", new { crops = count }), 3); } if (curr.HasWeather(CurrentWeather.Sandstorm)) { SDVUtilities.ShowMessage(ClimatesOfFerngill.Translator.Get("hud-text.desc_sandstorm_dry", new { crops = count }), 3); } } } else { SDVUtilities.ShowMessage(ClimatesOfFerngill.Translator.Get("hud-text.desc_heatwave"), 3); } } } if (Game1.timeOfDay == ExpireTime && ClimatesOfFerngill.WeatherOpt.AllowCropDeath) { ClimatesOfFerngill.Logger.Log("Beginning Crop Death code"); //if it's still de watered - kill it. Farm f = Game1.getFarm(); bool cDead = false; foreach (Vector2 v in CropList) { HoeDirt hd = (HoeDirt)f.terrainFeatures[v]; if (hd.state.Value == HoeDirt.dry) { if (ClimatesOfFerngill.WeatherOpt.Verbose) { ClimatesOfFerngill.Logger.Log($"Killing crop at {v}. Crop is {hd.crop.indexOfHarvest}"); } hd.crop.dead.Value = true; cDead = true; } } CropList.Clear(); //clear the list if (cDead) { SDVUtilities.ShowMessage(ClimatesOfFerngill.Translator.Get("hud-text.desc_heatwave_cropdeath"), 3); } } }
/// <summary>Raised after the in-game clock time changes.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void OnTimeChanged(object sender, TimeChangedEventArgs e) { if (!Game1.hasLoadedGame) { return; } if (!Context.IsMainPlayer) { return; } Conditions.TenMinuteUpdate(); if (Conditions.HasWeather(CurrentWeather.Fog)) { if (!Game1.currentLocation.IsOutdoors && Game1.currentLocation is DecoratableLocation && WeatherOpt.DarkenLightInFog) { var loc = (DecoratableLocation)Game1.currentLocation; foreach (Furniture f in loc.furniture) { //Yes, *add* lights removes them. No, don't ask me why. if (f.furniture_type.Value == Furniture.window) { //if (WeatherOpt.Verbose) Monitor.Log($"Attempting to remove the light for {f.name}"); Helper.Reflection.GetMethod(f, "addLights").Invoke(Game1.currentLocation); } } } } if (Game1.currentLocation.IsOutdoors && Conditions.HasWeather(CurrentWeather.Lightning) && !Conditions.HasWeather(CurrentWeather.Rain) && Game1.timeOfDay < 2400) { Utility.performLightningUpdate(); } //queued messages clear if (Game1.timeOfDay == 610 && queuedMsg != null) { Game1.hudMessages.Add(queuedMsg); queuedMsg = null; } //frost works at night, heatwave works during the day if (Game1.timeOfDay == 1700) { if (Conditions.HasWeather(CurrentWeather.Heatwave)) { ExpireTime = 2000; Farm f = Game1.getFarm(); int count = 0, maxCrops = (int)Math.Floor(SDVUtilities.CropCountInFarm(f) * WeatherOpt.DeadCropPercentage); foreach (KeyValuePair <Vector2, TerrainFeature> tf in f.terrainFeatures.Pairs) { if (count >= maxCrops) { break; } if (tf.Value is HoeDirt curr && curr.crop != null) { if (Dice.NextDouble() <= WeatherOpt.CropResistance) { CropList.Add(tf.Key); curr.state.Value = HoeDirt.dry; count++; } } } if (CropList.Count > 0) { if (WeatherOpt.AllowCropDeath) { SDVUtilities.ShowMessage(Helper.Translation.Get("hud-text.desc_heatwave_kill"), 3); } else { SDVUtilities.ShowMessage(Helper.Translation.Get("hud-text.desc_heatwave_dry"), 3); } } } } if (Game1.timeOfDay == ExpireTime && WeatherOpt.AllowCropDeath) { //if it's still de watered - kill it. Farm f = Game1.getFarm(); bool cDead = false; foreach (Vector2 v in CropList) { HoeDirt hd = (HoeDirt)f.terrainFeatures[v]; if (hd.state.Value == HoeDirt.dry) { hd.crop.dead.Value = true; cDead = true; } } if (cDead) { SDVUtilities.ShowMessage(Helper.Translation.Get("hud-text.desc_heatwave_cropdeath"), 3); } } }
/// <summary> /// Handles the ten minute update tick /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Parameters</param> private void TenMinuteUpdate(object sender, EventArgsIntChanged e) { if (!Game1.hasLoadedGame) { return; } Conditions.TenMinuteUpdate(); if (IsEclipse) { Game1.globalOutdoorLighting = .5f; Game1.ambientLight = nightColor; Game1.currentLocation.switchOutNightTiles(); ResetTicker = 1; if (!Game1.currentLocation.isOutdoors && Game1.currentLocation is DecoratableLocation) { var loc = Game1.currentLocation as DecoratableLocation; foreach (Furniture f in loc.furniture) { if (f.furniture_type == Furniture.window) { Helper.Reflection.GetMethod(f, "addLights").Invoke(new object[] { Game1.currentLocation }); } } } if ((Game1.farmEvent == null && Game1.random.NextDouble() < (0.25 - Game1.dailyLuck / 2.0)) && ((WeatherOpt.SpawnMonsters && Game1.spawnMonstersAtNight) || (WeatherOpt.SpawnMonstersAllFarms))) { Monitor.Log("Spawning a monster, or attempting to.", LogLevel.Debug); if (Game1.random.NextDouble() < 0.25) { if (this.Equals(Game1.currentLocation)) { Game1.getFarm().spawnFlyingMonstersOffScreen(); return; } } else { Game1.getFarm().spawnGroundMonsterOffScreen(); } } } if (Conditions.HasWeather(CurrentWeather.Fog)) { if (!Game1.currentLocation.isOutdoors && Game1.currentLocation is DecoratableLocation) { var loc = Game1.currentLocation as DecoratableLocation; foreach (Furniture f in loc.furniture) { //Yes, *add* lights removes them. No, don't ask me why. if (f.furniture_type == Furniture.window) { //if (WeatherOpt.Verbose) Monitor.Log($"Attempting to remove the light for {f.name}"); Helper.Reflection.GetMethod(f, "addLights").Invoke(new object[] { Game1.currentLocation }); } } } } if (Game1.currentLocation.isOutdoors && Conditions.HasWeather(CurrentWeather.Lightning) && Game1.timeOfDay < 2400) { Utility.performLightningUpdate(); } //queued messages clear if (Game1.timeOfDay == 610 && queuedMsg != null) { Game1.hudMessages.Add(queuedMsg); queuedMsg = null; } //frost works at night, heatwave works during the day if (Game1.timeOfDay == 1700) { if (Conditions.HasWeather(CurrentWeather.Heatwave)) { ExpireTime = 2000; Farm f = Game1.getFarm(); int count = 0, maxCrops = (int)Math.Floor(SDVUtilities.CropCountInFarm(f) * WeatherOpt.DeadCropPercentage); foreach (KeyValuePair <Vector2, TerrainFeature> tf in f.terrainFeatures) { if (count >= maxCrops) { break; } if (tf.Value is HoeDirt curr && curr.crop != null) { if (Dice.NextDouble() <= WeatherOpt.CropResistance) { CropList.Add(tf.Key); curr.state = HoeDirt.dry; count++; } } } if (CropList.Count > 0) { if (WeatherOpt.AllowCropDeath) { SDVUtilities.ShowMessage(Helper.Translation.Get("hud-text.desc_heatwave_kill")); } else { SDVUtilities.ShowMessage(Helper.Translation.Get("hud-text.desc_heatwave_dry")); } } } } if (Game1.timeOfDay == ExpireTime && WeatherOpt.AllowCropDeath) { //if it's still de watered - kill it. Farm f = Game1.getFarm(); bool cDead = false; foreach (Vector2 v in CropList) { HoeDirt hd = (HoeDirt)f.terrainFeatures[v]; if (hd.state == HoeDirt.dry) { hd.crop.dead = true; cDead = true; } } if (cDead) { SDVUtilities.ShowMessage(Helper.Translation.Get("hud-text.desc_heatwave_cropdeath")); } } float oldStamina = Game1.player.stamina; Game1.player.stamina += StaminaMngr.TenMinuteTick(Conditions, TicksOutside, TicksTotal, Dice); if (Game1.player.stamina <= 0) { SDVUtilities.FaintPlayer(); } TicksTotal = 0; TicksOutside = 0; }