Elin Decompiled Documentation EA 23.355 Stable
Loading...
Searching...
No Matches
SurvivalManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Runtime.Serialization;
5using Newtonsoft.Json;
6using UnityEngine;
7
8public class SurvivalManager : EClass
9{
10 public class Flags : EClass
11 {
12 [JsonProperty]
13 public int[] ints = new int[50];
14
16
17 public int spawnedFloor
18 {
19 get
20 {
21 return ints[3];
22 }
23 set
24 {
25 ints[3] = value;
26 }
27 }
28
29 public int floors
30 {
31 get
32 {
33 return ints[4];
34 }
35 set
36 {
37 ints[4] = value;
38 }
39 }
40
41 public int searchWreck
42 {
43 get
44 {
45 return ints[5];
46 }
47 set
48 {
49 ints[5] = value;
50 }
51 }
52
53 public int dateNextRaid
54 {
55 get
56 {
57 return ints[6];
58 }
59 set
60 {
61 ints[6] = value;
62 }
63 }
64
65 public int raidRound
66 {
67 get
68 {
69 return ints[7];
70 }
71 set
72 {
73 ints[7] = value;
74 }
75 }
76
77 public int raidLv
78 {
79 get
80 {
81 return ints[8];
82 }
83 set
84 {
85 ints[8] = value;
86 }
87 }
88
89 public bool raid
90 {
91 get
92 {
93 return bits[0];
94 }
95 set
96 {
97 bits[0] = value;
98 }
99 }
100
101 public bool gotTaxChest
102 {
103 get
104 {
105 return bits[1];
106 }
107 set
108 {
109 bits[1] = value;
110 }
111 }
112
113 public bool gotGaragara
114 {
115 get
116 {
117 return bits[2];
118 }
119 set
120 {
121 bits[2] = value;
122 }
123 }
124
125 public bool gotSkyWorkbench
126 {
127 get
128 {
129 return bits[4];
130 }
131 set
132 {
133 bits[4] = value;
134 }
135 }
136
137 [OnSerializing]
138 private void _OnSerializing(StreamingContext context)
139 {
140 ints[0] = (int)bits.Bits;
141 }
142
143 [OnDeserialized]
144 private void _OnDeserialized(StreamingContext context)
145 {
146 bits.Bits = (uint)ints[0];
147 }
148 }
149
150 [JsonProperty]
151 public Flags flags = new Flags();
152
153 [JsonProperty]
154 public List<string> listReward = new List<string>();
155
156 [JsonProperty]
158
159 [JsonProperty]
160 public List<Zone> listGateZone = new List<Zone>();
161
162 public bool IsInRaid => GetRaidEvent() != null;
163
165 {
166 return EClass._zone.events.GetEvent<ZoneEventRaid>();
167 }
168
169 public void Meteor(Point pos, Action action)
170 {
171 EffectMeteor.Create(pos, 0, 1, delegate
172 {
173 action();
174 });
175 }
176
177 public void MeteorThing(Point pos, string id, bool install = false)
178 {
179 if (pos == null)
180 {
181 pos = EClass.pc.pos.Copy();
182 }
183 Meteor(pos, delegate
184 {
186 if (card.id == "rod_wish")
187 {
188 card.SetCharge(1);
189 }
190 if (install)
191 {
192 card.Install();
193 }
194 });
195 }
196
197 public void MeteorThing(Point pos, Thing t, bool install = false)
198 {
199 if (pos == null)
200 {
201 pos = EClass.pc.pos.Copy();
202 }
203 Meteor(pos, delegate
204 {
205 Card card = EClass._zone.AddCard(t, pos);
206 if (install)
207 {
208 card.Install();
209 }
210 });
211 }
212
213 public void OnAdvanceHour()
214 {
216 {
217 Point point = new Point(EClass._map.CenterX + 1, EClass._map.CenterZ + 1);
218 if (!point.HasObj)
219 {
220 point.SetObj(46);
221 }
222 }
223 if (EClass.world.date.hour == 0 || EClass.debug.enable)
224 {
226 }
227 }
228
229 public void RefreshGateZones()
230 {
231 listGateZone.ForeachReverse(delegate(Zone z)
232 {
233 if (z == null || z.destryoed)
234 {
235 listGateZone.Remove(z);
236 }
237 });
238 if (listGateZone.Count == 0)
239 {
240 for (int num = 0; num < 3; num++)
241 {
242 if (EClass.rnd(4) == 0)
243 {
244 IEnumerable<Spatial> enumerable = EClass.game.spatials.map.Values.Where((Spatial a) => a.source.costSkyTravel > 0 && !listGateZone.Contains(a) && a != gateZone);
245 if (enumerable.Count() > 0)
246 {
247 listGateZone.Add(enumerable.RandomItem() as Zone);
248 }
249 }
250 else
251 {
252 Zone item = EClass.world.region.CreateRandomSite(new Point(1, 1), (EClass.rnd(5) == 0) ? "dungeon_water" : null, updateMesh: false);
253 listGateZone.Add(item);
254 }
255 }
256 }
257 foreach (Zone item2 in listGateZone)
258 {
259 if (item2.dateExpire > 0)
260 {
261 item2.dateExpire = EClass.world.date.GetRaw() + 10080;
262 }
263 }
264 }
265
266 public void RefreshRewards()
267 {
268 if (listReward.Count <= 0)
269 {
270 Add(new string[7] { "659", "758", "759", "806", "828", "1190", "1191" });
271 if (flags.raidLv < 50)
272 {
273 Add(new string[7] { "pillow_jure", "pillow_ehekatl", "pillow_opatos", "pillow_kumiromi", "pillow_lulwy", "pillow_mani", "pillow_itzpalt" });
274 }
275 else
276 {
277 Add(new string[1] { "rod_wish" });
278 }
279 }
280 void Add(string[] ids)
281 {
282 foreach (string item in ids)
283 {
284 listReward.Add(item);
285 }
286 }
287 }
288
289 public void OnExpandFloor(Point pos)
290 {
291 int n = 0;
292 bool done = false;
293 EClass._map.ForeachCell(delegate(Cell c)
294 {
295 if (!c.sourceFloor.tileType.IsSkipFloor)
296 {
297 n++;
298 }
299 });
300 Check(6, delegate
301 {
302 EClass._zone.ClaimZone(debug: false, pos);
303 });
304 Check(9, delegate
305 {
307 });
308 Check(20, delegate
309 {
310 AddMemeber("fiama");
311 });
312 Check(40, delegate
313 {
314 AddMemeber("nino");
315 });
316 Check(60, delegate
317 {
318 AddMemeber("loytel");
320 });
321 Check(80, delegate
322 {
323 AddMemeber("farris");
324 });
325 Check(100, delegate
326 {
327 EClass._zone.AddCard(ThingGen.Create("core_defense"), pos).Install();
328 });
329 void AddMemeber(string id)
330 {
331 if (EClass.game.cards.globalCharas.Find(id) == null)
332 {
334 }
335 }
336 void Check(int a, Action action)
337 {
338 if (!done && flags.floors < a && n >= a)
339 {
340 Meteor(pos, action);
341 EClass.game.survival.flags.floors = a;
342 done = true;
343 }
344 }
345 }
346
347 public void CheckLoytelDebt()
348 {
349 if (EClass.game.cards.globalCharas.Find("loytel") != null && !EClass.game.quests.IsAdded<QuestDebt>())
350 {
351 Quest quest = EClass.game.quests.Add("debt", "loytel");
352 EClass.game.quests.globalList.Remove(quest);
353 EClass.game.quests.Start(quest);
354 }
355 }
356
357 public bool OnMineWreck(Point point)
358 {
359 if (EClass._zone.events.GetEvent<ZoneEventSurvival>() == null)
360 {
362 }
364 SourceObj.Row sourceObj = point.cell.sourceObj;
365 int searchWreck = EClass.game.survival.flags.searchWreck;
366 string[] array = new string[6] { "log", "rock", "branch", "bone", "grass", "vine" };
367 int chanceChange = 25;
368 int num = searchWreck / 50 + 1;
369 if (searchWreck == 0)
370 {
371 Thing t = ThingGen.CreateParcel(null, ThingGen.Create("log").SetNum(6), ThingGen.Create("rock").SetNum(4), ThingGen.Create("resin").SetNum(2), ThingGen.Create("money2").SetNum(10), ThingGen.Create("1267"), ThingGen.CreateRod(50311, 8));
372 Pop(t);
373 }
374 switch (sourceObj.alias)
375 {
376 case "nest_bird":
377 chanceChange = 65;
378 return Pop(ThingGen.Create((EClass.rnd(10) == 0) ? "egg_fertilized" : "_egg").TryMakeRandomItem(num));
379 case "wreck_wood":
380 array = new string[8] { "log", "log", "branch", "grass", "vine", "resin", "leaf", "chunk" };
381 break;
382 case "wreck_junk":
383 chanceChange = 100;
384 return Pop(ThingGen.CreateFromFilter("wreck_junk", num));
385 case "wreck_stone":
386 chanceChange = 30;
387 array = new string[4] { "rock", "rock", "stone", "bone" };
388 break;
389 case "wreck_scrap":
390 chanceChange = 75;
391 array = new string[1] { "scrap" };
392 break;
393 case "wreck_cloth":
394 chanceChange = 75;
395 array = new string[1] { "fiber" };
396 break;
397 case "wreck_precious":
398 chanceChange = 100;
399 return Pop(ThingGen.CreateFromFilter("shop_magic", num));
400 default:
401 return false;
402 }
404 {
407 {
408 case 5:
409 case 6:
410 return Pop(ThingGen.CreateFloor(33, 97).SetNum(3));
411 case 7:
412 case 8:
413 return Pop(ThingGen.CreateFloor(43, 66).SetNum(3));
414 default:
415 return Pop(ThingGen.CreateFloor(40, 45).SetNum(3));
416 }
417 }
418 if (EClass.rnd(20) == 0)
419 {
420 return Pop(TraitSeed.MakeRandomSeed());
421 }
422 if (EClass.rnd(12 + num / 5) == 0)
423 {
424 return Pop(ThingGen.Create("money2"));
425 }
426 if (searchWreck > 10 && EClass.rnd(40 + num) == 0)
427 {
428 TreasureType treasureType = ((EClass.rnd(10) == 0) ? TreasureType.BossNefia : ((EClass.rnd(10) == 0) ? TreasureType.Map : TreasureType.RandomChest));
429 Thing t2 = ThingGen.Create(treasureType switch
430 {
431 TreasureType.Map => "chest_treasure",
432 TreasureType.BossNefia => "chest_boss",
433 _ => "chest3",
434 });
435 ThingGen.CreateTreasureContent(t2, num, treasureType, clearContent: true);
436 MeteorThing(GetRandomPoint(), t2, install: true);
437 }
438 if (EClass.rnd(12) == 0)
439 {
440 Point pos = point.GetNearestPoint(allowBlock: false, allowChara: false, allowInstalled: false, ignoreCenter: true) ?? point;
441 if (searchWreck < 100 || EClass.rnd(3) != 0)
442 {
444 }
445 else
446 {
447 EClass._zone.SpawnMob(pos, SpawnSetting.HomeEnemy(Mathf.Max(num - 5, 1)));
448 }
449 }
450 return Pop(ThingGen.Create(array.RandomItem()).SetNum(1 + EClass.rnd(3)));
451 bool Next()
452 {
454 int searchWreck2 = EClass.game.survival.flags.searchWreck;
455 Point pos2 = point.GetNearestPoint(allowBlock: false, allowChara: false, allowInstalled: false, ignoreCenter: true) ?? point;
456 if (searchWreck2 == 20)
457 {
458 Thing container = ThingGen.CreateParcel(null, ThingGen.CreateRecipe("container_shipping"), ThingGen.CreateRecipe("stonecutter"), ThingGen.CreateRecipe("factory_stone"), ThingGen.CreateRecipe("workbench2"), ThingGen.Create("crystal_earth").SetNum(3));
459 Meteor(pos2, delegate
460 {
461 EClass._zone.AddCard(container, pos2);
462 });
463 }
464 if (searchWreck2 > (EClass.debug.enable ? 5 : 100) && !flags.gotTaxChest)
465 {
466 MeteorThing(pos2, "chest_tax", install: true);
467 flags.gotTaxChest = true;
468 }
469 else if (searchWreck2 > (EClass.debug.enable ? 10 : 200) && !flags.gotGaragara)
470 {
471 MeteorThing(pos2, "rolling_fortune", install: true);
472 flags.gotGaragara = true;
473 }
474 else if (EClass.player.stats.days > 1 && !flags.gotSkyWorkbench)
475 {
476 MeteorThing(pos2, ThingGen.CreateRecipe("workbench_sky"));
477 flags.gotSkyWorkbench = true;
478 }
479 NextObj();
480 return true;
481 }
482 void NextObj()
483 {
484 if (EClass.rnd(100) < chanceChange)
485 {
486 string[] source = new string[12]
487 {
488 "nest_bird", "wreck_wood", "wreck_wood", "wreck_wood", "wreck_wood", "wreck_wood", "wreck_stone", "wreck_stone", "wreck_scrap", "wreck_junk",
489 "wreck_cloth", "wreck_precious"
490 };
491 EClass._map.SetObj(point.x, point.z, EClass.sources.objs.alias[source.RandomItem()].id);
492 }
493 }
494 bool Pop(Thing t3)
495 {
496 EClass._map.TrySmoothPick(point, t3, EClass.pc);
497 Next();
498 return true;
499 }
500 }
501
503 {
505 Point point = ((traitCoreZone != null) ? traitCoreZone.owner.pos : EClass._map.GetCenterPos());
506 List<Cell> list = new List<Cell>();
507 EClass._map.ForeachSphere(point.x, point.z, 50f, delegate(Point p)
508 {
509 if (!p.IsSky && !p.IsBlocked && !p.HasObj && !p.HasThing)
510 {
511 list.Add(p.cell);
512 }
513 });
514 if (list.Count == 0)
515 {
516 return null;
517 }
518 return list.RandomItem().GetPoint();
519 }
520
522 {
523 return EClass.sources.charas.rows.Where(delegate(SourceChara.Row r)
524 {
525 if (r.quality != 4 || r.race == "god" || r.size.Length != 0)
526 {
527 return false;
528 }
529 switch (r.id)
530 {
531 case "fiama":
532 case "loytel":
533 case "nino":
534 case "big_daddy":
535 case "big_daddy2":
536 case "littleOne":
537 case "mamani":
538 return false;
539 default:
540 if (EClass.game.cards.globalCharas.Find(r.id) == null)
541 {
542 return r.LV < flags.raidLv + 10;
543 }
544 return false;
545 }
546 }).ToList();
547 }
548
549 public void OnUpdateRecruit(FactionBranch branch)
550 {
551 List<SourceChara.Row> list = ListUnrecruitedUniques();
552 for (int i = 0; i < (EClass.debug.enable ? 10 : 2); i++)
553 {
554 SourceChara.Row row = list.RandomItem();
555 if (row == null)
556 {
557 continue;
558 }
559 bool flag = true;
560 foreach (HireInfo item in branch.listRecruit)
561 {
562 if (item.chara.id == row.id)
563 {
564 flag = false;
565 }
566 }
567 if (flag)
568 {
569 Chara chara = CharaGen.Create(row.id);
570 chara.RemoveEditorTag(EditorTag.AINoMove);
571 branch.AddRecruit(chara);
572 list.Remove(row);
573 }
574 }
575 }
576
577 public void StartRaid()
578 {
579 flags.raid = true;
580 Point pos = EClass.pc.pos.GetNearestPoint(allowBlock: false, allowChara: false, allowInstalled: false, ignoreCenter: true) ?? EClass.pc.pos;
581 Meteor(pos, delegate
582 {
583 EClass._zone.AddCard(ThingGen.Create("teleporter_demon"), pos).Install();
584 });
585 flags.dateNextRaid = EClass.world.date.GetRaw(72);
586 }
587}
if(!match.Success)
EditorTag
Definition: EditorTag.cs:2
TreasureType
Definition: TreasureType.cs:2
Chara Find(string id)
Definition: CardManager.cs:20
GlobalCharaList globalCharas
Definition: CardManager.cs:46
Definition: Card.cs:11
Thing TryMakeRandomItem(int lv=-1, TryMakeRandomItemSource itemSource=TryMakeRandomItemSource.Default, Chara crafter=null)
Definition: Card.cs:5758
void RemoveEditorTag(EditorTag tag)
Definition: Card.cs:2743
virtual Chara Chara
Definition: Card.cs:2122
Thing SetNum(int a)
Definition: Card.cs:3676
Point pos
Definition: Card.cs:60
Card Install()
Definition: Card.cs:3922
Definition: Cell.cs:7
SourceFloor.Row sourceFloor
Definition: Cell.cs:1092
SourceObj.Row sourceObj
Definition: Cell.cs:1112
static Chara Create(string id, int lv=-1)
Definition: CharaGen.cs:17
Definition: Chara.cs:10
FactionBranch homeBranch
Definition: Chara.cs:1115
Definition: Check.cs:5
bool enable
Definition: CoreDebug.cs:302
int hour
Definition: Date.cs:74
int GetRaw(int offsetHours=0)
Definition: Date.cs:328
Definition: EClass.cs:6
static Game game
Definition: EClass.cs:9
static Zone _zone
Definition: EClass.cs:21
static World world
Definition: EClass.cs:41
static Map _map
Definition: EClass.cs:19
static int rnd(long a)
Definition: EClass.cs:59
static SourceManager sources
Definition: EClass.cs:43
static Player player
Definition: EClass.cs:13
static Chara pc
Definition: EClass.cs:15
static CoreDebug debug
Definition: EClass.cs:49
static void Create(Point center, int radius, int count, Action< int, Point > onComplete)
Definition: EffectMeteor.cs:40
void AddRecruit(Chara c)
List< HireInfo > listRecruit
void AddMemeber(Chara c)
SurvivalManager survival
Definition: Game.cs:228
SpatialManager spatials
Definition: Game.cs:153
CardManager cards
Definition: Game.cs:156
QuestManager quests
Definition: Game.cs:183
int CenterZ
Definition: MapBounds.cs:24
Point GetCenterPos()
Definition: MapBounds.cs:52
int CenterX
Definition: MapBounds.cs:22
new void ForeachCell(Action< Cell > action)
Definition: Map.cs:2512
Thing FindThing(Func< Thing, bool > func)
Definition: Map.cs:2778
void ForeachSphere(int _x, int _z, float r, Action< Point > action)
Definition: Map.cs:2546
void TrySmoothPick(Cell cell, Thing t, Chara c)
Definition: Map.cs:1944
void SetObj(int x, int z, int id=0, int value=1, int dir=0)
Definition: Map.cs:1675
int days
Definition: Player.cs:75
Stats stats
Definition: Player.cs:1086
Definition: Point.cs:9
void SetObj(int id=0, int value=1, int dir=0)
Definition: Point.cs:934
Point Copy()
Definition: Point.cs:491
bool IsSky
Definition: Point.cs:224
bool IsBlocked
Definition: Point.cs:363
int x
Definition: Point.cs:36
Point GetNearestPoint(bool allowBlock=false, bool allowChara=true, bool allowInstalled=true, bool ignoreCenter=false, int minRadius=0)
Definition: Point.cs:624
int z
Definition: Point.cs:39
bool HasThing
Definition: Point.cs:251
bool HasObj
Definition: Point.cs:137
Cell cell
Definition: Point.cs:51
bool IsAdded(string id)
Quest Add(string id, string idGlobalChara=null)
Definition: QuestManager.cs:29
Quest Start(string id, string idGlobalChara)
Definition: QuestManager.cs:41
List< Quest > globalList
Definition: QuestManager.cs:14
Definition: Quest.cs:7
Zone CreateRandomSite(Zone center, int radius=8, string idSource=null, bool updateMesh=true, int lv=0)
Definition: Region.cs:141
SourceObj objs
SourceChara charas
GlobalSpatialList map
SourceZone.Row source
Definition: Spatial.cs:453
bool destryoed
Definition: Spatial.cs:45
int dateExpire
Definition: Spatial.cs:166
static SpawnSetting HomeWild(int lv)
static SpawnSetting HomeEnemy(int lv)
void _OnSerializing(StreamingContext context)
void _OnDeserialized(StreamingContext context)
List< string > listReward
bool OnMineWreck(Point point)
ZoneEventRaid GetRaidEvent()
void OnUpdateRecruit(FactionBranch branch)
void Meteor(Point pos, Action action)
void OnExpandFloor(Point pos)
void MeteorThing(Point pos, Thing t, bool install=false)
void MeteorThing(Point pos, string id, bool install=false)
List< Zone > listGateZone
List< SourceChara.Row > ListUnrecruitedUniques()
static Thing CreateFromFilter(string id, int lv=-1)
Definition: ThingGen.cs:63
static Thing CreateParcel(string idLang=null, params Thing[] things)
Definition: ThingGen.cs:42
static void CreateTreasureContent(Thing t, int lv, TreasureType type, bool clearContent)
Definition: ThingGen.cs:271
static Thing CreateFloor(int id, int idMat, bool platform=false)
Definition: ThingGen.cs:108
static Thing CreateRecipe(string id)
Definition: ThingGen.cs:152
static Thing CreateRod(int ele, int charge=-1)
Definition: ThingGen.cs:217
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
string alias
Definition: TileRow.cs:13
static Thing MakeRandomSeed(bool enc=false)
Definition: TraitSeed.cs:97
Card owner
Definition: Trait.cs:28
Region region
Definition: World.cs:23
GameDate date
Definition: World.cs:6
void Add(ZoneEvent e, bool allowDuplicate=false)
Definition: Zone.cs:12
ZoneEventManager events
Definition: Zone.cs:43
void ClaimZone(bool debug=false, Point pos=null)
Definition: Zone.cs:1888
Chara SpawnMob(string id, Point pos=null)
Definition: Zone.cs:2988
Card AddCard(Card t, Point point)
Definition: Zone.cs:2159
uint Bits
Definition: BitArray32.cs:6