Elin Decompiled Documentation EA 23.211 Nightly Patch 1
Loading...
Searching...
No Matches
BaseTaskHarvest.cs
Go to the documentation of this file.
1using System;
2using UnityEngine;
3
5{
6 public enum HarvestType
7 {
8 Floor,
9 Block,
10 Obj,
11 Thing,
13 }
14
15 public Thing target;
16
18
19 public int matHardness;
20
21 public int idEle;
22
23 public int reqLv;
24
25 public int toolLv;
26
27 public int maxProgress;
28
29 public int efficiency;
30
31 public int difficulty;
32
33 public int effectFrame = 1;
34
35 public bool isToolRequired;
36
37 public Thing tool;
38
39 public bool IsTooHard
40 {
41 get
42 {
44 {
45 return reqLv > toolLv;
46 }
47 return false;
48 }
49 }
50
51 public bool IsHarvest => pos.cell.CanHarvest();
52
53 public virtual string IdRecipe => "";
54
55 public virtual bool CanReapSeed => pos.cell.CanReapSeed();
56
57 public virtual HarvestType harvestType => HarvestType.Block;
58
59 public virtual bool IsGrowth => false;
60
61 public override bool CanPressRepeat => true;
62
63 public override int LeftHand => -1;
64
66
67 public virtual string GetBaseText(string str)
68 {
69 return base.GetText(str);
70 }
71
72 public override string GetTextSmall(Card c)
73 {
74 return pos.cell.GetObjName();
75 }
76
77 public override string GetText(string str = "")
78 {
79 if (owner == null)
80 {
81 owner = EClass.pc;
82 }
84 string text = "tHarvest".lang(GetBaseText(str), (EClass.pc.Tool == null) ? "hand".lang() : owner.Tool.NameSimple, toolLv.ToString() ?? "");
85 if (EClass.pc.HasElement(1661))
86 {
88 switch (recipeLearnState)
89 {
90 case RecipeManager.LearnState.Learnable:
91 text = text + " " + "TaskDisassemble_newrecipe".lang();
92 break;
93 default:
94 text = text + " " + ("TaskDisassemble_" + recipeLearnState).lang();
95 break;
96 case RecipeManager.LearnState.Unavailable:
97 break;
98 }
99 }
100 text = text + " (" + GetTextDifficulty() + ")";
101 if (IsTooHard)
102 {
103 text = text.TagColor(Color.gray);
104 }
105 return text;
106 }
107
108 public static Thing GetBestTool(Chara c, Point p)
109 {
111 {
112 pos = p
113 };
114 task.SetOwner(c);
115 Thing tool = null;
116 int best = 0;
117 c.things.Foreach(delegate(Thing t)
118 {
119 if (t.trait is TraitTool)
120 {
121 task.SetTarget(c, t);
122 if (task.efficiency > best)
123 {
124 best = task.efficiency;
125 tool = t;
126 }
127 }
128 });
129 return tool;
130 }
131
132 public void SetTarget(Chara c, Thing _tool = null)
133 {
134 if (c == null)
135 {
136 c = EClass.pc;
137 }
138 if (_tool == null)
139 {
140 _tool = c.Tool;
141 }
142 tool = _tool;
143 string[] array = null;
144 SourceMaterial.Row row = null;
145 switch (this.harvestType)
146 {
147 case HarvestType.Obj:
148 array = pos.sourceObj.reqHarvest;
149 row = pos.cell.matObj;
150 break;
151 case HarvestType.Thing:
152 array = target.trait.ReqHarvest.Split(',');
153 row = target.material;
154 break;
155 case HarvestType.Disassemble:
156 if (target == null)
157 {
158 return;
159 }
160 array = new string[2] { "handicraft", "1" };
161 row = target.material;
162 break;
163 case HarvestType.Floor:
164 if (pos.cell.HasBridge)
165 {
166 array = pos.sourceBridge.reqHarvest;
167 row = pos.matBridge;
168 }
169 else
170 {
171 array = pos.sourceFloor.reqHarvest;
172 row = pos.matFloor;
173 }
174 break;
175 case HarvestType.Block:
176 if (pos.HasBlock)
177 {
178 array = pos.sourceBlock.reqHarvest;
179 row = pos.matBlock;
180 break;
181 }
182 array = new string[pos.sourceFloor.reqHarvest.Length];
183 Array.Copy(pos.sourceFloor.reqHarvest, array, pos.sourceFloor.reqHarvest.Length);
184 array[0] = "mining";
185 row = pos.matFloor;
186 break;
187 }
188 matHardness = row.hardness;
189 if (this.harvestType == HarvestType.Obj)
190 {
191 matHardness = matHardness * ((pos.growth != null) ? pos.growth.GetHp() : pos.sourceObj.hp) / 100;
192 }
193 if (row.tag.Contains("hard"))
194 {
195 matHardness *= 3;
196 }
197 HarvestType harvestType = this.harvestType;
198 if ((uint)harvestType <= 1u && row.id == 0)
199 {
200 matHardness *= 100;
201 }
202 idEle = (IsHarvest ? 250 : EClass.sources.elements.alias[array[0]].id);
203 reqElement = Element.Create(idEle);
204 int num = array[1].ToInt();
205 reqLv = matHardness + num;
206 isToolRequired = ((!IsHarvest && idEle != 250) ? true : false);
207 toolLv = 0;
208 if (tool != null)
209 {
210 int num2 = ((idEle == 220 || idEle == 225) ? GetToolEfficiency(tool, row) : 100);
211 toolLv += tool.material.hardness * num2 / 100;
212 toolLv += (int)(tool.encLV + tool.blessedState);
213 }
214 toolLv += c.Evalue(idEle) * 3 / 2;
215 if (toolLv < 0)
216 {
217 toolLv = 1;
218 }
219 efficiency = (toolLv + 5) * 100 / ((reqLv + 5) * 140 / 100);
220 if (efficiency < 50)
221 {
222 efficiency = 50;
223 }
224 if (IsTooHard)
225 {
226 difficulty = 3;
227 }
228 else if (efficiency > 150)
229 {
230 difficulty = 0;
231 }
232 else if (efficiency > 100)
233 {
234 difficulty = 1;
235 }
236 else
237 {
238 difficulty = 2;
239 }
240 PlantData plantData = EClass._map.TryGetPlant(pos.cell);
241 if (this.harvestType == HarvestType.Obj && IsHarvest && plantData != null && plantData.size > 0)
242 {
243 maxProgress = (int)Mathf.Clamp(Rand.Range(8f, 10f) * (float)(100 + plantData.size * 100 + plantData.size * plantData.size * 30) / (float)efficiency, 2f, 1000f);
244 }
245 else
246 {
247 maxProgress = (int)Mathf.Clamp(Rand.Range(8f, 16f) * 100f / (float)efficiency, 2f, 30f);
248 }
249 }
250
251 public static int GetReqEle(string _raw)
252 {
253 string[] array = _raw.Split(',');
254 return EClass.sources.elements.alias[array[0]].id;
255 }
256
258 {
259 int[] toolEfficiency = GetToolEfficiency(mat);
260 _ = new int[2];
261 if (!t.HasElement(220))
262 {
263 toolEfficiency[0] = 0;
264 }
265 if (!t.HasElement(225))
266 {
267 toolEfficiency[1] = 0;
268 }
269 if (t.trait is TraitToolHammer)
270 {
271 toolEfficiency[0] = 50 + owner.Evalue(261);
272 }
273 int num = 20;
274 int[] array = toolEfficiency;
275 foreach (int num2 in array)
276 {
277 if (num2 > num)
278 {
279 num = num2;
280 }
281 }
282 return num;
283 }
284
285 public override bool CanProgress()
286 {
287 if (tool != owner.Tool)
288 {
289 return false;
290 }
291 return base.CanProgress();
292 }
293
295 {
296 switch (mat.category)
297 {
298 case "bone":
299 return new int[2] { 100, 50 };
300 case "ore":
301 case "crystal":
302 case "rock":
303 case "gem":
304 return new int[2] { 100, 25 };
305 case "organic":
306 case "skin":
307 return new int[2] { 50, 100 };
308 case "grass":
309 case "fiber":
310 case "wood":
311 return new int[2] { 25, 100 };
312 case "soil":
313 case "water":
314 return new int[2] { 100, 100 };
315 default:
316 return new int[2] { 100, 100 };
317 }
318 }
319
320 public string GetTextDifficulty()
321 {
322 return Lang.GetList("skillDiff")[difficulty];
323 }
324}
new Chara owner
Definition: AIAct.cs:14
void SetOwner(Chara c)
Definition: AIAct.cs:179
override CursorInfo CursorIcon
string GetTextDifficulty()
override string GetTextSmall(Card c)
int GetToolEfficiency(Thing t, SourceMaterial.Row mat)
static Thing GetBestTool(Chara c, Point p)
virtual string GetBaseText(string str)
override bool CanPressRepeat
virtual bool CanReapSeed
override int LeftHand
virtual bool IsGrowth
virtual HarvestType harvestType
override bool CanProgress()
virtual string IdRecipe
int[] GetToolEfficiency(SourceMaterial.Row mat)
override string GetText(string str="")
void SetTarget(Chara c, Thing _tool=null)
static int GetReqEle(string _raw)
Definition: Card.cs:11
bool HasElement(int ele, int req=1)
Definition: Card.cs:5767
SourceMaterial.Row material
Definition: Card.cs:2025
Thing Tool
Definition: Card.cs:2384
Trait trait
Definition: Card.cs:51
ThingContainer things
Definition: Card.cs:36
string NameSimple
Definition: Card.cs:2113
int Evalue(int ele)
Definition: Card.cs:2545
bool CanHarvest()
Definition: Cell.cs:1664
string GetObjName()
Definition: Cell.cs:1604
bool CanReapSeed()
Definition: Cell.cs:1669
Definition: Chara.cs:10
static CursorInfo Cut
Definition: CursorSystem.cs:62
Definition: EClass.cs:5
static Map _map
Definition: EClass.cs:18
static SourceManager sources
Definition: EClass.cs:42
static Player player
Definition: EClass.cs:12
static Chara pc
Definition: EClass.cs:14
static Element Create(int id, int v=0)
Definition: ELEMENT.cs:1100
Definition: Lang.cs:6
static string[] GetList(string id)
Definition: Lang.cs:114
PlantData TryGetPlant(Point p)
Definition: Map.cs:1942
int size
Definition: PlantData.cs:15
RecipeManager recipes
Definition: Player.cs:1094
Definition: Point.cs:9
Cell cell
Definition: Point.cs:51
Definition: Rand.cs:4
static int Range(int min, int max)
Definition: Rand.cs:42
LearnState GetRecipeLearnState(string idRecipe)
SourceElement elements
Point pos
Definition: TaskPoint.cs:11
void Foreach(Action< Thing > action, bool onlyAccessible=true)
Definition: Thing.cs:8
virtual string ReqHarvest
Definition: Trait.cs:302