Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
Weather.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using Newtonsoft.Json;
4
5public class Weather : EClass
6{
7 [JsonObject(MemberSerialization.OptOut)]
8 public class Forecast
9 {
10 public int duration;
11
13 }
14
15 public enum Condition
16 {
17 Fine,
18 Cloudy,
19 Rain,
21 Snow,
23 Ether,
24 Blossom,
25 None
26 }
27
28 public class WeatherForecast
29 {
30 public Date date;
31
32 public Dictionary<Condition, int> cons = new Dictionary<Condition, int>();
33
34 public void Add(Condition con, int h)
35 {
36 if (cons.ContainsKey(con))
37 {
38 cons[con] += h;
39 }
40 else
41 {
42 cons[con] = h;
43 }
44 }
45
46 public void Finish()
47 {
48 if (cons.Count == 0)
49 {
50 return;
51 }
52 int num = cons.Sum((KeyValuePair<Condition, int> c) => c.Value);
53 if (num == 0)
54 {
55 return;
56 }
57 foreach (Condition item in cons.Keys.ToList())
58 {
59 cons[item] = cons[item] * 100 / num;
60 }
61 }
62 }
63
64 private const int maxForecasts = 10;
65
66 [JsonProperty]
68
69 [JsonProperty]
70 public int duration = 8;
71
72 [JsonProperty]
73 public int lastRain;
74
75 [JsonProperty]
76 public List<Forecast> forecasts = new List<Forecast>();
77
79 {
80 get
81 {
83 {
84 return _currentCondition;
85 }
87 }
88 }
89
91
92 public bool IsHazard
93 {
94 get
95 {
96 if (CurrentCondition != Condition.Rain && CurrentCondition != Condition.RainHeavy && CurrentCondition != Condition.Snow && CurrentCondition != Condition.SnowHeavy)
97 {
98 return CurrentCondition == Condition.Ether;
99 }
100 return true;
101 }
102 }
103
104 public bool IsFineOrCloudy
105 {
106 get
107 {
108 if (CurrentCondition != 0)
109 {
110 return CurrentCondition == Condition.Cloudy;
111 }
112 return true;
113 }
114 }
115
116 public bool IsRaining
117 {
118 get
119 {
120 if (CurrentCondition != Condition.Rain)
121 {
122 return CurrentCondition == Condition.RainHeavy;
123 }
124 return true;
125 }
126 }
127
128 public bool IsSnowing
129 {
130 get
131 {
132 if (CurrentCondition != Condition.Snow)
133 {
134 return CurrentCondition == Condition.SnowHeavy;
135 }
136 return true;
137 }
138 }
139
140 public bool IsBlossom
141 {
142 get
143 {
144 if (CurrentCondition != Condition.Blossom)
145 {
146 if (IsFineOrCloudy)
147 {
148 return EClass._map.config.blossom;
149 }
150 return false;
151 }
152 return true;
153 }
154 }
155
156 public bool IsEther => CurrentCondition == Condition.Ether;
157
158 public string GetName()
159 {
161 }
162
163 public string GetName(Condition condition)
164 {
165 return ("weather" + condition).lang();
166 }
167
168 public void RefreshWeather()
169 {
170 if (EClass._map.IsIndoor)
171 {
172 return;
173 }
174 bool flag = EClass._zone.IsSnowCovered;
175 if (EClass._zone is Region)
176 {
178 flag = elomap.GetTileInfo(EClass.pc.pos.x + elomap.minX, EClass.pc.pos.z + elomap.minY)?.IsSnow ?? false;
180 {
181 flag = true;
182 }
183 }
184 if (IsSnowing)
185 {
186 if (!flag)
187 {
188 _currentCondition = ((_currentCondition == Condition.Snow) ? Condition.Rain : Condition.RainHeavy);
189 }
190 }
191 else if (IsRaining && flag)
192 {
193 _currentCondition = ((_currentCondition == Condition.Rain) ? Condition.Snow : Condition.SnowHeavy);
194 }
195 }
196
197 public void OnChangeHour()
198 {
199 duration--;
200 if (duration < 0)
201 {
203 }
204 }
205
206 public Forecast GetForecast(Date date, Condition current)
207 {
208 Forecast forecast = new Forecast();
209 forecast.condition = ((EClass.rnd(4) == 0) ? season.GetRandomWeather(date, current) : Condition.Fine);
210 forecast.duration = EClass.rnd(24) + 10;
211 date.AddHour(forecast.duration);
212 return forecast;
213 }
214
215 public List<WeatherForecast> GetWeatherForecast()
216 {
218 List<WeatherForecast> list = new List<WeatherForecast>();
219 Date date = EClass.world.date.Copy();
220 WeatherForecast weatherForecast = new WeatherForecast
221 {
222 date = date.Copy()
223 };
224 list.Add(weatherForecast);
225 Forecast forecast = new Forecast
226 {
227 condition = _currentCondition,
229 };
230 int num = forecast.duration;
231 int num2 = -1;
232 for (int i = 0; i < 10000; i++)
233 {
234 num--;
235 weatherForecast.Add(forecast.condition, 1);
236 if (num < 0)
237 {
238 num2++;
239 if (forecasts.Count <= num2)
240 {
241 list.Remove(weatherForecast);
242 break;
243 }
244 forecast = forecasts[num2];
245 num = forecast.duration;
246 }
247 date.AddHour(1);
248 if (date.day != weatherForecast.date.day)
249 {
250 weatherForecast.Finish();
251 weatherForecast = new WeatherForecast
252 {
253 date = date.Copy()
254 };
255 list.Add(weatherForecast);
256 }
257 }
258 return list;
259 }
260
261 public void RefreshForecasts()
262 {
263 if (forecasts.Count >= 10)
264 {
265 return;
266 }
267 Date date = EClass.world.date.Copy();
268 Condition current = Condition.Fine;
269 for (int i = 0; i < 10; i++)
270 {
271 if (forecasts.Count > i)
272 {
273 Forecast forecast = forecasts[i];
274 date.AddHour(forecast.duration);
275 current = forecast.condition;
276 }
277 else
278 {
279 Forecast forecast2 = GetForecast(date, current);
280 forecasts.Add(forecast2);
281 current = forecast2.condition;
282 }
283 }
284 }
285
287 {
288 if (CurrentCondition == Condition.Rain || CurrentCondition == Condition.RainHeavy)
289 {
290 return 0L;
291 }
293 }
294
295 public void SetRandomCondition()
296 {
297 SetCondition(Util.RandomEnum<Condition>());
298 }
299
300 public void SetConditionFromForecast(bool silent = false)
301 {
303 Forecast forecast = forecasts[0];
304 SetCondition(forecast.condition, forecast.duration, silent);
305 forecasts.RemoveAt(0);
306 }
307
308 public void SetCondition(Condition condition, int _duration = 20, bool silent = false)
309 {
310 if (condition == Condition.Fine)
311 {
312 foreach (Chara member in EClass.pc.party.members)
313 {
314 if (member.HasElement(1558) && EClass.rnd(4) == 0)
315 {
316 condition = Condition.Rain;
317 Msg.Say("drawRain", member);
318 break;
319 }
320 }
321 }
323 {
324 switch (condition)
325 {
326 case Condition.Rain:
327 condition = Condition.Snow;
328 break;
329 case Condition.RainHeavy:
330 condition = Condition.SnowHeavy;
331 break;
332 }
333 }
335 {
336 switch (condition)
337 {
338 case Condition.Snow:
339 condition = Condition.Rain;
340 break;
341 case Condition.SnowHeavy:
342 condition = Condition.RainHeavy;
343 break;
344 }
345 }
346 if (_currentCondition == Condition.Rain || _currentCondition == Condition.RainHeavy)
347 {
349 }
350 duration = _duration;
351 if (condition != _currentCondition)
352 {
353 _currentCondition = condition;
355 Msg.Say("weather_" + condition);
356 if (IsRaining)
357 {
359 }
361 }
362 }
363}
bool HasElement(int ele, int req=1)
Definition: Card.cs:5214
Point pos
Definition: Card.cs:55
Definition: Chara.cs:10
Party party
Definition: Chara.cs:43
BaseGameScreen screen
Definition: Core.cs:67
Definition: Date.cs:4
void AddHour(int a)
Definition: Date.cs:215
Date Copy()
Definition: Date.cs:197
int GetRaw(int offsetHours=0)
Definition: Date.cs:322
int day
Definition: Date.cs:62
int GetElapsedMins(int rawDate)
Definition: Date.cs:347
Definition: EClass.cs:5
static Scene scene
Definition: EClass.cs:30
static int rnd(int a)
Definition: EClass.cs:50
static Core core
Definition: EClass.cs:6
static Zone _zone
Definition: EClass.cs:20
static World world
Definition: EClass.cs:40
static Map _map
Definition: EClass.cs:18
static Chara pc
Definition: EClass.cs:14
EloMap elomap
Definition: EloMapActor.cs:7
bool IsSnow
Definition: EloMap.cs:55
Definition: EloMap.cs:8
int minX
Definition: EloMap.cs:112
int minY
Definition: EloMap.cs:114
TileInfo GetTileInfo(int gx, int gy)
Definition: EloMap.cs:287
Weather.Condition fixedCondition
Definition: MapConfig.cs:47
bool blossom
Definition: MapConfig.cs:41
bool IsIndoor
Definition: Map.cs:131
MapConfig config
Definition: Map.cs:37
Definition: Msg.cs:5
static string Say(string idLang, string ref1, string ref2=null, string ref3=null, string ref4=null)
Definition: Msg.cs:58
List< Chara > members
Definition: Party.cs:18
int x
Definition: Point.cs:36
int z
Definition: Point.cs:39
Definition: Region.cs:7
EloMapActor elomapActor
Definition: Scene.cs:97
Definition: Season.cs:5
bool isWinter
Definition: Season.cs:53
Weather.Condition GetRandomWeather(Date date, Weather.Condition current)
Definition: Season.cs:64
virtual bool IsSnowZone
Definition: Spatial.cs:528
virtual bool IsSnowCovered
Definition: Spatial.cs:531
Condition condition
Definition: Weather.cs:12
Dictionary< Condition, int > cons
Definition: Weather.cs:32
void Add(Condition con, int h)
Definition: Weather.cs:34
void SetConditionFromForecast(bool silent=false)
Definition: Weather.cs:300
long GetTimeSinceLastRain()
Definition: Weather.cs:286
bool IsEther
Definition: Weather.cs:156
Season season
Definition: Weather.cs:90
int lastRain
Definition: Weather.cs:73
string GetName()
Definition: Weather.cs:158
void SetCondition(Condition condition, int _duration=20, bool silent=false)
Definition: Weather.cs:308
string GetName(Condition condition)
Definition: Weather.cs:163
bool IsBlossom
Definition: Weather.cs:141
Forecast GetForecast(Date date, Condition current)
Definition: Weather.cs:206
List< WeatherForecast > GetWeatherForecast()
Definition: Weather.cs:215
Condition _currentCondition
Definition: Weather.cs:67
bool IsSnowing
Definition: Weather.cs:129
int duration
Definition: Weather.cs:70
void RefreshForecasts()
Definition: Weather.cs:261
Condition CurrentCondition
Definition: Weather.cs:79
bool IsRaining
Definition: Weather.cs:117
void SetRandomCondition()
Definition: Weather.cs:295
bool IsHazard
Definition: Weather.cs:93
const int maxForecasts
Definition: Weather.cs:64
List< Forecast > forecasts
Definition: Weather.cs:76
void RefreshWeather()
Definition: Weather.cs:168
bool IsFineOrCloudy
Definition: Weather.cs:105
void OnChangeHour()
Definition: Weather.cs:197
GameDate date
Definition: World.cs:6
Season season
Definition: World.cs:9
void RainWater()
Definition: Zone.cs:3115