public static PartRecipe SimpleTwoPartRecipe(int partID, int partAmount, int part2ID, int part2Amount, int resultID, int resultAmount = 1) { PartRecipe ans = SimplePartRecipe(partID, partAmount, resultID, resultAmount); ans.addPart(part2ID, part2Amount); return(ans); }
public static int orderByID(PartRecipe x, PartRecipe y) { int res = x.result.type.CompareTo(y.result.type); if (res != 0) { return(res); } res = x.parts.Count.CompareTo(y.parts.Count); if (res != 0) { return(res); } int xCount = 0; int yCount = 0; for (int i = 0; i < x.parts.Count; i++) { xCount += x.parts[i].stack; yCount += y.parts[i].stack; } if (xCount != yCount) { return(xCount.CompareTo(yCount)); } for (int i = 0; i < x.parts.Count; i++) { res = x.parts[i].type.CompareTo(y.parts[i].type); if (res != 0) { return(res); } } return(0); }
public virtual bool EqualsIgnoreStack(object obj) { PartRecipe eq = obj as PartRecipe; if (eq == null) { return(false); } if (this.result.type != eq.result.type) { return(false); } if (this.parts.Count != eq.parts.Count) { return(false); } int matches = 0; for (int i = 0; i < this.parts.Count; i++) { for (int k = i; k < this.parts.Count; k++) { if (this.parts[i].type == eq.parts[k].type) { matches++; } } } return(matches >= this.parts.Count); }
public static PartRecipe SimplePartRecipe(int partID, int partAmount, int resultID, int resultAmount = 1) { PartRecipe ans = new PartRecipe(); Item part = new Item(); part.SetDefaults(partID, true); part.stack = partAmount; ans.parts.Add(part); ans.result = new Item(); ans.result.SetDefaults(resultID, true); ans.result.stack = resultAmount; return(ans); }
public static void addRecipe(PartRecipe recipe) { bool added = false; if (recipe.result.IsAir) { return; } if (!recipesByResult.ContainsKey(ARareItemSwapJPANs.ItemToTag(recipe.result))) { recipesByResult[ARareItemSwapJPANs.ItemToTag(recipe.result)] = new List <PartRecipe>(); } for (int i = 0; i < recipesByResult[ARareItemSwapJPANs.ItemToTag(recipe.result)].Count; i++) { if (recipesByResult[ARareItemSwapJPANs.ItemToTag(recipe.result)][i].EqualsIgnoreStack(recipe)) { recipe.addCategory(recipesByResult[ARareItemSwapJPANs.ItemToTag(recipe.result)][i].categories); allRecipes.Remove(recipesByResult[ARareItemSwapJPANs.ItemToTag(recipe.result)][i]); recipesByResult[ARareItemSwapJPANs.ItemToTag(recipe.result)][i] = recipe; allRecipes.Add(recipe); added = true; } } if (!added) { allRecipes.Add(recipe); recipesByResult[ARareItemSwapJPANs.ItemToTag(recipe.result)].Add(recipe); } foreach (string cat in recipe.categories) { added = false; if (!recipesByCategory.ContainsKey(cat)) { recipesByCategory[cat] = new List <PartRecipe>(); } for (int i = 0; i < recipesByCategory[cat].Count; i++) { if (recipesByCategory[cat][i].EqualsIgnoreStack(recipe)) { recipesByCategory[cat][i] = recipe; added = true; } } if (!added) { recipesByCategory[cat].Add(recipe); foreach (Item p in recipe.parts) { added = false; string newCat = "By Part Cost/" + p.Name;; if (!recipesByCategory.ContainsKey(newCat)) { recipesByCategory[newCat] = new List <PartRecipe>(); } for (int i = 0; i < recipesByCategory[newCat].Count; i++) { if (recipesByCategory[newCat][i].EqualsIgnoreStack(recipe)) { recipesByCategory[newCat][i] = recipe; added = true; } } if (!added) { recipesByCategory[newCat].Add(recipe); } newCat = "By Part Cost/" + p.Name + "/" + cat; if (!recipesByCategory.ContainsKey(newCat)) { recipesByCategory[newCat] = new List <PartRecipe>(); } recipesByCategory[newCat].Add(recipe); } } } }