Elin Decompiled Documentation EA 23.102 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 }
12
13 public static string[] ListFoodEffect = new string[2] { "exp", "pot" };
14
15 public static void ModRandomFoodEnc(Thing t)
16 {
17 List<Element> list = new List<Element>();
18 foreach (Element value in t.elements.dict.Values)
19 {
20 if (value.IsFoodTrait)
21 {
22 list.Add(value);
23 }
24 }
25 if (list.Count != 0)
26 {
27 Element element = list.RandomItem();
28 t.elements.ModBase(element.id, EClass.rnd(6) + 1);
29 if (element.Value > 60)
30 {
31 t.elements.SetTo(element.id, 60);
32 }
33 }
34 }
35
36 public static void AddRandomFoodEnc(Thing t)
37 {
38 List<SourceElement.Row> list = EClass.sources.elements.rows.Where((SourceElement.Row e) => e.foodEffect.Length > 1 && ListFoodEffect.Contains(e.foodEffect[0])).ToList();
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 SourceElement.Row row = list.RandomItemWeighted((SourceElement.Row a) => a.chance);
49 t.elements.SetBase(row.id, 1);
50 t.c_seed = row.id;
51 }
52 }
53
54 public static void MakeDish(Thing food, int lv, Chara crafter = null)
55 {
57 List<Thing> list = new List<Thing>();
58 RecipeSource recipeSource = RecipeManager.Get(food.id);
59 Debug.Log(recipeSource);
60 if (recipeSource == null)
61 {
62 return;
63 }
64 int num = Mathf.Min(EClass.rnd(lv), 50);
65 foreach (Recipe.Ingredient ingredient in recipeSource.GetIngredients())
66 {
67 Thing thing = ThingGen.Create(ingredient.id);
68 TraitSeed.LevelSeed(thing, null, EClass.rnd(lv / 4) + 1);
69 thing.SetEncLv(thing.encLV / 2);
70 if (num > 0 && EClass.rnd(3) == 0)
71 {
72 thing.elements.SetBase(2, num);
73 }
74 list.Add(thing);
75 }
76 MakeDish(food, list, num, crafter);
77 }
78
79 public static void MakeDish(Card food, List<Thing> ings, int qualityBonus, Chara crafter = null)
80 {
81 List<Thing> list = new List<Thing>();
82 bool flag = food.sourceCard.vals.Contains("fixed");
83 for (int i = 0; i < ings.Count; i++)
84 {
85 Thing thing = ings[i];
86 if (flag)
87 {
88 list.Add(thing);
89 break;
90 }
91 if (!IsIgnoreName(thing))
92 {
93 list.Add(thing);
94 }
95 }
96 if (list.Count > 0)
97 {
98 Thing thing2 = list.RandomItem();
99 if (thing2 != null)
100 {
101 food.MakeRefFrom(thing2);
102 if (thing2.c_idRefCard != null)
103 {
104 food.c_idRefCard = thing2.c_idRefCard;
105 food.c_altName = food.TryGetFoodName(thing2);
106 if (thing2.id == "_egg" || thing2.id == "egg_fertilized")
107 {
108 food.c_altName = "_egg".lang(food.c_altName);
109 }
110 }
111 }
112 }
113 MixIngredients(food, ings, MixType.Food, qualityBonus, crafter);
114 static bool IsIgnoreName(Card t)
115 {
116 if (t == null)
117 {
118 return true;
119 }
120 switch (t.sourceCard._origin)
121 {
122 case "dough":
123 case "dish":
124 case "dish_lunch":
125 return true;
126 default:
127 return false;
128 }
129 }
130 }
131
132 public static Thing MixIngredients(string idProduct, List<Thing> ings, MixType type, int idMat = 0, Chara crafter = null)
133 {
134 Thing thing = ThingGen.Create(idProduct);
135 if (idMat != 0)
136 {
137 thing.ChangeMaterial(idMat);
138 }
139 MixIngredients(thing, ings, type, 999, crafter);
140 return thing;
141 }
142
143 public static Card MixIngredients(Card product, List<Thing> ings, MixType type, int maxQuality, Chara crafter = null)
144 {
145 bool isFood = type == MixType.Food;
146 int nutFactor = 100 - (ings.Count - 1) * 5;
147 if (crafter != null && crafter.Evalue(1650) >= 3)
148 {
149 nutFactor -= 10;
150 }
151 foreach (Element value2 in product.elements.dict.Values)
152 {
153 int id = value2.id;
154 if ((uint)(id - 914) > 1u && value2.Value >= 0 && (value2.HasTag("noInherit") || IsValidTrait(value2)))
155 {
156 product.elements.SetTo(value2.id, 0);
157 }
158 }
159 if (product.HasTag(CTAG.dish_bonus))
160 {
161 foreach (Element value3 in product.sourceCard.model.elements.dict.Values)
162 {
163 if (value3.IsFoodTraitMain)
164 {
165 product.elements.ModBase(value3.id, value3.Value);
166 }
167 }
168 }
169 if (isFood)
170 {
171 product.elements.SetTo(10, 5);
172 }
173 int num = 0;
174 int num2 = 0;
175 foreach (Thing ing in ings)
176 {
177 if (ing != null)
178 {
179 MixElements(ing);
180 if (isFood)
181 {
182 num += Mathf.Clamp(ing.SelfWeight * 80 / 100, 50, 400 + ing.SelfWeight / 20);
183 int value = ing.GetValue();
184 num2 += value;
185 }
186 }
187 }
188 if (isFood)
189 {
190 product.isWeightChanged = true;
191 product.c_weight = num;
192 product.c_priceAdd = num2;
193 }
194 if (product.HasElement(652))
195 {
196 product.ChangeWeight((isFood ? num : product.Thing.source.weight) * 100 / (100 + product.Evalue(652)));
197 }
198 if (product.elements.Value(2) > maxQuality)
199 {
200 product.elements.SetTo(2, maxQuality);
201 }
202 string id2 = product.id;
203 if (!(id2 == "zassouni"))
204 {
205 if (id2 == "map")
206 {
207 int num3 = 1 + product.Evalue(2) + product.Evalue(751);
208 if (num3 < 1)
209 {
210 num3 = 1;
211 }
212 foreach (Thing ing2 in ings)
213 {
214 if (ing2 != null && ing2.Thing != null && !(ing2.id != "gem"))
215 {
216 num3 *= ing2.Thing.material.hardness / 20 + 2;
217 }
218 }
219 if (num3 > EClass.pc.FameLv + 10 - 1)
220 {
221 num3 = EClass.pc.FameLv + 10 - 1;
222 }
223 product.SetInt(25, num3);
224 }
225 }
226 else
227 {
228 product.elements.ModBase(10, 6);
229 }
230 return product;
231 bool IsValidTrait(Element e)
232 {
233 if (e.HasTag("noInherit"))
234 {
235 return false;
236 }
237 switch (type)
238 {
239 case MixType.General:
240 if (e.IsTrait)
241 {
242 return true;
243 }
244 if (e.IsFoodTrait)
245 {
246 return product.ShowFoodEnc;
247 }
248 break;
249 case MixType.Food:
250 if (e.IsFoodTrait || e.IsTrait || e.id == 2)
251 {
252 return true;
253 }
254 break;
255 }
256 return false;
257 }
258 void MixElements(Card t)
259 {
260 if (t != null)
261 {
262 foreach (Element value4 in t.elements.dict.Values)
263 {
264 if (IsValidTrait(value4))
265 {
266 if (isFood && value4.IsFoodTraitMain)
267 {
268 product.elements.ModBase(value4.id, value4.Value);
269 }
270 else
271 {
272 int num4 = product.elements.Base(value4.id);
273 if ((num4 <= 0 && value4.Value < 0 && value4.Value < num4) || (value4.Value > 0 && value4.Value > num4))
274 {
275 product.elements.SetTo(value4.id, value4.Value);
276 }
277 }
278 }
279 }
280 if (isFood)
281 {
282 product.elements.ModBase(10, t.Evalue(10) * nutFactor / 100);
283 }
284 }
285 }
286 }
287}
CTAG
Definition: CTAG.cs:2
string _origin
Definition: CardRow.cs:15
Definition: Card.cs:11
int FameLv
Definition: Card.cs:2158
ElementContainerCard elements
Definition: Card.cs:37
string id
Definition: Card.cs:31
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Definition: Card.cs:2838
int GetValue(bool sell=false)
Definition: Card.cs:6387
int encLV
Definition: Card.cs:310
void SetEncLv(int a)
Definition: Card.cs:3567
virtual Thing Thing
Definition: Card.cs:1934
int Evalue(int ele)
Definition: Card.cs:2431
virtual CardRow sourceCard
Definition: Card.cs:2007
Thing Add(string id, int num=1, int lv=1)
Definition: Card.cs:2878
string c_idRefCard
Definition: Card.cs:1637
Definition: Chara.cs:10
static void MakeDish(Thing food, int lv, Chara crafter=null)
Definition: CraftUtil.cs:54
static void MakeDish(Card food, List< Thing > ings, int qualityBonus, Chara crafter=null)
Definition: CraftUtil.cs:79
static void AddRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:36
static Thing MixIngredients(string idProduct, List< Thing > ings, MixType type, int idMat=0, Chara crafter=null)
Definition: CraftUtil.cs:132
static void ModRandomFoodEnc(Thing t)
Definition: CraftUtil.cs:15
static string[] ListFoodEffect
Definition: CraftUtil.cs:13
static Card MixIngredients(Card product, List< Thing > ings, MixType type, int maxQuality, Chara crafter=null)
Definition: CraftUtil.cs:143
Definition: EClass.cs:5
static int rnd(int a)
Definition: EClass.cs:50
static SourceManager sources
Definition: EClass.cs:42
static Chara pc
Definition: EClass.cs:14
Dictionary< int, Element > dict
Element SetBase(string alias, int v, int potential=0)
int id
Definition: ELEMENT.cs:240
bool HasTag(string tag)
Definition: ELEMENT.cs:463
int Value
Definition: ELEMENT.cs:282
bool IsFoodTrait
Definition: ELEMENT.cs:354
bool IsTrait
Definition: ELEMENT.cs:352
bool IsFoodTraitMain
Definition: ELEMENT.cs:357
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