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