Elin Decompiled Documentation EA 23.187 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 bool raid
78 {
79 get
80 {
81 return bits[0];
82 }
83 set
84 {
85 bits[0] = value;
86 }
87 }
88
89 [OnSerializing]
90 private void _OnSerializing(StreamingContext context)
91 {
92 ints[0] = (int)bits.Bits;
93 }
94
95 [OnDeserialized]
96 private void _OnDeserialized(StreamingContext context)
97 {
98 bits.Bits = (uint)ints[0];
99 }
100 }
101
102 [JsonProperty]
103 public Flags flags = new Flags();
104
105 public bool IsInRaid => GetRaidEvent() != null;
106
108 {
109 return EClass._zone.events.GetEvent<ZoneEventRaid>();
110 }
111
112 public void Meteor(Point pos, Action action)
113 {
114 EffectMeteor.Create(pos, 0, 1, delegate
115 {
116 action();
117 });
118 }
119
120 public void OnExpandFloor(Point pos)
121 {
122 int i = 0;
123 bool done = false;
124 EClass._map.ForeachCell(delegate(Cell c)
125 {
126 if (!c.sourceFloor.tileType.IsSkipFloor)
127 {
128 i++;
129 }
130 });
131 Check(9, delegate
132 {
133 EClass._zone.ClaimZone(debug: false, pos);
134 });
135 Check(15, delegate
136 {
138 });
139 Check(25, delegate
140 {
142 });
143 Check(40, delegate
144 {
146 });
147 Check(50, delegate
148 {
149 EClass._zone.AddCard(ThingGen.Create("core_defense"), pos).Install();
150 });
151 void Check(int a, Action action)
152 {
153 if (!done && flags.floors < a && i >= a)
154 {
155 Meteor(pos, action);
156 EClass.game.survival.flags.floors = a;
157 done = true;
158 }
159 }
160 }
161
162 public bool OnMineWreck(Point point)
163 {
164 if (EClass._zone.events.GetEvent<ZoneEventSurvival>() == null)
165 {
167 }
168 SourceObj.Row sourceObj = point.cell.sourceObj;
169 int searchWreck = EClass.game.survival.flags.searchWreck;
170 string[] array = new string[6] { "log", "rock", "branch", "bone", "grass", "vine" };
171 int chanceChange = 25;
172 int num = searchWreck / 50 + 3;
173 if (searchWreck == 0)
174 {
175 Pop(ThingGen.Create("log").SetNum(6));
176 Pop(ThingGen.Create("rock").SetNum(4));
177 }
178 switch (sourceObj.alias)
179 {
180 case "nest_bird":
181 chanceChange = 100;
182 return Pop(ThingGen.Create((EClass.rnd(10) == 0) ? "egg_fertilized" : "_egg").TryMakeRandomItem(num));
183 case "wreck_wood":
184 array = new string[6] { "log", "log", "branch", "grass", "vine", "resin" };
185 break;
186 case "wreck_junk":
187 chanceChange = 50;
188 return Pop(ThingGen.CreateFromFilter("shop_junk", num));
189 case "wreck_stone":
190 chanceChange = 30;
191 array = new string[4] { "rock", "rock", "stone", "bone" };
192 break;
193 case "wreck_scrap":
194 chanceChange = 75;
195 array = new string[1] { "scrap" };
196 break;
197 case "wreck_cloth":
198 chanceChange = 75;
199 array = new string[1] { "fiber" };
200 break;
201 case "wreck_precious":
202 chanceChange = 100;
203 return Pop(ThingGen.CreateFromFilter("shop_magic", num));
204 default:
205 return false;
206 }
207 if (EClass.rnd(3) == 0 && EClass.game.survival.flags.spawnedFloor < 4)
208 {
210 return Pop(ThingGen.CreateFloor(40, 45).SetNum(3));
211 }
212 if (EClass.rnd(20) == 0)
213 {
214 return Pop(TraitSeed.MakeRandomSeed());
215 }
216 if (EClass.rnd(12) == 0)
217 {
218 return Pop(ThingGen.Create("money2"));
219 }
220 if (EClass.rnd(12) == 0)
221 {
222 Point pos = point.GetNearestPoint(allowBlock: false, allowChara: false, allowInstalled: false, ignoreCenter: true) ?? point;
223 if (searchWreck < 50 || EClass.rnd(3) != 0)
224 {
226 }
227 else
228 {
229 EClass._zone.SpawnMob(pos, SpawnSetting.HomeEnemy(Mathf.Max(num - 5, 1)));
230 }
231 }
232 return Pop(ThingGen.Create(array.RandomItem()).SetNum(1 + EClass.rnd(3)));
233 bool Next()
234 {
236 Point pos2 = point.GetNearestPoint(allowBlock: false, allowChara: false, allowInstalled: false, ignoreCenter: true) ?? point;
238 {
239 Meteor(pos2, delegate
240 {
241 EClass._zone.AddCard(ThingGen.CreateRecipe("container_shipping"), pos2);
242 });
243 }
244 NextObj();
245 return true;
246 }
247 void NextObj()
248 {
249 if (EClass.rnd(100) < chanceChange)
250 {
251 string[] source = new string[11]
252 {
253 "nest_bird", "wreck_wood", "wreck_wood", "wreck_wood", "wreck_wood", "wreck_stone", "wreck_stone", "wreck_scrap", "wreck_junk", "wreck_cloth",
254 "wreck_precious"
255 };
256 EClass._map.SetObj(point.x, point.z, EClass.sources.objs.alias[source.RandomItem()].id);
257 }
258 }
259 bool Pop(Thing t)
260 {
261 EClass._map.TrySmoothPick(point, t, EClass.pc);
262 Next();
263 return true;
264 }
265 }
266
268 {
269 return EClass.sources.charas.rows.Where(delegate(SourceChara.Row r)
270 {
271 if (r.quality != 4 || r.race == "god" || r.size.Length != 0)
272 {
273 return false;
274 }
275 switch (r.id)
276 {
277 case "fiama":
278 case "loytel":
279 case "nino":
280 case "big_daddy":
281 case "littleOne":
282 return false;
283 default:
284 return EClass.game.cards.globalCharas.Find(r.id) == null;
285 }
286 }).ToList();
287 }
288
289 public void OnUpdateRecruit(FactionBranch branch)
290 {
291 List<SourceChara.Row> list = ListUnrecruitedUniques();
292 for (int i = 0; i < (EClass.debug.enable ? 10 : 2); i++)
293 {
294 SourceChara.Row row = list.RandomItem();
295 if (row != null)
296 {
297 Chara chara = CharaGen.Create(row.id);
298 chara.RemoveEditorTag(EditorTag.AINoMove);
299 branch.AddRecruit(chara);
300 list.Remove(row);
301 }
302 }
303 }
304
305 public void StartRaid()
306 {
307 SE.Play("warhorn");
308 Msg.Say("warhorn");
309 flags.raid = true;
310 Point pos = EClass.pc.pos.GetNearestPoint(allowBlock: false, allowChara: false, allowInstalled: false, ignoreCenter: true) ?? EClass.pc.pos;
311 Meteor(pos, delegate
312 {
313 EClass._zone.AddCard(ThingGen.Create("teleporter_demon"), pos).Install();
314 });
315 flags.dateNextRaid = EClass.world.date.GetRaw(72);
316 }
317}
EditorTag
Definition: EditorTag.cs:2
string id
Definition: CardRow.cs:7
Thing TryMakeRandomItem(int lv=-1, TryMakeRandomItemSource itemSource=TryMakeRandomItemSource.Default, Chara crafter=null)
Definition: Card.cs:5204
void RemoveEditorTag(EditorTag tag)
Definition: Card.cs:2572
virtual Chara Chara
Definition: Card.cs:2032
Thing SetNum(int a)
Definition: Card.cs:3393
Point pos
Definition: Card.cs:57
Card Install()
Definition: Card.cs:3633
Definition: Cell.cs:7
SourceFloor.Row sourceFloor
Definition: Cell.cs:1054
SourceObj.Row sourceObj
Definition: Cell.cs:1072
static Chara Create(string id, int lv=-1)
Definition: CharaGen.cs:17
Definition: Chara.cs:10
FactionBranch homeBranch
Definition: Chara.cs:1052
Definition: Check.cs:5
int GetRaw(int offsetHours=0)
Definition: Date.cs:322
Definition: EClass.cs:5
static Game game
Definition: EClass.cs:8
static Zone _zone
Definition: EClass.cs:20
static World world
Definition: EClass.cs:40
static Map _map
Definition: EClass.cs:18
static int rnd(long a)
Definition: EClass.cs:58
static SourceManager sources
Definition: EClass.cs:42
static Chara pc
Definition: EClass.cs:14
static CoreDebug debug
Definition: EClass.cs:48
static void Create(Point center, int radius, int count, Action< int, Point > onComplete)
Definition: EffectMeteor.cs:33
void AddRecruit(Chara c)
void AddMemeber(Chara c)
SurvivalManager survival
Definition: Game.cs:224
new void ForeachCell(Action< Cell > action)
Definition: Map.cs:2346
void TrySmoothPick(Cell cell, Thing t, Chara c)
Definition: Map.cs:1804
void SetObj(int x, int z, int id=0, int value=1, int dir=0)
Definition: Map.cs:1535
Definition: Msg.cs:5
static string Say(string idLang, string ref1, string ref2=null, string ref3=null, string ref4=null)
Definition: Msg.cs:58
Definition: Point.cs:9
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:607
int z
Definition: Point.cs:39
Cell cell
Definition: Point.cs:51
SourceObj objs
SourceChara charas
static SpawnSetting HomeWild(int lv)
Definition: SpawnSetting.cs:91
static SpawnSetting HomeEnemy(int lv)
void _OnSerializing(StreamingContext context)
void _OnDeserialized(StreamingContext context)
bool OnMineWreck(Point point)
ZoneEventRaid GetRaidEvent()
void OnUpdateRecruit(FactionBranch branch)
void Meteor(Point pos, Action action)
void OnExpandFloor(Point pos)
List< SourceChara.Row > ListUnrecruitedUniques()
static Thing CreateFromFilter(string id, int lv=-1)
Definition: ThingGen.cs:63
static Thing CreateFloor(int id, int idMat, bool platform=false)
Definition: ThingGen.cs:108
static Thing CreateRecipe(string id)
Definition: ThingGen.cs:144
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
string alias
Definition: TileRow.cs:12
static Thing MakeRandomSeed(bool enc=false)
Definition: TraitSeed.cs:187
GameDate date
Definition: World.cs:6
void Add(ZoneEvent e, bool allowDuplicate=false)
ZoneEventManager events
Definition: Zone.cs:40
void ClaimZone(bool debug=false, Point pos=null)
Definition: Zone.cs:1700
Chara SpawnMob(Point pos=null, SpawnSetting setting=null)
Definition: Zone.cs:2691
Card AddCard(Card t, Point point)
Definition: Zone.cs:1937
uint Bits
Definition: BitArray32.cs:6