Elin Decompiled Documentation EA 23.222 Stable nyan
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 && (row.factory.IsEmpty() || !(row.factory[0] == "x")))
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 (SourceObj.Row row5 in EClass.sources.objs.rows)
78 {
79 Create(row5, "Obj");
80 }
81 foreach (SourceCellEffect.Row row6 in EClass.sources.cellEffects.rows)
82 {
83 Create(row6, "Liquid");
84 }
85 rebuild = false;
86 }
87
88 public static void Create(RenderRow row, string type, string suffix = "")
89 {
90 RecipeSource recipeSource = new RecipeSource();
91 recipeSource.id = row.RecipeID + suffix;
92 recipeSource.isBridge = type == "Bridge";
93 recipeSource.isBridgePillar = type == "BridgePillar";
94 recipeSource.type = type;
95 recipeSource.row = row;
96 recipeSource.isChara = row is SourceChara.Row;
97 list.Add(recipeSource);
98 dict[recipeSource.id] = recipeSource;
99 _ = row.components;
100 Recipe.Create(recipeSource).BuildIngredientList();
101 }
102
103 public static RecipeSource Get(string id)
104 {
105 return dict.TryGetValue(id);
106 }
107
108 public RecipeSource GetSource(string id)
109 {
110 return dict.TryGetValue(id);
111 }
112
113 public void Add(string id, bool showEffect = true)
114 {
115 if (id.IsEmpty())
116 {
117 return;
118 }
119 RecipeSource recipeSource = Get(id);
120 if (recipeSource == null)
121 {
122 return;
123 }
124 if (!knownRecipes.ContainsKey(id))
125 {
126 newRecipes.Add(id);
127 knownRecipes[id] = 0;
128 }
129 knownRecipes[id]++;
130 int num = knownRecipes[id];
131 if (showEffect)
132 {
133 EClass.pc.PlaySound("idea");
134 EClass.pc.ShowEmo(Emo.idea, 0.5f, skipSame: false);
135 }
136 EClass.pc.Say("learnRecipe" + ((num == 1) ? "New" : ""), dict[id].Name.ToTitleCase(), num.ToString() ?? "");
137 if (num == 1 && !recipeSource.isBridgePillar)
138 {
139 if (recipeSource.NeedFactory)
140 {
141 EClass.pc.Say("recipe_factory", recipeSource.NameFactory);
142 }
143 else
144 {
145 EClass.pc.Say("recipe_nofactory");
146 }
147 }
148 recipeSource = Get(id + "-p");
149 if (recipeSource != null && !knownRecipes.ContainsKey(recipeSource.id))
150 {
151 Add(recipeSource.id, showEffect: false);
152 }
153 recipeSource = Get(id.Replace("-p", ""));
154 if (recipeSource != null && !knownRecipes.ContainsKey(recipeSource.id))
155 {
156 Add(recipeSource.id, showEffect: false);
157 }
158 if (recipeSource.row.category == "floor")
159 {
160 recipeSource = Get(id + "-b");
161 if (recipeSource != null && !knownRecipes.ContainsKey(recipeSource.id))
162 {
163 Add(recipeSource.id, showEffect: false);
164 }
165 recipeSource = Get(id.Replace("-b", ""));
166 if (recipeSource != null && !knownRecipes.ContainsKey(recipeSource.id))
167 {
168 Add(recipeSource.id, showEffect: false);
169 }
170 }
171 }
172
173 public bool IsKnown(string id)
174 {
176 {
177 return EClass.player.recipes.knownRecipes.ContainsKey(id);
178 }
179 return true;
180 }
181
182 public List<RecipeSource> ListSources(Thing factory, List<RecipeSource> newRecipes = null)
183 {
184 BuildList();
185 List<RecipeSource> list = new List<RecipeSource>();
187 {
188 if (item.isBridgePillar || (factory == null && item.idFactory != "self") || (factory != null && !factory.trait.Contains(item)) || item.isChara || item.noListing)
189 {
190 continue;
191 }
192 if (!EClass.debug.godCraft && !EClass.player.recipes.knownRecipes.ContainsKey(item.id))
193 {
194 bool flag = false;
195 if (item.row.recipeKey != null && item.row.recipeKey.Length != 0 && item.row.recipeKey[0][0] == '*')
196 {
197 flag = true;
198 }
199 string id = item.id;
200 if (!(id == "waystone"))
201 {
202 if (id == "container_shipping" && EClass.game.quests.GetPhase<QuestShippingChest>() >= 0)
203 {
204 flag = true;
205 }
206 }
207 else if (EClass.game.quests.GetPhase<QuestExploration>() >= 6)
208 {
209 flag = true;
210 }
211 if (!flag)
212 {
213 continue;
214 }
215 if (newRecipes != null)
216 {
218 if (EClass.player.recipes.newRecipes.Contains(item.id))
219 {
220 newRecipes.Add(item);
222 }
223 }
224 }
225 list.Add(item);
226 }
227 return list;
228 }
229
230 public void OnSleep(bool ehe = false)
231 {
232 int slept = EClass.player.stats.slept;
233 Rand.SetSeed(EClass.game.seed + slept);
234 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))))
235 {
236 Msg.Say("learnRecipeSleep");
237 Rand.SetSeed();
238 Add(GetRandomRecipe((ehe ? 5 : 0) + EClass.rnd(EClass.rnd(EClass.rnd(10)))));
239 }
240 }
241
242 public void ComeUpWithRandomRecipe(string idCat = null, int lvBonus = 0)
243 {
244 string randomRecipe = GetRandomRecipe(lvBonus, idCat, onlyUnlearned: true);
245 if (randomRecipe != null)
246 {
247 Msg.Say("learnRecipeIdea");
248 Add(randomRecipe);
249 }
250 }
251
252 public LearnState GetRecipeLearnState(string idRecipe)
253 {
254 if (idRecipe.IsEmpty())
255 {
256 return LearnState.Unavailable;
257 }
258 RecipeSource recipeSource = Get(idRecipe);
259 if (recipeSource == null || (!recipeSource.NeedFactory && !recipeSource.IsQuickCraft))
260 {
261 return LearnState.Unavailable;
262 }
263 if (EClass.player.recipes.knownRecipes.ContainsKey(idRecipe))
264 {
265 return LearnState.AlreadyLearned;
266 }
267 int id = recipeSource.GetReqSkill().id;
268 if (EClass.pc.Evalue(id) + 5 < recipeSource.row.LV)
269 {
270 return LearnState.InsufficientSkill;
271 }
272 return LearnState.Learnable;
273 }
274
275 public void ComeUpWithRecipe(string idRecipe, int chanceForRandomRecipe = 0)
276 {
277 if (idRecipe.IsEmpty())
278 {
279 return;
280 }
281 RecipeSource recipeSource = Get(idRecipe);
282 int num = EClass.pc.Evalue(1661);
283 if (EClass.rnd((num >= 2) ? 5 : ((num == 1) ? 8 : 10)) != 0 && !EClass.debug.enable)
284 {
285 return;
286 }
287 if (recipeSource == null || EClass.player.recipes.knownRecipes.ContainsKey(idRecipe) || (!recipeSource.NeedFactory && !recipeSource.IsQuickCraft))
288 {
289 if (recipeSource != null && chanceForRandomRecipe > 0 && EClass.rnd(EClass.debug.enable ? 1 : chanceForRandomRecipe) == 0)
290 {
291 ComeUpWithRandomRecipe(recipeSource.row.Category.id);
292 }
293 return;
294 }
295 int id = recipeSource.GetReqSkill().id;
296 if (EClass.pc.Evalue(id) + 5 < recipeSource.row.LV)
297 {
298 Msg.Say("recipeReqLv", EClass.sources.elements.map[id].GetName());
299 return;
300 }
301 Msg.Say("learnRecipeIdea");
302 Add(idRecipe);
303 }
304
305 public static RecipeSource GetUnlearnedRecipe(int lvBonus, string cat, bool onlyUnlearned)
306 {
307 BuildList();
308 List<RecipeSource> list = new List<RecipeSource>();
310 {
311 if (!item.alwaysKnown && (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"))
312 {
313 list.Add(item);
314 }
315 }
316 return list.RandomItemWeighted((RecipeSource r) => (r.row.chance == 0) ? 100 : r.row.chance);
317 }
318
319 public static RecipeSource GetLearnedRecipe(string cat = null)
320 {
321 List<RecipeSource> list = new List<RecipeSource>();
322 foreach (string key in EClass.player.recipes.knownRecipes.Keys)
323 {
324 RecipeSource recipeSource = Get(key);
325 if (recipeSource != null && recipeSource.row is SourceThing.Row && (recipeSource.NeedFactory || recipeSource.IsQuickCraft) && (cat == null || recipeSource.row.Category.IsChildOf(cat)))
326 {
327 list.Add(recipeSource);
328 }
329 }
330 return list.RandomItemWeighted((RecipeSource r) => (r.row.chance == 0) ? 100 : r.row.chance);
331 }
332
333 public static string GetRandomRecipe(int lvBonus, string cat = null, bool onlyUnlearned = false)
334 {
335 RecipeSource recipeSource = null;
336 recipeSource = GetUnlearnedRecipe(lvBonus, cat, onlyUnlearned);
337 if (recipeSource == null)
338 {
339 recipeSource = GetLearnedRecipe(cat);
340 }
341 return recipeSource?.id;
342 }
343
344 public void OnVersionUpdate()
345 {
346 EClass.pc.things.Foreach(delegate(Thing t)
347 {
348 knownIngredients.Add(t.id);
349 });
350 knownIngredients.Add("flower");
351 }
352}
Emo
Definition: Emo.cs:2
bool isChara
Definition: CardRow.cs:55
bool isOrigin
Definition: CardRow.cs:52
string id
Definition: Card.cs:35
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:6009
void ShowEmo(Emo _emo=Emo.none, float duration=0f, bool skipSame=true)
Definition: Card.cs:5977
ThingContainer things
Definition: Card.cs:38
int Evalue(int ele)
Definition: Card.cs:2559
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:6661
bool godCraft
Definition: CoreDebug.cs:181
bool enable
Definition: CoreDebug.cs:286
bool allRecipe
Definition: CoreDebug.cs:233
Definition: EClass.cs:5
static Game game
Definition: EClass.cs:8
static int rnd(long a)
Definition: EClass.cs:58
static SourceManager sources
Definition: EClass.cs:42
static Player player
Definition: EClass.cs:12
static Chara pc
Definition: EClass.cs:14
static CoreDebug debug
Definition: EClass.cs:48
int id
Definition: ELEMENT.cs:250
QuestManager quests
Definition: Game.cs:179
int seed
Definition: Game.cs:197
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:1094
Stats stats
Definition: Player.cs:1013
Definition: Rand.cs:4
static void SetSeed(int a=-1)
Definition: Rand.cs:37
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:49
string NameFactory
Definition: RecipeSource.cs:73
bool isBridgePillar
Definition: RecipeSource.cs:15
bool NeedFactory
Definition: RecipeSource.cs:61
Definition: Recipe.cs:7
static Recipe Create(RecipeSource _source, int idMat=-1, Thing ing=null)
Definition: Recipe.cs:326
virtual void BuildIngredientList()
Definition: Recipe.cs:527
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:6
SourceCard cards
SourceObj objs
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