Elin Decompiled Documentation EA 23.324 Nightly
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 Drink
13 }
14
15 public enum WrapType
16 {
17 Love,
18 Dark
19 }
20
21 public static string[] ListFoodEffect = new string[2] { "exp", "pot" };
22
23 public static void ModRandomFoodEnc(Thing t)
24 {
25 List<Element> list = new List<Element>();
26 foreach (Element value in t.elements.dict.Values)
27 {
28 if (value.IsFoodTrait)
29 {
30 list.Add(value);
31 }
32 }
33 if (list.Count != 0)
34 {
35 Element element = list.RandomItem();
36 t.elements.ModBase(element.id, EClass.rnd(6) + 1);
37 if (element.Value > 60)
38 {
39 t.elements.SetTo(element.id, 60);
40 }
41 }
42 }
43
44 public static void AddRandomFoodEnc(Thing t)
45 {
46 List<SourceElement.Row> list = EClass.sources.elements.rows.Where((SourceElement.Row e) => e.foodEffect.Length > 1 && ListFoodEffect.Contains(e.foodEffect[0])).ToList();
47 list.ForeachReverse(delegate(SourceElement.Row e)
48 {
49 if (t.elements.dict.ContainsKey(e.id))
50 {
51 list.Remove(e);
52 }
53 });
54 if (list.Count != 0)
55 {
56 SourceElement.Row row = list.RandomItemWeighted((SourceElement.Row a) => a.chance);
57 t.elements.SetBase(row.id, 1);
58 t.c_seed = row.id;
59 }
60 }
61
62 public static void MakeDish(Thing food, int lv, Chara crafter = null, int seed = -1)
63 {
65 List<Thing> list = new List<Thing>();
66 RecipeSource recipeSource = RecipeManager.Get(food.id);
67 if (recipeSource == null || !recipeSource.IsCraftable())
68 {
69 return;
70 }
71 SetSeed();
72 int num = Mathf.Min(EClass.rnd(lv), 50);
73 foreach (Recipe.Ingredient ingredient in recipeSource.GetIngredients())
74 {
75 SetSeed();
76 Thing thing = (ingredient.useCat ? ThingGen.CreateFromCategory(ingredient.id, lv) : ThingGen.Create(ingredient.id, -1, lv));
77 if (thing.id == "deadbody")
78 {
79 thing = ThingGen.Create("_meat");
80 }
81 SetSeed();
82 thing = thing.TryMakeRandomItem(lv, TryMakeRandomItemSource.Cooking, crafter);
83 SetSeed();
84 TraitSeed.LevelSeed(thing, null, EClass.rnd(lv / 4) + 1);
85 thing.SetEncLv(thing.encLV / 2);
86 if (num > 0 && EClass.rnd(3) == 0)
87 {
88 thing.elements.SetBase(2, num);
89 }
90 list.Add(thing);
91 }
92 MakeDish(food, list, num, crafter);
93 if (crafter != null && crafter.id != "rodwyn")
94 {
95 if (food.HasElement(709))
96 {
97 food.elements.Remove(709);
98 }
99 if (food.HasElement(708) && !crafter.HasElement(1205))
100 {
101 food.elements.Remove(708);
102 }
103 }
104 if (seed != -1)
105 {
106 Rand.SetSeed();
107 }
108 void SetSeed()
109 {
110 if (seed != -1)
111 {
113 seed++;
114 }
115 }
116 }
117
118 public static string GetBloodText(Chara c)
119 {
120 string text = "";
121 List<Element> list = MakeBloodMeal(EClass.pc, c, msg: false).elements.ListElements((Element e) => e.IsFoodTraitMain, (Element a, Element b) => b.Value - a.Value);
122 int num = Mathf.Min(list.Count(), 3, EClass.debug.godMode ? 3 : (1 + EClass.pc.Evalue(6607) / 15));
123 for (int i = 0; i < num; i++)
124 {
125 Element element = list[i];
126 string[] textArray = element.source.GetTextArray("textAlt");
127 int num2 = Mathf.Clamp(element.Value / 10 + 1, (element.Value < 0 || textArray.Length <= 2) ? 1 : 2, textArray.Length - 1);
128 string text2 = textArray[num2];
129 if (i != 0)
130 {
131 text += ", ";
132 }
133 text += text2;
134 }
135 if (!text.IsEmpty())
136 {
137 text = " (" + text + ")";
138 }
139 return text;
140 }
141
142 public static int GetFoodScore(Thing food)
143 {
144 int num = 0;
145 foreach (Element value in food.elements.dict.Values)
146 {
147 if (value.IsFoodTraitMain)
148 {
149 num += value.Value;
150 }
151 }
152 return num;
153 }
154
155 public static Thing MakeBloodMeal(Chara sucker, Chara feeder, bool msg = true)
156 {
157 Thing c_bloodData = feeder.c_bloodData;
158 if (c_bloodData == null)
159 {
160 int num = ((feeder.GetInt(118) == 0) ? (EClass.game.seed + feeder.uid) : feeder.GetInt(118));
161 Rand.SetSeed(num);
162 c_bloodData = ThingGen.CreateFromCategory("meal", 100);
163 if (msg)
164 {
165 sucker.Say("food_blood", c_bloodData);
166 }
167 MakeDish(c_bloodData, 100, null, num + feeder.uid);
168 c_bloodData.elements.SetTo(709, 0);
169 c_bloodData.elements.SetTo(708, 0);
170 c_bloodData.elements.SetTo(701, 0);
171 feeder.c_bloodData = c_bloodData.Duplicate(1);
172 }
173 else
174 {
175 c_bloodData = c_bloodData.Duplicate(1);
176 if (msg)
177 {
178 sucker.Say("food_blood", c_bloodData);
179 }
180 }
181 c_bloodData.elements.SetTo(2, Mathf.Min(EClass.curve(feeder.LV, 30, 10, 65), 200));
182 c_bloodData.elements.ModBase(710, 15 + (int)Mathf.Min(Mathf.Sqrt(sucker.Evalue(6607) + Mathf.Max(sucker.LER, 0)), 55f));
183 return c_bloodData;
184 }
185
186 public static Thing MakeBloodSample(Chara sucker, Chara feeder)
187 {
188 Thing thing = MakeBloodMeal(sucker, feeder);
189 Thing thing2 = ThingGen.Create("bloodsample");
190 foreach (Element value in thing.elements.dict.Values)
191 {
192 thing2.elements.SetTo(value.id, value.Value);
193 }
194 thing2.elements.SetTo(10, 0);
195 thing2.MakeRefFrom(feeder);
196 thing2.c_idRefCard = thing.id;
197 thing2.SetInt(118, EClass.game.seed + feeder.uid);
198 return thing2;
199 }
200
201 public static Thing MakeDarkSoup()
202 {
203 Thing thing = ThingGen.Create("soup_dark");
204 for (int i = 0; i < 4 + EClass.rnd(4); i++)
205 {
206 Chara c = EClass._map.charas.RandomItem();
207 WrapIngredient(thing, c, GetRandomDarkSoupIngredient(c), WrapType.Dark);
208 }
210 {
211 thing.c_IDTState = 1;
212 }
213 return thing;
214 }
215
217 {
218 return ThingGen.CreateFromFilter("darksoup", c.LV);
219 }
220
221 public static Thing MakeLoveLunch(Chara c)
222 {
223 Thing thing = ThingGen.Create("lunch_love");
224 thing.MakeRefFrom(c);
225 int num = c.uid + EClass.world.date.year * 10000 + EClass.world.date.month * 100;
226 Rand.SetSeed(num);
227 float num2 = Mathf.Clamp(1f + Mathf.Sqrt(c.Evalue(287) / 5), 2f, 6f);
229 {
230 thing.c_IDTState = 5;
231 }
232 for (int i = 0; (float)i < num2; i++)
233 {
234 Rand.SetSeed(num + i);
235 WrapIngredient(thing, c, GetRandomLoveLunchIngredient(c), WrapType.Love);
236 }
237 thing.elements.SetBase(701, 0);
238 if (thing.Evalue(753) < 0)
239 {
240 thing.elements.SetBase(753, 0);
241 }
242 if (EClass.pc.HasElement(1250) && !thing.HasElement(710))
243 {
244 thing.elements.SetBase(710, 1);
245 }
246 Rand.SetSeed();
247 return thing;
248 }
249
251 {
252 Thing thing = null;
253 for (int i = 0; i < 3; i++)
254 {
255 thing = ThingGen.Create("dish", -1, c.Evalue(287) + 5 + (EClass.debug.enable ? c.LV : 0));
256 if (!thing.HasTag(CTAG.dish_fail))
257 {
258 break;
259 }
260 }
261 MakeDish(thing, c.LV, c);
262 return thing;
263 }
264
265 public static void WrapIngredient(Card product, Chara c, Card ing, WrapType wrapType)
266 {
267 if (product.c_mixedFoodData == null)
268 {
269 product.c_mixedFoodData = new MixedFoodData();
270 }
271 product.c_mixedFoodData.texts.Add(ing.Name + ((wrapType == WrapType.Dark) ? "isMixedBy".lang(c.NameSimple) : ""));
272 foreach (Element value in ing.elements.dict.Values)
273 {
274 if (!IsValidTrait(value))
275 {
276 continue;
277 }
278 if (value.IsFoodTraitMain)
279 {
280 int num = value.Value;
281 if (ing.id == "lunch_dystopia" && (wrapType == WrapType.Dark || num < 0))
282 {
283 num *= -1;
284 }
285 product.elements.ModBase(value.id, num);
286 }
287 else
288 {
289 int num2 = product.elements.Base(value.id);
290 if ((num2 <= 0 && value.Value < 0 && value.Value < num2) || (value.Value > 0 && value.Value > num2))
291 {
292 product.elements.SetTo(value.id, value.Value);
293 }
294 }
295 }
296 product.elements.ModBase(10, ing.Evalue(10));
297 static bool IsValidTrait(Element e)
298 {
299 if (e.HasTag("noInherit"))
300 {
301 return false;
302 }
303 if (e.IsFoodTrait || e.IsTrait || e.id == 2)
304 {
305 return true;
306 }
307 return false;
308 }
309 }
310
311 public static void MakeDish(Card food, List<Thing> ings, int qualityBonus, Chara crafter = null)
312 {
313 List<Thing> list = new List<Thing>();
314 bool flag = food.sourceCard.vals.Contains("fixed");
315 for (int i = 0; i < ings.Count; i++)
316 {
317 Thing thing = ings[i];
318 if (flag)
319 {
320 list.Add(thing);
321 break;
322 }
323 if (!IsIgnoreName(thing))
324 {
325 list.Add(thing);
326 }
327 }
328 if (list.Count > 0)
329 {
330 Thing thing2 = list.RandomItem();
331 if (thing2 != null)
332 {
333 food.MakeRefFrom(thing2);
334 if (thing2.c_idRefCard != null)
335 {
336 food.c_idRefCard = thing2.c_idRefCard;
337 food.c_altName = food.TryGetFoodName(thing2);
338 if (thing2.id == "_egg" || thing2.id == "egg_fertilized")
339 {
340 food.c_altName = "_egg".lang(food.c_altName);
341 }
342 }
343 }
344 }
345 MixIngredients(food, ings, MixType.Food, qualityBonus, crafter);
346 static bool IsIgnoreName(Card t)
347 {
348 if (t == null)
349 {
350 return true;
351 }
352 switch (t.sourceCard._origin)
353 {
354 case "dough":
355 case "dish":
356 case "dish_lunch":
357 return true;
358 default:
359 return false;
360 }
361 }
362 }
363
364 public static Thing MixIngredients(string idProduct, List<Thing> ings, MixType type, int idMat = 0, Chara crafter = null)
365 {
366 Thing thing = ThingGen.Create(idProduct);
367 if (idMat != 0)
368 {
369 thing.ChangeMaterial(idMat);
370 }
371 MixIngredients(thing, ings, type, 999, crafter);
372 return thing;
373 }
374
375 public static Card MixIngredients(Card product, List<Thing> ings, MixType type, int maxQuality, Chara crafter = null)
376 {
377 bool noMix = type == MixType.NoMix || product.HasTag(CTAG.noMix);
378 bool isFood = type == MixType.Food;
379 bool isDrink = type == MixType.Drink;
380 bool isFoodOrDrink = isFood || isDrink;
381 int nutFactor = 100 - (ings.Count - 1) * 5;
382 Thing thing = ((ings.Count > 0) ? ings[0] : null);
383 bool creative = crafter?.HasElement(487) ?? false;
384 if (crafter != null && crafter.Evalue(1650) >= 3)
385 {
386 nutFactor -= 10;
387 }
388 if (isDrink)
389 {
390 nutFactor = 100 / ings.Count;
391 }
392 if (!noMix)
393 {
394 foreach (Element value2 in product.elements.dict.Values)
395 {
396 int id = value2.id;
397 if ((uint)(id - 914) > 1u && value2.Value >= 0 && (value2.HasTag("noInherit") || IsValidTrait(value2)))
398 {
399 product.elements.SetTo(value2.id, 0);
400 }
401 }
402 }
403 if (product.HasCraftBonusTrait())
404 {
405 foreach (Element item in product.ListCraftBonusTraits())
406 {
407 product.elements.ModBase(item.id, item.Value);
408 }
409 }
410 if (isDrink)
411 {
412 product.elements.SetTo(10, 0);
413 }
414 if (isFood)
415 {
416 product.elements.SetTo(10, 5);
417 }
418 int num = 0;
419 int num2 = 0;
420 int num3 = 0;
421 foreach (Thing ing in ings)
422 {
423 if (ing != null)
424 {
425 MixElements(ing);
426 num3 += ing.c_priceCopy;
427 if (isFood)
428 {
429 num += Mathf.Clamp(ing.SelfWeight * 80 / 100, 50, 400 + ing.SelfWeight / 20);
430 int value = ing.GetValue();
431 num2 += value;
432 }
433 if (product.id == "1300" && product.GetInt(118) == 0)
434 {
435 product.SetInt(118, ing.GetInt(118));
436 product.c_idRefCard = ing.c_idRefCard;
437 }
438 }
439 }
440 if (isFood)
441 {
442 product.isWeightChanged = true;
443 product.c_weight = num;
444 product.c_priceAdd = num2;
445 }
446 product.c_priceCopy = num3;
447 if (thing != null && product.trait is TraitFoodFishSlice)
448 {
449 product.elements.SetTo(10, thing.Evalue(10) / 4);
450 product.isWeightChanged = true;
451 product.c_weight = Mathf.Min(thing.SelfWeight / 6, 1000);
452 product.c_idRefCard = thing.id;
453 product.c_priceCopy = ((thing.c_priceCopy == 0) ? thing.GetValue() : thing.c_priceCopy);
454 product.c_fixedValue = ((thing.c_fixedValue == 0) ? thing.sourceCard.value : thing.c_fixedValue) / 4;
455 product.c_priceAdd = 0;
456 product.decay = thing.decay;
457 product.elements.SetBase(707, 1);
458 product.SetTier(thing.tier, setTraits: false);
459 product.idSkin = ((thing.trait is TraitFoodFishSlice) ? thing.idSkin : (thing.HasTag(CTAG.bigFish) ? 1 : 0));
460 }
461 if (product.HasElement(652))
462 {
463 product.ChangeWeight((isFood ? num : product.Thing.source.weight) * 100 / (100 + product.Evalue(652)));
464 }
465 if (product.elements.Value(2) > maxQuality)
466 {
467 product.elements.SetTo(2, maxQuality);
468 }
469 string id2 = product.id;
470 if (!(id2 == "zassouni"))
471 {
472 if (id2 == "map")
473 {
474 int num4 = 1 + product.Evalue(2) + product.Evalue(751);
475 if (num4 < 1)
476 {
477 num4 = 1;
478 }
479 foreach (Thing ing2 in ings)
480 {
481 if (ing2 != null && ing2.Thing != null && !(ing2.id != "gem"))
482 {
483 num4 *= ing2.Thing.material.hardness / 20 + 2;
484 }
485 }
486 if (num4 > EClass.pc.FameLv + 10 - 1)
487 {
488 num4 = EClass.pc.FameLv + 10 - 1;
489 }
490 product.SetInt(25, num4);
491 }
492 }
493 else
494 {
495 product.elements.ModBase(10, 6);
496 }
497 if (product.HasElement(762))
498 {
499 product.elements.ModBase(10, product.Evalue(762) / 5);
500 if (product.Evalue(10) < 1)
501 {
502 product.elements.SetTo(10, 1);
503 }
504 }
505 if (creative && isFood && product.category.IsChildOf("meal"))
506 {
507 product.elements.SetBase(764, 1);
508 }
509 return product;
510 bool IsValidTrait(Element e)
511 {
512 if (e.HasTag("noInherit"))
513 {
514 return false;
515 }
516 switch (type)
517 {
518 case MixType.General:
519 if (e.IsTrait)
520 {
521 return true;
522 }
523 if (e.IsFoodTrait)
524 {
525 return product.IsInheritFoodTraits;
526 }
527 break;
528 case MixType.Food:
529 case MixType.Drink:
530 if (e.IsFoodTrait || e.IsTrait || e.id == 2)
531 {
532 return true;
533 }
534 break;
535 }
536 return false;
537 }
538 void MixElements(Card t)
539 {
540 if (t != null)
541 {
542 foreach (Element value3 in t.elements.dict.Values)
543 {
544 if (IsValidTrait(value3) && (!noMix || value3.id == 2))
545 {
546 if (isFoodOrDrink && value3.IsFoodTraitMain)
547 {
548 int num5 = value3.Value;
549 if (product.id == "lunch_dystopia")
550 {
551 num5 *= -1;
552 }
553 if (creative && num5 > 500)
554 {
555 num5 = 500;
556 }
557 product.elements.ModBase(value3.id, num5);
558 }
559 else
560 {
561 int num6 = product.elements.Base(value3.id);
562 if ((num6 <= 0 && value3.Value < 0 && value3.Value < num6) || (value3.Value > 0 && value3.Value > num6))
563 {
564 product.elements.SetTo(value3.id, value3.Value);
565 }
566 }
567 }
568 }
569 if (isFood)
570 {
571 product.elements.ModBase(10, t.Evalue(10) * nutFactor / 100);
572 }
573 if (isDrink)
574 {
575 product.elements.ModBase(10, Mathf.CeilToInt((float)t.Evalue(10) * (float)nutFactor / 100f));
576 }
577 }
578 }
579 }
580}
CTAG
Definition: CTAG.cs:2
@ noMix
@ seed
TryMakeRandomItemSource
string _origin
Definition: CardRow.cs:15
Definition: Card.cs:11
int FameLv
Definition: Card.cs:2368
Thing TryMakeRandomItem(int lv=-1, TryMakeRandomItemSource itemSource=TryMakeRandomItemSource.Default, Chara crafter=null)
Definition: Card.cs:5723
ElementContainerCard elements
Definition: Card.cs:42
string id
Definition: Card.cs:36
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Definition: Card.cs:3210
Card MakeRefFrom(string id)
Definition: Card.cs:5992
string Name
Definition: Card.cs:2191
MixedFoodData c_mixedFoodData
Definition: Card.cs:1957
int c_priceCopy
Definition: Card.cs:1188
int LER
Definition: Card.cs:2411
Thing c_bloodData
Definition: Card.cs:1969
bool HasTag(CTAG tag)
Definition: Card.cs:2728
int uid
Definition: Card.cs:125
int encLV
Definition: Card.cs:329
void SetEncLv(int a)
Definition: Card.cs:4038
bool HasCraftBonusTrait()
Definition: Card.cs:7411
string NameSimple
Definition: Card.cs:2193
virtual Thing Thing
Definition: Card.cs:2110
int Evalue(int ele)
Definition: Card.cs:2704
Thing Duplicate(int num)
Definition: Card.cs:3618
virtual CardRow sourceCard
Definition: Card.cs:2183
List< Element > ListCraftBonusTraits()
Definition: Card.cs:7416
Thing Add(string id, int num=1, int lv=1)
Definition: Card.cs:3250
int GetValue(PriceType priceType=PriceType.Default, bool sell=false)
Definition: Card.cs:7647
int GetInt(string id, int? defaultInt=null)
Definition: Card.cs:2567
bool HasElement(int ele, bool includeNagative=false)
Definition: Card.cs:6336
int LV
Definition: Card.cs:389
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:7272
string c_idRefCard
Definition: Card.cs:1777
Definition: Chara.cs:10
bool godMode
Definition: CoreDebug.cs:188
bool enable
Definition: CoreDebug.cs:301
bool autoIdentify
Definition: CoreDebug.cs:204
static int GetFoodScore(Thing food)
Definition: CraftUtil.cs:142
static Thing GetRandomDarkSoupIngredient(Chara c)
Definition: CraftUtil.cs:216
static Thing MakeLoveLunch(Chara c)
Definition: CraftUtil.cs:221
static void WrapIngredient(Card product, Chara c, Card ing, WrapType wrapType)
Definition: CraftUtil.cs:265
static Thing MakeDarkSoup()
Definition: CraftUtil.cs:201
static Thing MakeBloodSample(Chara sucker, Chara feeder)
Definition: CraftUtil.cs:186
static void MakeDish(Card food, List< Thing > ings, int qualityBonus, Chara crafter=null)
Definition: CraftUtil.cs:311
static void AddRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:44
static Thing MixIngredients(string idProduct, List< Thing > ings, MixType type, int idMat=0, Chara crafter=null)
Definition: CraftUtil.cs:364
static Thing MakeBloodMeal(Chara sucker, Chara feeder, bool msg=true)
Definition: CraftUtil.cs:155
static void ModRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:23
static string[] ListFoodEffect
Definition: CraftUtil.cs:21
static Thing GetRandomLoveLunchIngredient(Chara c)
Definition: CraftUtil.cs:250
static void MakeDish(Thing food, int lv, Chara crafter=null, int seed=-1)
Definition: CraftUtil.cs:62
static string GetBloodText(Chara c)
Definition: CraftUtil.cs:118
static Card MixIngredients(Card product, List< Thing > ings, MixType type, int maxQuality, Chara crafter=null)
Definition: CraftUtil.cs:375
Definition: EClass.cs:6
static Game game
Definition: EClass.cs:9
static int curve(long _a, int start, int step, int rate=75)
Definition: EClass.cs:69
static Map _map
Definition: EClass.cs:19
static int rnd(long a)
Definition: EClass.cs:59
static SourceManager sources
Definition: EClass.cs:43
static Chara pc
Definition: EClass.cs:15
static CoreDebug debug
Definition: EClass.cs:49
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:257
SourceElement.Row source
Definition: ELEMENT.cs:280
bool HasTag(string tag)
Definition: ELEMENT.cs:480
int Value
Definition: ELEMENT.cs:299
bool IsFoodTrait
Definition: ELEMENT.cs:371
bool IsTrait
Definition: ELEMENT.cs:369
bool IsFoodTraitMain
Definition: ELEMENT.cs:374
int seed
Definition: Game.cs:201
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:44
static void BuildList()
static RecipeSource Get(string id)
List< Recipe.Ingredient > GetIngredients()
bool IsCraftable()
Definition: Recipe.cs:7
SourceElement elements
static Thing CreateFromFilter(string id, int lv=-1)
Definition: ThingGen.cs:63
static Thing CreateFromCategory(string idCat, int lv=-1)
Definition: ThingGen.cs:75
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:64
static void LevelSeed(Thing t, SourceObj.Row obj, int num)
Definition: TraitSeed.cs:184