-
Notifications
You must be signed in to change notification settings - Fork 0
/
WeatherHooks.cs
260 lines (242 loc) · 9.42 KB
/
WeatherHooks.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using RWCustom;
using System.Text.RegularExpressions;
using System.IO;
using System.Runtime.CompilerServices;
public class WeatherHooks
{
public static Dictionary<Room, WeatherController.WeatherSettings> roomSettings = new Dictionary<Room, WeatherController.WeatherSettings>();
public static DebugWeatherUI debugUI;
public static List<RoomRain.DangerType> invalidDangerTypes = new List<RoomRain.DangerType>() //Invalid dangerTypes, don't spawn a WeatherController if the room uses one of these
{
RoomRain.DangerType.AerieBlizzard,
RoomRain.DangerType.Flood,
RoomRain.DangerType.None,
MoreSlugcats.MoreSlugcatsEnums.RoomRainDangerType.Blizzard
};
public static float rainIntensity; //OLD - used for classic snow
public static void Patch()
{
On.Room.Update += Room_Update;
On.Room.Loaded += Room_Loaded;
On.AbstractRoom.RealizeRoom += AbstractRoom_RealizeRoom;
On.StoryGameSession.AddPlayer += StoryGameSession_AddPlayer;
On.Lightning.ctor += Lightning_ctor;
On.ArenaGameSession.SpawnPlayers += ArenaGameSession_SpawnPlayers;
On.Player.ctor += Player_ctor;
On.StoryGameSession.ctor += StoryGameSession_ctor;
On.RainWorld.Update += RainWorld_Update;
On.AbstractRoom.Abstractize += AbstractRoom_Abstractize; //Remove settings
On.WinState.CycleCompleted += WinState_CycleCompleted;
}
private static void WinState_CycleCompleted(On.WinState.orig_CycleCompleted orig, WinState self, RainWorldGame game)
{
orig.Invoke(self, game);
if (WeatherForecast.regionWeatherForecasts != null)
{
//Progress weather
foreach (KeyValuePair<string, List<WeatherForecast.Weather.WeatherType>> pair in WeatherForecast.regionWeatherForecasts)
{
pair.Value[0] = pair.Value[1];
pair.Value[1] = pair.Value[2];
pair.Value[2] = WeatherForecast.NextWeather(pair.Key, pair.Value[1]);
}
WeatherData.Save();
}
}
private static void AbstractRoom_Abstractize(On.AbstractRoom.orig_Abstractize orig, AbstractRoom self)
{
if (roomSettings.ContainsKey(self.realizedRoom))
{
roomSettings.Remove(self.realizedRoom);
}
orig.Invoke(self);
}
private static void RainWorld_Update(On.RainWorld.orig_Update orig, RainWorld self)
{
orig.Invoke(self);
if (ForecastConfig.debugMode.Value)
{
if (self.processManager.currentMainLoop is RainWorldGame)
{
if (debugUI == null)
{
debugUI = new DebugWeatherUI();
}
else
{
debugUI.Update();
}
}
}
}
private static void StoryGameSession_ctor(On.StoryGameSession.orig_ctor orig, StoryGameSession self, SlugcatStats.Name saveStateNumber, RainWorldGame game)
{
orig.Invoke(self, saveStateNumber, game);
//Load save data first if there isn't any, run the next two methods
WeatherData.Load();
if (WeatherForecast.regionWeatherProbability == null || WeatherForecast.regionWeatherProbability.Keys.Count == 0)
{
WeatherForecast.GenerateWeathers();
}
if (WeatherForecast.regionWeatherForecasts == null || WeatherForecast.regionWeatherForecasts.Keys.Count == 0)
{
WeatherForecast.InitialWeather();
}
WeatherForecast.ClearAll();
roomSettings.Clear();
if (ForecastConfig.debugMode.Value && ForecastMod.exposureControllers != null)
{
for (int i = 0; i < ForecastMod.exposureControllers.Count; i++)
{
ForecastMod.exposureControllers[i].RemoveDebugLabels();
}
}
if (ForecastConfig.weatherType.Value == 1 && ForecastConfig.endBlizzard.Value)
{
ForecastMod.exposureControllers = new List<ExposureController>();
}
}
private static void Player_ctor(On.Player.orig_ctor orig, Player self, AbstractCreature abstractCreature, World world)
{
orig.Invoke(self, abstractCreature, world);
if (ForecastConfig.weatherType.Value == 1 && ForecastConfig.endBlizzard.Value && self.room.game.session is StoryGameSession)
{
ForecastMod.exposureControllers.Add(new ExposureController(self));
}
}
private static void AbstractRoom_RealizeRoom(On.AbstractRoom.orig_RealizeRoom orig, AbstractRoom self, World world, RainWorldGame game)
{
orig.Invoke(self, world, game);
//Add Weather Object
if (self.realizedRoom != null && self.realizedRoom.roomRain != null)
{
if (!self.shelter && !self.gate && !invalidDangerTypes.Contains(self.realizedRoom.roomRain.dangerType))
{
if (!roomSettings.ContainsKey(self.realizedRoom))
{
self.realizedRoom.AddObject(new WeatherController(self.realizedRoom));
}
}
}
}
private static void ArenaGameSession_SpawnPlayers(On.ArenaGameSession.orig_SpawnPlayers orig, ArenaGameSession self, Room room, List<int> suggestedDens)
{
orig.Invoke(self, room, suggestedDens);
int ceilingCount = 0;
if (self != null && room.roomRain != null)
{
for (int r = 0; r < room.TileWidth; r++)
{
if (room.Tiles[r, room.TileHeight - 1].Solid)
{
ceilingCount++;
}
}
if (ceilingCount < (room.Width * 0.95))
{
room.AddObject(new WeatherController(room));
}
}
}
private static void Lightning_ctor(On.Lightning.orig_ctor orig, Lightning self, Room room, float intensity, bool bkgOnly)
{
orig.Invoke(self, room, intensity, bkgOnly);
//self.bkgGradient = new Color[2];
//if (!room.game.IsArenaSession && (room.world.region.name == "UW" || room.world.region.name == "TR"))
//{
// self.bkgGradient[0] = new Color(0.19607843f, 0.23529412f, 0.78431374f);
// self.bkgGradient[1] = new Color(0.21176471f, 1f, 0.22352941f);
//}
//else
//{
// self.bkgGradient[0] = room.game.cameras[0].currentPalette.skyColor;
// self.bkgGradient[1] = Color.Lerp(room.game.cameras[0].currentPalette.skyColor, new Color(1f, 1f, 1f), rainIntensity);
//}
}
private static void StoryGameSession_AddPlayer(On.StoryGameSession.orig_AddPlayer orig, StoryGameSession self, AbstractCreature player)
{
orig.Invoke(self, player);
//Rain Direction
int direction = 2;
switch (ForecastConfig.windDirection.Value)
{
case 0:
direction = UnityEngine.Random.Range(1, 4);
ForecastMod.blizzardDirection = direction;
break;
case 1:
direction = 1;
break;
case 2:
direction = 2;
break;
case 3:
direction = 3;
break;
}
int leftOrRight = direction;
if (direction == 2)
{
if (UnityEngine.Random.value >= 0.5f)
{
leftOrRight = 3;
}
else
{
leftOrRight = 1;
}
}
ForecastMod.blizzardDirection = leftOrRight;
}
private static void Room_Loaded(On.Room.orig_Loaded orig, Room self)
{
orig.Invoke(self);
if (ForecastConfig.weatherType.Value == 1 && ForecastConfig.endBlizzard.Value)
{
if (self.game != null && !self.abstractRoom.shelter)
{
self.AddObject(new WeatherSounds(self));
}
}
}
private static void Room_Update(On.Room.orig_Update orig, Room self)
{
orig.Invoke(self);
if (ForecastConfig.weatherType.Value == 1 && ForecastConfig.endBlizzard.Value && self.world.rainCycle.RainDarkPalette > 0f)
{
//Update exposure
if (ForecastMod.exposureControllers != null & ForecastMod.exposureControllers.Count > 0)
{
for (int i = 0; i < ForecastMod.exposureControllers.Count; i++)
{
ForecastMod.exposureControllers[i].Update();
}
}
}
if (ForecastConfig.debugMode.Value && self.BeingViewed)
{
//Fast Forward Cycle Timer
if (Input.GetKey(KeyCode.Alpha4))
{
self.world.rainCycle.timer += 25;
}
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Alpha4))
{
//Toggle AerieBlizzard and normal Blizzard
if (self.roomSettings.DangerType == RoomRain.DangerType.AerieBlizzard)
{
self.roomSettings.DangerType = MoreSlugcats.MoreSlugcatsEnums.RoomRainDangerType.Blizzard;
}
else if (self.roomSettings.DangerType == MoreSlugcats.MoreSlugcatsEnums.RoomRainDangerType.Blizzard)
{
self.roomSettings.DangerType = RoomRain.DangerType.AerieBlizzard;
}
}
}
}
}