ShadowCommander is MVP.

This commit is contained in:
FL-OZ
2020-04-30 23:07:27 -05:00
parent 93c3e86c9f
commit 5d4c0609ec
4 changed files with 26 additions and 27 deletions

View File

@@ -1,14 +1,6 @@
using System.Collections.Generic; using Content.Server.GameObjects.EntitySystems;
using Content.Server.GameObjects.Components.Sound;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.GameObjects.Components;
using Content.Shared.Audio;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Prototypes;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
using Content.Server.GameObjects.Components.Chemistry; using Content.Server.GameObjects.Components.Chemistry;
using Content.Shared.Chemistry; using Content.Shared.Chemistry;
@@ -64,34 +56,41 @@ namespace Content.Server.GameObjects.Components.Kitchen
{ {
if(CanSatisfyRecipe(r)) if(CanSatisfyRecipe(r))
{ {
RemoveContents(r);
var resultPrototype = r.Result; var resultPrototype = r.Result;
_entityManager.SpawnEntity(resultPrototype, Owner.Transform.GridPosition); _entityManager.SpawnEntity(resultPrototype, Owner.Transform.GridPosition);
return; return;
} }
}
} }
} }
private bool CanSatisfyRecipe(FoodRecipePrototype recipe)
{
foreach (var item in recipe.Ingredients)
{
if (!_contents.ContainsReagent(item.Key, out var amount))
{
return false;
} }
private bool CanSatisfyRecipe(MealRecipePrototype recipe) if (amount.Int() < item.Value)
{ {
foreach(var ingredient in recipe.Ingredients) return false;
{ }
var ingName = ingredient.Key.ToString(); }
var ingQuantity = ingredient.Value;
if (_contents.ContainsReagent(ingName, out var amt) && amt >= ingQuantity)
{
_contents.TryRemoveReagent(ingName, ReagentUnit.New(ingQuantity));
return true; return true;
} }
private void RemoveContents(FoodRecipePrototype recipe)
{
foreach(var item in recipe.Ingredients)
{
_contents.TryRemoveReagent(item.Key, ReagentUnit.New(item.Value));
} }
return false;
} }
} }
} }

View File

@@ -12,21 +12,21 @@ namespace Content.Shared.Kitchen
#pragma warning disable 649 #pragma warning disable 649
[Dependency] private readonly IPrototypeManager _prototypeManager; [Dependency] private readonly IPrototypeManager _prototypeManager;
#pragma warning restore 649 #pragma warning restore 649
public List<MealRecipePrototype> Recipes { get; private set; } public List<FoodRecipePrototype> Recipes { get; private set; }
public void Initialize() public void Initialize()
{ {
Recipes = new List<MealRecipePrototype>(); Recipes = new List<FoodRecipePrototype>();
foreach (var item in _prototypeManager.EnumeratePrototypes<MealRecipePrototype>()) foreach (var item in _prototypeManager.EnumeratePrototypes<FoodRecipePrototype>())
{ {
Recipes.Add(item); Recipes.Add(item);
} }
Recipes.Sort(new RecipeComparer()); Recipes.Sort(new RecipeComparer());
} }
private class RecipeComparer : IComparer<MealRecipePrototype> private class RecipeComparer : IComparer<FoodRecipePrototype>
{ {
int IComparer<MealRecipePrototype>.Compare(MealRecipePrototype x, MealRecipePrototype y) int IComparer<FoodRecipePrototype>.Compare(FoodRecipePrototype x, FoodRecipePrototype y)
{ {
if (x == null || y == null) if (x == null || y == null)
{ {

View File

@@ -15,7 +15,7 @@ namespace Content.Shared.Prototypes.Kitchen
[Prototype("microwaveMealRecipe")] [Prototype("microwaveMealRecipe")]
public class MealRecipePrototype : IPrototype, IIndexedPrototype public class FoodRecipePrototype : IPrototype, IIndexedPrototype
{ {
private string _id; private string _id;

View File

@@ -1,7 +1,7 @@
- type: microwaveMealRecipe - type: microwaveMealRecipe
id: RecipeCheeseburger id: RecipeCheeseburger
name: "Cheeseburger Recipe" name: Cheeseburger Recipe
result: FoodCheeseburger result: FoodCheeseburger
ingredients: ingredients:
chem.Flour: 15 chem.H2O: 15
chem.Nutriment: 5 chem.Nutriment: 5