public bool SatisfiesRecipe(Recipe recipeTarget) { // Check temperature if(recipeTarget.Boils) { if(CurrentTemperature < recipeTarget.TemperatureThreshold) { return false; } } if(recipeTarget.Freezes) { if(CurrentTemperature > recipeTarget.TemperatureThreshold) { return false; } } // Check we have the requisite reagents bool hasAllReagents = true; bool hasEnoughReagents = true; foreach(KeyValuePair<Reagent, int> recipeReagent in recipeTarget.InputReagents) { if(!CurrentReagents.ContainsKey(recipeReagent.Key)) { hasAllReagents = false; } else { if(CurrentReagents[recipeReagent.Key] < recipeReagent.Value) { hasEnoughReagents = false; } } } if(hasEnoughReagents && hasAllReagents) { return true; } return false; }
public static void PopulateRecipes() { RecipeWaterFreeze = new Recipes.WaterFreeze((Reagents.Water)Water, (Reagents.Ice)Ice); }
// Double, double toil and trouble // Fire burn, and cauldron bubble public void ResolveRecipe(Recipe recipeTarget) { while (SatisfiesRecipe(recipeTarget)) { RemoveMultiple(recipeTarget.InputReagents); AddMultiple(recipeTarget.OutputReagents); recipeTarget.OnRecipeComplete(); } }