Elin Modding Docs Doc
Loading...
Searching...
No Matches
CraftUtil.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Runtime.CompilerServices;
5using UnityEngine;
6
7// Token: 0x02000535 RID: 1333
8public class CraftUtil : EClass
9{
10 // Token: 0x0600241E RID: 9246 RVA: 0x000CB218 File Offset: 0x000C9418
11 public static void ModRandomFoodEnc(Thing t)
12 {
13 List<Element> list = new List<Element>();
14 foreach (Element element in t.elements.dict.Values)
15 {
16 if (element.IsFoodTrait)
17 {
18 list.Add(element);
19 }
20 }
21 if (list.Count == 0)
22 {
23 return;
24 }
25 Element element2 = list.RandomItem<Element>();
26 t.elements.ModBase(element2.id, EClass.rnd(6) + 1);
27 if (element2.Value > 60)
28 {
29 t.elements.SetTo(element2.id, 60);
30 }
31 }
32
33 // Token: 0x0600241F RID: 9247 RVA: 0x000CB2CC File Offset: 0x000C94CC
34 public static void AddRandomFoodEnc(Thing t)
35 {
36 List<SourceElement.Row> list = (from e in EClass.sources.elements.rows
37 where e.foodEffect.Length > 1 && CraftUtil.ListFoodEffect.Contains(e.foodEffect[0])
38 select e).ToList<SourceElement.Row>();
39 list.ForeachReverse(delegate(SourceElement.Row e)
40 {
41 if (t.elements.dict.ContainsKey(e.id))
42 {
43 list.Remove(e);
44 }
45 });
46 if (list.Count == 0)
47 {
48 return;
49 }
50 SourceElement.Row row = list.RandomItemWeighted((SourceElement.Row a) => (float)a.chance);
51 t.elements.SetBase(row.id, 1, 0);
52 t.c_seed = row.id;
53 }
54
55 // Token: 0x06002420 RID: 9248 RVA: 0x000CB3A0 File Offset: 0x000C95A0
56 public static void MakeDish(Thing food, int lv)
57 {
58 RecipeManager.BuildList();
59 List<Thing> list = new List<Thing>();
60 RecipeSource recipeSource = RecipeManager.Get(food.id);
61 Debug.Log(recipeSource);
62 if (recipeSource == null)
63 {
64 return;
65 }
66 int num = Mathf.Min(EClass.rnd(lv), 50);
67 foreach (Recipe.Ingredient ingredient in recipeSource.GetIngredients())
68 {
69 Thing thing = ThingGen.Create(ingredient.id, -1, -1);
70 TraitSeed.LevelSeed(thing, null, EClass.rnd(lv / 4) + 1);
71 thing.SetEncLv(thing.encLV / 2);
72 if (num > 0 && EClass.rnd(3) == 0)
73 {
74 thing.elements.SetBase(2, num, 0);
75 }
76 list.Add(thing);
77 }
78 CraftUtil.MakeDish(food, list, num);
79 }
80
81 // Token: 0x06002421 RID: 9249 RVA: 0x000CB478 File Offset: 0x000C9678
82 public static void MakeDish(Card food, List<Thing> ings, int qualityBonus)
83 {
84 List<Thing> list = new List<Thing>();
85 bool flag = food.sourceCard.vals.Contains("fixed");
86 for (int i = 0; i < ings.Count; i++)
87 {
88 Thing thing = ings[i];
89 if (flag)
90 {
91 list.Add(thing);
92 break;
93 }
94 if (!CraftUtil.<MakeDish>g__IsIgnoreName|5_0(thing))
95 {
96 list.Add(thing);
97 }
98 }
99 if (list.Count > 0)
100 {
101 Thing thing2 = list.RandomItem<Thing>();
102 if (thing2 != null)
103 {
104 food.MakeRefFrom(thing2, null);
105 if (thing2.c_idRefCard != null)
106 {
107 food.c_idRefCard = thing2.c_idRefCard;
108 food.c_altName = food.TryGetFoodName(thing2);
109 if (thing2.id == "_egg" || thing2.id == "egg_fertilized")
110 {
111 food.c_altName = "_egg".lang(food.c_altName, null, null, null, null);
112 }
113 }
114 }
115 }
116 CraftUtil.MixIngredients(food, ings, CraftUtil.MixType.Food, qualityBonus);
117 }
118
119 // Token: 0x06002422 RID: 9250 RVA: 0x000CB564 File Offset: 0x000C9764
120 public static Thing MixIngredients(string idProduct, List<Thing> ings, CraftUtil.MixType type, int idMat = 0)
121 {
122 Thing thing = ThingGen.Create(idProduct, -1, -1);
123 if (idMat != 0)
124 {
125 thing.ChangeMaterial(idMat);
126 }
127 CraftUtil.MixIngredients(thing, ings, type, 999);
128 return thing;
129 }
130
131 // Token: 0x06002423 RID: 9251 RVA: 0x000CB594 File Offset: 0x000C9794
132 public static Card MixIngredients(Card product, List<Thing> ings, CraftUtil.MixType type, int maxQuality)
133 {
134 CraftUtil.<>c__DisplayClass7_0 CS$<>8__locals1;
135 CS$<>8__locals1.type = type;
136 CS$<>8__locals1.product = product;
137 CS$<>8__locals1.isFood = (CS$<>8__locals1.type == CraftUtil.MixType.Food);
138 foreach (Element element in CS$<>8__locals1.product.elements.dict.Values)
139 {
140 int id = element.id;
141 if (id - 914 > 1 && element.Value >= 0 && CraftUtil.<MixIngredients>g__IsValidTrait|7_0(element, ref CS$<>8__locals1))
142 {
143 CS$<>8__locals1.product.elements.SetTo(element.id, 0);
144 }
145 }
146 if (CS$<>8__locals1.isFood)
147 {
148 CS$<>8__locals1.product.elements.SetTo(10, 5);
149 }
150 int num = 0;
151 int num2 = 0;
152 foreach (Thing thing in ings)
153 {
154 if (thing != null)
155 {
156 CraftUtil.<MixIngredients>g__MixElements|7_1(thing, ref CS$<>8__locals1);
157 if (CS$<>8__locals1.isFood)
158 {
159 num += Mathf.Clamp(thing.SelfWeight * 80 / 100, 50, 400 + thing.SelfWeight / 20);
160 int value = thing.GetValue(false);
161 num2 += value;
162 }
163 }
164 }
165 if (CS$<>8__locals1.isFood)
166 {
167 CS$<>8__locals1.product.isWeightChanged = true;
168 CS$<>8__locals1.product.c_weight = num;
169 CS$<>8__locals1.product.c_priceAdd = num2;
170 }
171 if (CS$<>8__locals1.product.elements.Value(2) > maxQuality)
172 {
173 CS$<>8__locals1.product.elements.SetTo(2, maxQuality);
174 }
175 return CS$<>8__locals1.product;
176 }
177
178 // Token: 0x06002426 RID: 9254 RVA: 0x000CB774 File Offset: 0x000C9974
179 [CompilerGenerated]
180 internal static bool <MakeDish>g__IsIgnoreName|5_0(Card t)
181 {
182 if (t == null)
183 {
184 return true;
185 }
186 string origin = t.sourceCard._origin;
187 return origin == "dough" || origin == "dish" || origin == "dish_lunch";
188 }
189
190 // Token: 0x06002427 RID: 9255 RVA: 0x000CB7BC File Offset: 0x000C99BC
191 [CompilerGenerated]
192 internal static bool <MixIngredients>g__IsValidTrait|7_0(Element e, ref CraftUtil.<>c__DisplayClass7_0 A_1)
193 {
194 CraftUtil.MixType type = A_1.type;
195 if (type != CraftUtil.MixType.General)
196 {
197 if (type == CraftUtil.MixType.Food)
198 {
199 if (e.IsFoodTrait || e.IsTrait || e.id == 2)
200 {
201 return true;
202 }
203 }
204 }
205 else
206 {
207 if (e.IsTrait)
208 {
209 return true;
210 }
211 if (e.IsFoodTrait)
212 {
213 return A_1.product.ShowFoodEnc;
214 }
215 }
216 return false;
217 }
218
219 // Token: 0x06002428 RID: 9256 RVA: 0x000CB814 File Offset: 0x000C9A14
220 [CompilerGenerated]
221 internal static void <MixIngredients>g__MixElements|7_1(Card t, ref CraftUtil.<>c__DisplayClass7_0 A_1)
222 {
223 if (t == null)
224 {
225 return;
226 }
227 foreach (Element element in t.elements.dict.Values)
228 {
229 if (CraftUtil.<MixIngredients>g__IsValidTrait|7_0(element, ref A_1))
230 {
231 if (A_1.isFood && element.IsFoodTraitMain)
232 {
233 A_1.product.elements.ModBase(element.id, element.Value);
234 }
235 else
236 {
237 int num = A_1.product.elements.Base(element.id);
238 if ((num <= 0 && element.Value < 0 && element.Value < num) || (element.Value > 0 && element.Value > num))
239 {
240 A_1.product.elements.SetTo(element.id, element.Value);
241 }
242 }
243 }
244 }
245 if (A_1.isFood)
246 {
247 A_1.product.elements.ModBase(10, t.Evalue(10));
248 }
249 }
250
251 // Token: 0x04001394 RID: 5012
252 public static string[] ListFoodEffect = new string[]
253 {
254 "exp",
255 "pot"
256 };
257
258 // Token: 0x02000A46 RID: 2630
259 public enum MixType
260 {
261 // Token: 0x04002A49 RID: 10825
262 General,
263 // Token: 0x04002A4A RID: 10826
264 Food
265 }
266}
Definition Card.cs:13
Definition Thing.cs:10