A shit ton of microwave stuff i can't really explain this.

This commit is contained in:
FL-OZ
2020-05-01 17:19:04 -05:00
parent a65d60dc2c
commit 13fba25edc
10 changed files with 116 additions and 60 deletions

View File

@@ -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)
{
}
}
}

View File

@@ -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<IEntitySystemManager>().GetEntitySystem<AudioSystem>();
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
var sprite = component.Owner.GetComponent<ISpriteComponent>();
_soundComponent ??= component.Owner.GetComponent<SoundComponent>();
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;
}

View File

@@ -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<SolutionComponent>();
}
}
_contents ??= Owner.TryGetComponent(out SolutionComponent solutionComponent)
? solutionComponent
: Owner.AddComponent<SolutionComponent>();
_storage = ContainerManagerComponent.Ensure<Container>("microwave_entity_container", Owner, out var existed);
_appearance = Owner.GetComponent<AppearanceComponent>();
_powerDevice = Owner.GetComponent<PowerDeviceComponent>();
_audioSystem = _entitySystemManager.GetEntitySystem<AudioSystem>();
@@ -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;
}
_busy = true;
wzhzhzh();
}
//This is required.
private void wzhzhzh()
{
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");
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;
}
}
SetAppearance(MicrowaveVisualState.Cooking);
Timer.Spawn(_cookTimeSeconds, () =>
{
_contents.RemoveAllSolution();
_entityManager.SpawnEntity(_badRecipeName, Owner.Transform.GridPosition);
_audioSystem.Play("/Audio/machines/ding.ogg");
SetAppearance(MicrowaveVisualState.Idle);
});
}
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));
}

View File

@@ -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;
}

View File

@@ -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<string, int> _ingredients;
public string _id;
public string _name => Loc.GetString(Name);
private string Name;
public string _result;
public IReadOnlyDictionary<string, int> _ingredients => Ingredients;
private Dictionary<string, int> Ingredients;
public int _cookTime;
public string ID => _id;
public string Name => Loc.GetString(_name);
public string Result => _result;
public IReadOnlyDictionary<string, int> 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<string, int>());
}
serializer.DataField(ref Ingredients, "ingredients", new Dictionary<string, int>());
serializer.DataField(ref _cookTime, "time", 5);
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -12,6 +12,7 @@
- type: Appearance
visuals:
- type: MicrowaveVisualizer
- type: Sound
- type: Collidable
shapes:

View File

@@ -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