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