private bool CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary <string, int> solids) { foreach (var reagent in recipe.IngredientsReagents) { if (!_solution.ContainsReagent(reagent.Key, out var amount)) { return(false); } if (amount.Int() < reagent.Value) { return(false); } } foreach (var solid in recipe.IngredientsSolids) { if (!solids.ContainsKey(solid.Key)) { return(false); } if (solids[solid.Key] < solid.Value) { return(false); } } return(true); }
private MicrowaveSuccessState CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary <string, int> solids) { foreach (var reagent in recipe.IngredientsReagents) { if (!_solution.ContainsReagent(reagent.Key, out var amount)) { return(MicrowaveSuccessState.RecipeFail); } if (amount.Int() < reagent.Value) { return(MicrowaveSuccessState.RecipeFail); } } foreach (var solid in recipe.IngredientsSolids) { if (!solids.ContainsKey(solid.Key)) { return(MicrowaveSuccessState.RecipeFail); } if (solids[solid.Key] < solid.Value) { return(MicrowaveSuccessState.RecipeFail); } } return(MicrowaveSuccessState.RecipePass); }
private bool CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary <string, int> solids, Dictionary <string, FixedPoint2> reagents) { if (_currentCookTimerTime != recipe.CookTime) { return(false); } foreach (var solid in recipe.IngredientsSolids) { if (!solids.ContainsKey(solid.Key)) { return(false); } if (solids[solid.Key] < solid.Value) { return(false); } } foreach (var reagent in recipe.IngredientsReagents) { if (!reagents.ContainsKey(reagent.Key)) { return(false); } if (reagents[reagent.Key] < reagent.Value) { return(false); } } return(true); }
private (FoodRecipePrototype, int) CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary <string, int> solids, Dictionary <string, FixedPoint2> reagents) { int portions = 0; if (_currentCookTimerTime % recipe.CookTime != 0) { //can't be a multiple of this recipe return(recipe, 0); } foreach (var solid in recipe.IngredientsSolids) { if (!solids.ContainsKey(solid.Key)) { return(recipe, 0); } if (solids[solid.Key] < solid.Value) { return(recipe, 0); } else { portions = portions == 0 ? solids[solid.Key] / solid.Value.Int() : Math.Min(portions, solids[solid.Key] / solid.Value.Int()); } } foreach (var reagent in recipe.IngredientsReagents) { if (!reagents.ContainsKey(reagent.Key)) { return(recipe, 0); } if (reagents[reagent.Key] < reagent.Value) { return(recipe, 0); } else { portions = portions == 0 ? reagents[reagent.Key].Int() / reagent.Value.Int() : Math.Min(portions, reagents[reagent.Key].Int() / reagent.Value.Int()); } } //cook only as many of those portions as time allows return(recipe, (int)Math.Min(portions, _currentCookTimerTime / recipe.CookTime)); }
private MicrowaveSuccessState CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary <string, int> solids) { if (_currentCookTimerTime != recipe.CookTime) { return(MicrowaveSuccessState.RecipeFail); } if (!EntitySystem.Get <SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution)) { return(MicrowaveSuccessState.RecipeFail); } foreach (var reagent in recipe.IngredientsReagents) { if (!solution.ContainsReagent(reagent.Key, out var amount)) { return(MicrowaveSuccessState.RecipeFail); } if (amount.Int() < reagent.Value) { return(MicrowaveSuccessState.RecipeFail); } } foreach (var solid in recipe.IngredientsSolids) { if (!solids.ContainsKey(solid.Key)) { return(MicrowaveSuccessState.RecipeFail); } if (solids[solid.Key] < solid.Value) { return(MicrowaveSuccessState.RecipeFail); } } return(MicrowaveSuccessState.RecipePass); }
private void SubtractContents(FoodRecipePrototype recipe) { foreach (var recipeReagent in recipe.IngredientsReagents) { _solution.TryRemoveReagent(recipeReagent.Key, ReagentUnit.New(recipeReagent.Value)); } foreach (var recipeSolid in recipe.IngredientsSolids) { for (var i = 0; i < recipeSolid.Value; i++) { foreach (var item in _storage.ContainedEntities) { if (item.Prototype.ID == recipeSolid.Key) { _storage.Remove(item); item.Delete(); break; } } } } }
private void SubtractContents(FoodRecipePrototype recipe) { var solutionUid = Owner; if (!EntitySystem.Get <SolutionContainerSystem>().TryGetSolution(Owner, SolutionName, out var solution)) { return; } foreach (var recipeReagent in recipe.IngredientsReagents) { EntitySystem.Get <SolutionContainerSystem>() .TryRemoveReagent(solutionUid, solution, recipeReagent.Key, FixedPoint2.New(recipeReagent.Value)); } foreach (var recipeSolid in recipe.IngredientsSolids) { for (var i = 0; i < recipeSolid.Value; i++) { foreach (var item in _storage.ContainedEntities) { var metaData = _entities.GetComponent <MetaDataComponent>(item); if (metaData.EntityPrototype == null) { continue; } if (metaData.EntityPrototype.ID == recipeSolid.Key) { _storage.Remove(item); _entities.DeleteEntity(item); break; } } } } }
//This is required. It's 'cook'. private void wzhzhzh() { if (!HasContents) { return; } _busy = true; // Convert storage into Dictionary of ingredients var solidsDict = new Dictionary <string, int>(); foreach (var item in _storage.ContainedEntities) { if (solidsDict.ContainsKey(item.Prototype.ID)) { solidsDict[item.Prototype.ID]++; } else { solidsDict.Add(item.Prototype.ID, 1); } } // Check recipes FoodRecipePrototype recipeToCook = null; foreach (var r in _recipeManager.Recipes) { if (!CanSatisfyRecipe(r, solidsDict)) { continue; } recipeToCook = r; } var goodMeal = (recipeToCook != null) && (_currentCookTimerTime == (uint)recipeToCook.CookTime) ? true : false; SetAppearance(MicrowaveVisualState.Cooking); _audioSystem.Play(_startCookingSound, Owner, AudioParams.Default); Timer.Spawn((int)(_currentCookTimerTime * _cookTimeMultiplier), () => { if (goodMeal) { SubtractContents(recipeToCook); } else { VaporizeReagents(); VaporizeSolids(); } var entityToSpawn = goodMeal ? recipeToCook.Result : _badRecipeName; _entityManager.SpawnEntity(entityToSpawn, Owner.Transform.GridPosition); _audioSystem.Play(_cookingCompleteSound, Owner, AudioParams.Default); SetAppearance(MicrowaveVisualState.Idle); _busy = false; UpdateUserInterface(); }); UpdateUserInterface(); }
private void SubtractContents(FoodRecipePrototype recipe) { var totalReagentsToRemove = new Dictionary <string, FixedPoint2>(recipe.IngredientsReagents); var solutionContainerSystem = EntitySystem.Get <SolutionContainerSystem>(); // this is spaghetti ngl foreach (var item in _storage.ContainedEntities) { if (!_entities.TryGetComponent <SolutionContainerManagerComponent>(item, out var solMan)) { continue; } // go over every solution foreach (var(_, solution) in solMan.Solutions) { foreach (var(reagent, _) in recipe.IngredientsReagents) { // removed everything if (!totalReagentsToRemove.ContainsKey(reagent)) { continue; } if (!solution.ContainsReagent(reagent)) { continue; } var quant = solution.GetReagentQuantity(reagent); if (quant >= totalReagentsToRemove[reagent]) { quant = totalReagentsToRemove[reagent]; totalReagentsToRemove.Remove(reagent); } else { totalReagentsToRemove[reagent] -= quant; } solutionContainerSystem.TryRemoveReagent(item, solution, reagent, quant); } } } foreach (var recipeSolid in recipe.IngredientsSolids) { for (var i = 0; i < recipeSolid.Value; i++) { foreach (var item in _storage.ContainedEntities) { var metaData = _entities.GetComponent <MetaDataComponent>(item); if (metaData.EntityPrototype == null) { continue; } if (metaData.EntityPrototype.ID == recipeSolid.Key) { _storage.Remove(item); _entities.DeleteEntity(item); break; } } } } }
// ReSharper disable once InconsistentNaming // ReSharper disable once IdentifierTypo private void wzhzhzh() { if (!_hasContents) { return; } _busy = true; // Convert storage into Dictionary of ingredients var solidsDict = new Dictionary <string, int>(); foreach (var item in _storage.ContainedEntities) { if (solidsDict.ContainsKey(item.Prototype.ID)) { solidsDict[item.Prototype.ID]++; } else { solidsDict.Add(item.Prototype.ID, 1); } } var failState = MicrowaveSuccessState.RecipeFail; foreach (var id in solidsDict.Keys) { if (_recipeManager.SolidAppears(id)) { continue; } failState = MicrowaveSuccessState.UnwantedForeignObject; break; } // Check recipes FoodRecipePrototype recipeToCook = null; foreach (var r in _recipeManager.Recipes.Where(r => CanSatisfyRecipe(r, solidsDict) == MicrowaveSuccessState.RecipePass)) { recipeToCook = r; } var goodMeal = (recipeToCook != null) && (_currentCookTimerTime == (uint)recipeToCook.CookTime); SetAppearance(MicrowaveVisualState.Cooking); _audioSystem.PlayFromEntity(_startCookingSound, Owner, AudioParams.Default); Timer.Spawn((int)(_currentCookTimerTime * _cookTimeMultiplier), (System.Action)(() => { if (_lostPower) { return; } if (failState == MicrowaveSuccessState.UnwantedForeignObject) { VaporizeReagents(); EjectSolids(); } else { if (goodMeal) { SubtractContents(recipeToCook); } else { VaporizeReagents(); VaporizeSolids(); } if (recipeToCook != null) { var entityToSpawn = goodMeal ? recipeToCook.Result : _badRecipeName; _entityManager.SpawnEntity(entityToSpawn, Owner.Transform.GridPosition); } } _audioSystem.PlayFromEntity(_cookingCompleteSound, Owner, AudioParams.Default.WithVolume(-1f)); SetAppearance(MicrowaveVisualState.Idle); _busy = false; _uiDirty = true; })); _lostPower = false; _uiDirty = true; }