Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
TaskHarvest.cs
Go to the documentation of this file.
1using UnityEngine;
2
4{
5 public bool wasReapSeed;
6
7 public bool wasCrime;
8
9 public bool harvestingCrop;
10
12
13 public bool IsObj => mode == HarvestType.Obj;
14
15 public bool IsReapSeed
16 {
17 get
18 {
19 if (IsObj && CanReapSeed && owner.Tool != null)
20 {
22 {
23 return owner.Tool.category.IsChildOf("scythe");
24 }
25 return true;
26 }
27 return false;
28 }
29 }
30
31 public override HarvestType harvestType => mode;
32
33 public override int RightHand => 1005;
34
35 public override int destDist => 1;
36
37 public override bool IsGrowth => pos.growth != null;
38
39 public override bool IsHostileAct
40 {
41 get
42 {
43 if (!wasCrime)
44 {
45 if (mode == HarvestType.Disassemble)
46 {
47 Thing thing = target;
48 if (thing != null && thing.isNPCProperty)
49 {
50 goto IL_007b;
51 }
52 }
53 if (mode == HarvestType.Obj)
54 {
55 if (!pos.sourceObj.ContainsTag("crime"))
56 {
57 if (pos.growth != null && pos.growth.IsCrimeToHarvest)
58 {
59 return !(EClass._zone is Zone_Harvest);
60 }
61 return false;
62 }
63 return true;
64 }
65 return false;
66 }
67 goto IL_007b;
68 IL_007b:
69 return true;
70 }
71 }
72
73 public override bool CanManualCancel()
74 {
75 return true;
76 }
77
78 public override string GetBaseText(string str)
79 {
80 if (IsReapSeed)
81 {
82 return "TaskHarvestSeed".lang();
83 }
84 if (mode == HarvestType.Disassemble)
85 {
86 string text = (HaveHarvestThing() ? "TaskDisassemble" : "TaskDisassemble_destroy").lang();
87 string idRecipe = (IsObj ? pos.sourceObj.RecipeID : ((target != null) ? target.source.RecipeID : ""));
89 {
90 text = text + " " + "TaskDisassemble_newrecipe".lang();
91 }
92 return text;
93 }
94 if (!base.IsHarvest)
95 {
96 return base.GetBaseText(str);
97 }
98 return "actHarvest".lang();
99 }
100
101 public override string GetTextSmall(Card c)
102 {
103 if (IsObj)
104 {
105 return base.GetTextSmall(c);
106 }
107 if (target == null)
108 {
109 return "";
110 }
111 return target.Name;
112 }
113
114 public static TaskHarvest TryGetAct(Chara c, Point p)
115 {
116 Thing t = c.Tool;
117 bool hasTool = t != null && (t.HasElement(225) || t.HasElement(220));
118 bool hasDiggingTool = t != null && t.HasElement(230);
119 if (t != null)
120 {
121 if (t.trait is TraitToolShears)
122 {
123 return null;
124 }
125 if (t.trait is TraitToolWaterCan)
126 {
127 return null;
128 }
129 if (t.trait is TraitToolMusic)
130 {
131 return null;
132 }
133 if (t.trait is TraitToolSickle && !p.cell.CanReapSeed())
134 {
135 return null;
136 }
137 }
138 if (p.HasObj && IsValidTarget(p.sourceObj.reqHarvest))
139 {
140 return new TaskHarvest
141 {
142 pos = p.Copy()
143 };
144 }
145 if (p.HasThing)
146 {
147 for (int num = p.Things.Count - 1; num >= 0; num--)
148 {
149 t = p.Things[num];
150 if (t.trait.ReqHarvest != null && IsValidTarget(t.trait.ReqHarvest.Split(',')))
151 {
152 return new TaskHarvest
153 {
154 pos = p.Copy(),
155 mode = HarvestType.Thing,
156 target = t
157 };
158 }
159 }
160 for (int num2 = p.Things.Count - 1; num2 >= 0; num2--)
161 {
162 t = p.Things[num2];
164 {
165 return new TaskHarvest
166 {
167 pos = p.Copy(),
168 mode = HarvestType.Disassemble,
169 target = t
170 };
171 }
172 }
173 }
174 return null;
175 bool IsValidTarget(string[] raw)
176 {
177 if (raw[0] == "digging")
178 {
179 return hasDiggingTool;
180 }
181 bool num3 = p.cell.CanHarvest();
182 int num4 = (num3 ? 250 : EClass.sources.elements.alias[raw[0]].id);
183 bool flag = ((!num3 && num4 != 250) ? true : false);
184 if (!flag && t != null && !t.trait.CanHarvest)
185 {
186 return false;
187 }
188 return !flag || hasTool;
189 }
190 }
191
192 public override bool CanProgress()
193 {
194 if (tool != null && tool.trait is TraitToolSickle && !pos.cell.CanReapSeed())
195 {
196 return false;
197 }
198 if (IsObj)
199 {
201 if (base.CanProgress())
202 {
203 return pos.HasObj;
204 }
205 return false;
206 }
207 if (target == null || !target.ExistsOnMap)
208 {
209 return false;
210 }
211 return base.CanProgress();
212 }
213
214 public override HitResult GetHitResult()
215 {
216 if (harvestingCrop && !base.IsHarvest)
217 {
218 return HitResult.Default;
219 }
220 if (IsObj)
221 {
222 if (base.IsHarvest)
223 {
224 return HitResult.Valid;
225 }
226 if (pos.HasObj)
227 {
228 return HitResult.Valid;
229 }
231 {
232 return HitResult.Valid;
233 }
234 return HitResult.Default;
235 }
236 if (target == null || !target.ExistsOnMap)
237 {
238 return HitResult.Default;
239 }
240 return HitResult.Valid;
241 }
242
243 public override void OnCreateProgress(Progress_Custom p)
244 {
246 string i = (IsObj ? pos.cell.GetObjName() : target.Name);
247 SourceMaterial.Row mat = (IsObj ? pos.cell.matObj : target.material);
248 GrowSystem growth = pos.growth;
249 float num = (base.IsHarvest ? 0.5f : ((!IsObj) ? 1f : ((growth != null) ? growth.MtpProgress : 1f)));
250 int exp = 50;
253 p.textHint = i;
254 p.maxProgress = (int)((float)(maxProgress * 150) * num / 100f);
255 p.interval = 1;
256 p.onProgressBegin = delegate
257 {
258 if (TryGetAct(owner, pos) == null)
259 {
260 p.Cancel();
261 }
262 else if (base.IsTooHard)
263 {
264 owner.Say((mode == HarvestType.Disassemble) ? "tooHardToDisassemble" : "tooHardToHarvest", owner, i);
265 p.Cancel();
266 }
267 else if (mode == HarvestType.Disassemble)
268 {
269 owner.Say("disassemble_start", owner, owner.Tool, i);
270 }
271 else if (owner.Tool == null)
272 {
273 owner.Say("harvestHand_start", owner, i);
274 }
275 else
276 {
277 owner.Say("harvest_start", owner, owner.Tool, i);
278 }
279 };
280 p.onProgress = delegate(Progress_Custom _p)
281 {
284 if (_p.progress % 2 == 0)
285 {
286 if (IsObj)
287 {
288 if (base.IsHarvest && growth != null)
289 {
291 if (growth.AnimeProgress != 0)
292 {
293 pos.Animate(growth.AnimeProgress);
294 }
295 return;
296 }
297 pos.Animate(AnimeID.HitObj);
298 }
299 else
300 {
301 target.PlayAnime(AnimeID.HitObj);
302 }
304 mat.PlayHitEffect(pos);
305 mat.AddBlood(pos);
306 effectFrame += maxProgress / 4 + 1;
307 if (EClass._zone.IsCrime(owner, this))
308 {
310 }
311 }
312 };
313 p.onProgressComplete = delegate
314 {
315 string idRecipe = (IsObj ? pos.sourceObj.RecipeID : ((target != null) ? target.source.RecipeID : ""));
317 int num2 = ((EClass.rnd(3) != 0) ? 1 : 0);
318 if (IsObj)
319 {
320 SourceObj.Row sourceObj = pos.sourceObj;
321 bool flag = false;
322 if (difficulty >= 0 && EClass.rnd(6) == 0)
323 {
324 flag = true;
325 }
326 if (difficulty >= 2 && EClass.rnd(3) == 0)
327 {
328 flag = true;
329 }
330 if (flag && growth != null)
331 {
332 growth.OnHitFail(owner);
333 }
334 if (EClass._zone is Zone_Harvest && !base.IsHarvest && pos.IsFarmField)
335 {
337 pos.SetObj();
338 }
339 else
340 {
341 if (base.IsHarvest && !IsReapSeed)
342 {
343 if (pos.growth.CanHarvest())
344 {
345 harvestingCrop = true;
346 }
348 }
349 else if (growth != null && !IsReapSeed)
350 {
352 }
353 else
354 {
355 EClass._map.MineObj(pos, this);
356 }
357 if (sourceObj.alias == "mound")
358 {
359 if (EClass.rnd(7) == 0)
360 {
361 EClass._zone.AddThing("plat", pos);
362 }
363 else if (EClass.rnd(3) == 0)
364 {
366 }
367 else
368 {
369 EClass._zone.AddThing("bone", pos);
370 }
371 }
372 }
373 }
374 else
375 {
376 exp = target.Num * 5;
377 num2 = target.Num / 3 + EClass.rnd(target.Num / 3 + 2);
379 {
380 HarvestThing();
381 }
382 }
383 if (EClass._zone.IsCrime(owner, this) && EClass.rnd(3) != 0)
384 {
386 }
387 if (backerObj != null)
388 {
389 if (backerObj != null && !backerObj.loot.IsEmpty() && !EClass.player.doneBackers.Contains(backerObj.id))
390 {
391 if (EClass.sources.cards.map.ContainsKey(backerObj.loot))
392 {
393 Thing thing = ThingGen.Create(backerObj.loot);
394 switch (backerObj.id)
395 {
396 case 490:
397 case 867:
398 case 5160:
399 thing.c_charges = 0;
400 thing.c_priceFix = -100;
401 break;
402 case 2531:
403 thing.MakeFoodFrom("cloud_electric");
404 break;
405 case 1027:
406 thing.ChangeMaterial(25);
407 thing.SetBlessedState(BlessedState.Doomed);
408 thing.ChangeRarity(Rarity.Legendary);
409 break;
410 case 4565:
411 EClass._zone.AddThing("rod", pos);
412 EClass._zone.AddThing("money", pos).SetNum(121);
413 break;
414 case 5367:
415 thing.Dye("obsidian");
416 break;
417 case 471:
418 case 1828:
419 case 5765:
420 thing.SetBlessedState(BlessedState.Cursed);
421 break;
422 case 5529:
423 thing.ChangeMaterial(25);
424 break;
425 case 1854:
426 thing.decay = 10000;
427 break;
428 case 4788:
429 thing.SetEncLv(1);
430 break;
431 case 4615:
432 thing.ChangeMaterial("meat");
433 break;
434 }
435 EClass._zone.AddCard(thing, pos);
436 }
437 else
438 {
439 Debug.LogError("exception: Backer Loot not valid:" + backerObj.id + "/" + backerObj.loot);
440 }
441 Debug.Log(backerObj.id + "/" + backerObj.Name + "/" + backerObj.loot);
442 }
443 EClass.player.doneBackers.Add(backerObj.id);
444 if (!backerObj.Text.IsEmpty() && EClass.core.config.backer.Show(backerObj))
445 {
446 bool num3 = backerObj.type == 1;
447 Msg.Say(num3 ? "backerRemain_read" : "backerTree_read");
448 Msg.Say(num3 ? "backerRemain" : "backerTree", backerObj.Text);
449 }
450 }
451 if (owner.IsPC)
452 {
454 }
456 if (wasReapSeed)
457 {
458 owner.ModExp(286, 20);
459 }
460 owner.stamina.Mod(-num2);
461 if (owner != null && owner.IsPC)
462 {
464 }
465 };
466 }
467
468 public string GetIdDismantled()
469 {
470 string result = target.source.components[0].Split('|')[0].Split('/')[0];
472 {
473 result = target.material.thing;
474 }
475 return result;
476 }
477
478 public bool ShouldGenerateDismantled(string dest)
479 {
480 if (target.trait is TraitGrave)
481 {
482 return false;
483 }
484 if (dest.Contains("$") || dest.Contains("#") || dest.Contains("@") || dest.Contains("-"))
485 {
486 return false;
487 }
488 if (dest == target.id || !EClass.sources.cards.map.ContainsKey(dest))
489 {
490 return false;
491 }
492 if (target.source.components.IsEmpty())
493 {
494 return false;
495 }
496 return true;
497 }
498
499 public bool HaveHarvestThing()
500 {
501 string idDismantled = GetIdDismantled();
502 return ShouldGenerateDismantled(idDismantled);
503 }
504
505 public void HarvestThing()
506 {
507 string text = GetIdDismantled();
508 float num = target.Num;
509 float num2 = 1.0999999f;
510 if (text == "log" || text == "rock")
511 {
512 num2 = 2.1999998f;
513 }
514 string text2 = target.id;
515 if (text2 == "glass" || text2 == "brick")
516 {
517 num2 = 2.1999998f;
518 }
519 if (target.trait is TraitAmmo)
520 {
521 num2 = 50f;
522 }
523 float num3 = num % num2;
524 num /= num2;
525 Debug.Log("num:" + num + " div:" + num3 + " chance:" + num2 + " check:" + (num2 - num3 + 1f));
526 if (num3 > 0f && EClass.rndf(num2 - num3 + 1f) < 1f)
527 {
528 num += 1f;
529 }
530 if (target.sockets != null)
531 {
533 }
534 int decay = target.decay;
535 int lV = target.LV;
536 target.Die(null, EClass.pc);
537 if ((int)num <= 0 || !ShouldGenerateDismantled(text))
538 {
539 return;
540 }
541 if (target.isCopy)
542 {
543 text = "ash3";
544 }
546 {
547 fixedQuality = true
548 });
549 Thing thing = ThingGen.Create(text, 1, Mathf.Max(1, lV * 2 / 3));
550 if (thing != null)
551 {
552 thing.SetNum((int)num);
554 thing.decay = decay;
555 if (thing.IsDecayed && thing.IsFood)
556 {
557 thing.elements.SetBase(73, -10);
558 }
560 }
561 }
562}
AnimeID
Definition: AnimeID.cs:2
BlessedState
Definition: BlessedState.cs:2
HitResult
Definition: HitResult.cs:2
Rarity
Definition: Rarity.cs:2
virtual Status Cancel()
Definition: AIAct.cs:291
new Chara owner
Definition: AIAct.cs:14
int progress
Definition: AIProgress.cs:5
virtual bool CanReapSeed
void SetTarget(Chara c, Thing _tool=null)
static BuildMenu Instance
Definition: BuildMenu.cs:77
static void Set(CardBlueprint _bp)
virtual void NextFrame()
Definition: Card.cs:11
bool IsDecayed
Definition: Card.cs:2147
bool isMasked
Definition: Card.cs:562
ElementContainerCard elements
Definition: Card.cs:37
string id
Definition: Card.cs:31
bool isNPCProperty
Definition: Card.cs:526
bool HasElement(int ele, int req=1)
Definition: Card.cs:5214
SourceMaterial.Row material
Definition: Card.cs:1927
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:5404
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Definition: Card.cs:2838
bool isCopy
Definition: Card.cs:850
Thing Tool
Definition: Card.cs:2270
bool IsEquipmentOrRangedOrAmmo
Definition: Card.cs:2090
void CalculateFOV()
Definition: Card.cs:5728
string Name
Definition: Card.cs:2013
bool ExistsOnMap
Definition: Card.cs:1961
void EjectSockets()
Definition: Card.cs:3323
Thing SetNum(int a)
Definition: Card.cs:3242
virtual void Die(Element e=null, Card origin=null, AttackSource attackSource=AttackSource.None)
Definition: Card.cs:4471
int decay
Definition: Card.cs:202
bool IsFood
Definition: Card.cs:2051
virtual void SetBlessedState(BlessedState s)
Definition: Card.cs:3572
Point pos
Definition: Card.cs:55
void Dye(string idMat)
Definition: Card.cs:5267
Trait trait
Definition: Card.cs:49
void SetEncLv(int a)
Definition: Card.cs:3567
Card MakeFoodFrom(string _id)
Definition: Card.cs:4918
bool isHidden
Definition: Card.cs:502
void ModExp(string alias, int a)
Definition: Card.cs:2508
int Num
Definition: Card.cs:154
void PlayAnime(AnimeID id, bool force=false)
Definition: Card.cs:5423
SourceCategory.Row category
Definition: Card.cs:1925
virtual void ChangeRarity(Rarity q)
Definition: Card.cs:3597
List< int > sockets
Definition: Card.cs:43
CardRenderer renderer
Definition: Card.cs:57
int LV
Definition: Card.cs:370
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:6046
bool CanHarvest()
Definition: Cell.cs:1660
string GetObjName()
Definition: Cell.cs:1600
bool CanReapSeed()
Definition: Cell.cs:1665
Definition: Chara.cs:10
override bool IsPC
Definition: Chara.cs:597
Stats stamina
Definition: Chara.cs:955
override void LookAt(Card c)
Definition: Chara.cs:3219
BackerContentConfig backer
Definition: CoreConfig.cs:600
bool enable
Definition: CoreDebug.cs:285
bool godBuild
Definition: CoreDebug.cs:303
CoreConfig config
Definition: Core.cs:70
Definition: EClass.cs:5
static Game game
Definition: EClass.cs:8
static int rnd(int a)
Definition: EClass.cs:50
static Core core
Definition: EClass.cs:6
static Zone _zone
Definition: EClass.cs:20
static Map _map
Definition: EClass.cs:18
static SourceManager sources
Definition: EClass.cs:42
static float rndf(float a)
Definition: EClass.cs:79
static Player player
Definition: EClass.cs:12
static Chara pc
Definition: EClass.cs:14
static CoreDebug debug
Definition: EClass.cs:48
void ModExp(int ele, int a, bool chain=false)
Element SetBase(string alias, int v, int potential=0)
bool disableUsermapBenefit
GamePrincipal principal
Definition: Game.cs:221
bool CanHarvest()
Definition: GrowSystem.cs:482
virtual AnimeID AnimeProgress
Definition: GrowSystem.cs:95
virtual void OnHitFail(Chara c)
Definition: GrowSystem.cs:500
virtual bool IsCrimeToHarvest
Definition: GrowSystem.cs:89
void OnProgressComplete(Chara c)
Definition: GrowSystem.cs:504
virtual string GetSoundProgress()
Definition: GrowSystem.cs:121
void Harvest(Chara c)
Definition: GrowSystem.cs:599
void DestroyObj(Point point)
Definition: Map.cs:1812
void TrySmoothPick(Cell cell, Thing t, Chara c)
Definition: Map.cs:1791
void MineObj(Point point, Task task=null, Chara c=null)
Definition: Map.cs:1827
SourceBacker.Row GetBackerObj(Point p)
Definition: Map.cs:1579
Definition: Msg.cs:5
static string Say(string idLang, string ref1, string ref2=null, string ref3=null, string ref4=null)
Definition: Msg.cs:58
RecipeManager recipes
Definition: Player.cs:898
void ModKarma(int a)
Definition: Player.cs:2289
HashSet< int > doneBackers
Definition: Player.cs:874
Definition: Point.cs:9
bool HasDecal
Definition: Point.cs:139
void SetObj(int id=0, int value=1, int dir=0)
Definition: Point.cs:892
Point Copy()
Definition: Point.cs:467
bool IsBlocked
Definition: Point.cs:339
List< Thing > Things
Definition: Point.cs:314
bool IsFarmField
Definition: Point.cs:127
SoundSource PlaySound(string id, bool synced=true, float v=1f, bool spatial=true)
Definition: Point.cs:1217
bool HasThing
Definition: Point.cs:239
SourceObj.Row sourceObj
Definition: Point.cs:69
bool TryWitnessCrime(Chara criminal, Chara target=null, int radius=4, Func< Chara, bool > funcWitness=null)
Definition: Point.cs:845
bool HasObj
Definition: Point.cs:137
Cell cell
Definition: Point.cs:51
void Animate(AnimeID id, bool animeBlock=false)
Definition: Point.cs:1266
GrowSystem growth
Definition: Point.cs:77
void ComeUpWithRecipe(string idRecipe, int chanceForRandomRecipe=0)
bool CanCeomUpWithRecipe(string idRecipe)
Dictionary< string, CardRow > map
Definition: SourceCard.cs:8
SourceCard cards
SourceElement elements
string GetSoundImpact(RenderRow c=null)
void AddBlood(Point p, int a=1)
void PlayHitEffect(Point p, int emit=2)
virtual void Mod(int a)
Definition: Stats.cs:135
override bool CanProgress()
Definition: TaskHarvest.cs:192
bool HaveHarvestThing()
Definition: TaskHarvest.cs:499
override string GetTextSmall(Card c)
Definition: TaskHarvest.cs:101
string GetIdDismantled()
Definition: TaskHarvest.cs:468
bool wasReapSeed
Definition: TaskHarvest.cs:5
HarvestType mode
Definition: TaskHarvest.cs:11
bool IsReapSeed
Definition: TaskHarvest.cs:16
override bool IsHostileAct
Definition: TaskHarvest.cs:40
bool harvestingCrop
Definition: TaskHarvest.cs:9
void HarvestThing()
Definition: TaskHarvest.cs:505
bool wasCrime
Definition: TaskHarvest.cs:7
override int destDist
Definition: TaskHarvest.cs:35
static TaskHarvest TryGetAct(Chara c, Point p)
Definition: TaskHarvest.cs:114
override bool IsGrowth
Definition: TaskHarvest.cs:37
override HitResult GetHitResult()
Definition: TaskHarvest.cs:214
override HarvestType harvestType
Definition: TaskHarvest.cs:31
override int RightHand
Definition: TaskHarvest.cs:33
bool ShouldGenerateDismantled(string dest)
Definition: TaskHarvest.cs:478
override string GetBaseText(string str)
Definition: TaskHarvest.cs:78
override void OnCreateProgress(Progress_Custom p)
Definition: TaskHarvest.cs:243
override bool CanManualCancel()
Definition: TaskHarvest.cs:73
Point pos
Definition: TaskPoint.cs:11
static Thing CreateFromCategory(string idCat, int lv=-1)
Definition: ThingGen.cs:75
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
SourceThing.Row source
Definition: Thing.cs:11
string alias
Definition: TileRow.cs:12
virtual bool CanHarvest
Definition: Trait.cs:86
virtual bool CanBeDisassembled
Definition: Trait.cs:294
virtual string ReqHarvest
Definition: Trait.cs:291
Card AddThing(string id, int x, int z)
Definition: Zone.cs:1883
virtual bool IsUserZone
Definition: Zone.cs:264
bool IsCrime(Chara c, Act act)
Definition: Zone.cs:3259
Card AddCard(Card t, Point point)
Definition: Zone.cs:1893