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