Elin Modding Docs Doc
Loading...
Searching...
No Matches
RecipeManager.cs
1using System;
2using System.Collections.Generic;
3using Newtonsoft.Json;
4using UnityEngine;
5
6// Token: 0x0200005E RID: 94
7public class RecipeManager : EClass
8{
9 // Token: 0x06000268 RID: 616 RVA: 0x00012C68 File Offset: 0x00010E68
10 public static void BuildList()
11 {
12 if (!RecipeManager.rebuild && RecipeManager.list.Count > 0)
13 {
14 return;
15 }
16 Debug.Log("Rebuilding recipe list");
17 RecipeManager.list.Clear();
18 RecipeManager.dict.Clear();
19 foreach (CardRow cardRow in EClass.sources.cards.rows)
20 {
21 if (!cardRow.isOrigin && (cardRow.factory.IsEmpty() || !(cardRow.factory[0] == "x")))
22 {
23 RecipeManager.Create(cardRow, "", cardRow.isChara ? "-c" : "");
24 }
25 }
26 foreach (SourceBlock.Row row in EClass.sources.blocks.rows)
27 {
28 RecipeManager.Create(row, "Block", "");
29 if (row.tileType == TileType.Pillar)
30 {
31 RecipeManager.Create(row, "BridgePillar", "-p");
32 }
33 }
34 foreach (SourceFloor.Row row2 in EClass.sources.floors.rows)
35 {
36 if (!row2.tag.Contains("noFloor"))
37 {
38 RecipeManager.Create(row2, "Floor", "");
39 }
40 }
41 foreach (SourceFloor.Row row3 in EClass.sources.floors.rows)
42 {
43 if (!row3.tag.Contains("noBridge") && !row3.factory.IsEmpty() && row3.factory[0] != "x")
44 {
45 RecipeManager.Create(row3, "Bridge", "-b");
46 }
47 }
48 foreach (SourceObj.Row row4 in EClass.sources.objs.rows)
49 {
50 RecipeManager.Create(row4, "Obj", "");
51 }
52 foreach (SourceCellEffect.Row row5 in EClass.sources.cellEffects.rows)
53 {
54 RecipeManager.Create(row5, "Liquid", "");
55 }
56 RecipeManager.rebuild = false;
57 }
58
59 // Token: 0x06000269 RID: 617 RVA: 0x00012F4C File Offset: 0x0001114C
60 public static void Create(RenderRow row, string type, string suffix = "")
61 {
62 RecipeSource recipeSource = new RecipeSource();
63 recipeSource.id = row.RecipeID + suffix;
64 recipeSource.isBridge = (type == "Bridge");
65 recipeSource.isBridgePillar = (type == "BridgePillar");
66 recipeSource.type = type;
67 recipeSource.row = row;
68 recipeSource.isChara = (row is SourceChara.Row);
69 RecipeManager.list.Add(recipeSource);
70 RecipeManager.dict[recipeSource.id] = recipeSource;
71 string[] components = row.components;
72 Recipe.Create(recipeSource, -1, null).BuildIngredientList();
73 }
74
75 // Token: 0x0600026A RID: 618 RVA: 0x00012FE0 File Offset: 0x000111E0
76 public static RecipeSource Get(string id)
77 {
78 return RecipeManager.dict.TryGetValue(id, null);
79 }
80
81 // Token: 0x0600026B RID: 619 RVA: 0x00012FEE File Offset: 0x000111EE
82 public RecipeSource GetSource(string id)
83 {
84 return RecipeManager.dict.TryGetValue(id, null);
85 }
86
87 // Token: 0x0600026C RID: 620 RVA: 0x00012FFC File Offset: 0x000111FC
88 public void Add(string id, bool showEffect = true)
89 {
90 if (id.IsEmpty())
91 {
92 return;
93 }
94 RecipeSource recipeSource = RecipeManager.Get(id);
95 if (recipeSource == null)
96 {
97 return;
98 }
99 if (!this.knownRecipes.ContainsKey(id))
100 {
101 this.newRecipes.Add(id);
102 this.knownRecipes[id] = 0;
103 }
104 Dictionary<string, int> dictionary = this.knownRecipes;
105 int num = dictionary[id];
106 dictionary[id] = num + 1;
107 int num2 = this.knownRecipes[id];
108 if (showEffect)
109 {
110 EClass.pc.PlaySound("idea", 1f, true);
111 EClass.pc.ShowEmo(Emo.idea, 0.5f, false);
112 }
113 EClass.pc.Say("learnRecipe" + ((num2 == 1) ? "New" : ""), RecipeManager.dict[id].Name.ToTitleCase(false), num2.ToString() ?? "");
114 if (recipeSource.row.category == "floor")
115 {
116 recipeSource = RecipeManager.Get(id + "-b");
117 if (recipeSource != null && !this.knownRecipes.ContainsKey(recipeSource.id))
118 {
119 this.Add(recipeSource.id, false);
120 }
121 recipeSource = RecipeManager.Get(id.Replace("-b", ""));
122 if (recipeSource != null && !this.knownRecipes.ContainsKey(recipeSource.id))
123 {
124 this.Add(recipeSource.id, false);
125 }
126 }
127 }
128
129 // Token: 0x0600026D RID: 621 RVA: 0x00013164 File Offset: 0x00011364
130 public bool IsKnown(string id)
131 {
132 return EClass.debug.allRecipe || EClass.player.recipes.knownRecipes.ContainsKey(id);
133 }
134
135 // Token: 0x0600026E RID: 622 RVA: 0x0001318C File Offset: 0x0001138C
136 public List<RecipeSource> ListSources(Thing factory, List<RecipeSource> newRecipes = null)
137 {
138 RecipeManager.BuildList();
139 List<RecipeSource> list = new List<RecipeSource>();
140 foreach (RecipeSource recipeSource in RecipeManager.list)
141 {
142 if (!recipeSource.isBridgePillar && (factory != null || !(recipeSource.idFactory != "self")) && (factory == null || factory.trait.Contains(recipeSource)) && !recipeSource.isChara && !recipeSource.noListing)
143 {
144 if (!EClass.debug.godCraft && !EClass.player.recipes.knownRecipes.ContainsKey(recipeSource.id))
145 {
146 bool flag = false;
147 if (recipeSource.row.recipeKey != null && recipeSource.row.recipeKey.Length != 0 && recipeSource.row.recipeKey[0][0] == '*')
148 {
149 flag = true;
150 }
151 string id = recipeSource.id;
152 if (!(id == "waystone"))
153 {
154 if (id == "container_shipping")
155 {
156 if (EClass.game.quests.GetPhase<QuestShippingChest>() >= 0)
157 {
158 flag = true;
159 }
160 }
161 }
162 else if (EClass.game.quests.GetPhase<QuestExploration>() >= 6)
163 {
164 flag = true;
165 }
166 if (!flag)
167 {
168 continue;
169 }
170 if (newRecipes != null)
171 {
172 EClass.player.recipes.Add(recipeSource.id, true);
173 if (EClass.player.recipes.newRecipes.Contains(recipeSource.id))
174 {
175 newRecipes.Add(recipeSource);
176 EClass.player.recipes.newRecipes.Remove(recipeSource.id);
177 }
178 }
179 }
180 list.Add(recipeSource);
181 }
182 }
183 return list;
184 }
185
186 // Token: 0x0600026F RID: 623 RVA: 0x00013358 File Offset: 0x00011558
187 public void OnSleep(bool ehe = false)
188 {
189 int slept = EClass.player.stats.slept;
190 Rand.SetSeed(EClass.game.seed + slept);
191 if (slept > 3 && EClass.rnd(3) == 0)
192 {
193 return;
194 }
195 if (EClass.rnd(EClass.pc.Evalue(1642) + 1) <= 0)
196 {
197 if (slept > 15 && EClass.rnd(3) == 0)
198 {
199 return;
200 }
201 if (slept > 30 && EClass.rnd(3) == 0)
202 {
203 return;
204 }
205 if (slept > 60 && EClass.rnd(3) == 0)
206 {
207 return;
208 }
209 }
210 Msg.Say("learnRecipeSleep");
211 Rand.SetSeed(-1);
212 this.Add(RecipeManager.GetRandomRecipe((ehe ? 5 : 0) + EClass.rnd(EClass.rnd(EClass.rnd(10))), null, false), true);
213 }
214
215 // Token: 0x06000270 RID: 624 RVA: 0x00013410 File Offset: 0x00011610
216 public void ComeUpWithRandomRecipe(string idCat = null, int lvBonus = 0)
217 {
218 string randomRecipe = RecipeManager.GetRandomRecipe(lvBonus, idCat, true);
219 if (randomRecipe == null)
220 {
221 return;
222 }
223 Msg.Say("learnRecipeIdea");
224 this.Add(randomRecipe, true);
225 }
226
227 // Token: 0x06000271 RID: 625 RVA: 0x00013440 File Offset: 0x00011640
228 public void ComeUpWithRecipe(string idRecipe, int chanceForRandomRecipe = 0)
229 {
230 if (idRecipe.IsEmpty())
231 {
232 return;
233 }
234 RecipeSource recipeSource = RecipeManager.Get(idRecipe);
235 if (EClass.rnd(10) != 0 && !EClass.debug.enable)
236 {
237 return;
238 }
239 if (recipeSource == null || EClass.player.recipes.knownRecipes.ContainsKey(idRecipe) || (!recipeSource.NeedFactory && !recipeSource.IsQuickCraft))
240 {
241 if (recipeSource != null && chanceForRandomRecipe > 0 && EClass.rnd(EClass.debug.enable ? 1 : chanceForRandomRecipe) == 0)
242 {
243 this.ComeUpWithRandomRecipe(recipeSource.row.Category.id, 0);
244 }
245 return;
246 }
247 int id = recipeSource.GetReqSkill().id;
248 if (EClass.pc.Evalue(id) + 5 < recipeSource.row.LV)
249 {
250 Msg.Say("recipeReqLv", EClass.sources.elements.map[id].GetName(), null, null, null);
251 return;
252 }
253 Msg.Say("learnRecipeIdea");
254 this.Add(idRecipe, true);
255 }
256
257 // Token: 0x06000272 RID: 626 RVA: 0x00013538 File Offset: 0x00011738
258 public static RecipeSource GetUnlearnedRecipe(int lvBonus, string cat, bool onlyUnlearned)
259 {
260 RecipeManager.BuildList();
261 List<RecipeSource> list = new List<RecipeSource>();
262 foreach (RecipeSource recipeSource in RecipeManager.list)
263 {
264 if ((recipeSource.NeedFactory || recipeSource.IsQuickCraft) && (cat == null || recipeSource.row.Category.IsChildOf(cat)) && (!onlyUnlearned || !EClass.player.recipes.knownRecipes.ContainsKey(recipeSource.id)) && EClass.pc.Evalue(recipeSource.GetReqSkill().id) + 5 + lvBonus >= recipeSource.row.LV)
265 {
266 list.Add(recipeSource);
267 }
268 }
269 return list.RandomItemWeighted((RecipeSource r) => (float)((r.row.chance == 0) ? 100 : r.row.chance));
270 }
271
272 // Token: 0x06000273 RID: 627 RVA: 0x00013628 File Offset: 0x00011828
273 public static RecipeSource GetLearnedRecipe(string cat = null)
274 {
275 List<RecipeSource> list = new List<RecipeSource>();
276 foreach (string id in EClass.player.recipes.knownRecipes.Keys)
277 {
278 RecipeSource recipeSource = RecipeManager.Get(id);
279 if (recipeSource != null && recipeSource.row is SourceThing.Row && (recipeSource.NeedFactory || recipeSource.IsQuickCraft) && (cat == null || recipeSource.row.Category.IsChildOf(cat)))
280 {
281 list.Add(recipeSource);
282 }
283 }
284 return list.RandomItemWeighted((RecipeSource r) => (float)((r.row.chance == 0) ? 100 : r.row.chance));
285 }
286
287 // Token: 0x06000274 RID: 628 RVA: 0x000136F0 File Offset: 0x000118F0
288 public static string GetRandomRecipe(int lvBonus, string cat = null, bool onlyUnlearned = false)
289 {
290 RecipeSource recipeSource = RecipeManager.GetUnlearnedRecipe(lvBonus, cat, onlyUnlearned);
291 if (recipeSource == null)
292 {
293 recipeSource = RecipeManager.GetLearnedRecipe(cat);
294 }
295 if (recipeSource == null)
296 {
297 return null;
298 }
299 return recipeSource.id;
300 }
301
302 // Token: 0x06000275 RID: 629 RVA: 0x0001371D File Offset: 0x0001191D
303 public void OnVersionUpdate()
304 {
305 EClass.pc.things.Foreach(delegate(Thing t)
306 {
307 this.knownIngredients.Add(t.id);
308 }, true);
309 this.knownIngredients.Add("flower");
310 }
311
312 // Token: 0x04000508 RID: 1288
313 public static bool rebuild;
314
315 // Token: 0x04000509 RID: 1289
316 public static List<RecipeSource> list = new List<RecipeSource>();
317
318 // Token: 0x0400050A RID: 1290
319 public static Dictionary<string, RecipeSource> dict = new Dictionary<string, RecipeSource>();
320
321 // Token: 0x0400050B RID: 1291
322 [JsonProperty]
323 public HashSet<string> knownIngredients = new HashSet<string>();
324
325 // Token: 0x0400050C RID: 1292
326 [JsonProperty]
327 public Dictionary<string, int> knownRecipes = new Dictionary<string, int>();
328
329 // Token: 0x0400050D RID: 1293
330 [JsonProperty]
331 public HashSet<string> hoveredRecipes = new HashSet<string>();
332
333 // Token: 0x0400050E RID: 1294
334 [JsonProperty]
335 public HashSet<string> newRecipes = new HashSet<string>();
336}
Definition Msg.cs:7
Definition Thing.cs:10