internal static int GetNewRainAmount(int prevRain, ITranslationHelper Translation, bool showRain = true) { int currRain = prevRain; double ChanceOfRainChange = ClimatesOfFerngill.WeatherOpt.VRChangeChance; bool massiveChange = false; //do some rain chance pre pumping if (currRain == 0) { ChanceOfRainChange += .20; } if (currRain > WeatherUtilities.GetRainCategoryMidPoint(RainLevels.Torrential)) { ChanceOfRainChange += .10; } if (WeatherUtilities.GetRainCategory(currRain) == RainLevels.NoahsFlood) { ChanceOfRainChange += .15; } double FlipChance = .5; //so, lower: decrease, higher: increase if (WeatherUtilities.IsSevereRainFall(currRain)) { FlipChance += .2; } if (WeatherUtilities.GetRainCategory(currRain) == RainLevels.Torrential || WeatherUtilities.GetRainCategory(currRain) == RainLevels.Typhoon || WeatherUtilities.GetRainCategory(currRain) == RainLevels.NoahsFlood) { FlipChance += .15; //15% chance remaining of increasing. } if (WeatherUtilities.GetRainCategory(currRain) == RainLevels.Typhoon || WeatherUtilities.GetRainCategory(currRain) == RainLevels.NoahsFlood) { FlipChance += .1456; //.44% chance remaning of increasing. } if (WeatherUtilities.GetRainCategory(currRain) == RainLevels.NoahsFlood) { FlipChance += .0018; //.26% chance remaning of increasing. } if (currRain == ClimatesOfFerngill.WeatherOpt.MaxRainFall) { FlipChance = 1; //you must go ddown. } if (currRain <= WeatherUtilities.GetRainCategoryMidPoint(RainLevels.Light)) { FlipChance -= .2; //70% chance of increasing } if (currRain <= WeatherUtilities.GetRainCategoryMidPoint(RainLevels.Sunshower)) { FlipChance -= .1; //80% chance of increasing } if (currRain == 0) { FlipChance -= .15; //95% chance of increasing } if (ClimatesOfFerngill.WeatherOpt.Verbose) { ClimatesOfFerngill.Logger.Log($"Rain is {prevRain}, current chance for rain change is {ChanceOfRainChange}."); ClimatesOfFerngill.Logger.Log($"Calculated chance for rain decreasing: {WeatherUtilities.GetStepChance(currRain, increase: false).ToString("N3")}, rain increasing: {WeatherUtilities.GetStepChance(currRain, increase: true).ToString("N3")}. Flip chance is {FlipChance.ToString("N3")} "); } // I just spent nine minutes typing out an invalid explanation for this. :| // So, i'm renaming the variables. // And redoing this entirely. It's a lot of duplicated effort. //Greater than flip chance is increase, lesser is decrease if (ClimatesOfFerngill.Dice.NextDouble() < ChanceOfRainChange) { // Handle rain changes. // first check for a massive change 145% to 245% double stepRoll = ClimatesOfFerngill.Dice.NextDouble(); if (ClimatesOfFerngill.Dice.NextDouble() > FlipChance) { if (ClimatesOfFerngill.WeatherOpt.Verbose) { ClimatesOfFerngill.Logger.Log("Increasing rain!"); } if (stepRoll <= WeatherUtilities.GetStepChance(currRain, increase: true)) { //get the multiplier. This should be between 145% and 245% int mult = Math.Max(1, (int)(Math.Floor(ClimatesOfFerngill.Dice.NextDouble() + .68))); if (currRain == 0) { currRain = 15 * mult; } else { currRain = (int)(Math.Floor(currRain * mult * 1.0)); } massiveChange = true; } } else { if (stepRoll <= WeatherUtilities.GetStepChance(currRain, increase: false)) { ClimatesOfFerngill.Logger.Log("Increasing rain!"); currRain = (int)(Math.Floor(currRain / (ClimatesOfFerngill.Dice.NextDouble() + 1.45))); massiveChange = true; } } if (!massiveChange) { double mult = (1 + (ClimatesOfFerngill.Dice.NextDouble() * 1.3) - .55); if (currRain == 0) { currRain = 4; } if (currRain < WeatherUtilities.GetRainCategoryMidPoint(RainLevels.Light)) { mult += 4.5; } currRain = (int)(Math.Floor(currRain * mult)); } } if (!ClimatesOfFerngill.WeatherOpt.HazardousWeather) { if (ClimatesOfFerngill.WeatherOpt.Verbose) { ClimatesOfFerngill.Logger.Log("Triggering Hazardous Weather Failsafe"); } currRain = WeatherUtilities.GetRainCategoryMidPoint(RainLevels.Severe); } if (WeatherConditions.PreventGoingOutside(currRain)) { if (Game1.timeOfDay >= 2300) { //drop the rain to at least allow the person to return home if they aren't. currRain = WeatherUtilities.GetRainCategoryMidPoint(RainLevels.Severe); } } if (currRain > ClimatesOfFerngill.WeatherOpt.MaxRainFall) { currRain = ClimatesOfFerngill.WeatherOpt.MaxRainFall; } if (currRain < 0) { currRain = 0; } if (currRain != prevRain && Game1.timeOfDay != 600 && showRain && !(Game1.currentLocation is Desert)) { if (WeatherUtilities.GetRainCategory(currRain) == RainLevels.None) { Game1.addHUDMessage(new HUDMessage(Translation.Get("hud-text.NearlyNoRain"))); return(currRain); } else if (currRain > prevRain) { if (WeatherUtilities.GetRainCategory(currRain) != WeatherUtilities.GetRainCategory(prevRain)) { Game1.addHUDMessage(new HUDMessage(Translation.Get("hud-text.CateIncrease", new { currRain, category = WeatherUtilities.DescRainCategory(currRain) }))); return(currRain); } else if (Math.Abs(currRain / prevRain) >= ClimatesOfFerngill.WeatherOpt.VRainNotifThreshold || ClimatesOfFerngill.WeatherOpt.Verbose) { Game1.addHUDMessage(new HUDMessage(Translation.Get("hud-text.Increase", new { currRain }))); return(currRain); } } else { if (WeatherUtilities.GetRainCategory(currRain) != WeatherUtilities.GetRainCategory(prevRain)) { Game1.addHUDMessage(new HUDMessage(Translation.Get("hud-text.CateDecrease", new { currRain, category = WeatherUtilities.DescRainCategory(currRain) }))); return(currRain); } else if (Math.Abs(currRain / prevRain) >= ClimatesOfFerngill.WeatherOpt.VRainNotifThreshold || ClimatesOfFerngill.WeatherOpt.Verbose) { Game1.addHUDMessage(new HUDMessage(Translation.Get("hud-text.Decrease", new { currRain }))); return(currRain); } } } return(currRain); }