Reformat the way recipe prototypes work to something sensible.
More work on Microwave component.
This commit is contained in:
@@ -143,6 +143,7 @@ namespace Content.Client
|
|||||||
"Bucket",
|
"Bucket",
|
||||||
"Puddle",
|
"Puddle",
|
||||||
"CanSpill",
|
"CanSpill",
|
||||||
|
"Microwave"
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var ignoreName in registerIgnore)
|
foreach (var ignoreName in registerIgnore)
|
||||||
|
|||||||
@@ -1,34 +1,135 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using Content.Server.GameObjects.Components.Sound;
|
using Content.Server.GameObjects.Components.Sound;
|
||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
|
using Content.Server.GameObjects.Components;
|
||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Interfaces.Random;
|
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Random;
|
|
||||||
using Robust.Shared.Serialization;
|
|
||||||
using Robust.Shared.Utility;
|
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
|
using Content.Server.GameObjects.Components.Chemistry;
|
||||||
|
using Content.Shared.Chemistry;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
using Content.Shared.Kitchen;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.Components.Kitchen
|
namespace Content.Server.GameObjects.Components.Kitchen
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
|
[ComponentReference(typeof(IActivate))]
|
||||||
public class KitchenMicrowaveComponent : Component, IActivate
|
public class KitchenMicrowaveComponent : Component, IActivate
|
||||||
{
|
{
|
||||||
|
|
||||||
#pragma warning disable 649
|
#pragma warning disable 649
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager;
|
[Dependency] private readonly IPrototypeManager _prototypeManager;
|
||||||
|
[Dependency] private readonly IEntityManager _entityManager;
|
||||||
#pragma warning restore 649
|
#pragma warning restore 649
|
||||||
|
|
||||||
public override string Name => "Microwave";
|
public override string Name => "Microwave";
|
||||||
|
|
||||||
public void Activate(ActivateEventArgs eventArgs)
|
private AppearanceComponent _appearanceComponent;
|
||||||
|
|
||||||
|
[ViewVariables]
|
||||||
|
private string _useSound;
|
||||||
|
[ViewVariables]
|
||||||
|
private string _outputPrototype;
|
||||||
|
[ViewVariables]
|
||||||
|
private SolutionComponent _contents;
|
||||||
|
|
||||||
|
private static List<MicrowaveMealRecipePrototype> _allRecipes;
|
||||||
|
|
||||||
|
public override void ExposeData(ObjectSerializer serializer)
|
||||||
{
|
{
|
||||||
|
base.ExposeData(serializer);
|
||||||
|
if(_allRecipes == null)
|
||||||
|
{
|
||||||
|
_allRecipes = new List<MicrowaveMealRecipePrototype>();
|
||||||
|
foreach (var recipe in _prototypeManager.EnumeratePrototypes<MicrowaveMealRecipePrototype>())
|
||||||
|
{
|
||||||
|
|
||||||
|
_allRecipes.Add(recipe);
|
||||||
|
|
||||||
|
}
|
||||||
|
_allRecipes.Sort(new RecipeComparer());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class RecipeComparer : IComparer<MicrowaveMealRecipePrototype>
|
||||||
|
{
|
||||||
|
int IComparer<MicrowaveMealRecipePrototype>.Compare(MicrowaveMealRecipePrototype x, MicrowaveMealRecipePrototype y)
|
||||||
|
{
|
||||||
|
if(x == null || y == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(x.Ingredients.Count < y.Ingredients.Count)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
if (_contents == null)
|
||||||
|
{
|
||||||
|
if (Owner.TryGetComponent(out SolutionComponent solutionComponent))
|
||||||
|
{
|
||||||
|
_contents = solutionComponent;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_contents = Owner.AddComponent<SolutionComponent>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||||
|
{
|
||||||
|
if(_contents.ReagentList.Count > 0)
|
||||||
|
{
|
||||||
|
DetermineRecipe();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DetermineRecipe()
|
||||||
|
{
|
||||||
|
foreach (var r in _allRecipes)
|
||||||
|
{
|
||||||
|
if(CheckReagents(r))
|
||||||
|
{
|
||||||
|
var outputFromRecipe = r.OutPutPrototype;
|
||||||
|
_entityManager.SpawnEntity(outputFromRecipe, Owner.Transform.GridPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CheckReagents(MicrowaveMealRecipePrototype recipe)
|
||||||
|
{
|
||||||
|
foreach(var ingredient in recipe.Ingredients)
|
||||||
|
{
|
||||||
|
var ingName = ingredient.Key.ToString();
|
||||||
|
var ingQuantity = ingredient.Value;
|
||||||
|
if (!_contents.ContainsReagent(ingName, out var amt) && amt != ingQuantity) return false;
|
||||||
|
_contents.TryRemoveReagent(ingName, ReagentUnit.New(ingQuantity));
|
||||||
|
|
||||||
|
//This doesnt work.
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,35 +14,25 @@ namespace Content.Shared.Kitchen
|
|||||||
|
|
||||||
[Prototype("microwaveMealRecipe")]
|
[Prototype("microwaveMealRecipe")]
|
||||||
|
|
||||||
public class FoodRecipe : IPrototype, IIndexedPrototype
|
public class MicrowaveMealRecipePrototype : IPrototype, IIndexedPrototype
|
||||||
{
|
{
|
||||||
|
|
||||||
public string ID {get; private set;}
|
public string ID {get; private set;}
|
||||||
public string Name {get; private set;}
|
public string Name {get; private set;}
|
||||||
|
|
||||||
public string Description {get; private set;}
|
public string OutPutPrototype { get; private set; }
|
||||||
|
public Dictionary<string,int> Ingredients {get; private set;}
|
||||||
public Dictionary<string,int> Ingredients {get; private set;}
|
|
||||||
|
|
||||||
private const char Seperator = ',';
|
|
||||||
|
|
||||||
public void LoadFrom(YamlMappingNode mapping)
|
public void LoadFrom(YamlMappingNode mapping)
|
||||||
{
|
{
|
||||||
ID = mapping.GetNode("id").ToString();
|
ID = mapping.GetNode("id").ToString();
|
||||||
Name = Loc.GetString(mapping.GetNode("name").ToString());
|
Name = Loc.GetString(mapping.GetNode("name").ToString());
|
||||||
Description = Loc.GetString(mapping.GetNode("description").ToString());
|
OutPutPrototype = mapping.GetNode("output").ToString();
|
||||||
if(mapping.TryGetNode("ingredients", out YamlSequenceNode tempDict))
|
if(mapping.TryGetNode("ingredients", out YamlMappingNode ingDict))
|
||||||
{
|
{
|
||||||
Ingredients = new Dictionary<string, int>();
|
Ingredients = new Dictionary<string, int>();
|
||||||
foreach (var node in tempDict.Children)
|
foreach (var kvp in ingDict.Children)
|
||||||
{
|
{
|
||||||
var pair = node.ToString();
|
Ingredients.Add(kvp.Key.ToString(), kvp.Value.AsInt());
|
||||||
if (pair == null) continue;
|
|
||||||
|
|
||||||
var split = pair.Split(Seperator);
|
|
||||||
var ingnName = split[0];
|
|
||||||
if (int.TryParse(split[1], out var amt)) Ingredients.Add(ingnName, amt);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
30
Resources/Prototypes/Entities/kitchen.yml
Normal file
30
Resources/Prototypes/Entities/kitchen.yml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
- type: entity
|
||||||
|
id: KitchenMicrowave
|
||||||
|
name: Microwave
|
||||||
|
description: It's magic.
|
||||||
|
components:
|
||||||
|
- type: Microwave
|
||||||
|
- type: Clickable
|
||||||
|
- type: InteractionOutline
|
||||||
|
- type: Solution
|
||||||
|
maxVol: 100
|
||||||
|
caps: 1
|
||||||
|
|
||||||
|
- type: Collidable
|
||||||
|
shapes:
|
||||||
|
- !type:PhysShapeAabb
|
||||||
|
bounds: "-0.5,0,0.5,1"
|
||||||
|
layer: 15
|
||||||
|
IsScrapingFloor: true
|
||||||
|
- type: Sprite
|
||||||
|
netsync: false
|
||||||
|
sprite: Buildings/medical_scanner.rsi
|
||||||
|
layers:
|
||||||
|
- state: scanner_open
|
||||||
|
map: ["enum.MedicalScannerVisualLayers.Machine"]
|
||||||
|
- state: scanner_terminal_blue
|
||||||
|
map: ["enum.MedicalScannerVisualLayers.Terminal"]
|
||||||
|
- type: PowerDevice
|
||||||
|
- type: Icon
|
||||||
|
sprite: Buildings/medical_scanner.rsi
|
||||||
|
state: scanner_open
|
||||||
@@ -1,7 +1,17 @@
|
|||||||
- type: microwaveMealRecipe
|
- type: microwaveMealRecipe
|
||||||
id: RecipeBurger
|
id: RecipeCheeseburger
|
||||||
name: "Burger"
|
name: "Cheeseburger Recipe"
|
||||||
description: "A burger, in space."
|
output: FoodCheeseburger
|
||||||
ingredients:
|
ingredients:
|
||||||
- "Flour,15"
|
chem.H2O: 15
|
||||||
- "Meat,5"
|
chem.Nutriment: 5
|
||||||
|
|
||||||
|
- type: microwaveMealRecipe
|
||||||
|
id: RecipeFlashlight
|
||||||
|
name: "Flashlight Recipe"
|
||||||
|
output: FlashlightLantern
|
||||||
|
ingredients:
|
||||||
|
chem.H2O: 15
|
||||||
|
chem.Nutriment: 20
|
||||||
|
chem.Glucose: 5
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user