diff --git a/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs b/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs new file mode 100644 index 0000000000..7c15ecb885 --- /dev/null +++ b/Content.Client/GameObjects/Components/Kitchen/MicrowaveBoundUserInterface.cs @@ -0,0 +1,16 @@ +using Robust.Client.GameObjects.Components.UserInterface; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Content.Client.GameObjects.Components.Kitchen +{ + public class MicrowaveBoundUserInterface : BoundUserInterface + { + + public MicrowaveBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner,uiKey) + { + + } + } +} diff --git a/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs b/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs index bebc196dfc..124dafb8e2 100644 --- a/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs +++ b/Content.Client/GameObjects/Components/Kitchen/MicrowaveVisualizer.cs @@ -1,20 +1,34 @@ -using Content.Shared.GameObjects.Components.Power; +using System.Reflection.Metadata.Ecma335; +using Content.Client.GameObjects.Components.Sound; +using Content.Shared.GameObjects.Components.Power; +using Content.Shared.GameObjects.Components.Sound; using Content.Shared.Kitchen; -using Robust.Client.Animations; using Robust.Client.GameObjects; +using Robust.Client.GameObjects.EntitySystems; using Robust.Client.Interfaces.GameObjects.Components; -using System; -using System.Collections.Generic; -using System.Text; +using Robust.Shared.Audio; +using Robust.Shared.Interfaces.GameObjects; +using Robust.Shared.IoC; +using YamlDotNet.RepresentationModel; namespace Content.Client.GameObjects.Components.Kitchen { public sealed class MicrowaveVisualizer : AppearanceVisualizer - { + { + private SoundComponent _soundComponent; + private const string _microwaveSoundLoop = "/Audio/machines/microwave_loop.ogg"; + public override void LoadData(YamlMappingNode node) + { + base.LoadData(node); + //_audioSystem = IoCManager.Resolve().GetEntitySystem(); + + } + public override void OnChangeData(AppearanceComponent component) { base.OnChangeData(component); var sprite = component.Owner.GetComponent(); + _soundComponent ??= component.Owner.GetComponent(); if (!component.TryGetData(PowerDeviceVisuals.VisualState, out MicrowaveVisualState state)) { state = MicrowaveVisualState.Idle; @@ -24,11 +38,18 @@ namespace Content.Client.GameObjects.Components.Kitchen case MicrowaveVisualState.Idle: sprite.LayerSetState(MicrowaveVisualizerLayers.Base, "mw"); sprite.LayerSetState(MicrowaveVisualizerLayers.BaseUnlit, "mw_unlit"); + _soundComponent.StopAllSounds(); break; case MicrowaveVisualState.Cooking: sprite.LayerSetState(MicrowaveVisualizerLayers.Base, "mw"); sprite.LayerSetState(MicrowaveVisualizerLayers.BaseUnlit, "mw_running_unlit"); + var audioParams = AudioParams.Default; + audioParams.Loop = true; + var schedSound = new ScheduledSound(); + schedSound.Filename = _microwaveSoundLoop; + schedSound.AudioParams = audioParams; + _soundComponent.AddScheduledSound(schedSound); break; } diff --git a/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs b/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs index 02f451ce57..63c2da2b10 100644 --- a/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs +++ b/Content.Server/GameObjects/Components/Kitchen/KitchenMicrowaveComponent.cs @@ -1,4 +1,6 @@ -using Content.Server.GameObjects.EntitySystems; +using System; +using System.Linq; +using Content.Server.GameObjects.EntitySystems; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.ViewVariables; @@ -12,6 +14,8 @@ using Robust.Shared.Timers; using Robust.Server.GameObjects; using Content.Shared.GameObjects.Components.Power; using Robust.Server.GameObjects.EntitySystems; +using Robust.Server.GameObjects.Components.Container; +using Robust.Shared.Log; using Content.Server.GameObjects.Components.Power; namespace Content.Server.GameObjects.Components.Kitchen @@ -29,38 +33,38 @@ namespace Content.Server.GameObjects.Components.Kitchen public override string Name => "Microwave"; - private int _cookTimeSeconds; + private int _cookTimeDefault; + private int _cookTimeMultiplier; //For upgrades and stuff I guess? private string _badRecipeName; [ViewVariables] private SolutionComponent _contents; + [ViewVariables] + public bool _busy = false; + private AppearanceComponent _appearance; private AudioSystem _audioSystem; private PowerDeviceComponent _powerDevice; + + private Container _storage; public override void ExposeData(ObjectSerializer serializer) { base.ExposeData(serializer); serializer.DataField(ref _badRecipeName, "failureResult", "FoodBadRecipe"); - serializer.DataField(ref _cookTimeSeconds, "cookTime", 5000); + serializer.DataField(ref _cookTimeDefault, "cookTime", 5); + serializer.DataField(ref _cookTimeMultiplier, "cookTimeMultiplier", 1000); } public override void Initialize() { base.Initialize(); - if (_contents == null) - { - if (Owner.TryGetComponent(out SolutionComponent solutionComponent)) - { - _contents = solutionComponent; - } - else - { - _contents = Owner.AddComponent(); - } - } + _contents ??= Owner.TryGetComponent(out SolutionComponent solutionComponent) + ? solutionComponent + : Owner.AddComponent(); + _storage = ContainerManagerComponent.Ensure("microwave_entity_container", Owner, out var existed); _appearance = Owner.GetComponent(); _powerDevice = Owner.GetComponent(); _audioSystem = _entitySystemManager.GetEntitySystem(); @@ -68,40 +72,50 @@ namespace Content.Server.GameObjects.Components.Kitchen void IActivate.Activate(ActivateEventArgs eventArgs) { - if (_contents.ReagentList.Count == 0 || !_powerDevice.Powered) + + if (!_powerDevice.Powered || _busy) return; + if (_contents.ReagentList.Count <= 0) { return; } - foreach(var r in _recipeManager.Recipes) - { - if(CanSatisfyRecipe(r)) - { - SetAppearance(MicrowaveVisualState.Cooking); - Timer.Spawn(_cookTimeSeconds, () => - { - RemoveContents(r); - _entityManager.SpawnEntity(r.Result, Owner.Transform.GridPosition); - - _audioSystem.Play("/Audio/machines/ding.ogg"); - SetAppearance(MicrowaveVisualState.Idle); - }); - return; - } - } - - SetAppearance(MicrowaveVisualState.Cooking); - Timer.Spawn(_cookTimeSeconds, () => - { - _contents.RemoveAllSolution(); - _entityManager.SpawnEntity(_badRecipeName, Owner.Transform.GridPosition); - _audioSystem.Play("/Audio/machines/ding.ogg"); - SetAppearance(MicrowaveVisualState.Idle); - }); + _busy = true; + wzhzhzh(); } + //This is required. + private void wzhzhzh() + { + foreach(var r in _recipeManager.Recipes) + { + + var success = CanSatisfyRecipe(r); + SetAppearance(MicrowaveVisualState.Cooking); + _audioSystem.Play("/Audio/machines/microwave_start_beep.ogg"); + var time = success ? r._cookTime : _cookTimeDefault; + Timer.Spawn(time * _cookTimeMultiplier, () => + { + + if (success) + { + SubtractContents(r); + } + else + { + _contents.RemoveAllSolution(); + } + + var entityToSpawn = success ? r._result : _badRecipeName; + _entityManager.SpawnEntity(entityToSpawn, Owner.Transform.GridPosition); + _audioSystem.Play("/Audio/machines/microwave_done_beep.ogg"); + SetAppearance(MicrowaveVisualState.Idle); + _busy = false; + }); + return; + } + } private bool CanSatisfyRecipe(FoodRecipePrototype recipe) { - foreach (var item in recipe.Ingredients) + foreach (var item in recipe._ingredients) { if (!_contents.ContainsReagent(item.Key, out var amount)) { @@ -117,9 +131,9 @@ namespace Content.Server.GameObjects.Components.Kitchen return true; } - private void RemoveContents(FoodRecipePrototype recipe) + private void SubtractContents(FoodRecipePrototype recipe) { - foreach(var item in recipe.Ingredients) + foreach(var item in recipe._ingredients) { _contents.TryRemoveReagent(item.Key, ReagentUnit.New(item.Value)); } diff --git a/Content.Shared/Kitchen/RecipeManager.cs b/Content.Shared/Kitchen/RecipeManager.cs index 6b653ee96a..eb238b105d 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._ingredients.Count < y._ingredients.Count) { return 1; } - if (x.Ingredients.Count > y.Ingredients.Count) + if (x._ingredients.Count > y._ingredients.Count) { return -1; } diff --git a/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs b/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs index f120499af4..4a61598629 100644 --- a/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs +++ b/Content.Shared/Prototypes/Kitchen/MicrowaveMealRecipePrototype.cs @@ -18,24 +18,26 @@ namespace Content.Shared.Prototypes.Kitchen public class FoodRecipePrototype : IPrototype, IIndexedPrototype { - private string _id; - private string _name; - private string _result; - private Dictionary _ingredients; + public string _id; + public string _name => Loc.GetString(Name); + private string Name; + public string _result; + public IReadOnlyDictionary _ingredients => Ingredients; + private Dictionary Ingredients; + public int _cookTime; public string ID => _id; - public string Name => Loc.GetString(_name); - public string Result => _result; - public IReadOnlyDictionary Ingredients => _ingredients; public void LoadFrom(YamlMappingNode mapping) { var serializer = YamlObjectSerializer.NewReader(mapping); 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 _ingredients, "ingredients", new Dictionary()); + serializer.DataField(ref Ingredients, "ingredients", new Dictionary()); + serializer.DataField(ref _cookTime, "time", 5); } + } } diff --git a/Resources/Audio/machines/microwave_done_beep.ogg b/Resources/Audio/machines/microwave_done_beep.ogg new file mode 100644 index 0000000000..e11bd45107 Binary files /dev/null and b/Resources/Audio/machines/microwave_done_beep.ogg differ diff --git a/Resources/Audio/machines/microwave_loop.ogg b/Resources/Audio/machines/microwave_loop.ogg new file mode 100644 index 0000000000..d72097e73b Binary files /dev/null and b/Resources/Audio/machines/microwave_loop.ogg differ diff --git a/Resources/Audio/machines/microwave_start_beep.ogg b/Resources/Audio/machines/microwave_start_beep.ogg new file mode 100644 index 0000000000..43f6c24660 Binary files /dev/null and b/Resources/Audio/machines/microwave_start_beep.ogg differ diff --git a/Resources/Prototypes/Entities/kitchen.yml b/Resources/Prototypes/Entities/kitchen.yml index 806ef99b7f..5828bd07ea 100644 --- a/Resources/Prototypes/Entities/kitchen.yml +++ b/Resources/Prototypes/Entities/kitchen.yml @@ -12,6 +12,7 @@ - type: Appearance visuals: - type: MicrowaveVisualizer + - type: Sound - type: Collidable shapes: diff --git a/Resources/Prototypes/Kitchen/meal_recipes.yml b/Resources/Prototypes/Kitchen/meal_recipes.yml index f763dc616b..660f7eef2a 100644 --- a/Resources/Prototypes/Kitchen/meal_recipes.yml +++ b/Resources/Prototypes/Kitchen/meal_recipes.yml @@ -2,6 +2,7 @@ id: RecipeCheeseburger name: Cheeseburger Recipe result: FoodCheeseburger + time: 10 ingredients: chem.H2O: 15 chem.Nutriment: 5 @@ -10,6 +11,7 @@ id: RecipeFlashlight name: Flashlight Recipe result: FoodCheeseWedge + time: 5 ingredients: chem.H2O: 15 chem.Glucose: 5