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