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

View File

@@ -12,21 +12,21 @@ namespace Content.Shared.Kitchen
#pragma warning disable 649
[Dependency] private readonly IPrototypeManager _prototypeManager;
#pragma warning restore 649
public List<MealRecipePrototype> Recipes { get; private set; }
public List<FoodRecipePrototype> Recipes { get; private set; }
public void Initialize()
{
Recipes = new List<MealRecipePrototype>();
foreach (var item in _prototypeManager.EnumeratePrototypes<MealRecipePrototype>())
Recipes = new List<FoodRecipePrototype>();
foreach (var item in _prototypeManager.EnumeratePrototypes<FoodRecipePrototype>())
{
Recipes.Add(item);
}
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)
{

View File

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

View File

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