Elin Decompiled Documentation EA 23.309 Nightly Patch 1
Loading...
Searching...
No Matches
RecipeManager.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using Newtonsoft.Json;
3using UnityEngine;
4
5public class RecipeManager : EClass
6{
7 public enum LearnState
8 {
13 }
14
15 public static bool rebuild;
16
17 public static List<RecipeSource> list = new List<RecipeSource>();
18
19 public static Dictionary<string, RecipeSource> dict = new Dictionary<string, RecipeSource>();
20
21 [JsonProperty]
22 public HashSet<string> knownIngredients = new HashSet<string>();
23
24 [JsonProperty]
25 public HashSet<string> craftedRecipes = new HashSet<string>();
26
27 [JsonProperty]
28 public Dictionary<string, int> knownRecipes = new Dictionary<string, int>();
29
30 [JsonProperty]
31 public HashSet<string> hoveredRecipes = new HashSet<string>();
32
33 [JsonProperty]
34 public HashSet<string> newRecipes = new HashSet<string>();
35
36 [JsonProperty]
37 public Dictionary<string, List<int>> lastIngredients = new Dictionary<string, List<int>>();
38
39 public static void BuildList()
40 {
41 if (!rebuild && list.Count > 0)
42 {
43 return;
44 }
45 Debug.Log("Rebuilding recipe list");
46 list.Clear();
47 dict.Clear();
48 foreach (CardRow row in EClass.sources.cards.rows)
49 {
50 if (!row.isOrigin)
51 {
52 Create(row, "", row.isChara ? "-c" : "");
53 }
54 }
55 foreach (SourceBlock.Row row2 in EClass.sources.blocks.rows)
56 {
57 Create(row2, "Block");
58 if (row2.tileType == TileType.Pillar)
59 {
60 Create(row2, "BridgePillar", "-p");
61 }
62 }
63 foreach (SourceFloor.Row row3 in EClass.sources.floors.rows)
64 {
65 if (!row3.tag.Contains("noFloor"))
66 {
67 Create(row3, "Floor");
68 }
69 }
70 foreach (SourceFloor.Row row4 in EClass.sources.floors.rows)
71 {
72 if (!row4.tag.Contains("noBridge") && !row4.factory.IsEmpty() && row4.factory[0] != "x")
73 {
74 Create(row4, "Bridge", "-b");
75 }
76 }
77 foreach (SourceDeco.Row row5 in EClass.sources.decos.rows)
78 {
79 Create(row5, "Deco");
80 }
81 foreach (SourceObj.Row row6 in EClass.sources.objs.rows)
82 {
83 Create(row6, "Obj");
84 }
85 foreach (SourceCellEffect.Row row7 in EClass.sources.cellEffects.rows)
86 {
87 Create(row7, "Liquid");
88 }
89 rebuild = false;
90 }
91
92 public static void Create(RenderRow row, string type, string suffix = "")
93 {
94 RecipeSource recipeSource = new RecipeSource();
95 recipeSource.id = row.RecipeID + suffix;
96 recipeSource.isBridge = type == "Bridge";
97 recipeSource.isBridgePillar = type == "BridgePillar";
98 recipeSource.type = type;
99 recipeSource.row = row;
100 recipeSource.isChara = row is SourceChara.Row;
101 if (!row.factory.IsEmpty() && row.factory[0] == "x")
102 {
103 recipeSource.noListing = true;
104 }
105 list.Add(recipeSource);
106 dict[recipeSource.id] = recipeSource;
107 _ = row.components;
108 Recipe.Create(recipeSource).BuildIngredientList();
109 }
110
111 public static RecipeSource Get(string id)
112 {
113 return dict.TryGetValue(id);
114 }
115
116 public RecipeSource GetSource(string id)
117 {
118 return dict.TryGetValue(id);
119 }
120
121 public void Add(string id, bool showEffect = true)
122 {
123 if (id.IsEmpty())
124 {
125 return;
126 }
127 RecipeSource recipeSource = Get(id);
128 if (recipeSource == null)
129 {
130 return;
131 }
132 if (!knownRecipes.ContainsKey(id))
133 {
134 newRecipes.Add(id);
135 knownRecipes[id] = 0;
136 }
137 knownRecipes[id]++;
138 int num = knownRecipes[id];
139 if (showEffect)
140 {
141 EClass.pc.PlaySound("idea");
142 EClass.pc.ShowEmo(Emo.idea, 0.5f, skipSame: false);
143 }
144 EClass.pc.Say("learnRecipe" + ((num == 1) ? "New" : ""), dict[id].Name.ToTitleCase(), num.ToString() ?? "");
145 if (num == 1 && !recipeSource.isBridgePillar)
146 {
147 if (recipeSource.NeedFactory)
148 {
149 EClass.pc.Say("recipe_factory", recipeSource.NameFactory);
150 }
151 else
152 {
153 EClass.pc.Say("recipe_nofactory");
154 }
155 }
156 recipeSource = Get(id + "-p");
157 if (recipeSource != null && !knownRecipes.ContainsKey(recipeSource.id))
158 {
159 Add(recipeSource.id, showEffect: false);
160 }
161 recipeSource = Get(id.Replace("-p", ""));
162 if (recipeSource != null && !knownRecipes.ContainsKey(recipeSource.id))
163 {
164 Add(recipeSource.id, showEffect: false);
165 }
166 if (recipeSource.row.category == "floor")
167 {
168 recipeSource = Get(id + "-b");
169 if (recipeSource != null && !knownRecipes.ContainsKey(recipeSource.id))
170 {
171 Add(recipeSource.id, showEffect: false);
172 }
173 recipeSource = Get(id.Replace("-b", ""));
174 if (recipeSource != null && !knownRecipes.ContainsKey(recipeSource.id))
175 {
176 Add(recipeSource.id, showEffect: false);
177 }
178 }
179 }
180
181 public bool IsKnown(string id)
182 {
184 {
185 return EClass.player.recipes.knownRecipes.ContainsKey(id);
186 }
187 return true;
188 }
189
190 public List<RecipeSource> ListSources(Thing factory, List<RecipeSource> newRecipes = null)
191 {
192 BuildList();
193 List<RecipeSource> list = new List<RecipeSource>();
195 {
196 if (item.isBridgePillar || (factory == null && item.idFactory != "self") || (factory != null && !factory.trait.Contains(item)) || item.isChara || item.noListing)
197 {
198 continue;
199 }
200 if (!EClass.debug.godCraft && !EClass.player.recipes.knownRecipes.ContainsKey(item.id))
201 {
202 bool flag = false;
203 if (item.row.recipeKey != null && item.row.recipeKey.Length != 0 && item.row.recipeKey[0][0] == '*')
204 {
205 flag = true;
206 }
207 string id = item.id;
208 if (!(id == "waystone"))
209 {
210 if (id == "container_shipping" && EClass.game.quests.GetPhase<QuestShippingChest>() >= 0)
211 {
212 flag = true;
213 }
214 }
215 else if (EClass.game.quests.GetPhase<QuestExploration>() >= 6)
216 {
217 flag = true;
218 }
219 if (!flag)
220 {
221 continue;
222 }
223 if (newRecipes != null)
224 {
226 if (EClass.player.recipes.newRecipes.Contains(item.id))
227 {
228 newRecipes.Add(item);
230 }
231 }
232 }
233 list.Add(item);
234 }
235 return list;
236 }
237
238 public void OnSleep(bool ehe = false)
239 {
240 int slept = EClass.player.stats.slept;
241 Rand.SetSeed(EClass.game.seed + slept);
242 if ((slept <= 3 || EClass.rnd(ehe ? 777 : 3) != 0) && (EClass.rnd(EClass.pc.Evalue(1642) + 1) > 0 || ((slept <= 15 || EClass.rnd(3) != 0) && (slept <= 30 || EClass.rnd(3) != 0) && (slept <= 60 || EClass.rnd(3) != 0))))
243 {
244 Msg.Say("learnRecipeSleep");
245 Rand.SetSeed();
246 Add(GetRandomRecipe((ehe ? 5 : 0) + EClass.rnd(EClass.rnd(EClass.rnd(10)))));
247 }
248 }
249
250 public void ComeUpWithRandomRecipe(string idCat = null, int lvBonus = 0)
251 {
252 string randomRecipe = GetRandomRecipe(lvBonus, idCat, onlyUnlearned: true);
253 if (randomRecipe != null)
254 {
255 Msg.Say("learnRecipeIdea");
256 Add(randomRecipe);
257 }
258 }
259
260 public LearnState GetRecipeLearnState(string idRecipe)
261 {
262 if (idRecipe.IsEmpty())
263 {
264 return LearnState.Unavailable;
265 }
266 RecipeSource recipeSource = Get(idRecipe);
267 if (recipeSource == null || (!recipeSource.NeedFactory && !recipeSource.IsQuickCraft))
268 {
269 return LearnState.Unavailable;
270 }
271 if (EClass.player.recipes.knownRecipes.ContainsKey(idRecipe))
272 {
273 return LearnState.AlreadyLearned;
274 }
275 int id = recipeSource.GetReqSkill().id;
276 if (EClass.pc.Evalue(id) + 5 < recipeSource.row.LV)
277 {
278 return LearnState.InsufficientSkill;
279 }
280 return LearnState.Learnable;
281 }
282
283 public void ComeUpWithRecipe(string idRecipe, int chanceForRandomRecipe = 0)
284 {
285 if (idRecipe.IsEmpty())
286 {
287 return;
288 }
289 RecipeSource recipeSource = Get(idRecipe);
290 int num = EClass.pc.Evalue(1661);
291 if (EClass.rnd((num >= 2) ? 5 : ((num == 1) ? 8 : 10)) != 0 && !EClass.debug.enable)
292 {
293 return;
294 }
295 if (recipeSource == null || EClass.player.recipes.knownRecipes.ContainsKey(idRecipe) || (!recipeSource.NeedFactory && !recipeSource.IsQuickCraft))
296 {
297 if (recipeSource != null && chanceForRandomRecipe > 0 && EClass.rnd(EClass.debug.enable ? 1 : chanceForRandomRecipe) == 0)
298 {
299 ComeUpWithRandomRecipe(recipeSource.row.Category.id);
300 }
301 return;
302 }
303 int id = recipeSource.GetReqSkill().id;
304 if (EClass.pc.Evalue(id) + 5 < recipeSource.row.LV)
305 {
306 Msg.Say("recipeReqLv", EClass.sources.elements.map[id].GetName());
307 return;
308 }
309 Msg.Say("learnRecipeIdea");
310 Add(idRecipe);
311 }
312
313 public static RecipeSource GetUnlearnedRecipe(int lvBonus, string cat, bool onlyUnlearned)
314 {
315 BuildList();
316 List<RecipeSource> list = new List<RecipeSource>();
318 {
319 if (!item.alwaysKnown && !item.noRandomRecipe && (item.NeedFactory || item.IsQuickCraft) && (cat == null || item.row.Category.IsChildOf(cat)) && (!onlyUnlearned || !EClass.player.recipes.knownRecipes.ContainsKey(item.id)) && EClass.pc.Evalue(item.GetReqSkill().id) + 5 + lvBonus >= item.row.LV && !item.row.ContainsTag("hiddenRecipe"))
320 {
321 list.Add(item);
322 }
323 }
324 return list.RandomItemWeighted((RecipeSource r) => (r.row.chance == 0) ? 100 : r.row.chance);
325 }
326
327 public static RecipeSource GetLearnedRecipe(string cat = null)
328 {
329 List<RecipeSource> list = new List<RecipeSource>();
330 foreach (string key in EClass.player.recipes.knownRecipes.Keys)
331 {
332 RecipeSource recipeSource = Get(key);
333 if (recipeSource != null && recipeSource.row is SourceThing.Row && !recipeSource.noRandomRecipe && (recipeSource.NeedFactory || recipeSource.IsQuickCraft) && (cat == null || recipeSource.row.Category.IsChildOf(cat)))
334 {
335 list.Add(recipeSource);
336 }
337 }
338 return list.RandomItemWeighted((RecipeSource r) => (r.row.chance == 0) ? 100 : r.row.chance);
339 }
340
341 public static string GetRandomRecipe(int lvBonus, string cat = null, bool onlyUnlearned = false)
342 {
343 RecipeSource recipeSource = null;
344 recipeSource = GetUnlearnedRecipe(lvBonus, cat, onlyUnlearned);
345 if (recipeSource == null)
346 {
347 recipeSource = GetLearnedRecipe(cat);
348 }
349 return recipeSource?.id;
350 }
351
352 public void OnVersionUpdate()
353 {
354 EClass.pc.things.Foreach(delegate(Thing t)
355 {
356 knownIngredients.Add(t.id);
357 });
358 knownIngredients.Add("flower");
359 }
360}
Emo
Definition: Emo.cs:2
bool isChara
Definition: CardRow.cs:55
bool isOrigin
Definition: CardRow.cs:52
string id
Definition: Card.cs:36
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:6481
void ShowEmo(Emo _emo=Emo.none, float duration=0f, bool skipSame=true)
Definition: Card.cs:6449
ThingContainer things
Definition: Card.cs:39
int Evalue(int ele)
Definition: Card.cs:2625
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:7159
bool godCraft
Definition: CoreDebug.cs:196
bool enable
Definition: CoreDebug.cs:301
bool allRecipe
Definition: CoreDebug.cs:248
Definition: EClass.cs:6
static Game game
Definition: EClass.cs:9
static int rnd(long a)
Definition: EClass.cs:59
static SourceManager sources
Definition: EClass.cs:43
static Player player
Definition: EClass.cs:13
static Chara pc
Definition: EClass.cs:15
static CoreDebug debug
Definition: EClass.cs:49
int id
Definition: ELEMENT.cs:255
QuestManager quests
Definition: Game.cs:183
int seed
Definition: Game.cs:201
Definition: Msg.cs:5
static string Say(string idLang, string ref1, string ref2=null, string ref3=null, string ref4=null)
Definition: Msg.cs:58
int slept
Definition: Player.cs:102
RecipeManager recipes
Definition: Player.cs:1164
Stats stats
Definition: Player.cs:1083
int GetPhase(string id)
Definition: Rand.cs:4
static void SetSeed(int a=-1)
Definition: Rand.cs:44
static bool rebuild
Dictionary< string, List< int > > lastIngredients
static void BuildList()
HashSet< string > craftedRecipes
static List< RecipeSource > list
void ComeUpWithRecipe(string idRecipe, int chanceForRandomRecipe=0)
bool IsKnown(string id)
static RecipeSource Get(string id)
static RecipeSource GetLearnedRecipe(string cat=null)
static Dictionary< string, RecipeSource > dict
HashSet< string > knownIngredients
static void Create(RenderRow row, string type, string suffix="")
static RecipeSource GetUnlearnedRecipe(int lvBonus, string cat, bool onlyUnlearned)
LearnState GetRecipeLearnState(string idRecipe)
void OnSleep(bool ehe=false)
Dictionary< string, int > knownRecipes
List< RecipeSource > ListSources(Thing factory, List< RecipeSource > newRecipes=null)
void Add(string id, bool showEffect=true)
void OnVersionUpdate()
HashSet< string > hoveredRecipes
static string GetRandomRecipe(int lvBonus, string cat=null, bool onlyUnlearned=false)
void ComeUpWithRandomRecipe(string idCat=null, int lvBonus=0)
RecipeSource GetSource(string id)
HashSet< string > newRecipes
Element GetReqSkill()
RenderRow row
Definition: RecipeSource.cs:5
bool IsQuickCraft
Definition: RecipeSource.cs:51
string NameFactory
Definition: RecipeSource.cs:75
bool isBridgePillar
Definition: RecipeSource.cs:15
bool noRandomRecipe
Definition: RecipeSource.cs:25
bool NeedFactory
Definition: RecipeSource.cs:63
Definition: Recipe.cs:7
static Recipe Create(RecipeSource _source, int idMat=-1, Thing ing=null)
Definition: Recipe.cs:325
virtual void BuildIngredientList()
Definition: Recipe.cs:534
string[] factory
Definition: RenderRow.cs:54
SourceCategory.Row Category
Definition: RenderRow.cs:119
string category
Definition: RenderRow.cs:46
string[] components
Definition: RenderRow.cs:52
int chance
Definition: RenderRow.cs:24
int LV
Definition: RenderRow.cs:22
List< CardRow > rows
Definition: SourceCard.cs:7
SourceCard cards
SourceObj objs
SourceDeco decos
SourceCellEffect cellEffects
SourceBlock blocks
SourceElement elements
SourceFloor floors
void Foreach(Action< Thing > action, bool onlyAccessible=true)
Definition: Thing.cs:8
static TileTypePillar Pillar
Definition: TileType.cs:41