Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
GameUpdater.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using Algorithms;
3using UnityEngine;
4
5public class GameUpdater : EClass
6{
7 public class Updater : EClass
8 {
9 public int index;
10
11 public int updatesPerFrame;
12
13 public int maxCount;
14
15 public float duration = 1f;
16
17 public float _updatesPerFrame;
18
19 public Point pos = new Point();
20
21 public virtual void FixedUpdate()
22 {
23 }
24
25 public void SetUpdatesPerFrame(int _maxcount, float _duration)
26 {
27 duration = _duration;
28 maxCount = _maxcount;
29 if (maxCount <= 0)
30 {
32 return;
33 }
34 _updatesPerFrame += EClass.scene.actionMode.gameSpeed * (float)maxCount / (1f / delta) / duration;
37 }
38 }
39
40 public class AreaUpdater : Updater
41 {
42 public override void FixedUpdate()
43 {
44 List<Area> listArea = EClass._map.rooms.listArea;
45 if (listArea.Count == 0)
46 {
47 return;
48 }
49 SetUpdatesPerFrame(listArea.Count, 1f);
50 for (int i = 0; i < updatesPerFrame; i++)
51 {
52 index++;
53 if (index >= listArea.Count)
54 {
55 index = 0;
56 }
57 listArea[index].Update();
58 }
59 }
60 }
61
62 public class SurfaceUpdater : Updater
63 {
64 public int x;
65
66 public int z;
67
68 public int SizeXZ => EClass._map.SizeXZ;
69
70 public int Size => EClass._map.Size;
71
72 public override void FixedUpdate()
73 {
74 if (!pos.Set(x, z).IsValid)
75 {
76 x = (z = 0);
77 }
79 _ = EClass._map.Roaming.raceMap.TryGetValue("fish")?.num;
80 bool isRaining = EClass.world.weather.IsRaining;
81 for (int i = 0; i < updatesPerFrame; i++)
82 {
83 pos.Set(x, z);
84 _ = pos.sourceObj;
85 bool flag = pos.sourceBlock.id != 0;
86 Cell cell = pos.cell;
87 bool flag2 = EClass._map.IsIndoor || cell.HasRoof;
88 if (cell.effect != null)
89 {
90 if (cell.HasFire)
91 {
92 if (isRaining)
93 {
94 pos.ModFire(-5);
95 }
96 else if (EClass.rnd(2) == 0)
97 {
98 pos.ModFire(-2);
99 }
100 }
101 else if (cell.HasLiquid && (!isRaining || cell.IsTopWater || cell.HasRoof))
102 {
103 EClass._map.ModLiquid(pos.x, pos.z, -1);
104 }
105 }
106 if (isRaining)
107 {
108 if (!flag2)
109 {
110 if (cell.IsFarmField)
111 {
112 cell.isWatered = true;
113 }
114 if (EClass.rnd(500) == 0 && !flag && !cell.blocked && !cell.HasObj && !cell.IsTopWaterAndNoSnow && !EClass._zone.IsRegion)
115 {
116 EClass._map.SetLiquid(pos.x, pos.z, 1, EClass.rnd(3) + 1);
117 }
118 }
119 if (EClass.rnd(50) == 0 && cell.decal != 0)
120 {
121 cell.decal = 0;
122 }
123 }
124 if (EClass.rnd(30) == 0 && cell.decal != 0 && !pos.IsInBounds)
125 {
126 cell.decal = 0;
127 }
128 x++;
129 if (x >= Size)
130 {
131 x = 0;
132 z++;
133 if (z >= Size)
134 {
135 z = 0;
136 }
137 }
138 }
139 }
140 }
141
143 {
144 public override void FixedUpdate()
145 {
146 if (!pos.Set(x, z).IsValid)
147 {
148 x = (z = 0);
149 }
150 SetUpdatesPerFrame(base.SizeXZ, 1f);
151 for (int i = 0; i < updatesPerFrame; i++)
152 {
153 pos.Set(x, z);
154 Cell cell = pos.cell;
155 if (cell.effect != null && cell.effect.WillFade)
156 {
157 cell.effect.amount--;
158 if (cell.effect.amount <= 0)
159 {
161 }
162 }
163 x++;
164 if (x >= base.Size)
165 {
166 x = 0;
167 z++;
168 if (z >= base.Size)
169 {
170 z = 0;
171 }
172 }
173 }
174 }
175 }
176
177 public class LogicUpdater : Updater
178 {
179 public virtual LogicalPointManager manager => null;
180
181 public virtual float UpdateDuration => 1f;
182
183 public virtual bool RefreshTile => true;
184
185 public override void FixedUpdate()
186 {
187 List<LogicalPoint> list = manager.list;
188 if (list.Count == 0)
189 {
190 return;
191 }
193 bool flag = false;
194 for (int i = 0; i < updatesPerFrame; i++)
195 {
196 index++;
197 if (index >= list.Count)
198 {
199 index = 0;
200 flag = true;
201 }
202 list[index].Update();
203 }
204 if (RefreshTile)
205 {
206 foreach (Point refresh in manager.refreshList)
207 {
208 EClass._map.RefreshSingleTile(refresh.x, refresh.z);
209 }
210 }
211 manager.refreshList.Clear();
212 }
213 }
214
216 {
218
219 public override float UpdateDuration => 5f;
220 }
221
222 public class SensorUpdater : Updater
223 {
224 public override void FixedUpdate()
225 {
226 List<Chara> charas = EClass._map.charas;
227 SetUpdatesPerFrame(charas.Count, 1f);
228 for (int i = 0; i < updatesPerFrame; i++)
229 {
230 index++;
231 if (index >= charas.Count)
232 {
233 index = 0;
234 }
235 Chara chara = charas[index];
236 if (chara.IsAliveInCurrentZone && !chara.IsPC)
237 {
238 chara.FindNewEnemy();
239 }
240 }
241 }
242 }
243
244 public class CharaUpdater : Updater
245 {
246 public override void FixedUpdate()
247 {
248 if (Game.isPaused)
249 {
250 return;
251 }
252 List<Chara> charas = EClass._map.charas;
253 SetUpdatesPerFrame(charas.Count, 0.05f);
254 float gameDelta = Core.gameDelta;
255 for (int i = 0; i < charas.Count; i++)
256 {
257 Chara chara = charas[i];
258 if (Game.isPaused && !chara.IsPC)
259 {
260 break;
261 }
262 chara.roundTimer += gameDelta;
263 float actTime = chara.actTime;
264 if (chara.roundTimer > actTime)
265 {
266 chara.Tick();
267 chara.roundTimer -= actTime;
268 if (chara.ai is GoalEndTurn)
269 {
270 chara.SetNoGoal();
271 break;
272 }
273 if (i > charas.Count)
274 {
275 break;
276 }
277 }
278 }
279 }
280 }
281
283 {
284 public override void FixedUpdate()
285 {
286 List<Chara> charas = EClass._map.charas;
287 SetUpdatesPerFrame(charas.Count, 0.01f * (float)EClass.pc.Speed * (EClass._zone.IsRegion ? 0.1f : 1f));
288 for (int i = 0; i < updatesPerFrame; i++)
289 {
290 index++;
291 if (index >= charas.Count)
292 {
293 index = 0;
294 }
295 Chara chara = charas[index];
296 for (int num = chara.conditions.Count - 1; num >= 0; num--)
297 {
298 if (num < chara.conditions.Count)
299 {
300 Condition condition = chara.conditions[num];
301 if (condition.TimeBased)
302 {
303 condition.Tick();
304 }
305 if (chara.isDead)
306 {
307 break;
308 }
309 }
310 }
311 }
312 }
313 }
314
315 public class ThingUpdater : Updater
316 {
317 public override void FixedUpdate()
318 {
319 List<Thing> things = EClass._map.things;
320 SetUpdatesPerFrame(things.Count, 1f);
321 for (int i = 0; i < updatesPerFrame; i++)
322 {
323 index++;
324 if (index >= things.Count)
325 {
326 index = 0;
327 }
328 Thing thing = things[index];
329 if (thing.fov != null)
330 {
331 thing.CalculateFOV();
332 }
333 if (thing.trait.HaveUpdate)
334 {
335 thing.trait.Update();
336 }
337 if ((thing.id == "snow" || thing.id == "flyer") && EClass.rnd(30) == 0 && !thing.IsInstalled && !LayerDragGrid.Instance && !LayerCraft.Instance)
338 {
339 thing.Destroy();
340 }
341 }
342 }
343 }
344
345 public static float delta;
346
348
350
352
354
356
358
360
362
364
365 public Updater[] all;
366
367 private float dateTimer;
368
369 private float counterTimer;
370
371 private int counter;
372
373 private float timerThunder;
374
375 public void Reset()
376 {
377 area = new AreaUpdater();
378 surface = new SurfaceUpdater();
380 fire = new FireUpdater();
381 chara = new CharaUpdater();
383 thing = new ThingUpdater();
384 sensor = new SensorUpdater();
385 }
386
387 public void Update100ms()
388 {
390 {
392 }
393 bool flag = EClass.world.weather.CurrentCondition == Weather.Condition.RainHeavy;
394 bool flag2 = EClass._map.config.indoor || (EClass.pc.IsInActiveZone && (EClass.pc.pos.cell.room?.HasRoof ?? false));
395 bool flag3 = EClass.pc.pos.cell.room?.data.atrium ?? false;
396 float mtpVolume = ((EClass._zone.lv <= -2) ? 0f : ((flag2 && !flag3) ? 0.5f : 1f));
398 {
399 for (int i = 0; i < EClass.setting.weather.splashCount * ((!flag) ? 1 : 2); i++)
400 {
401 Point randomPoint = EClass.screen.GetRandomPoint();
402 if (!randomPoint.IsValid)
403 {
404 continue;
405 }
406 Cell cell = randomPoint.cell;
407 if (!cell.HasRoof && cell._block == 0 && !randomPoint.IsSky)
408 {
409 if (cell.IsTopWaterAndNoSnow)
410 {
411 EClass.scene.psRainSplash.Emit(randomPoint.PositionCenter(), Vector3.zero, Rand.Range(0.6f, 1.1f), 0.2f, Color.white);
412 }
413 else
414 {
415 EClass.scene.psRainSplashWater.Emit(randomPoint.PositionCenter(), Vector3.zero, Rand.Range(0.6f, 1.1f), 0.2f, Color.white);
416 }
417 }
418 }
419 }
420 if (!flag)
421 {
422 return;
423 }
424 timerThunder += 0.1f;
426 {
428 {
429 ScreenFlash.Play("storm" + (EClass.rnd(2) + 1), (flag2 && !flag3) ? 0.3f : 1f);
430 }
431 EClass.Sound.Play("Ambience/Random/storm", mtpVolume);
433 }
434 }
435
436 public void FixedUpdate()
437 {
439 if (!EClass.scene.paused)
440 {
441 if (all == null)
442 {
444 }
445 delta = Core.delta;
454 }
455 }
456
457 public void Update()
458 {
459 if (EClass.game.activeZone == null)
460 {
461 return;
462 }
464 if (EClass.debug.testLOS)
465 {
467 {
468 Zone zone = EClass.game.spatials.Find("palmia");
470 if (pathProgress.HasPath)
471 {
472 Debug.Log(pathProgress.nodes.Count);
473 foreach (PathFinderNode node in pathProgress.nodes)
474 {
475 Point point2 = new Point(node.X, node.Z);
477 }
478 }
479 }
480 Point hit2 = Scene.HitPoint;
481 if (hit2.IsValid)
482 {
483 for (int i = 0; i < EClass._map.charas.Count; i++)
484 {
485 Chara tg = EClass._map.charas[i];
486 if (!Los.IsVisible(hit2, tg.pos))
487 {
488 continue;
489 }
490 Los.IsVisible(hit2, tg.pos, delegate(Point point, bool blocked)
491 {
493 if (Input.GetKey(KeyCode.LeftControl))
494 {
495 Debug.Log(tg.Name + ": Distance:" + hit2.Distance(tg.pos));
496 }
497 });
498 }
499 }
500 }
502 {
503 Point hit = Scene.HitPoint;
504 if (hit.IsValid)
505 {
506 EClass._map.ForeachSphere(hit.x, hit.z, 6f, delegate(Point p)
507 {
508 if (p.IsValid && Los.IsVisible(hit, p))
509 {
510 EClass.screen.tileMap.passGuideFloor.Add(p, 20f);
511 }
512 });
513 }
514 }
515 if (EClass.scene.paused)
516 {
517 return;
518 }
521 dateTimer += delta;
523 {
524 dateTimer = 0f;
526 }
528 if (!(counterTimer > 0.1f))
529 {
530 return;
531 }
532 counterTimer = 0f;
533 counter++;
534 if (counter == 10)
535 {
536 counter = 0;
537 }
538 switch (counter)
539 {
540 case 1:
542 break;
543 case 5:
544 if ((bool)EClass.Sound.currentAmbience)
545 {
546 EClass.Sound.currentAmbience.TryEmit(EClass.world.date.IsDay, ref Point.shared.Set(EClass.pc.pos.x + EClass.rnd(5) - EClass.rnd(5), EClass.pc.pos.z).Clamp().Position());
547 }
548 break;
549 }
550 }
551
552 public string GetText()
553 {
554 if (all == null)
555 {
556 return "";
557 }
558 string text = "";
559 Updater[] array = all;
560 foreach (Updater updater in array)
561 {
562 text = text + updater.GetType().Name + ": " + updater.updatesPerFrame + " / frame " + updater.maxCount + " in " + updater.duration + "sec \n";
563 }
564 return text;
565 }
566}
bool atrium
Definition: AreaData.cs:66
AreaData data
Definition: BaseArea.cs:29
Point GetRandomPoint()
BaseTileMap tileMap
MeshPass passGuideBlock
Definition: BaseTileMap.cs:137
MeshPass passGuideFloor
Definition: BaseTileMap.cs:139
Point pos
Definition: Card.cs:55
int amount
Definition: CellEffect.cs:26
bool WillFade
Definition: CellEffect.cs:173
Definition: Cell.cs:7
byte _block
Definition: Cell.cs:30
Room room
Definition: Cell.cs:102
CellEffect effect
Definition: Cell.cs:94
byte decal
Definition: Cell.cs:44
bool IsTopWaterAndNoSnow
Definition: Cell.cs:712
bool IsFarmField
Definition: Cell.cs:730
bool IsTopWater
Definition: Cell.cs:700
bool HasLiquid
Definition: Cell.cs:673
bool HasRoof
Definition: Cell.cs:648
bool HasFire
Definition: Cell.cs:676
bool HasObj
Definition: Cell.cs:641
Definition: Chara.cs:10
int Speed
Definition: Chara.cs:906
GraphicSetting graphic
Definition: CoreConfig.cs:594
bool testLOS2
Definition: CoreDebug.cs:149
bool testLOS
Definition: CoreDebug.cs:147
Definition: Core.cs:14
static float gameDelta
Definition: Core.cs:21
static float delta
Definition: Core.cs:17
CoreConfig config
Definition: Core.cs:70
bool IsDay
Definition: Date.cs:109
Definition: EClass.cs:5
static Game game
Definition: EClass.cs:8
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 FactionBranch Branch
Definition: EClass.cs:22
static BaseGameScreen screen
Definition: EClass.cs:32
static Chara pc
Definition: EClass.cs:14
static CoreDebug debug
Definition: EClass.cs:48
static SoundManager Sound
Definition: EClass.cs:46
static GameSetting setting
Definition: EClass.cs:34
int minX
Definition: EloMap.cs:112
int minY
Definition: EloMap.cs:114
HomeResourceManager resources
void AdvanceMin(int a)
Definition: GameDate.cs:22
WeatherSetting weather
Definition: GameSetting.cs:313
float secsPerHour
Definition: GameSetting.cs:319
override void FixedUpdate()
Definition: GameUpdater.cs:42
override void FixedUpdate()
Definition: GameUpdater.cs:246
override void FixedUpdate()
Definition: GameUpdater.cs:284
override LogicalPointManager manager
Definition: GameUpdater.cs:217
override float UpdateDuration
Definition: GameUpdater.cs:219
override void FixedUpdate()
Definition: GameUpdater.cs:185
virtual float UpdateDuration
Definition: GameUpdater.cs:181
virtual bool RefreshTile
Definition: GameUpdater.cs:183
virtual LogicalPointManager manager
Definition: GameUpdater.cs:179
override void FixedUpdate()
Definition: GameUpdater.cs:224
override void FixedUpdate()
Definition: GameUpdater.cs:72
override void FixedUpdate()
Definition: GameUpdater.cs:317
void SetUpdatesPerFrame(int _maxcount, float _duration)
Definition: GameUpdater.cs:25
virtual void FixedUpdate()
Definition: GameUpdater.cs:21
void Update100ms()
Definition: GameUpdater.cs:387
ConditionUpdater condition
Definition: GameUpdater.cs:357
AreaUpdater area
Definition: GameUpdater.cs:347
string GetText()
Definition: GameUpdater.cs:552
FireUpdater fire
Definition: GameUpdater.cs:353
float dateTimer
Definition: GameUpdater.cs:367
CharaUpdater chara
Definition: GameUpdater.cs:355
void FixedUpdate()
Definition: GameUpdater.cs:436
SurfaceUpdater surface
Definition: GameUpdater.cs:349
void Update()
Definition: GameUpdater.cs:457
Updater[] all
Definition: GameUpdater.cs:365
static float delta
Definition: GameUpdater.cs:345
float counterTimer
Definition: GameUpdater.cs:369
SensorUpdater sensor
Definition: GameUpdater.cs:361
void Reset()
Definition: GameUpdater.cs:375
RecipeUpdater recipe
Definition: GameUpdater.cs:363
ThingUpdater thing
Definition: GameUpdater.cs:359
FastSurfaceUpdater surfaceFast
Definition: GameUpdater.cs:351
float timerThunder
Definition: GameUpdater.cs:373
Definition: Game.cs:8
static bool isPaused
Definition: Game.cs:149
SpatialManager spatials
Definition: Game.cs:152
Zone activeZone
Definition: Game.cs:245
static LayerCraft Instance
Definition: LayerCraft.cs:8
static LayerDragGrid Instance
HashSet< Point > refreshList
List< LogicalPoint > list
Definition: Los.cs:5
static bool IsVisible(Point p1, Point p2, Action< Point, bool > _onVisit=null)
Definition: Los.cs:167
int Size
Definition: MapBounds.cs:20
bool IsIndoor
Definition: Map.cs:131
void ForeachSphere(int _x, int _z, float r, Action< Point > action)
Definition: Map.cs:2358
void RefreshSunMap()
Definition: Map.cs:2700
void RefreshSingleTile(int x, int z)
Definition: Map.cs:2081
int SizeXZ
Definition: Map.cs:133
void SetLiquid(int x, int z, CellEffect effect=null)
Definition: Map.cs:1464
PropsRoaming Roaming
Definition: Map.cs:125
List< Thing > things
Definition: Map.cs:49
void ModLiquid(int x, int z, int amount)
Definition: Map.cs:1500
RoomManager rooms
Definition: Map.cs:31
void SetEffect(int x, int z, CellEffect effect=null)
Definition: Map.cs:1495
CellEffectManager effectManager
Definition: Map.cs:89
List< Chara > charas
Definition: Map.cs:81
void Add(Point point, float tile=0f, float color=0f)
Definition: MeshPass.cs:122
void RequestPathImmediate(PathProgress progress)
Definition: PathManager.cs:41
static PathManager Instance
Definition: PathManager.cs:16
List< PathFinderNode > nodes
Definition: PathProgress.cs:16
Definition: Point.cs:9
static Point shared
Definition: Point.cs:20
ref Vector3 Position(int height)
Definition: Point.cs:524
bool IsSky
Definition: Point.cs:212
Point Set(int _x, int _z)
Definition: Point.cs:479
ref Vector3 PositionTopdown()
Definition: Point.cs:545
int x
Definition: Point.cs:36
void ModFire(int value, bool extinguish=false)
Definition: Point.cs:897
int z
Definition: Point.cs:39
ref Vector3 PositionCenter()
Definition: Point.cs:563
SourceObj.Row sourceObj
Definition: Point.cs:69
bool IsValid
Definition: Point.cs:88
Point Clamp(bool useBounds=false)
Definition: Point.cs:972
bool IsInBounds
Definition: Point.cs:104
Cell cell
Definition: Point.cs:51
Dictionary< string, PropSet > raceMap
Definition: Props.cs:14
Definition: Rand.cs:4
static int Range(int min, int max)
Definition: Rand.cs:42
void FixedUpdate()
List< Area > listArea
Definition: RoomManager.cs:10
bool HasRoof
Definition: Room.cs:29
Definition: Scene.cs:8
ParticleSystem psRainSplashWater
Definition: Scene.cs:111
static Point HitPoint
Definition: Scene.cs:21
ParticleSystem psRainSplash
Definition: Scene.cs:109
EloMap elomap
Definition: Scene.cs:143
bool paused
Definition: Scene.cs:134
static void Play(string id, float mtp=1f)
Definition: ScreenFlash.cs:24
Zone Find(string id)
virtual bool IsRegion
Definition: Spatial.cs:501
int y
Definition: Spatial.cs:106
int x
Definition: Spatial.cs:94
Definition: Thing.cs:8
static void Refresh()
Condition
Definition: Weather.cs:16
bool IsRaining
Definition: Weather.cs:117
GameDate date
Definition: World.cs:6
Weather weather
Definition: World.cs:12
void Tick(float delta)
Definition: Zone.cs:12
ZoneEventManager events
Definition: Zone.cs:40
bool IsPCFaction
Definition: Zone.cs:464