-
Notifications
You must be signed in to change notification settings - Fork 1
/
MoreRealismController.cs
224 lines (185 loc) · 7.74 KB
/
MoreRealismController.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
using System.Collections;
using System.Collections.Generic;
using MoreRealism.Windows;
using UnityEngine;
namespace MoreRealism
{
public class MoreRealismController : SerializedMonoBehaviour
{
public static string Version = "1.4";
public static MoreRealismController Instance;
public List<BaseWindow> windows = new List<BaseWindow>();
public MoreRealismSettings settings = null;
public bool isLoaded = false;
private bool _prefabFlag = false;
public void SetAsPrefab()
{
_prefabFlag = true;
}
public void Load()
{
if (_prefabFlag || GameController.Instance.isInScenarioEditor)
return;
if (isLoaded)
this.Unload();
if (settings == null)
settings = new MoreRealismSettings();
windows.Add(new MainWindow(this));
windows.Add(new MessageBoxWindow(this));
windows.Add(new DebuggingWindow(this));
GameController.Instance.addSerializedObject(this);
isLoaded = true;
string notif = "You are currently playing on a park with these options enabled :\n";
notif += this.settings.dayNightCycleEnabled ? "\n- Day/night cycle" : "";
notif += this.settings.kickOutGuestsAtNight ? "\n- Close the park for half of the night" : "";
notif += this.settings.closeEverythingAtNight ? "\n- Close attractions and shops for half of the night" : "";
GetWindow<MessageBoxWindow>().Show(notif, 350, 150);
}
public void Unload()
{
if (_prefabFlag)
return;
isLoaded = false;
windows.Clear();
}
private void Update()
{
//Debug.Log("[MoreRealism] testing update");
if (_prefabFlag)
return;
if (isLoaded)
{
// Check for settings window input
if (InputManager.getKeyUp("TheMasterCado@MoreRealism/openSettings"))
{
BaseWindow mainWindow = GetWindow<MainWindow>();
mainWindow.ToggleWindowState();
}
if (Input.GetKeyUp(KeyCode.Escape))
foreach (var window in windows)
if (window.isOpen)
window.CloseWindow();
if (settings.dayNightCycleEnabled)
CheckDayNightCycle();
}
}
private void CheckDayNightCycle()
{
if (ParkInfo.ParkTime >= settings.nextDayNightSwitchTime)
{
GameController.Instance.park.weatherController.IsNight = !GameController.Instance.park.weatherController.IsNight;
settings.nextDayNightSwitchTime = (int)(ParkInfo.ParkTime + settings.cycleLenghtMonths * 300);
}
if (settings.kickOutGuestsAtNight && ParkInfo.ParkTime >= settings.nextParkStateSwitchTime)
{
if (GameController.Instance.park.weatherController.IsNight)
{
GameController.Instance.park.setState(Park.State.CLOSED_SEND_GUESTS_HOME);
settings.nextParkStateSwitchTime = settings.nextDayNightSwitchTime;
}
else
{
GameController.Instance.park.setState(Park.State.OPENED);
settings.nextParkStateSwitchTime = (int)(settings.nextDayNightSwitchTime + settings.cycleLenghtMonths * 150);
}
}
if (settings.closeEverythingAtNight && ParkInfo.ParkTime >= settings.nextEverythingStateSwitchTime)
{
int compareDiff;
if (settings.cycleLenghtMonths < 1)
compareDiff = (int)(settings.cycleLenghtMonths * 60 + 2);
else
compareDiff = 65;
if (settings.nextParkStateSwitchTime - settings.nextEverythingStateSwitchTime > compareDiff)
{
foreach (Attraction attr in GameController.Instance.park.getAttractions())
{
if (attr.isOpened())
attr.setState(Attraction.State.CLOSED);
}
foreach (Shop sh in GameController.Instance.park.getShops())
{
sh.close();
}
if (settings.cycleLenghtMonths < 1)
settings.nextEverythingStateSwitchTime = (int)(settings.nextParkStateSwitchTime - (settings.cycleLenghtMonths * 60));
else
settings.nextEverythingStateSwitchTime = settings.nextParkStateSwitchTime - 60;
}
else
{
foreach (Attraction attr in GameController.Instance.park.getAttractions())
{
if (attr.canOpen(out string b))
attr.setState(Attraction.State.OPENED);
}
foreach (Shop sh in GameController.Instance.park.getShops())
{
sh.open();
}
if (settings.cycleLenghtMonths < 1)
settings.nextEverythingStateSwitchTime = (int)(settings.nextParkStateSwitchTime + (settings.cycleLenghtMonths * 60) + settings.cycleLenghtMonths * 450);
else
settings.nextEverythingStateSwitchTime = (int)(settings.nextParkStateSwitchTime + 60 + settings.cycleLenghtMonths * 450);
}
}
}
public void SaveSettings()
{
if (_prefabFlag)
return;
GameController.Instance.park.weatherController.IsNight = false;
settings.nextDayNightSwitchTime = (int)(ParkInfo.ParkTime + settings.cycleLenghtMonths * 300);
if (settings.kickOutGuestsAtNight)
{
settings.nextParkStateSwitchTime = (int)(settings.nextDayNightSwitchTime + settings.cycleLenghtMonths * 150);
if (settings.closeEverythingAtNight)
{
settings.nextEverythingStateSwitchTime = settings.nextParkStateSwitchTime + 60;
}
}
}
public T GetWindow<T>() where T : BaseWindow
{
if (_prefabFlag)
return null;
foreach (var window in windows)
if (window is T)
return (T) window;
return null;
}
private void OnGUI()
{
foreach (var window in windows)
if (window.isOpen)
window.DrawWindow();
}
public override void deserialize(SerializationContext context, Dictionary<string, object> values)
{
if (_prefabFlag)
return;
settings = new MoreRealismSettings();
settings.deserialize(context, values);
base.deserialize(context, values);
Instance.Kill();
Instance = this;
EventManager.Instance.OnStartPlayingPark += Instance.Load;
}
public override void serialize(SerializationContext context, Dictionary<string, object> values)
{
if (_prefabFlag)
return;
settings.serialize(context, values);
base.serialize(context, values);
}
public void closeAllWindows()
{
foreach (BaseWindow w in windows)
w.CloseWindow();
}
public override string getReferenceName()
{
return "MoreRealismController";
}
}
}