-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathModEntry.cs
101 lines (85 loc) · 3.46 KB
/
ModEntry.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System;
using BetterRNG.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using Zoryn.Common;
namespace BetterRNG;
/// <summary>The main entry point.</summary>
public class ModEntry : Mod
{
/*********
** Properties
*********/
/// <summary>The mod configuration.</summary>
private ModConfig Config;
private WeightedGeneric<string>[] Weather;
/*********
** Accessors
*********/
internal static MersenneTwister Twister { get; private set; }
/*********
** 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>
public override void Entry(IModHelper helper)
{
CommonHelper.RemoveObsoleteFiles(this, "BetterRNG.pdb");
// read config
this.Config = helper.ReadConfig<ModConfig>();
// init randomness
Game1.random = ModEntry.Twister = new MersenneTwister();
this.Weather = new[]
{
WeightedGeneric<string>.Create(this.Config.SunnyChance, Game1.weather_sunny),
WeightedGeneric<string>.Create(this.Config.CloudySnowyChance, Game1.weather_debris),
WeightedGeneric<string>.Create(this.Config.RainyChance, Game1.weather_rain),
WeightedGeneric<string>.Create(this.Config.StormyChance, Game1.weather_lightning),
WeightedGeneric<string>.Create(this.Config.HarshSnowyChance, Game1.weather_snow)
};
// hook events
helper.Events.GameLoop.DayStarted += this.OnDayStarted;
helper.Events.Input.ButtonsChanged += this.OnButtonsChanged;
}
/*********
** Private methods
*********/
/// <summary>Raised after the player starts a new day.</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnDayStarted(object sender, DayStartedEventArgs e)
{
this.DetermineRng();
}
/// <inheritdoc cref="IInputEvents.ButtonsChanged"/>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event arguments.</param>
private void OnButtonsChanged(object sender, ButtonsChangedEventArgs e)
{
if (this.Config.ReloadKey.JustPressed())
{
this.Config = this.Helper.ReadConfig<ModConfig>();
this.Monitor.Log("Config reloaded", LogLevel.Info);
}
}
/// <summary>Randomise the daily luck and weather.</summary>
private void DetermineRng()
{
if (this.Config.EnableDailyLuckOverride)
Game1.player.team.sharedDailyLuck.Value = Math.Min(0.100000001490116, ModEntry.Twister.Next(-100, 101) / 1000.0);
if (Context.IsMainPlayer && this.Config.EnableWeatherOverride)
{
string targetWeather = this.Weather.Choose().TValue;
if (targetWeather == Game1.weather_snow && Game1.season != Season.Winter)
targetWeather = Game1.weather_lightning;
if (targetWeather == Game1.weather_rain && Game1.season == Season.Winter)
targetWeather = Game1.weather_debris;
if (targetWeather == Game1.weather_lightning && Game1.season == Season.Winter)
targetWeather = Game1.weather_snow;
if (targetWeather == Game1.weather_festival)
targetWeather = Game1.weather_sunny;
Game1.weatherForTomorrow = targetWeather;
}
}
}