Add (not working) basis for allowing solids (entities) in recipes.

This commit is contained in:
FL-OZ
2020-05-02 01:29:20 -05:00
parent dd19466578
commit dba0949c5b
9 changed files with 132 additions and 56 deletions

View File

@@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Content.Client.GameObjects.Components.Mobs;
using Content.Shared.Kitchen; using Content.Shared.Kitchen;
using Robust.Shared.GameObjects.Components.UserInterface; using Robust.Shared.GameObjects.Components.UserInterface;
@@ -29,7 +30,7 @@ namespace Content.Client.GameObjects.Components.Kitchen
base.UpdateState(state); base.UpdateState(state);
if (!(state is MicrowaveUserInterfaceState cstate)) if (!(state is MicrowaveUserInterfaceState cstate))
return; return;
_menu.RefreshReagents(cstate.ContainedReagents); _menu.RefreshContents(cstate.ReagentsReagents, cstate.ContainedSolids);
} }

View File

@@ -2,8 +2,10 @@
using Content.Shared.Chemistry; using Content.Shared.Chemistry;
using Content.Shared.GameObjects; using Content.Shared.GameObjects;
using Content.Shared.Kitchen; using Content.Shared.Kitchen;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Maths; using Robust.Shared.Maths;
@@ -37,7 +39,7 @@ namespace Content.Client.GameObjects.Components.Kitchen
}; };
var ejectButton = new Button() var ejectButton = new Button()
{ {
Label = { Text = Loc.GetString("EJECT CONTENTS")} Label = { Text = Loc.GetString("EJECT REAGENTS")}
}; };
var scrollContainer = new ScrollContainer() var scrollContainer = new ScrollContainer()
{ {
@@ -71,7 +73,7 @@ namespace Content.Client.GameObjects.Components.Kitchen
} }
public void RefreshReagents(List<Solution.ReagentQuantity> reagents) public void RefreshContents(List<Solution.ReagentQuantity> reagents, Dictionary<string,int> solids)
{ {
InnerScrollContainer.RemoveAllChildren(); InnerScrollContainer.RemoveAllChildren();
foreach (var item in reagents) foreach (var item in reagents)
@@ -84,6 +86,18 @@ namespace Content.Client.GameObjects.Components.Kitchen
Text = $"{item.Quantity} {proto.Name}" Text = $"{item.Quantity} {proto.Name}"
}); });
} }
foreach (var item in solids)
{
IoCManager.Resolve<IPrototypeManager>().TryIndex(item.Key, out EntityPrototype proto);
var solidLabel = new Button()
{
Text = $"{item.Value} {proto.Name}"
};
InnerScrollContainer.AddChild(solidLabel);
}
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)

View File

@@ -1,9 +1,11 @@
using System.Linq; using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
using Content.Server.GameObjects.Components.Chemistry; using Content.Server.GameObjects.Components.Chemistry;
using Content.Server.GameObjects.Components.Nutrition;
using Content.Shared.Chemistry; using Content.Shared.Chemistry;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
@@ -17,17 +19,19 @@ using Robust.Server.GameObjects.Components.Container;
using Content.Server.GameObjects.Components.Power; using Content.Server.GameObjects.Components.Power;
using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.Prototypes;
namespace Content.Server.GameObjects.Components.Kitchen namespace Content.Server.GameObjects.Components.Kitchen
{ {
[RegisterComponent] [RegisterComponent]
[ComponentReference(typeof(IActivate))] [ComponentReference(typeof(IActivate))]
public class KitchenMicrowaveComponent : SharedMicrowaveComponent, IActivate, ISolutionChange public class KitchenMicrowaveComponent : SharedMicrowaveComponent, IActivate, IAttackBy, ISolutionChange
{ {
#pragma warning disable 649 #pragma warning disable 649
[Dependency] private readonly IEntitySystemManager _entitySystemManager; [Dependency] private readonly IEntitySystemManager _entitySystemManager;
[Dependency] private readonly IEntityManager _entityManager; [Dependency] private readonly IEntityManager _entityManager;
[Dependency] private readonly RecipeManager _recipeManager; [Dependency] private readonly RecipeManager _recipeManager;
[Dependency] private readonly IPrototypeManager _prototypeManager;
#pragma warning restore 649 #pragma warning restore 649
private int _cookTimeDefault; private int _cookTimeDefault;
@@ -41,7 +45,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
private bool Powered => _powerDevice.Powered; private bool Powered => _powerDevice.Powered;
private bool HasContents => _contents.ReagentList.Count > 0; private bool HasContents => _contents.ReagentList.Count > 0 || _entityContents.Count > 0;
private AppearanceComponent _appearance; private AppearanceComponent _appearance;
@@ -51,6 +55,8 @@ namespace Content.Server.GameObjects.Components.Kitchen
private Container _storage; private Container _storage;
private Dictionary<string, int> _entityContents;
private BoundUserInterface _userInterface; private BoundUserInterface _userInterface;
void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs) => UpdateUserInterface(); void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs) => UpdateUserInterface();
public override void ExposeData(ObjectSerializer serializer) public override void ExposeData(ObjectSerializer serializer)
@@ -74,6 +80,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
_audioSystem = _entitySystemManager.GetEntitySystem<AudioSystem>(); _audioSystem = _entitySystemManager.GetEntitySystem<AudioSystem>();
_userInterface = Owner.GetComponent<ServerUserInterfaceComponent>() _userInterface = Owner.GetComponent<ServerUserInterfaceComponent>()
.GetBoundUserInterface(MicrowaveUiKey.Key); .GetBoundUserInterface(MicrowaveUiKey.Key);
_entityContents = new Dictionary<string, int>();
_userInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage; _userInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
} }
@@ -92,7 +99,8 @@ namespace Content.Server.GameObjects.Components.Kitchen
case MicrowaveEjectMessage msg : case MicrowaveEjectMessage msg :
if (!HasContents) return; if (!HasContents) return;
EjectReagents(); DestroyReagents();
EjectSolids();
UpdateUserInterface(); UpdateUserInterface();
break; break;
} }
@@ -110,6 +118,31 @@ namespace Content.Server.GameObjects.Components.Kitchen
} }
public bool AttackBy(AttackByEventArgs eventArgs)
{
var itemEntity = eventArgs.User.GetComponent<HandsComponent>().GetActiveHand.Owner;
if (itemEntity.TryGetComponent(typeof(FoodComponent), out var food))
{
if (_entityContents.TryGetValue(itemEntity.Prototype.ID, out var quantity) && quantity > 0)
{
quantity++;
food.Owner.Delete();
UpdateUserInterface();
return true;
}
else
{
_storage.Insert(food.Owner);
}
_entityContents.Add(itemEntity.Prototype.ID, 1);
UpdateUserInterface();
return true;
}
return false;
}
//This is required. //This is required.
private void wzhzhzh() private void wzhzhzh()
{ {
@@ -130,7 +163,8 @@ namespace Content.Server.GameObjects.Components.Kitchen
} }
else else
{ {
EjectReagents(); DestroyReagents();
EjectSolids();
} }
var entityToSpawn = success ? r._result : _badRecipeName; var entityToSpawn = success ? r._result : _badRecipeName;
@@ -139,6 +173,8 @@ namespace Content.Server.GameObjects.Components.Kitchen
SetAppearance(MicrowaveVisualState.Idle); SetAppearance(MicrowaveVisualState.Idle);
_busy = false; _busy = false;
}); });
_busy = false;
UpdateUserInterface();
return; return;
} }
} }
@@ -146,20 +182,54 @@ namespace Content.Server.GameObjects.Components.Kitchen
/// <summary> /// <summary>
/// This actually deletes all the reagents. /// This actually deletes all the reagents.
/// </summary> /// </summary>
private void EjectReagents() private void DestroyReagents()
{ {
_contents.RemoveAllSolution(); _contents.RemoveAllSolution();
} }
private void EjectSolids()
{
foreach (var item in _storage.ContainedEntities.ToList())
{
_storage.Remove(item);
}
foreach (var kvp in _entityContents)
{
if (kvp.Value > 1 && _prototypeManager.TryIndex(kvp.Key, out EntityPrototype proto))
{
for(int i = 0; i <= kvp.Value - 1; i++)
_entityManager.SpawnEntity(proto.Name, Owner.Transform.GridPosition);
}
}
_entityContents.Clear();
}
private bool CanSatisfyRecipe(FoodRecipePrototype recipe) private bool CanSatisfyRecipe(FoodRecipePrototype recipe)
{ {
foreach (var item in recipe._ingredients) foreach (var reagent in recipe._ingReagents)
{ {
if (!_contents.ContainsReagent(item.Key, out var amount)) if (!_contents.ContainsReagent(reagent.Key, out var amount))
{ {
return false; return false;
} }
if (amount.Int() < item.Value) if (amount.Int() < reagent.Value)
{
return false;
}
}
foreach (var solid in recipe._ingSolids)
{
if (!_entityContents.TryGetValue(solid.Key, out var amount))
{
return false;
}
if (amount < solid.Value)
{ {
return false; return false;
} }
@@ -170,10 +240,16 @@ namespace Content.Server.GameObjects.Components.Kitchen
private void SubtractContents(FoodRecipePrototype recipe) private void SubtractContents(FoodRecipePrototype recipe)
{ {
foreach(var item in recipe._ingredients) foreach(var item in recipe._ingReagents)
{ {
_contents.TryRemoveReagent(item.Key, ReagentUnit.New(item.Value)); _contents.TryRemoveReagent(item.Key, ReagentUnit.New(item.Value));
} }
foreach(var item in recipe._ingSolids)
{
_entityContents.TryGetValue(item.Key, out var value);
value -= item.Value;
}
} }
private void SetAppearance(MicrowaveVisualState state) private void SetAppearance(MicrowaveVisualState state)
@@ -184,7 +260,9 @@ namespace Content.Server.GameObjects.Components.Kitchen
private void UpdateUserInterface() private void UpdateUserInterface()
{ {
_userInterface.SetState(new MicrowaveUserInterfaceState(_contents.Solution.Contents.ToList())); _userInterface.SetState(new MicrowaveUserInterfaceState(_contents.Solution.Contents.ToList(), solids:_entityContents));
} }
} }
} }

View File

@@ -33,12 +33,12 @@ namespace Content.Shared.Kitchen
return 0; return 0;
} }
if (x._ingredients.Count < y._ingredients.Count) if (x._ingReagents.Count < y._ingReagents.Count)
{ {
return 1; return 1;
} }
if (x._ingredients.Count > y._ingredients.Count) if (x._ingReagents.Count > y._ingReagents.Count)
{ {
return -1; return -1;
} }

View File

@@ -1,17 +0,0 @@
using Robust.Shared.Serialization;
using System;
using System.Collections.Generic;
using System.Text;
namespace Content.Shared.Kitchen
{
[Serializable, NetSerializable]
public enum MicrowaveVisualState
{
Idle,
Cooking
}
}

View File

@@ -37,10 +37,12 @@ namespace Content.Shared.Kitchen
[NetSerializable, Serializable] [NetSerializable, Serializable]
public class MicrowaveUserInterfaceState : BoundUserInterfaceState public class MicrowaveUserInterfaceState : BoundUserInterfaceState
{ {
public readonly List<Solution.ReagentQuantity> ContainedReagents; public readonly List<Solution.ReagentQuantity> ReagentsReagents;
public MicrowaveUserInterfaceState(List<Solution.ReagentQuantity> contained) public readonly Dictionary<string, int> ContainedSolids;
public MicrowaveUserInterfaceState(List<Solution.ReagentQuantity> reagents, Dictionary<string,int> solids)
{ {
ContainedReagents = contained; ReagentsReagents = reagents;
ContainedSolids = solids;
} }
} }

View File

@@ -22,8 +22,11 @@ namespace Content.Shared.Prototypes.Kitchen
public string _name => Loc.GetString(Name); public string _name => Loc.GetString(Name);
private string Name; private string Name;
public string _result; public string _result;
public IReadOnlyDictionary<string, int> _ingredients => Ingredients; public IReadOnlyDictionary<string, int> _ingReagents => IngredientsReagents;
private Dictionary<string, int> Ingredients; public IReadOnlyDictionary<string, int> _ingSolids => IngredientsSolids;
private Dictionary<string, int> IngredientsReagents;
private Dictionary<string, int> IngredientsSolids;
public int _cookTime; public int _cookTime;
public string ID => _id; public string ID => _id;
@@ -35,7 +38,8 @@ namespace Content.Shared.Prototypes.Kitchen
serializer.DataField(ref _id, "id", string.Empty); serializer.DataField(ref _id, "id", string.Empty);
serializer.DataField(ref Name, "name", string.Empty); serializer.DataField(ref Name, "name", string.Empty);
serializer.DataField(ref _result, "result", string.Empty); serializer.DataField(ref _result, "result", string.Empty);
serializer.DataField(ref Ingredients, "ingredients", new Dictionary<string, int>()); serializer.DataField(ref IngredientsReagents, "reagents", new Dictionary<string, int>());
serializer.DataField(ref IngredientsSolids, "solids", new Dictionary<string, int>());
serializer.DataField(ref _cookTime, "time", 5); serializer.DataField(ref _cookTime, "time", 5);
} }

View File

@@ -1486,7 +1486,7 @@
# parent: FoodBase # parent: FoodBase
# id: FoodMeat # id: FoodMeat
# name: Meat # name: Meat
# description: '' # description: A slab of meat.
# components: # components:
# - type: Food # - type: Food
# uses: 1 # uses: 1

View File

@@ -3,15 +3,9 @@
name: Cheeseburger Recipe name: Cheeseburger Recipe
result: FoodCheeseburger result: FoodCheeseburger
time: 10 time: 10
ingredients: reagents:
chem.H2O: 15 chem.H2O: 15
chem.Nutriment: 5 chem.Nutriment: 5
solids:
FoodMeatBreadSlice: 1
- type: microwaveMealRecipe
id: RecipeFlashlight
name: Flashlight Recipe
result: FoodCheeseWedge
time: 5
ingredients:
chem.H2O: 15
chem.Glucose: 5