fix microwave deleting entities at will (#1073)
Co-authored-by: FL-OZ <anotherscuffed@gmail.com>
This commit is contained in:
@@ -278,9 +278,21 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var failState = MicrowaveSuccessState.RecipeFail;
|
||||||
|
foreach(var id in solidsDict.Keys)
|
||||||
|
{
|
||||||
|
if(_recipeManager.SolidAppears(id))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
failState = MicrowaveSuccessState.UnwantedForeignObject;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Check recipes
|
// Check recipes
|
||||||
FoodRecipePrototype recipeToCook = null;
|
FoodRecipePrototype recipeToCook = null;
|
||||||
foreach (var r in _recipeManager.Recipes.Where(r => CanSatisfyRecipe(r, solidsDict)))
|
foreach (var r in _recipeManager.Recipes.Where(r => CanSatisfyRecipe(r, solidsDict) == MicrowaveSuccessState.RecipePass))
|
||||||
{
|
{
|
||||||
recipeToCook = r;
|
recipeToCook = r;
|
||||||
}
|
}
|
||||||
@@ -288,7 +300,6 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
|||||||
var goodMeal = (recipeToCook != null)
|
var goodMeal = (recipeToCook != null)
|
||||||
&&
|
&&
|
||||||
(_currentCookTimerTime == (uint)recipeToCook.CookTime);
|
(_currentCookTimerTime == (uint)recipeToCook.CookTime);
|
||||||
|
|
||||||
SetAppearance(MicrowaveVisualState.Cooking);
|
SetAppearance(MicrowaveVisualState.Cooking);
|
||||||
_audioSystem.Play(_startCookingSound, Owner, AudioParams.Default);
|
_audioSystem.Play(_startCookingSound, Owner, AudioParams.Default);
|
||||||
Timer.Spawn((int)(_currentCookTimerTime * _cookTimeMultiplier), () =>
|
Timer.Spawn((int)(_currentCookTimerTime * _cookTimeMultiplier), () =>
|
||||||
@@ -297,21 +308,31 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (goodMeal)
|
|
||||||
|
if(failState == MicrowaveSuccessState.UnwantedForeignObject)
|
||||||
{
|
{
|
||||||
SubtractContents(recipeToCook);
|
VaporizeReagents();
|
||||||
|
EjectSolids();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
VaporizeReagents();
|
if (goodMeal)
|
||||||
VaporizeSolids();
|
{
|
||||||
|
SubtractContents(recipeToCook);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
VaporizeReagents();
|
||||||
|
VaporizeSolids();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recipeToCook != null)
|
||||||
|
{
|
||||||
|
var entityToSpawn = goodMeal ? recipeToCook.Result : _badRecipeName;
|
||||||
|
_entityManager.SpawnEntity(entityToSpawn, Owner.Transform.GridPosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recipeToCook != null)
|
|
||||||
{
|
|
||||||
var entityToSpawn = goodMeal ? recipeToCook.Result : _badRecipeName;
|
|
||||||
_entityManager.SpawnEntity(entityToSpawn, Owner.Transform.GridPosition);
|
|
||||||
}
|
|
||||||
_audioSystem.Play(_cookingCompleteSound, Owner, AudioParams.Default.WithVolume(-1f));
|
_audioSystem.Play(_cookingCompleteSound, Owner, AudioParams.Default.WithVolume(-1f));
|
||||||
SetAppearance(MicrowaveVisualState.Idle);
|
SetAppearance(MicrowaveVisualState.Idle);
|
||||||
_busy = false;
|
_busy = false;
|
||||||
@@ -385,18 +406,18 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary<string,int> solids)
|
private MicrowaveSuccessState CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary<string,int> solids)
|
||||||
{
|
{
|
||||||
foreach (var reagent in recipe.IngredientsReagents)
|
foreach (var reagent in recipe.IngredientsReagents)
|
||||||
{
|
{
|
||||||
if (!_solution.ContainsReagent(reagent.Key, out var amount))
|
if (!_solution.ContainsReagent(reagent.Key, out var amount))
|
||||||
{
|
{
|
||||||
return false;
|
return MicrowaveSuccessState.RecipeFail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (amount.Int() < reagent.Value)
|
if (amount.Int() < reagent.Value)
|
||||||
{
|
{
|
||||||
return false;
|
return MicrowaveSuccessState.RecipeFail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,16 +425,17 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
|||||||
{
|
{
|
||||||
if (!solids.ContainsKey(solid.Key))
|
if (!solids.ContainsKey(solid.Key))
|
||||||
{
|
{
|
||||||
return false;
|
return MicrowaveSuccessState.RecipeFail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (solids[solid.Key] < solid.Value)
|
if (solids[solid.Key] < solid.Value)
|
||||||
{
|
{
|
||||||
return false;
|
return MicrowaveSuccessState.RecipeFail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
|
return MicrowaveSuccessState.RecipePass;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClickSound()
|
private void ClickSound()
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Content.Server.GameObjects.Components.Kitchen
|
||||||
|
{
|
||||||
|
public enum MicrowaveSuccessState
|
||||||
|
{
|
||||||
|
RecipePass,
|
||||||
|
RecipeFail,
|
||||||
|
UnwantedForeignObject
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ using Robust.Shared.Prototypes;
|
|||||||
|
|
||||||
namespace Content.Shared.Kitchen
|
namespace Content.Shared.Kitchen
|
||||||
{
|
{
|
||||||
|
|
||||||
public class RecipeManager
|
public class RecipeManager
|
||||||
{
|
{
|
||||||
#pragma warning disable 649
|
#pragma warning disable 649
|
||||||
@@ -24,6 +24,24 @@ namespace Content.Shared.Kitchen
|
|||||||
|
|
||||||
Recipes.Sort(new RecipeComparer());
|
Recipes.Sort(new RecipeComparer());
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Check if a prototype ids appears in any of the recipes that exist.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="solidIds"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool SolidAppears(string solidId)
|
||||||
|
{
|
||||||
|
foreach(var recipe in Recipes)
|
||||||
|
{
|
||||||
|
if(recipe.IngredientsSolids.ContainsKey(solidId))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private class RecipeComparer : Comparer<FoodRecipePrototype>
|
private class RecipeComparer : Comparer<FoodRecipePrototype>
|
||||||
{
|
{
|
||||||
public override int Compare(FoodRecipePrototype x, FoodRecipePrototype y)
|
public override int Compare(FoodRecipePrototype x, FoodRecipePrototype y)
|
||||||
@@ -32,7 +50,7 @@ namespace Content.Shared.Kitchen
|
|||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -x.IngredientsReagents.Count.CompareTo(y.IngredientsReagents.Count);
|
return -x.IngredientsReagents.Count.CompareTo(y.IngredientsReagents.Count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user