10 public static void BuildList()
16 Debug.Log(
"Rebuilding recipe list");
21 if (!cardRow.isOrigin && (cardRow.factory.IsEmpty() || !(cardRow.factory[0] ==
"x")))
23 RecipeManager.Create(cardRow,
"", cardRow.isChara ?
"-c" :
"");
36 if (!row2.tag.Contains(
"noFloor"))
43 if (!row3.tag.Contains(
"noBridge") && !row3.factory.IsEmpty() && row3.factory[0] !=
"x")
56 RecipeManager.rebuild =
false;
60 public static void Create(
RenderRow row,
string type,
string suffix =
"")
63 recipeSource.id = row.RecipeID + suffix;
64 recipeSource.isBridge = (type ==
"Bridge");
65 recipeSource.isBridgePillar = (type ==
"BridgePillar");
66 recipeSource.type = type;
67 recipeSource.row = row;
71 string[] components = row.components;
72 Recipe.Create(recipeSource, -1,
null).BuildIngredientList();
88 public void Add(
string id,
bool showEffect =
true)
95 if (recipeSource ==
null)
99 if (!this.knownRecipes.ContainsKey(
id))
101 this.newRecipes.Add(
id);
102 this.knownRecipes[id] = 0;
104 Dictionary<string, int> dictionary = this.knownRecipes;
105 int num = dictionary[id];
106 dictionary[id] = num + 1;
107 int num2 = this.knownRecipes[id];
110 EClass.pc.PlaySound(
"idea", 1f,
true);
111 EClass.pc.ShowEmo(Emo.idea, 0.5f,
false);
113 EClass.pc.Say(
"learnRecipe" + ((num2 == 1) ?
"New" :
""),
RecipeManager.dict[
id].Name.ToTitleCase(
false), num2.ToString() ??
"");
114 if (recipeSource.row.category ==
"floor")
117 if (recipeSource !=
null && !this.knownRecipes.ContainsKey(recipeSource.id))
119 this.Add(recipeSource.id,
false);
122 if (recipeSource !=
null && !this.knownRecipes.ContainsKey(recipeSource.id))
124 this.Add(recipeSource.id,
false);
130 public bool IsKnown(
string id)
132 return EClass.debug.allRecipe ||
EClass.player.recipes.knownRecipes.ContainsKey(
id);
136 public List<RecipeSource> ListSources(
Thing factory, List<RecipeSource> newRecipes =
null)
139 List<RecipeSource> list =
new List<RecipeSource>();
142 if (!recipeSource.isBridgePillar && (factory !=
null || !(recipeSource.idFactory !=
"self")) && (factory ==
null || factory.trait.Contains(recipeSource)) && !recipeSource.isChara && !recipeSource.noListing)
144 if (!
EClass.debug.godCraft && !
EClass.player.recipes.knownRecipes.ContainsKey(recipeSource.id))
147 if (recipeSource.row.recipeKey !=
null && recipeSource.row.recipeKey.Length != 0 && recipeSource.row.recipeKey[0][0] ==
'*')
151 string id = recipeSource.id;
152 if (!(
id ==
"waystone"))
154 if (
id ==
"container_shipping")
170 if (newRecipes !=
null)
172 EClass.player.recipes.Add(recipeSource.id,
true);
173 if (
EClass.player.recipes.newRecipes.Contains(recipeSource.id))
175 newRecipes.Add(recipeSource);
176 EClass.player.recipes.newRecipes.Remove(recipeSource.id);
180 list.Add(recipeSource);
187 public void OnSleep(
bool ehe =
false)
189 int slept =
EClass.player.stats.slept;
190 Rand.SetSeed(
EClass.game.seed + slept);
191 if (slept > 3 &&
EClass.rnd(3) == 0)
197 if (slept > 15 &&
EClass.rnd(3) == 0)
201 if (slept > 30 &&
EClass.rnd(3) == 0)
205 if (slept > 60 &&
EClass.rnd(3) == 0)
210 Msg.Say(
"learnRecipeSleep");
216 public void ComeUpWithRandomRecipe(
string idCat =
null,
int lvBonus = 0)
218 string randomRecipe =
RecipeManager.GetRandomRecipe(lvBonus, idCat,
true);
219 if (randomRecipe ==
null)
223 Msg.Say(
"learnRecipeIdea");
224 this.Add(randomRecipe,
true);
228 public void ComeUpWithRecipe(
string idRecipe,
int chanceForRandomRecipe = 0)
230 if (idRecipe.IsEmpty())
239 if (recipeSource ==
null ||
EClass.player.recipes.knownRecipes.ContainsKey(idRecipe) || (!recipeSource.NeedFactory && !recipeSource.IsQuickCraft))
241 if (recipeSource !=
null && chanceForRandomRecipe > 0 &&
EClass.rnd(
EClass.debug.enable ? 1 : chanceForRandomRecipe) == 0)
243 this.ComeUpWithRandomRecipe(recipeSource.row.Category.id, 0);
247 int id = recipeSource.GetReqSkill().id;
248 if (
EClass.pc.Evalue(
id) + 5 < recipeSource.row.LV)
250 Msg.Say(
"recipeReqLv",
EClass.sources.elements.map[
id].GetName(),
null,
null,
null);
253 Msg.Say(
"learnRecipeIdea");
254 this.Add(idRecipe,
true);
258 public static RecipeSource GetUnlearnedRecipe(
int lvBonus,
string cat,
bool onlyUnlearned)
261 List<RecipeSource> list =
new List<RecipeSource>();
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)
266 list.Add(recipeSource);
269 return list.RandomItemWeighted((
RecipeSource r) => (
float)((r.row.chance == 0) ? 100 : r.row.chance));
273 public static RecipeSource GetLearnedRecipe(
string cat =
null)
275 List<RecipeSource> list =
new List<RecipeSource>();
276 foreach (
string id in EClass.player.recipes.knownRecipes.Keys)
279 if (recipeSource !=
null && recipeSource.row is
SourceThing.
Row && (recipeSource.NeedFactory || recipeSource.IsQuickCraft) && (cat ==
null || recipeSource.row.Category.IsChildOf(cat)))
281 list.Add(recipeSource);
284 return list.RandomItemWeighted((
RecipeSource r) => (
float)((r.row.chance == 0) ? 100 : r.row.chance));
288 public static string GetRandomRecipe(
int lvBonus,
string cat =
null,
bool onlyUnlearned =
false)
291 if (recipeSource ==
null)
295 if (recipeSource ==
null)
299 return recipeSource.id;
303 public void OnVersionUpdate()
307 this.knownIngredients.Add(t.id);
309 this.knownIngredients.Add(
"flower");
313 public static bool rebuild;
316 public static List<RecipeSource> list =
new List<RecipeSource>();
319 public static Dictionary<string, RecipeSource> dict =
new Dictionary<string, RecipeSource>();
323 public HashSet<string> knownIngredients =
new HashSet<string>();
327 public Dictionary<string, int> knownRecipes =
new Dictionary<string, int>();
331 public HashSet<string> hoveredRecipes =
new HashSet<string>();
335 public HashSet<string> newRecipes =
new HashSet<string>();