Add batch cooking (#9359)
This commit is contained in:
@@ -268,13 +268,10 @@ namespace Content.Server.Kitchen.Components
|
||||
}
|
||||
|
||||
// Check recipes
|
||||
FoodRecipePrototype? recipeToCook = null;
|
||||
foreach (var r in _recipeManager.Recipes.Where(r =>
|
||||
CanSatisfyRecipe(r, solidsDict, reagentDict)))
|
||||
{
|
||||
recipeToCook = r;
|
||||
}
|
||||
|
||||
(FoodRecipePrototype, int) portionedRecipe = _recipeManager.Recipes.Select(
|
||||
r => CanSatisfyRecipe(r, solidsDict, reagentDict)).Where(r => r.Item2 > 0).FirstOrDefault();
|
||||
FoodRecipePrototype? recipeToCook = portionedRecipe.Item1;
|
||||
|
||||
SetAppearance(MicrowaveVisualState.Cooking);
|
||||
var time = _currentCookTimerTime * _cookTimeMultiplier;
|
||||
SoundSystem.Play(_startCookingSound.GetSound(), Filter.Pvs(Owner), Owner, AudioParams.Default);
|
||||
@@ -289,9 +286,12 @@ namespace Content.Server.Kitchen.Components
|
||||
|
||||
if (recipeToCook != null)
|
||||
{
|
||||
SubtractContents(recipeToCook);
|
||||
_entities.SpawnEntity(recipeToCook.Result,
|
||||
_entities.GetComponent<TransformComponent>(Owner).Coordinates);
|
||||
for (int i = 0; i < portionedRecipe.Item2; i++)
|
||||
{
|
||||
SubtractContents(recipeToCook);
|
||||
_entities.SpawnEntity(recipeToCook.Result,
|
||||
_entities.GetComponent<TransformComponent>(Owner).Coordinates);
|
||||
}
|
||||
}
|
||||
|
||||
EjectSolids();
|
||||
@@ -415,32 +415,42 @@ namespace Content.Server.Kitchen.Components
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary<string, int> solids, Dictionary<string, FixedPoint2> reagents)
|
||||
private (FoodRecipePrototype, int) CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary<string, int> solids, Dictionary<string, FixedPoint2> reagents)
|
||||
{
|
||||
if (_currentCookTimerTime != recipe.CookTime)
|
||||
int portions = 0;
|
||||
|
||||
if(_currentCookTimerTime % recipe.CookTime != 0)
|
||||
{
|
||||
return false;
|
||||
//can't be a multiple of this recipe
|
||||
return (recipe, 0);
|
||||
}
|
||||
|
||||
foreach (var solid in recipe.IngredientsSolids)
|
||||
{
|
||||
if (!solids.ContainsKey(solid.Key))
|
||||
return false;
|
||||
return (recipe, 0);
|
||||
|
||||
if (solids[solid.Key] < solid.Value)
|
||||
return false;
|
||||
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 false;
|
||||
return (recipe, 0);
|
||||
|
||||
if (reagents[reagent.Key] < reagent.Value)
|
||||
return false;
|
||||
return (recipe, 0);
|
||||
else
|
||||
portions = portions == 0 ? reagents[reagent.Key].Int() / reagent.Value.Int()
|
||||
: Math.Min(portions, reagents[reagent.Key].Int() / reagent.Value.Int());
|
||||
}
|
||||
|
||||
return true;
|
||||
//cook only as many of those portions as time allows
|
||||
return (recipe, (int)Math.Min(portions, _currentCookTimerTime / recipe.CookTime));
|
||||
}
|
||||
|
||||
public void ClickSound()
|
||||
|
||||
Reference in New Issue
Block a user