Stardew_Valley_Mods/[Storm]MoreRain/Class1.cs

105 lines
4.2 KiB
C#
Raw Normal View History

2016-03-09 16:28:58 +08:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Storm.ExternalEvent;
using Storm.StardewValley;
using Storm.StardewValley.Event;
using Storm.StardewValley.Wrapper;
using Storm;
using Microsoft.Xna.Framework;
namespace MoreRain
{
[Mod]
public class MoreRain : DiskResource
{
public const int weather_sunny = 0;
public const int weather_rain = 1;
//public const int weather_debris = 2;
public const int weather_lightning = 3;
// public const int weather_festival = 4;
// public const int weather_snow = 5;
// public const int weather_wedding = 6;
public Config ModConfig { get; private set; }
public bool RainUpdate = false;
[Subscribe]
2016-03-09 16:32:01 +08:00
//Credit goes to Zoryn for pieces of this config generation that I kinda repurposed.
2016-03-09 16:28:58 +08:00
public void InitializeCallback(InitializeEvent @event)
{
var configLocation = Path.Combine(PathOnDisk, "Config.json");
if (!File.Exists(configLocation))
{
2016-03-10 09:03:54 +08:00
2016-03-09 16:28:58 +08:00
Console.WriteLine("The config file for MoreRain was not found, guess I'll create it...");
ModConfig = new Config();
ModConfig.RainChance = 30;
ModConfig.ThunderChance = 10;
File.WriteAllBytes(configLocation, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(ModConfig)));
Console.WriteLine("The config file for MoreRain has been loaded.\n\t RainChance: {0}, ThunderChance: {1}",
ModConfig.RainChance, ModConfig.ThunderChance);
}
else
{
ModConfig = JsonConvert.DeserializeObject<Config>(Encoding.UTF8.GetString(File.ReadAllBytes(configLocation)));
Console.WriteLine("The config file for MoreRain has been loaded.\n\tRainChance: {0}, ThunderChance: {1}",
ModConfig.RainChance, ModConfig.ThunderChance);
}
Console.WriteLine("MoreRain Initialization Completed");
}
[Subscribe]
2016-03-12 09:58:26 +08:00
public void UpdateCallback(Storm.StardewValley.Event.PreNewDayEvent @event)
2016-03-09 16:28:58 +08:00
{
2016-03-10 09:03:54 +08:00
// Logging.LogToFile("THIS IS A SUPER LARGE TEST");
// Console.WriteLine(ModConfig.RainChance);
// Console.WriteLine(ModConfig.ThunderChance);
Random random = new Random();
2016-03-09 16:28:58 +08:00
int randomNumber = random.Next(0, 100); //sets ran variable to some num between 0 and 100
Random thunder_random = new Random();
int thunder_randomNumber = random.Next(0, 100);
if (randomNumber <= ModConfig.RainChance) //if the random variable is less than or equal to the chance for rain.
{
2016-03-09 16:32:01 +08:00
2016-03-09 16:28:58 +08:00
@event.Root.WeatherForTomorrow=weather_rain;
Console.WriteLine("It will rain tomorrow.");
}
else
{
@event.Root.WeatherForTomorrow = weather_sunny;
Console.WriteLine("It will not rain tomorrow.");
}
if (@event.Root.WeatherForTomorrow==weather_rain)
{
if (randomNumber <= ModConfig.ThunderChance) //if the random variable is less than or equal to the chance for rain.
{
@event.Root.WeatherForTomorrow=weather_lightning; //sets rainy weather tomorrow
Console.WriteLine("It will be stormy tomorrow.");
}
else
{
Console.WriteLine("There will be no lightning tomorrow.");
}
}
Console.WriteLine("RainMod has updated.");
}
}
public class Config
{
public int RainChance { get; set; }
public int ThunderChance { get; set; }
}
}