Elin Decompiled Documentation EA 23.130 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 static string[] ListFoodEffect = new string[2] { "exp", "pot" };
15
16 public static void ModRandomFoodEnc(Thing t)
17 {
18 List<Element> list = new List<Element>();
19 foreach (Element value in t.elements.dict.Values)
20 {
21 if (value.IsFoodTrait)
22 {
23 list.Add(value);
24 }
25 }
26 if (list.Count != 0)
27 {
28 Element element = list.RandomItem();
29 t.elements.ModBase(element.id, EClass.rnd(6) + 1);
30 if (element.Value > 60)
31 {
32 t.elements.SetTo(element.id, 60);
33 }
34 }
35 }
36
37 public static void AddRandomFoodEnc(Thing t)
38 {
39 List<SourceElement.Row> list = EClass.sources.elements.rows.Where((SourceElement.Row e) => e.foodEffect.Length > 1 && ListFoodEffect.Contains(e.foodEffect[0])).ToList();
40 list.ForeachReverse(delegate(SourceElement.Row e)
41 {
42 if (t.elements.dict.ContainsKey(e.id))
43 {
44 list.Remove(e);
45 }
46 });
47 if (list.Count != 0)
48 {
49 SourceElement.Row row = list.RandomItemWeighted((SourceElement.Row a) => a.chance);
50 t.elements.SetBase(row.id, 1);
51 t.c_seed = row.id;
52 }
53 }
54
55 public static void MakeDish(Thing food, int lv, Chara crafter = null)
56 {
58 List<Thing> list = new List<Thing>();
59 RecipeSource recipeSource = RecipeManager.Get(food.id);
60 Debug.Log(recipeSource);
61 if (recipeSource == null)
62 {
63 return;
64 }
65 int num = Mathf.Min(EClass.rnd(lv), 50);
66 foreach (Recipe.Ingredient ingredient in recipeSource.GetIngredients())
67 {
68 Thing thing = ThingGen.Create(ingredient.id);
69 TraitSeed.LevelSeed(thing, null, EClass.rnd(lv / 4) + 1);
70 thing.SetEncLv(thing.encLV / 2);
71 if (num > 0 && EClass.rnd(3) == 0)
72 {
73 thing.elements.SetBase(2, num);
74 }
75 list.Add(thing);
76 }
77 MakeDish(food, list, num, crafter);
78 if (crafter != null && crafter.id != "rodwyn")
79 {
80 if (food.HasElement(709))
81 {
82 food.elements.Remove(709);
83 }
84 if (food.HasElement(708) && !crafter.HasElement(1205))
85 {
86 food.elements.Remove(708);
87 }
88 }
89 }
90
91 public static void MakeDish(Card food, List<Thing> ings, int qualityBonus, Chara crafter = null)
92 {
93 List<Thing> list = new List<Thing>();
94 bool flag = food.sourceCard.vals.Contains("fixed");
95 for (int i = 0; i < ings.Count; i++)
96 {
97 Thing thing = ings[i];
98 if (flag)
99 {
100 list.Add(thing);
101 break;
102 }
103 if (!IsIgnoreName(thing))
104 {
105 list.Add(thing);
106 }
107 }
108 if (list.Count > 0)
109 {
110 Thing thing2 = list.RandomItem();
111 if (thing2 != null)
112 {
113 food.MakeRefFrom(thing2);
114 if (thing2.c_idRefCard != null)
115 {
116 food.c_idRefCard = thing2.c_idRefCard;
117 food.c_altName = food.TryGetFoodName(thing2);
118 if (thing2.id == "_egg" || thing2.id == "egg_fertilized")
119 {
120 food.c_altName = "_egg".lang(food.c_altName);
121 }
122 }
123 }
124 }
125 MixIngredients(food, ings, MixType.Food, qualityBonus, crafter);
126 static bool IsIgnoreName(Card t)
127 {
128 if (t == null)
129 {
130 return true;
131 }
132 switch (t.sourceCard._origin)
133 {
134 case "dough":
135 case "dish":
136 case "dish_lunch":
137 return true;
138 default:
139 return false;
140 }
141 }
142 }
143
144 public static Thing MixIngredients(string idProduct, List<Thing> ings, MixType type, int idMat = 0, Chara crafter = null)
145 {
146 Thing thing = ThingGen.Create(idProduct);
147 if (idMat != 0)
148 {
149 thing.ChangeMaterial(idMat);
150 }
151 MixIngredients(thing, ings, type, 999, crafter);
152 return thing;
153 }
154
155 public static Card MixIngredients(Card product, List<Thing> ings, MixType type, int maxQuality, Chara crafter = null)
156 {
157 bool noMix = type == MixType.NoMix || product.HasTag(CTAG.noMix);
158 bool isFood = type == MixType.Food;
159 int nutFactor = 100 - (ings.Count - 1) * 5;
160 Thing thing = ((ings.Count > 0) ? ings[0] : null);
161 if (crafter != null && crafter.Evalue(1650) >= 3)
162 {
163 nutFactor -= 10;
164 }
165 if (!noMix)
166 {
167 foreach (Element value2 in product.elements.dict.Values)
168 {
169 int id = value2.id;
170 if ((uint)(id - 914) > 1u && value2.Value >= 0 && (value2.HasTag("noInherit") || IsValidTrait(value2)))
171 {
172 product.elements.SetTo(value2.id, 0);
173 }
174 }
175 }
176 if (product.HasCraftBonusTrait())
177 {
178 foreach (Element item in product.ListCraftBonusTraits())
179 {
180 product.elements.ModBase(item.id, item.Value);
181 }
182 }
183 if (isFood)
184 {
185 product.elements.SetTo(10, 5);
186 }
187 int num = 0;
188 int num2 = 0;
189 int num3 = 0;
190 foreach (Thing ing in ings)
191 {
192 if (ing != null)
193 {
194 MixElements(ing);
195 num3 += ing.c_priceCopy;
196 if (isFood)
197 {
198 num += Mathf.Clamp(ing.SelfWeight * 80 / 100, 50, 400 + ing.SelfWeight / 20);
199 int value = ing.GetValue();
200 num2 += value;
201 }
202 }
203 }
204 if (isFood)
205 {
206 product.isWeightChanged = true;
207 product.c_weight = num;
208 product.c_priceAdd = num2;
209 }
210 product.c_priceCopy = num3;
211 if (thing != null && product.trait is TraitFoodFishSlice)
212 {
213 product.elements.SetTo(10, thing.Evalue(10) / 4);
214 product.isWeightChanged = true;
215 product.c_weight = Mathf.Min(thing.SelfWeight / 6, 1000);
216 product.c_idRefCard = thing.id;
217 product.c_priceCopy = ((thing.c_priceCopy == 0) ? thing.GetValue() : thing.c_priceCopy);
218 product.c_fixedValue = ((thing.c_fixedValue == 0) ? thing.sourceCard.value : thing.c_fixedValue) / 4;
219 product.c_priceAdd = 0;
220 product.decay = thing.decay;
221 product.elements.SetBase(707, 1);
222 product.SetTier(thing.tier, setTraits: false);
223 product.idSkin = ((thing.trait is TraitFoodFishSlice) ? thing.idSkin : (thing.HasTag(CTAG.bigFish) ? 1 : 0));
224 }
225 if (product.HasElement(652))
226 {
227 product.ChangeWeight((isFood ? num : product.Thing.source.weight) * 100 / (100 + product.Evalue(652)));
228 }
229 if (product.elements.Value(2) > maxQuality)
230 {
231 product.elements.SetTo(2, maxQuality);
232 }
233 string id2 = product.id;
234 if (!(id2 == "zassouni"))
235 {
236 if (id2 == "map")
237 {
238 int num4 = 1 + product.Evalue(2) + product.Evalue(751);
239 if (num4 < 1)
240 {
241 num4 = 1;
242 }
243 foreach (Thing ing2 in ings)
244 {
245 if (ing2 != null && ing2.Thing != null && !(ing2.id != "gem"))
246 {
247 num4 *= ing2.Thing.material.hardness / 20 + 2;
248 }
249 }
250 if (num4 > EClass.pc.FameLv + 10 - 1)
251 {
252 num4 = EClass.pc.FameLv + 10 - 1;
253 }
254 product.SetInt(25, num4);
255 }
256 }
257 else
258 {
259 product.elements.ModBase(10, 6);
260 }
261 if (product.HasElement(762))
262 {
263 product.elements.ModBase(10, product.Evalue(762) / 5);
264 if (product.Evalue(10) < 1)
265 {
266 product.elements.SetTo(10, 1);
267 }
268 }
269 return product;
270 bool IsValidTrait(Element e)
271 {
272 if (e.HasTag("noInherit"))
273 {
274 return false;
275 }
276 switch (type)
277 {
278 case MixType.General:
279 if (e.IsTrait)
280 {
281 return true;
282 }
283 if (e.IsFoodTrait)
284 {
285 return product.IsInheritFoodTraits;
286 }
287 break;
288 case MixType.Food:
289 if (e.IsFoodTrait || e.IsTrait || e.id == 2)
290 {
291 return true;
292 }
293 break;
294 }
295 return false;
296 }
297 void MixElements(Card t)
298 {
299 if (t != null)
300 {
301 foreach (Element value3 in t.elements.dict.Values)
302 {
303 if (IsValidTrait(value3) && (!noMix || value3.id == 2))
304 {
305 if (isFood && value3.IsFoodTraitMain)
306 {
307 product.elements.ModBase(value3.id, value3.Value);
308 }
309 else
310 {
311 int num5 = product.elements.Base(value3.id);
312 if ((num5 <= 0 && value3.Value < 0 && value3.Value < num5) || (value3.Value > 0 && value3.Value > num5))
313 {
314 product.elements.SetTo(value3.id, value3.Value);
315 }
316 }
317 }
318 }
319 if (isFood)
320 {
321 product.elements.ModBase(10, t.Evalue(10) * nutFactor / 100);
322 }
323 }
324 }
325 }
326}
CTAG
Definition: CTAG.cs:2
@ noMix
string _origin
Definition: CardRow.cs:15
Definition: Card.cs:11
int FameLv
Definition: Card.cs:2198
ElementContainerCard elements
Definition: Card.cs:37
string id
Definition: Card.cs:31
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Definition: Card.cs:2887
int c_priceCopy
Definition: Card.cs:1121
bool HasTag(CTAG tag)
Definition: Card.cs:2495
int encLV
Definition: Card.cs:310
void SetEncLv(int a)
Definition: Card.cs:3611
bool HasCraftBonusTrait()
Definition: Card.cs:6362
virtual Thing Thing
Definition: Card.cs:1958
int Evalue(int ele)
Definition: Card.cs:2471
virtual CardRow sourceCard
Definition: Card.cs:2031
List< Element > ListCraftBonusTraits()
Definition: Card.cs:6367
Thing Add(string id, int num=1, int lv=1)
Definition: Card.cs:2927
int GetValue(PriceType priceType=PriceType.Default, bool sell=false)
Definition: Card.cs:6598
string c_idRefCard
Definition: Card.cs:1661
Definition: Chara.cs:10
static void MakeDish(Thing food, int lv, Chara crafter=null)
Definition: CraftUtil.cs:55
static void MakeDish(Card food, List< Thing > ings, int qualityBonus, Chara crafter=null)
Definition: CraftUtil.cs:91
static void AddRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:37
static Thing MixIngredients(string idProduct, List< Thing > ings, MixType type, int idMat=0, Chara crafter=null)
Definition: CraftUtil.cs:144
static void ModRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:16
static string[] ListFoodEffect
Definition: CraftUtil.cs:14
static Card MixIngredients(Card product, List< Thing > ings, MixType type, int maxQuality, Chara crafter=null)
Definition: CraftUtil.cs:155
Definition: EClass.cs:5
static int rnd(int a)
Definition: EClass.cs:58
static SourceManager sources
Definition: EClass.cs:42
static Chara pc
Definition: EClass.cs:14
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:246
bool HasTag(string tag)
Definition: ELEMENT.cs:469
int Value
Definition: ELEMENT.cs:288
bool IsFoodTrait
Definition: ELEMENT.cs:360
bool IsTrait
Definition: ELEMENT.cs:358
bool IsFoodTraitMain
Definition: ELEMENT.cs:363
static void BuildList()
static RecipeSource Get(string id)
List< Recipe.Ingredient > GetIngredients()
Definition: Recipe.cs:7
SourceElement elements
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:62
static void LevelSeed(Thing t, SourceObj.Row obj, int num)
Definition: TraitSeed.cs:129