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