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