Elin Decompiled Documentation EA 23.241 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 Thing MakeBloodMeal(Chara sucker, Chara feeder, bool msg = true)
142 {
143 Thing c_bloodData = feeder.c_bloodData;
144 if (c_bloodData == null)
145 {
146 int num = ((feeder.GetInt(118) == 0) ? (EClass.game.seed + feeder.uid) : feeder.GetInt(118));
147 Rand.SetSeed(num);
148 c_bloodData = ThingGen.CreateFromCategory("meal", 100);
149 if (msg)
150 {
151 sucker.Say("food_blood", c_bloodData);
152 }
153 MakeDish(c_bloodData, 100, null, num + feeder.uid);
154 c_bloodData.elements.SetTo(709, 0);
155 c_bloodData.elements.SetTo(708, 0);
156 c_bloodData.elements.SetTo(701, 0);
157 feeder.c_bloodData = c_bloodData.Duplicate(1);
158 }
159 else
160 {
161 c_bloodData = c_bloodData.Duplicate(1);
162 if (msg)
163 {
164 sucker.Say("food_blood", c_bloodData);
165 }
166 }
167 c_bloodData.elements.SetTo(2, Mathf.Min(EClass.curve(feeder.LV, 30, 10, 65), 200));
168 c_bloodData.elements.ModBase(710, 15 + (int)Mathf.Min(Mathf.Sqrt(sucker.Evalue(6607) + Mathf.Max(sucker.LER, 0)), 55f));
169 return c_bloodData;
170 }
171
172 public static Thing MakeBloodSample(Chara sucker, Chara feeder)
173 {
174 Thing thing = MakeBloodMeal(sucker, feeder);
175 Thing thing2 = ThingGen.Create("bloodsample");
176 foreach (Element value in thing.elements.dict.Values)
177 {
178 thing2.elements.SetTo(value.id, value.Value);
179 }
180 thing2.elements.SetTo(10, 0);
181 thing2.MakeRefFrom(feeder);
182 thing2.c_idRefCard = thing.id;
183 thing2.SetInt(118, EClass.game.seed + feeder.uid);
184 return thing2;
185 }
186
187 public static Thing MakeDarkSoup()
188 {
189 Thing thing = ThingGen.Create("soup_dark");
190 for (int i = 0; i < 4 + EClass.rnd(4); i++)
191 {
192 Chara c = EClass._map.charas.RandomItem();
193 WrapIngredient(thing, c, GetRandomDarkSoupIngredient(c), WrapType.Dark);
194 }
196 {
197 thing.c_IDTState = 1;
198 }
199 return thing;
200 }
201
203 {
204 return ThingGen.CreateFromFilter("darksoup", c.LV);
205 }
206
207 public static Thing MakeLoveLunch(Chara c)
208 {
209 Thing thing = ThingGen.Create("lunch_love");
210 thing.MakeRefFrom(c);
211 int num = c.uid + EClass.world.date.year * 10000 + EClass.world.date.month * 100;
212 Rand.SetSeed(num);
213 float num2 = Mathf.Clamp(1f + Mathf.Sqrt(c.Evalue(287) / 5), 2f, 6f);
215 {
216 thing.c_IDTState = 5;
217 }
218 for (int i = 0; (float)i < num2; i++)
219 {
220 Rand.SetSeed(num + i);
221 WrapIngredient(thing, c, GetRandomLoveLunchIngredient(c), WrapType.Love);
222 }
223 thing.elements.SetBase(701, 0);
224 if (thing.Evalue(753) < 0)
225 {
226 thing.elements.SetBase(753, 0);
227 }
228 if (EClass.pc.HasElement(1250) && !thing.HasElement(710))
229 {
230 thing.elements.SetBase(710, 1);
231 }
232 Rand.SetSeed();
233 return thing;
234 }
235
237 {
238 Thing thing = null;
239 for (int i = 0; i < 3; i++)
240 {
241 thing = ThingGen.Create("dish", -1, c.Evalue(287) + 5 + (EClass.debug.enable ? c.LV : 0));
242 if (!thing.HasTag(CTAG.dish_fail))
243 {
244 break;
245 }
246 }
247 MakeDish(thing, c.LV, c);
248 return thing;
249 }
250
251 public static void WrapIngredient(Card product, Chara c, Card ing, WrapType wrapType)
252 {
253 if (product.c_mixedFoodData == null)
254 {
255 product.c_mixedFoodData = new MixedFoodData();
256 }
257 product.c_mixedFoodData.texts.Add(ing.Name + ((wrapType == WrapType.Dark) ? "isMixedBy".lang(c.NameSimple) : ""));
258 foreach (Element value in ing.elements.dict.Values)
259 {
260 if (!IsValidTrait(value))
261 {
262 continue;
263 }
264 if (value.IsFoodTraitMain)
265 {
266 int num = value.Value;
267 if (ing.id == "lunch_dystopia" && (wrapType == WrapType.Dark || num < 0))
268 {
269 num *= -1;
270 }
271 product.elements.ModBase(value.id, num);
272 }
273 else
274 {
275 int num2 = product.elements.Base(value.id);
276 if ((num2 <= 0 && value.Value < 0 && value.Value < num2) || (value.Value > 0 && value.Value > num2))
277 {
278 product.elements.SetTo(value.id, value.Value);
279 }
280 }
281 }
282 product.elements.ModBase(10, ing.Evalue(10));
283 static bool IsValidTrait(Element e)
284 {
285 if (e.HasTag("noInherit"))
286 {
287 return false;
288 }
289 if (e.IsFoodTrait || e.IsTrait || e.id == 2)
290 {
291 return true;
292 }
293 return false;
294 }
295 }
296
297 public static void MakeDish(Card food, List<Thing> ings, int qualityBonus, Chara crafter = null)
298 {
299 List<Thing> list = new List<Thing>();
300 bool flag = food.sourceCard.vals.Contains("fixed");
301 for (int i = 0; i < ings.Count; i++)
302 {
303 Thing thing = ings[i];
304 if (flag)
305 {
306 list.Add(thing);
307 break;
308 }
309 if (!IsIgnoreName(thing))
310 {
311 list.Add(thing);
312 }
313 }
314 if (list.Count > 0)
315 {
316 Thing thing2 = list.RandomItem();
317 if (thing2 != null)
318 {
319 food.MakeRefFrom(thing2);
320 if (thing2.c_idRefCard != null)
321 {
322 food.c_idRefCard = thing2.c_idRefCard;
323 food.c_altName = food.TryGetFoodName(thing2);
324 if (thing2.id == "_egg" || thing2.id == "egg_fertilized")
325 {
326 food.c_altName = "_egg".lang(food.c_altName);
327 }
328 }
329 }
330 }
331 MixIngredients(food, ings, MixType.Food, qualityBonus, crafter);
332 static bool IsIgnoreName(Card t)
333 {
334 if (t == null)
335 {
336 return true;
337 }
338 switch (t.sourceCard._origin)
339 {
340 case "dough":
341 case "dish":
342 case "dish_lunch":
343 return true;
344 default:
345 return false;
346 }
347 }
348 }
349
350 public static Thing MixIngredients(string idProduct, List<Thing> ings, MixType type, int idMat = 0, Chara crafter = null)
351 {
352 Thing thing = ThingGen.Create(idProduct);
353 if (idMat != 0)
354 {
355 thing.ChangeMaterial(idMat);
356 }
357 MixIngredients(thing, ings, type, 999, crafter);
358 return thing;
359 }
360
361 public static Card MixIngredients(Card product, List<Thing> ings, MixType type, int maxQuality, Chara crafter = null)
362 {
363 bool noMix = type == MixType.NoMix || product.HasTag(CTAG.noMix);
364 bool isFood = type == MixType.Food;
365 int nutFactor = 100 - (ings.Count - 1) * 5;
366 Thing thing = ((ings.Count > 0) ? ings[0] : null);
367 bool creative = crafter?.HasElement(487) ?? false;
368 if (crafter != null && crafter.Evalue(1650) >= 3)
369 {
370 nutFactor -= 10;
371 }
372 if (!noMix)
373 {
374 foreach (Element value2 in product.elements.dict.Values)
375 {
376 int id = value2.id;
377 if ((uint)(id - 914) > 1u && value2.Value >= 0 && (value2.HasTag("noInherit") || IsValidTrait(value2)))
378 {
379 product.elements.SetTo(value2.id, 0);
380 }
381 }
382 }
383 if (product.HasCraftBonusTrait())
384 {
385 foreach (Element item in product.ListCraftBonusTraits())
386 {
387 product.elements.ModBase(item.id, item.Value);
388 }
389 }
390 if (isFood)
391 {
392 product.elements.SetTo(10, 5);
393 }
394 int num = 0;
395 int num2 = 0;
396 int num3 = 0;
397 foreach (Thing ing in ings)
398 {
399 if (ing != null)
400 {
401 MixElements(ing);
402 num3 += ing.c_priceCopy;
403 if (isFood)
404 {
405 num += Mathf.Clamp(ing.SelfWeight * 80 / 100, 50, 400 + ing.SelfWeight / 20);
406 int value = ing.GetValue();
407 num2 += value;
408 }
409 if (product.id == "1300" && product.GetInt(118) == 0)
410 {
411 product.SetInt(118, ing.GetInt(118));
412 product.c_idRefCard = ing.c_idRefCard;
413 }
414 }
415 }
416 if (isFood)
417 {
418 product.isWeightChanged = true;
419 product.c_weight = num;
420 product.c_priceAdd = num2;
421 }
422 product.c_priceCopy = num3;
423 if (thing != null && product.trait is TraitFoodFishSlice)
424 {
425 product.elements.SetTo(10, thing.Evalue(10) / 4);
426 product.isWeightChanged = true;
427 product.c_weight = Mathf.Min(thing.SelfWeight / 6, 1000);
428 product.c_idRefCard = thing.id;
429 product.c_priceCopy = ((thing.c_priceCopy == 0) ? thing.GetValue() : thing.c_priceCopy);
430 product.c_fixedValue = ((thing.c_fixedValue == 0) ? thing.sourceCard.value : thing.c_fixedValue) / 4;
431 product.c_priceAdd = 0;
432 product.decay = thing.decay;
433 product.elements.SetBase(707, 1);
434 product.SetTier(thing.tier, setTraits: false);
435 product.idSkin = ((thing.trait is TraitFoodFishSlice) ? thing.idSkin : (thing.HasTag(CTAG.bigFish) ? 1 : 0));
436 }
437 if (product.HasElement(652))
438 {
439 product.ChangeWeight((isFood ? num : product.Thing.source.weight) * 100 / (100 + product.Evalue(652)));
440 }
441 if (product.elements.Value(2) > maxQuality)
442 {
443 product.elements.SetTo(2, maxQuality);
444 }
445 string id2 = product.id;
446 if (!(id2 == "zassouni"))
447 {
448 if (id2 == "map")
449 {
450 int num4 = 1 + product.Evalue(2) + product.Evalue(751);
451 if (num4 < 1)
452 {
453 num4 = 1;
454 }
455 foreach (Thing ing2 in ings)
456 {
457 if (ing2 != null && ing2.Thing != null && !(ing2.id != "gem"))
458 {
459 num4 *= ing2.Thing.material.hardness / 20 + 2;
460 }
461 }
462 if (num4 > EClass.pc.FameLv + 10 - 1)
463 {
464 num4 = EClass.pc.FameLv + 10 - 1;
465 }
466 product.SetInt(25, num4);
467 }
468 }
469 else
470 {
471 product.elements.ModBase(10, 6);
472 }
473 if (product.HasElement(762))
474 {
475 product.elements.ModBase(10, product.Evalue(762) / 5);
476 if (product.Evalue(10) < 1)
477 {
478 product.elements.SetTo(10, 1);
479 }
480 }
481 if (creative && isFood && product.category.IsChildOf("meal"))
482 {
483 product.elements.SetBase(764, 1);
484 }
485 return product;
486 bool IsValidTrait(Element e)
487 {
488 if (e.HasTag("noInherit"))
489 {
490 return false;
491 }
492 switch (type)
493 {
494 case MixType.General:
495 if (e.IsTrait)
496 {
497 return true;
498 }
499 if (e.IsFoodTrait)
500 {
501 return product.IsInheritFoodTraits;
502 }
503 break;
504 case MixType.Food:
505 if (e.IsFoodTrait || e.IsTrait || e.id == 2)
506 {
507 return true;
508 }
509 break;
510 }
511 return false;
512 }
513 void MixElements(Card t)
514 {
515 if (t != null)
516 {
517 foreach (Element value3 in t.elements.dict.Values)
518 {
519 if (IsValidTrait(value3) && (!noMix || value3.id == 2))
520 {
521 if (isFood && value3.IsFoodTraitMain)
522 {
523 int num5 = value3.Value;
524 if (product.id == "lunch_dystopia")
525 {
526 num5 *= -1;
527 }
528 if (creative && num5 > 500)
529 {
530 num5 = 500;
531 }
532 product.elements.ModBase(value3.id, num5);
533 }
534 else
535 {
536 int num6 = product.elements.Base(value3.id);
537 if ((num6 <= 0 && value3.Value < 0 && value3.Value < num6) || (value3.Value > 0 && value3.Value > num6))
538 {
539 product.elements.SetTo(value3.id, value3.Value);
540 }
541 }
542 }
543 }
544 if (isFood)
545 {
546 product.elements.ModBase(10, t.Evalue(10) * nutFactor / 100);
547 }
548 }
549 }
550 }
551}
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:5437
ElementContainerCard elements
Definition: Card.cs:41
string id
Definition: Card.cs:35
bool HasElement(int ele, int req=1)
Definition: Card.cs:5897
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Definition: Card.cs:3038
Card MakeRefFrom(string id)
Definition: Card.cs:5702
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:3861
bool HasCraftBonusTrait()
Definition: Card.cs:6919
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:3441
virtual CardRow sourceCard
Definition: Card.cs:2131
List< Element > ListCraftBonusTraits()
Definition: Card.cs:6924
Thing Add(string id, int num=1, int lv=1)
Definition: Card.cs:3078
int GetValue(PriceType priceType=PriceType.Default, bool sell=false)
Definition: Card.cs:7155
int LV
Definition: Card.cs:386
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:6781
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 Thing GetRandomDarkSoupIngredient(Chara c)
Definition: CraftUtil.cs:202
static Thing MakeLoveLunch(Chara c)
Definition: CraftUtil.cs:207
static void WrapIngredient(Card product, Chara c, Card ing, WrapType wrapType)
Definition: CraftUtil.cs:251
static Thing MakeDarkSoup()
Definition: CraftUtil.cs:187
static Thing MakeBloodSample(Chara sucker, Chara feeder)
Definition: CraftUtil.cs:172
static void MakeDish(Card food, List< Thing > ings, int qualityBonus, Chara crafter=null)
Definition: CraftUtil.cs:297
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:350
static Thing MakeBloodMeal(Chara sucker, Chara feeder, bool msg=true)
Definition: CraftUtil.cs:141
static void ModRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:22
static string[] ListFoodEffect
Definition: CraftUtil.cs:20
static Thing GetRandomLoveLunchIngredient(Chara c)
Definition: CraftUtil.cs:236
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:361
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