2018-12-30 18:00:05 +08:00
|
|
|
using System;
|
2017-07-30 06:16:23 +08:00
|
|
|
using System.Collections.Generic;
|
2017-08-06 03:51:44 +08:00
|
|
|
using Omegasis.MoreRain.Framework;
|
2017-07-28 08:28:39 +08:00
|
|
|
using StardewModdingAPI;
|
2017-07-30 06:16:23 +08:00
|
|
|
using StardewModdingAPI.Events;
|
2016-07-09 14:39:44 +08:00
|
|
|
using StardewValley;
|
|
|
|
|
2017-07-28 08:28:39 +08:00
|
|
|
namespace Omegasis.MoreRain
|
2016-07-09 14:39:44 +08:00
|
|
|
{
|
2017-07-30 06:16:23 +08:00
|
|
|
/// <summary>The mod entry point.</summary>
|
2016-07-09 14:39:44 +08:00
|
|
|
public class MoreRain : Mod
|
2017-03-03 10:52:39 +08:00
|
|
|
{
|
2017-07-30 06:16:23 +08:00
|
|
|
/*********
|
|
|
|
** Properties
|
|
|
|
*********/
|
|
|
|
/// <summary>The weathers that can be safely overridden.</summary>
|
|
|
|
private readonly HashSet<int> NormalWeathers = new HashSet<int> { Game1.weather_sunny, Game1.weather_rain, Game1.weather_lightning, Game1.weather_debris, Game1.weather_snow };
|
|
|
|
|
2017-08-06 03:51:44 +08:00
|
|
|
/// <summary>The mod configuration.</summary>
|
|
|
|
private ModConfig Config;
|
2017-07-30 06:16:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*********
|
|
|
|
** Public methods
|
|
|
|
*********/
|
|
|
|
/// <summary>The mod entry point, called after the mod is first loaded.</summary>
|
|
|
|
/// <param name="helper">Provides simplified APIs for writing mods.</param>
|
2016-12-09 08:34:28 +08:00
|
|
|
public override void Entry(IModHelper helper)
|
2016-07-09 14:39:44 +08:00
|
|
|
{
|
2017-08-06 03:51:44 +08:00
|
|
|
this.Config = helper.ReadConfig<ModConfig>();
|
|
|
|
|
2019-01-06 15:21:06 +08:00
|
|
|
helper.Events.GameLoop.SaveLoaded += this.OnSaveLoaded;
|
|
|
|
helper.Events.GameLoop.Saving += this.OnSaving;
|
2016-07-09 14:39:44 +08:00
|
|
|
}
|
|
|
|
|
2017-07-30 06:16:23 +08:00
|
|
|
|
|
|
|
/*********
|
|
|
|
** Private methods
|
|
|
|
*********/
|
2019-01-06 15:21:06 +08:00
|
|
|
/// <summary>Raised after the player loads a save slot and the world is initialised.</summary>
|
2017-07-30 06:16:23 +08:00
|
|
|
/// <param name="sender">The event sender.</param>
|
2019-01-06 15:21:06 +08:00
|
|
|
/// <param name="e">The event arguments.</param>
|
|
|
|
private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
|
2016-07-09 14:39:44 +08:00
|
|
|
{
|
2017-07-30 06:16:23 +08:00
|
|
|
this.HandleNewDay();
|
2016-07-09 14:39:44 +08:00
|
|
|
}
|
|
|
|
|
2019-01-06 15:21:06 +08:00
|
|
|
/// <summary>Raised before the game begins writes data to the save file (except the initial save creation).</summary>
|
2017-07-30 06:16:23 +08:00
|
|
|
/// <param name="sender">The event sender.</param>
|
2019-01-06 15:21:06 +08:00
|
|
|
/// <param name="e">The event arguments.</param>
|
|
|
|
private void OnSaving(object sender, SavingEventArgs e)
|
2016-07-09 14:39:44 +08:00
|
|
|
{
|
2017-08-06 03:23:10 +08:00
|
|
|
this.HandleNewDay();
|
2016-07-09 14:39:44 +08:00
|
|
|
}
|
|
|
|
|
2017-07-30 06:16:23 +08:00
|
|
|
/// <summary>Update all data for a new day.</summary>
|
|
|
|
private void HandleNewDay()
|
2016-07-09 14:39:44 +08:00
|
|
|
{
|
2017-07-30 06:16:23 +08:00
|
|
|
// skip if special weather
|
|
|
|
if (!this.NormalWeathers.Contains(Game1.weatherForTomorrow))
|
2016-07-09 14:39:44 +08:00
|
|
|
{
|
2017-07-30 06:16:23 +08:00
|
|
|
if (Game1.weatherForTomorrow == Game1.weather_festival)
|
|
|
|
this.VerboseLog("There is a festival tomorrow, therefore it will not rain.");
|
|
|
|
else if (Game1.weatherForTomorrow == Game1.weather_wedding)
|
|
|
|
this.VerboseLog("There is a wedding tomorrow and rain on your wedding day will not happen.");
|
|
|
|
else
|
|
|
|
this.VerboseLog("The weather tomorrow is unknown, so it will not rain.");
|
2016-07-09 14:39:44 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-30 06:16:23 +08:00
|
|
|
// set weather
|
2016-07-09 14:39:44 +08:00
|
|
|
Random random = new Random();
|
2017-07-30 06:16:23 +08:00
|
|
|
int chance = random.Next(0, 100);
|
|
|
|
switch (Game1.currentSeason)
|
2017-03-03 10:52:39 +08:00
|
|
|
{
|
2017-07-30 06:16:23 +08:00
|
|
|
case "spring":
|
|
|
|
// set rain
|
2017-08-06 03:51:44 +08:00
|
|
|
if (chance <= this.Config.SpringRainChance)
|
2017-03-03 10:52:39 +08:00
|
|
|
{
|
2017-07-30 06:16:23 +08:00
|
|
|
Game1.weatherForTomorrow = Game1.weather_rain;
|
|
|
|
this.VerboseLog("It will rain tomorrow.");
|
2018-06-09 02:40:23 +08:00
|
|
|
return;
|
2017-03-03 10:52:39 +08:00
|
|
|
}
|
|
|
|
|
2018-06-09 02:40:23 +08:00
|
|
|
if (chance <= this.Config.SpringThunderChance)
|
2017-03-03 10:52:39 +08:00
|
|
|
{
|
2018-06-09 02:40:23 +08:00
|
|
|
Game1.weatherForTomorrow = Game1.weather_lightning;
|
|
|
|
this.VerboseLog("It will be stormy tomorrow.");
|
|
|
|
return;
|
2017-03-03 10:52:39 +08:00
|
|
|
}
|
2017-07-30 06:16:23 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "summer":
|
|
|
|
// set rain
|
2017-08-06 03:51:44 +08:00
|
|
|
if (chance <= this.Config.SummerRainChance)
|
2017-03-03 10:52:39 +08:00
|
|
|
{
|
2017-07-30 06:16:23 +08:00
|
|
|
Game1.weatherForTomorrow = Game1.weather_rain;
|
|
|
|
this.VerboseLog("It will rain tomorrow.");
|
2018-06-09 02:40:23 +08:00
|
|
|
return;
|
2017-03-03 10:52:39 +08:00
|
|
|
}
|
2016-07-09 14:39:44 +08:00
|
|
|
|
2018-06-09 02:40:23 +08:00
|
|
|
|
|
|
|
if (chance <= this.Config.SummerThunderChance)
|
2017-03-03 10:52:39 +08:00
|
|
|
{
|
2018-06-09 02:40:23 +08:00
|
|
|
Game1.weatherForTomorrow = Game1.weather_lightning;
|
|
|
|
this.VerboseLog("It will be stormy tomorrow.");
|
|
|
|
return;
|
2017-03-03 10:52:39 +08:00
|
|
|
}
|
2017-07-30 06:16:23 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "fall":
|
|
|
|
case "autumn":
|
|
|
|
// set rain
|
2017-08-06 03:51:44 +08:00
|
|
|
if (chance <= this.Config.FallRainChance)
|
2016-07-09 14:39:44 +08:00
|
|
|
{
|
2017-07-30 06:16:23 +08:00
|
|
|
Game1.weatherForTomorrow = Game1.weather_rain;
|
|
|
|
this.VerboseLog("It will rain tomorrow.");
|
2018-06-09 02:40:23 +08:00
|
|
|
return;
|
2017-03-03 10:52:39 +08:00
|
|
|
}
|
|
|
|
|
2018-06-09 02:40:23 +08:00
|
|
|
if (chance <= this.Config.FallThunderChance)
|
2017-03-03 10:52:39 +08:00
|
|
|
{
|
2018-06-09 02:40:23 +08:00
|
|
|
Game1.weatherForTomorrow = Game1.weather_lightning;
|
|
|
|
this.VerboseLog("It will be stormy tomorrow.");
|
|
|
|
return;
|
2016-07-09 14:39:44 +08:00
|
|
|
}
|
2017-07-30 06:16:23 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "winter":
|
|
|
|
// set snow
|
2017-08-06 03:51:44 +08:00
|
|
|
if (chance <= this.Config.WinterSnowChance)
|
2017-03-03 10:52:39 +08:00
|
|
|
{
|
2017-07-30 06:16:23 +08:00
|
|
|
Game1.weatherForTomorrow = Game1.weather_snow;
|
|
|
|
this.VerboseLog("It will snow tomorrow.");
|
2017-03-03 10:52:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-30 06:16:23 +08:00
|
|
|
//StardewValley.Game1.weatherForTomorrow = StardewValley.Game1.weather_sunny;
|
|
|
|
this.VerboseLog("It will not snow tomorrow.");
|
2017-03-03 10:52:39 +08:00
|
|
|
}
|
2017-07-30 06:16:23 +08:00
|
|
|
break;
|
2016-07-09 14:39:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Log a message if <see cref="ModConfig.SuppressLog"/> is <c>false</c>.</summary>
|
2017-07-30 06:16:23 +08:00
|
|
|
/// <param name="message">The message to log.</param>
|
|
|
|
private void VerboseLog(string message)
|
|
|
|
{
|
2017-08-06 03:51:44 +08:00
|
|
|
if (!this.Config.SuppressLog)
|
2017-07-30 06:16:23 +08:00
|
|
|
this.Monitor.Log(message);
|
|
|
|
}
|
2016-07-09 14:39:44 +08:00
|
|
|
}
|
|
|
|
}
|