diff --git a/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs b/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs index 1fdd84c7e6..6a07143798 100644 --- a/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs @@ -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); } diff --git a/Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs b/Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs index 0b7016fdba..83a4a84552 100644 --- a/Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs +++ b/Content.Client/GameObjects/Components/Kitchen/MicrowaveMenu.cs @@ -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 reagents) + public void RefreshContents(List reagents, Dictionary 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().TryIndex(item.Key, out EntityPrototype proto); + var solidLabel = new Button() + { + Text = $"{item.Value} {proto.Name}" + }; + + InnerScrollContainer.AddChild(solidLabel); + } + } protected override void Dispose(bool disposing) diff --git a/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs b/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs index cd7c932235..8f7fc05429 100644 --- a/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs +++ b/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs @@ -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 _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(); _userInterface = Owner.GetComponent() .GetBoundUserInterface(MicrowaveUiKey.Key); + _entityContents = new Dictionary(); _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().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 /// /// This actually deletes all the reagents. /// - 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)); } + + } } diff --git a/Content.Shared/Kitchen/RecipeManager.cs b/Content.Shared/Kitchen/RecipeManager.cs index eb238b105d..72772f2434 100644 --- a/Content.Shared/Kitchen/RecipeManager.cs +++ b/Content.Shared/Kitchen/RecipeManager.cs @@ -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; } diff --git a/Content.Shared/Kitchen/SharedMicrowave.cs b/Content.Shared/Kitchen/SharedMicrowave.cs deleted file mode 100644 index a2b5b49e58..0000000000 --- a/Content.Shared/Kitchen/SharedMicrowave.cs +++ /dev/null @@ -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 - } - - -} diff --git a/Content.Shared/Kitchen/SharedMicrowaveComponent.cs b/Content.Shared/Kitchen/SharedMicrowaveComponent.cs index 59e34aa82f..fa506fd107 100644 --- a/Content.Shared/Kitchen/SharedMicrowaveComponent.cs +++ b/Content.Shared/Kitchen/SharedMicrowaveComponent.cs @@ -37,10 +37,12 @@ namespace Content.Shared.Kitchen [NetSerializable, Serializable] public class MicrowaveUserInterfaceState : BoundUserInterfaceState { - public readonly List ContainedReagents; - public MicrowaveUserInterfaceState(List contained) + public readonly List ReagentsReagents; + public readonly Dictionary ContainedSolids; + public MicrowaveUserInterfaceState(List reagents, Dictionary solids) { - ContainedReagents = contained; + ReagentsReagents = reagents; + ContainedSolids = solids; } } diff --git a/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs b/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs index 4a61598629..f54a1ac86c 100644 --- a/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs +++ b/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs @@ -22,8 +22,11 @@ namespace Content.Shared.Prototypes.Kitchen public string _name => Loc.GetString(Name); private string Name; public string _result; - public IReadOnlyDictionary _ingredients => Ingredients; - private Dictionary Ingredients; + public IReadOnlyDictionary _ingReagents => IngredientsReagents; + public IReadOnlyDictionary _ingSolids => IngredientsSolids; + + private Dictionary IngredientsReagents; + private Dictionary 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()); + serializer.DataField(ref IngredientsReagents, "reagents", new Dictionary()); + serializer.DataField(ref IngredientsSolids, "solids", new Dictionary()); serializer.DataField(ref _cookTime, "time", 5); } diff --git a/Resources/Prototypes/Entities/Items/Consumables/food.yml b/Resources/Prototypes/Entities/Items/Consumables/food.yml index 8e6dd97175..7ab00d754b 100644 --- a/Resources/Prototypes/Entities/Items/Consumables/food.yml +++ b/Resources/Prototypes/Entities/Items/Consumables/food.yml @@ -90,7 +90,7 @@ # name: Ambrosia vulgar is crushed # parent: FoodBase # id: FoodAmbrosiaVulgarIsCrushed -# description: +# description: # components: # - type: Food # uses: 1 @@ -137,7 +137,7 @@ # name: Bacon # parent: FoodBase # id: FoodBacon -# description: +# description: # components: # - type: Food # uses: 1 @@ -182,7 +182,7 @@ name: Bread (slice) parent: FoodBase id: FoodBreadSlice - description: + description: components: - type: Food contents: @@ -199,7 +199,7 @@ name: Banana bread (slice) parent: FoodBase id: FoodBananaBreadSlice - description: + description: components: - type: Food contents: @@ -233,7 +233,7 @@ # name: Bear meat # parent: FoodBase # id: FoodBearMeat -# description: +# description: # components: # - type: Food # uses: 1 @@ -612,7 +612,7 @@ # name: Cocoa # parent: FoodBase # id: FoodCocoa -# description: +# description: # components: # - type: Food # uses: 1 @@ -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 diff --git a/Resources/Prototypes/Kitchen/meal_recipes.yml b/Resources/Prototypes/Kitchen/meal_recipes.yml index 660f7eef2a..a1c3fc51ba 100644 --- a/Resources/Prototypes/Kitchen/meal_recipes.yml +++ b/Resources/Prototypes/Kitchen/meal_recipes.yml @@ -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