Elin Decompiled Documentation EA 23.187 Stable
Loading...
Searching...
No Matches
CraftUtil.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using UnityEngine;
4
5public class CraftUtil : EClass
6{
7 public enum MixType
8 {
10 Food,
11 NoMix
12 }
13
14 public enum WrapType
15 {
16 Love,
17 Dark
18 }
19
20 public static string[] ListFoodEffect = new string[2] { "exp", "pot" };
21
22 public static void ModRandomFoodEnc(Thing t)
23 {
24 List<Element> list = new List<Element>();
25 foreach (Element value in t.elements.dict.Values)
26 {
27 if (value.IsFoodTrait)
28 {
29 list.Add(value);
30 }
31 }
32 if (list.Count != 0)
33 {
34 Element element = list.RandomItem();
35 t.elements.ModBase(element.id, EClass.rnd(6) + 1);
36 if (element.Value > 60)
37 {
38 t.elements.SetTo(element.id, 60);
39 }
40 }
41 }
42
43 public static void AddRandomFoodEnc(Thing t)
44 {
45 List<SourceElement.Row> list = EClass.sources.elements.rows.Where((SourceElement.Row e) => e.foodEffect.Length > 1 && ListFoodEffect.Contains(e.foodEffect[0])).ToList();
46 list.ForeachReverse(delegate(SourceElement.Row e)
47 {
48 if (t.elements.dict.ContainsKey(e.id))
49 {
50 list.Remove(e);
51 }
52 });
53 if (list.Count != 0)
54 {
55 SourceElement.Row row = list.RandomItemWeighted((SourceElement.Row a) => a.chance);
56 t.elements.SetBase(row.id, 1);
57 t.c_seed = row.id;
58 }
59 }
60
61 public static void MakeDish(Thing food, int lv, Chara crafter = null)
62 {
64 List<Thing> list = new List<Thing>();
65 RecipeSource recipeSource = RecipeManager.Get(food.id);
66 Debug.Log(recipeSource);
67 if (recipeSource == null)
68 {
69 return;
70 }
71 int num = Mathf.Min(EClass.rnd(lv), 50);
72 foreach (Recipe.Ingredient ingredient in recipeSource.GetIngredients())
73 {
74 Thing thing = ThingGen.Create(ingredient.id, -1, lv);
75 if (thing.id == "deadbody")
76 {
77 thing = ThingGen.Create("_meat");
78 }
79 thing = thing.TryMakeRandomItem(lv, TryMakeRandomItemSource.Cooking, crafter);
80 TraitSeed.LevelSeed(thing, null, EClass.rnd(lv / 4) + 1);
81 thing.SetEncLv(thing.encLV / 2);
82 if (num > 0 && EClass.rnd(3) == 0)
83 {
84 thing.elements.SetBase(2, num);
85 }
86 list.Add(thing);
87 }
88 MakeDish(food, list, num, crafter);
89 if (crafter != null && crafter.id != "rodwyn")
90 {
91 if (food.HasElement(709))
92 {
93 food.elements.Remove(709);
94 }
95 if (food.HasElement(708) && !crafter.HasElement(1205))
96 {
97 food.elements.Remove(708);
98 }
99 }
100 }
101
102 public static Thing MakeDarkSoup()
103 {
104 Thing thing = ThingGen.Create("soup_dark");
105 for (int i = 0; i < 4 + EClass.rnd(4); i++)
106 {
107 Chara c = EClass._map.charas.RandomItem();
108 WrapIngredient(thing, c, GetRandomDarkSoupIngredient(c), WrapType.Dark);
109 }
111 {
112 thing.c_IDTState = 1;
113 }
114 return thing;
115 }
116
118 {
119 return ThingGen.CreateFromFilter("darksoup", c.LV);
120 }
121
122 public static Thing MakeLoveLunch(Chara c)
123 {
124 Thing thing = ThingGen.Create("lunch_love");
125 thing.MakeRefFrom(c);
126 int num = c.uid + EClass.world.date.year * 10000 + EClass.world.date.month * 100;
127 Rand.SetSeed(num);
128 float num2 = Mathf.Clamp(1f + Mathf.Sqrt(c.Evalue(287) / 5), 2f, 6f);
130 {
131 thing.c_IDTState = 5;
132 }
133 for (int i = 0; (float)i < num2; i++)
134 {
135 Rand.SetSeed(num + i);
136 WrapIngredient(thing, c, GetRandomLoveLunchIngredient(c), WrapType.Love);
137 }
138 thing.elements.SetBase(701, 0);
139 if (thing.Evalue(753) < 0)
140 {
141 thing.elements.SetBase(753, 0);
142 }
143 Rand.SetSeed();
144 return thing;
145 }
146
148 {
149 Thing thing = null;
150 for (int i = 0; i < 3; i++)
151 {
152 thing = ThingGen.Create("dish", -1, c.Evalue(287) + 5 + (EClass.debug.enable ? c.LV : 0));
153 if (!thing.HasTag(CTAG.dish_fail))
154 {
155 break;
156 }
157 }
158 MakeDish(thing, c.LV, c);
159 return thing;
160 }
161
162 public static void WrapIngredient(Card product, Chara c, Card ing, WrapType wrapType)
163 {
164 if (product.c_mixedFoodData == null)
165 {
166 product.c_mixedFoodData = new MixedFoodData();
167 }
168 product.c_mixedFoodData.texts.Add(ing.Name + ((wrapType == WrapType.Dark) ? "isMixedBy".lang(c.NameSimple) : ""));
169 foreach (Element value in ing.elements.dict.Values)
170 {
171 if (!IsValidTrait(value))
172 {
173 continue;
174 }
175 if (value.IsFoodTraitMain)
176 {
177 int num = value.Value;
178 if (ing.id == "lunch_dystopia" && (wrapType == WrapType.Dark || num < 0))
179 {
180 num *= -1;
181 }
182 product.elements.ModBase(value.id, num);
183 }
184 else
185 {
186 int num2 = product.elements.Base(value.id);
187 if ((num2 <= 0 && value.Value < 0 && value.Value < num2) || (value.Value > 0 && value.Value > num2))
188 {
189 product.elements.SetTo(value.id, value.Value);
190 }
191 }
192 }
193 product.elements.ModBase(10, ing.Evalue(10));
194 static bool IsValidTrait(Element e)
195 {
196 if (e.HasTag("noInherit"))
197 {
198 return false;
199 }
200 if (e.IsFoodTrait || e.IsTrait || e.id == 2)
201 {
202 return true;
203 }
204 return false;
205 }
206 }
207
208 public static void MakeDish(Card food, List<Thing> ings, int qualityBonus, Chara crafter = null)
209 {
210 List<Thing> list = new List<Thing>();
211 bool flag = food.sourceCard.vals.Contains("fixed");
212 for (int i = 0; i < ings.Count; i++)
213 {
214 Thing thing = ings[i];
215 if (flag)
216 {
217 list.Add(thing);
218 break;
219 }
220 if (!IsIgnoreName(thing))
221 {
222 list.Add(thing);
223 }
224 }
225 if (list.Count > 0)
226 {
227 Thing thing2 = list.RandomItem();
228 if (thing2 != null)
229 {
230 food.MakeRefFrom(thing2);
231 if (thing2.c_idRefCard != null)
232 {
233 food.c_idRefCard = thing2.c_idRefCard;
234 food.c_altName = food.TryGetFoodName(thing2);
235 if (thing2.id == "_egg" || thing2.id == "egg_fertilized")
236 {
237 food.c_altName = "_egg".lang(food.c_altName);
238 }
239 }
240 }
241 }
242 MixIngredients(food, ings, MixType.Food, qualityBonus, crafter);
243 static bool IsIgnoreName(Card t)
244 {
245 if (t == null)
246 {
247 return true;
248 }
249 switch (t.sourceCard._origin)
250 {
251 case "dough":
252 case "dish":
253 case "dish_lunch":
254 return true;
255 default:
256 return false;
257 }
258 }
259 }
260
261 public static Thing MixIngredients(string idProduct, List<Thing> ings, MixType type, int idMat = 0, Chara crafter = null)
262 {
263 Thing thing = ThingGen.Create(idProduct);
264 if (idMat != 0)
265 {
266 thing.ChangeMaterial(idMat);
267 }
268 MixIngredients(thing, ings, type, 999, crafter);
269 return thing;
270 }
271
272 public static Card MixIngredients(Card product, List<Thing> ings, MixType type, int maxQuality, Chara crafter = null)
273 {
274 bool noMix = type == MixType.NoMix || product.HasTag(CTAG.noMix);
275 bool isFood = type == MixType.Food;
276 int nutFactor = 100 - (ings.Count - 1) * 5;
277 Thing thing = ((ings.Count > 0) ? ings[0] : null);
278 bool creative = crafter?.HasElement(487) ?? false;
279 if (crafter != null && crafter.Evalue(1650) >= 3)
280 {
281 nutFactor -= 10;
282 }
283 if (!noMix)
284 {
285 foreach (Element value2 in product.elements.dict.Values)
286 {
287 int id = value2.id;
288 if ((uint)(id - 914) > 1u && value2.Value >= 0 && (value2.HasTag("noInherit") || IsValidTrait(value2)))
289 {
290 product.elements.SetTo(value2.id, 0);
291 }
292 }
293 }
294 if (product.HasCraftBonusTrait())
295 {
296 foreach (Element item in product.ListCraftBonusTraits())
297 {
298 product.elements.ModBase(item.id, item.Value);
299 }
300 }
301 if (isFood)
302 {
303 product.elements.SetTo(10, 5);
304 }
305 int num = 0;
306 int num2 = 0;
307 int num3 = 0;
308 foreach (Thing ing in ings)
309 {
310 if (ing != null)
311 {
312 MixElements(ing);
313 num3 += ing.c_priceCopy;
314 if (isFood)
315 {
316 num += Mathf.Clamp(ing.SelfWeight * 80 / 100, 50, 400 + ing.SelfWeight / 20);
317 int value = ing.GetValue();
318 num2 += value;
319 }
320 }
321 }
322 if (isFood)
323 {
324 product.isWeightChanged = true;
325 product.c_weight = num;
326 product.c_priceAdd = num2;
327 }
328 product.c_priceCopy = num3;
329 if (thing != null && product.trait is TraitFoodFishSlice)
330 {
331 product.elements.SetTo(10, thing.Evalue(10) / 4);
332 product.isWeightChanged = true;
333 product.c_weight = Mathf.Min(thing.SelfWeight / 6, 1000);
334 product.c_idRefCard = thing.id;
335 product.c_priceCopy = ((thing.c_priceCopy == 0) ? thing.GetValue() : thing.c_priceCopy);
336 product.c_fixedValue = ((thing.c_fixedValue == 0) ? thing.sourceCard.value : thing.c_fixedValue) / 4;
337 product.c_priceAdd = 0;
338 product.decay = thing.decay;
339 product.elements.SetBase(707, 1);
340 product.SetTier(thing.tier, setTraits: false);
341 product.idSkin = ((thing.trait is TraitFoodFishSlice) ? thing.idSkin : (thing.HasTag(CTAG.bigFish) ? 1 : 0));
342 }
343 if (product.HasElement(652))
344 {
345 product.ChangeWeight((isFood ? num : product.Thing.source.weight) * 100 / (100 + product.Evalue(652)));
346 }
347 if (product.elements.Value(2) > maxQuality)
348 {
349 product.elements.SetTo(2, maxQuality);
350 }
351 string id2 = product.id;
352 if (!(id2 == "zassouni"))
353 {
354 if (id2 == "map")
355 {
356 int num4 = 1 + product.Evalue(2) + product.Evalue(751);
357 if (num4 < 1)
358 {
359 num4 = 1;
360 }
361 foreach (Thing ing2 in ings)
362 {
363 if (ing2 != null && ing2.Thing != null && !(ing2.id != "gem"))
364 {
365 num4 *= ing2.Thing.material.hardness / 20 + 2;
366 }
367 }
368 if (num4 > EClass.pc.FameLv + 10 - 1)
369 {
370 num4 = EClass.pc.FameLv + 10 - 1;
371 }
372 product.SetInt(25, num4);
373 }
374 }
375 else
376 {
377 product.elements.ModBase(10, 6);
378 }
379 if (product.HasElement(762))
380 {
381 product.elements.ModBase(10, product.Evalue(762) / 5);
382 if (product.Evalue(10) < 1)
383 {
384 product.elements.SetTo(10, 1);
385 }
386 }
387 if (creative && isFood && product.category.IsChildOf("meal"))
388 {
389 product.elements.SetBase(764, 1);
390 }
391 return product;
392 bool IsValidTrait(Element e)
393 {
394 if (e.HasTag("noInherit"))
395 {
396 return false;
397 }
398 switch (type)
399 {
400 case MixType.General:
401 if (e.IsTrait)
402 {
403 return true;
404 }
405 if (e.IsFoodTrait)
406 {
407 return product.IsInheritFoodTraits;
408 }
409 break;
410 case MixType.Food:
411 if (e.IsFoodTrait || e.IsTrait || e.id == 2)
412 {
413 return true;
414 }
415 break;
416 }
417 return false;
418 }
419 void MixElements(Card t)
420 {
421 if (t != null)
422 {
423 foreach (Element value3 in t.elements.dict.Values)
424 {
425 if (IsValidTrait(value3) && (!noMix || value3.id == 2))
426 {
427 if (isFood && value3.IsFoodTraitMain)
428 {
429 int num5 = value3.Value;
430 if (product.id == "lunch_dystopia")
431 {
432 num5 *= -1;
433 }
434 if (creative && num5 > 500)
435 {
436 num5 = 500;
437 }
438 product.elements.ModBase(value3.id, num5);
439 }
440 else
441 {
442 int num6 = product.elements.Base(value3.id);
443 if ((num6 <= 0 && value3.Value < 0 && value3.Value < num6) || (value3.Value > 0 && value3.Value > num6))
444 {
445 product.elements.SetTo(value3.id, value3.Value);
446 }
447 }
448 }
449 }
450 if (isFood)
451 {
452 product.elements.ModBase(10, t.Evalue(10) * nutFactor / 100);
453 }
454 }
455 }
456 }
457}
CTAG
Definition: CTAG.cs:2
@ noMix
TryMakeRandomItemSource
string _origin
Definition: CardRow.cs:15
Definition: Card.cs:11
int FameLv
Definition: Card.cs:2260
Thing TryMakeRandomItem(int lv=-1, TryMakeRandomItemSource itemSource=TryMakeRandomItemSource.Default, Chara crafter=null)
Definition: Card.cs:5204
void MakeRefFrom(string id)
Definition: Card.cs:5458
ElementContainerCard elements
Definition: Card.cs:39
string id
Definition: Card.cs:33
bool HasElement(int ele, int req=1)
Definition: Card.cs:5638
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Definition: Card.cs:2994
string Name
Definition: Card.cs:2099
MixedFoodData c_mixedFoodData
Definition: Card.cs:1879
int c_priceCopy
Definition: Card.cs:1135
bool HasTag(CTAG tag)
Definition: Card.cs:2557
int encLV
Definition: Card.cs:312
void SetEncLv(int a)
Definition: Card.cs:3756
bool HasCraftBonusTrait()
Definition: Card.cs:6637
string NameSimple
Definition: Card.cs:2101
virtual Thing Thing
Definition: Card.cs:2020
int Evalue(int ele)
Definition: Card.cs:2533
virtual CardRow sourceCard
Definition: Card.cs:2093
List< Element > ListCraftBonusTraits()
Definition: Card.cs:6642
Thing Add(string id, int num=1, int lv=1)
Definition: Card.cs:3034
int GetValue(PriceType priceType=PriceType.Default, bool sell=false)
Definition: Card.cs:6873
int LV
Definition: Card.cs:372
string c_idRefCard
Definition: Card.cs:1711
Definition: Chara.cs:10
bool enable
Definition: CoreDebug.cs:286
bool autoIdentify
Definition: CoreDebug.cs:189
static Thing GetRandomDarkSoupIngredient(Chara c)
Definition: CraftUtil.cs:117
static Thing MakeLoveLunch(Chara c)
Definition: CraftUtil.cs:122
static void WrapIngredient(Card product, Chara c, Card ing, WrapType wrapType)
Definition: CraftUtil.cs:162
static Thing MakeDarkSoup()
Definition: CraftUtil.cs:102
static void MakeDish(Thing food, int lv, Chara crafter=null)
Definition: CraftUtil.cs:61
static void MakeDish(Card food, List< Thing > ings, int qualityBonus, Chara crafter=null)
Definition: CraftUtil.cs:208
static void AddRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:43
static Thing MixIngredients(string idProduct, List< Thing > ings, MixType type, int idMat=0, Chara crafter=null)
Definition: CraftUtil.cs:261
static void ModRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:22
static string[] ListFoodEffect
Definition: CraftUtil.cs:20
static Thing GetRandomLoveLunchIngredient(Chara c)
Definition: CraftUtil.cs:147
static Card MixIngredients(Card product, List< Thing > ings, MixType type, int maxQuality, Chara crafter=null)
Definition: CraftUtil.cs:272
Definition: EClass.cs:5
static Map _map
Definition: EClass.cs:18
static int rnd(long a)
Definition: EClass.cs:58
static SourceManager sources
Definition: EClass.cs:42
static Chara pc
Definition: EClass.cs:14
static CoreDebug debug
Definition: EClass.cs:48
Dictionary< int, Element > dict
Element ModBase(int ele, int v)
void SetTo(int id, int v)
Element SetBase(string alias, int v, int potential=0)
int id
Definition: ELEMENT.cs:248
bool HasTag(string tag)
Definition: ELEMENT.cs:471
int Value
Definition: ELEMENT.cs:290
bool IsFoodTrait
Definition: ELEMENT.cs:362
bool IsTrait
Definition: ELEMENT.cs:360
bool IsFoodTraitMain
Definition: ELEMENT.cs:365
List< Chara > charas
Definition: Map.cs:81
List< string > texts
Definition: MixedFoodData.cs:7
Definition: Rand.cs:4
static void SetSeed(int a=-1)
Definition: Rand.cs:37
static void BuildList()
static RecipeSource Get(string id)
List< Recipe.Ingredient > GetIngredients()
Definition: Recipe.cs:7
SourceElement elements
static Thing CreateFromFilter(string id, int lv=-1)
Definition: ThingGen.cs:63
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
override int SelfWeight
Definition: Thing.cs:82
static void LevelSeed(Thing t, SourceObj.Row obj, int num)
Definition: TraitSeed.cs:140