/// <summary> /// Deserializes the alloy /// </summary> /// <param name="reader"></param> /// <param name="resolver"></param> public void FromBytes(BinaryReader reader, IWorldAccessor resolver) { Code = reader.ReadString(); Ingredients = new CookingRecipeIngredient[reader.ReadInt32()]; for (int i = 0; i < Ingredients.Length; i++) { Ingredients[i] = new CookingRecipeIngredient(); Ingredients[i].FromBytes(reader, resolver.ClassRegistry); Ingredients[i].Resolve(resolver, "[FromBytes]"); } //NameComponentOrder = reader.ReadIntArray(); if (!reader.ReadBoolean()) { Shape = new CompositeShape() { Base = new AssetLocation(reader.ReadString()) }; } PerishableProps = new TransitionableProperties(); PerishableProps.FromBytes(reader, resolver.ClassRegistry); // CanBeServedInto = new JsonItemStack(); // CanBeServedInto.FromBytes(reader, resolver.ClassRegistry); // CanBeServedInto.Resolve(resolver, "[FromBytes]"); }
/// <summary> /// Creates a deep copy of this object /// </summary> /// <returns></returns> public CookingRecipeIngredient Clone() { CookingRecipeIngredient ingredient = new CookingRecipeIngredient() { Code = Code, MinQuantity = MinQuantity, MaxQuantity = MaxQuantity }; ingredient.ValidStacks = new CookingRecipeStack[ValidStacks.Length]; for (int i = 0; i < ValidStacks.Length; i++) { ingredient.ValidStacks[i] = ValidStacks[i].Clone(); } return(ingredient); }
public bool Matches(ItemStack[] inputStacks, ref int quantityServings) { List <ItemStack> inputStacksList = new List <ItemStack>(inputStacks); List <CookingRecipeIngredient> ingredientList = new List <CookingRecipeIngredient>(Ingredients); int totalOutputQuantity = 99999; int[] curQuantities = new int[ingredientList.Count]; for (int i = 0; i < curQuantities.Length; i++) { curQuantities[i] = 0; } while (inputStacksList.Count > 0) { ItemStack inputStack = inputStacksList[0]; inputStacksList.RemoveAt(0); if (inputStack == null) { continue; } bool found = false; for (int i = 0; i < ingredientList.Count; i++) { CookingRecipeIngredient ingred = ingredientList[i]; if (ingred.Matches(inputStack)) { if (curQuantities[i] >= ingred.MaxQuantity) { continue; } totalOutputQuantity = Math.Min(totalOutputQuantity, inputStack.StackSize); curQuantities[i]++; found = true; break; } } // This input stack does not fit in this cooking recipe if (!found) { return(false); } } // Any required ingredients left? for (int i = 0; i < ingredientList.Count; i++) { if (curQuantities[i] < ingredientList[i].MinQuantity) { return(false); } } quantityServings = totalOutputQuantity; // Too many ingredients? for (int i = 0; i < inputStacks.Length; i++) { if (inputStacks[i] == null) { continue; } if (inputStacks[i].StackSize > quantityServings) { return(false); } } return(true); }
/// <summary> /// Gets the name for ingredients in regards to food. /// </summary> /// <param name="worldForResolve">The world to resolve in.</param> /// <param name="recipeCode">The recipe code.</param> /// <param name="stacks">The stacks of items to add.</param> /// <returns>The name of the food type.</returns> public string GetNameForIngredients(IWorldAccessor worldForResolve, string recipeCode, ItemStack[] stacks) { OrderedDictionary <ItemStack, int> quantitiesByStack = new OrderedDictionary <ItemStack, int>(); quantitiesByStack = mergeStacks(worldForResolve, stacks); CookingRecipe recipe = worldForResolve.CookingRecipes.FirstOrDefault(rec => rec.Code == recipeCode); if (recipeCode == null || recipe == null) { return("unknown"); } int max = 1; string MealFormat = "meal"; string topping = string.Empty; ItemStack PrimaryIngredient = null; ItemStack SecondaryIngredient = null; List <string> OtherIngredients = new List <string>(); List <string> MashedNames = new List <string>(); List <string> GarnishedNames = new List <string>(); List <string> grainNames = new List <string>(); string mainIngredients; string everythingelse = ""; switch (recipeCode) { case "soup": { max = 0; foreach (var val in quantitiesByStack) { CookingRecipeIngredient ingred = recipe.GetIngrendientFor(val.Key); if (val.Key.Collectible.Code.Path.Contains("waterportion")) { continue; } if (ingred?.Code == "topping") { topping = "honeyportion"; continue; } if (max < val.Value) { max = val.Value; if (PrimaryIngredient != null) { SecondaryIngredient = PrimaryIngredient; } PrimaryIngredient = val.Key; } else { OtherIngredients.Add(ingredientName(val.Key, true)); } } if (max == 2) { max = 3; } else if (max == 3) { max = 4; } else { max = 2; } break; } case "porridge": { max = 0; foreach (var val in quantitiesByStack) { CookingRecipeIngredient ingred = recipe.GetIngrendientFor(val.Key); if (getFoodCat(val.Key) == EnumFoodCategory.Grain) { max++; if (PrimaryIngredient == null) { PrimaryIngredient = val.Key; } else if (SecondaryIngredient == null && val.Key != PrimaryIngredient) { SecondaryIngredient = val.Key; } continue; } if (ingred?.Code == "topping") { topping = "honeyportion"; continue; } MashedNames.Add(ingredientName(val.Key, true)); } break; } case "meatystew": { max = 0; foreach (var val in quantitiesByStack) { CookingRecipeIngredient ingred = recipe.GetIngrendientFor(val.Key); EnumFoodCategory foodCat = getFoodCat(val.Key); if (foodCat == EnumFoodCategory.Protein) { if (PrimaryIngredient == val.Key || SecondaryIngredient == val.Key) { continue; } if (PrimaryIngredient == null) { PrimaryIngredient = val.Key; } else if (SecondaryIngredient == null) { SecondaryIngredient = val.Key; } else { OtherIngredients.Add(ingredientName(val.Key, true)); } max += val.Value; continue; } if (ingred?.Code == "topping") { topping = "honeyportion"; continue; } OtherIngredients.Add(ingredientName(val.Key, true)); } recipeCode = "stew"; break; } case "vegetablestew": { max = 0; foreach (var val in quantitiesByStack) { if (getFoodCat(val.Key) == EnumFoodCategory.Vegetable) { if (PrimaryIngredient == val.Key || SecondaryIngredient == val.Key) { continue; } if (PrimaryIngredient == null) { PrimaryIngredient = val.Key; } else if (SecondaryIngredient == null) { SecondaryIngredient = val.Key; } else { GarnishedNames.Add(ingredientName(val.Key, true)); } max += val.Value; continue; } GarnishedNames.Add(ingredientName(val.Key, true)); } // Slightly ugly hack for soybean stew if (PrimaryIngredient == null) { foreach (var val in quantitiesByStack) { //CookingRecipeIngredient ingred = recipe.GetIngrendientFor(val.Key); - whats this for? PrimaryIngredient = val.Key; max += val.Value; } } recipeCode = "stew"; break; } case "jam": { foreach (var val in quantitiesByStack) { if (val.Key.Collectible.NutritionProps?.FoodCategory == EnumFoodCategory.Fruit) { return(Lang.Get("{0} jam", val.Key.GetName())); } } break; } } switch (max) { case 3: MealFormat += "-hearty-" + recipeCode; break; case 4: MealFormat += "-hefty-" + recipeCode; break; default: MealFormat += "-normal-" + recipeCode; break; } if (topping == "honeyportion") { MealFormat += "-honey"; } //mealformat is done. Time to do the main inredients. if (SecondaryIngredient != null) { mainIngredients = Lang.Get("multi-main-ingredients-format", getMainIngredientName(PrimaryIngredient, recipeCode), getMainIngredientName(SecondaryIngredient, recipeCode, true)); } else { mainIngredients = PrimaryIngredient == null ? "" : getMainIngredientName(PrimaryIngredient, recipeCode); } // Main ingredients are done. switch (recipeCode) { case "porridge": if (MashedNames.Count > 0) { everythingelse = getMealAddsString("meal-adds-porridge-mashed", MashedNames); } else { everythingelse = ""; } break; case "stew": if (OtherIngredients.Count > 0) { everythingelse = getMealAddsString("meal-adds-meatystew-boiled", OtherIngredients); } else if (GarnishedNames.Count > 0) { everythingelse = getMealAddsString("meal-adds-vegetablestew-garnish", GarnishedNames); } else { everythingelse = ""; } break; case "soup": if (OtherIngredients.Count > 0) { everythingelse = getMealAddsString("meal-adds-generic", OtherIngredients); } break; } //everything else is done. return(Lang.Get(MealFormat, mainIngredients, everythingelse).Trim().UcFirst()); }