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

View File

@@ -2,8 +2,10 @@
using Content.Shared.Chemistry;
using Content.Shared.GameObjects;
using Content.Shared.Kitchen;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
@@ -37,7 +39,7 @@ namespace Content.Client.GameObjects.Components.Kitchen
};
var ejectButton = new Button()
{
Label = { Text = Loc.GetString("EJECT CONTENTS")}
Label = { Text = Loc.GetString("EJECT REAGENTS")}
};
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();
foreach (var item in reagents)
@@ -84,6 +86,18 @@ namespace Content.Client.GameObjects.Components.Kitchen
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)

View File

@@ -1,9 +1,11 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using Content.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.ViewVariables;
using Content.Server.GameObjects.Components.Chemistry;
using Content.Server.GameObjects.Components.Nutrition;
using Content.Shared.Chemistry;
using Robust.Shared.Serialization;
using Robust.Shared.Interfaces.GameObjects;
@@ -17,17 +19,19 @@ using Robust.Server.GameObjects.Components.Container;
using Content.Server.GameObjects.Components.Power;
using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.Prototypes;
namespace Content.Server.GameObjects.Components.Kitchen
{
[RegisterComponent]
[ComponentReference(typeof(IActivate))]
public class KitchenMicrowaveComponent : SharedMicrowaveComponent, IActivate, ISolutionChange
public class KitchenMicrowaveComponent : SharedMicrowaveComponent, IActivate, IAttackBy, ISolutionChange
{
#pragma warning disable 649
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
[Dependency] private readonly IEntityManager _entityManager;
[Dependency] private readonly RecipeManager _recipeManager;
[Dependency] private readonly IPrototypeManager _prototypeManager;
#pragma warning restore 649
private int _cookTimeDefault;
@@ -41,7 +45,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
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;
@@ -51,6 +55,8 @@ namespace Content.Server.GameObjects.Components.Kitchen
private Container _storage;
private Dictionary<string, int> _entityContents;
private BoundUserInterface _userInterface;
void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs) => UpdateUserInterface();
public override void ExposeData(ObjectSerializer serializer)
@@ -74,6 +80,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
_audioSystem = _entitySystemManager.GetEntitySystem<AudioSystem>();
_userInterface = Owner.GetComponent<ServerUserInterfaceComponent>()
.GetBoundUserInterface(MicrowaveUiKey.Key);
_entityContents = new Dictionary<string, int>();
_userInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
}
@@ -92,7 +99,8 @@ namespace Content.Server.GameObjects.Components.Kitchen
case MicrowaveEjectMessage msg :
if (!HasContents) return;
EjectReagents();
DestroyReagents();
EjectSolids();
UpdateUserInterface();
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.
private void wzhzhzh()
{
@@ -130,7 +163,8 @@ namespace Content.Server.GameObjects.Components.Kitchen
}
else
{
EjectReagents();
DestroyReagents();
EjectSolids();
}
var entityToSpawn = success ? r._result : _badRecipeName;
@@ -139,6 +173,8 @@ namespace Content.Server.GameObjects.Components.Kitchen
SetAppearance(MicrowaveVisualState.Idle);
_busy = false;
});
_busy = false;
UpdateUserInterface();
return;
}
}
@@ -146,20 +182,54 @@ namespace Content.Server.GameObjects.Components.Kitchen
/// <summary>
/// This actually deletes all the reagents.
/// </summary>
private void EjectReagents()
private void DestroyReagents()
{
_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)
{
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;
}
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;
}
@@ -170,10 +240,16 @@ namespace Content.Server.GameObjects.Components.Kitchen
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));
}
foreach(var item in recipe._ingSolids)
{
_entityContents.TryGetValue(item.Key, out var value);
value -= item.Value;
}
}
private void SetAppearance(MicrowaveVisualState state)
@@ -184,7 +260,9 @@ namespace Content.Server.GameObjects.Components.Kitchen
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;
}
if (x._ingredients.Count < y._ingredients.Count)
if (x._ingReagents.Count < y._ingReagents.Count)
{
return 1;
}
if (x._ingredients.Count > y._ingredients.Count)
if (x._ingReagents.Count > y._ingReagents.Count)
{
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]
public class MicrowaveUserInterfaceState : BoundUserInterfaceState
{
public readonly List<Solution.ReagentQuantity> ContainedReagents;
public MicrowaveUserInterfaceState(List<Solution.ReagentQuantity> contained)
public readonly List<Solution.ReagentQuantity> ReagentsReagents;
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);
private string Name;
public string _result;
public IReadOnlyDictionary<string, int> _ingredients => Ingredients;
private Dictionary<string, int> Ingredients;
public IReadOnlyDictionary<string, int> _ingReagents => IngredientsReagents;
public IReadOnlyDictionary<string, int> _ingSolids => IngredientsSolids;
private Dictionary<string, int> IngredientsReagents;
private Dictionary<string, int> IngredientsSolids;
public int _cookTime;
public string ID => _id;
@@ -35,7 +38,8 @@ namespace Content.Shared.Prototypes.Kitchen
serializer.DataField(ref _id, "id", string.Empty);
serializer.DataField(ref Name, "name", 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);
}

View File

@@ -1482,11 +1482,11 @@
- type: Icon
sprite: Objects/Food/loadedbakedpotato.rsi
#- type: entity
# - type: entity
# parent: FoodBase
# id: FoodMeat
# name: Meat
# description: ''
# description: A slab of meat.
# components:
# - type: Food
# uses: 1

View File

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