Sweeping changes/improvements to the microwave. (#997)
Co-authored-by: FL-OZ <anotherscuffed@gmail.com> Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
@@ -5,7 +5,6 @@ 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;
|
||||
@@ -21,7 +20,6 @@ using Robust.Server.GameObjects.Components.UserInterface;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Server.Utility;
|
||||
using Robust.Shared.Audio;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Server.Interfaces.Chat;
|
||||
@@ -32,7 +30,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
public class KitchenMicrowaveComponent : SharedMicrowaveComponent, IActivate, IInteractUsing, ISolutionChange, ISuicideAct
|
||||
public class MicrowaveComponent : SharedMicrowaveComponent, IActivate, IInteractUsing, ISolutionChange
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
|
||||
@@ -62,25 +60,22 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
/// For right now, I don't think any recipe cook time should be greater than 60 seconds.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
private uint _currentCookTimerTime { get; set; } = 1;
|
||||
private uint _currentCookTimerTime = 1;
|
||||
#endregion
|
||||
|
||||
private bool Powered => _powerDevice.Powered;
|
||||
|
||||
private bool HasContents => _solution.ReagentList.Count > 0 || _storage.ContainedEntities.Count > 0;
|
||||
|
||||
void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs) => UpdateUserInterface();
|
||||
private bool _powered => _powerDevice.Powered;
|
||||
private bool _hasContents => _solution.ReagentList.Count > 0 || _storage.ContainedEntities.Count > 0;
|
||||
private bool _uiDirty = true;
|
||||
private bool _lostPower = false;
|
||||
private int _currentCookTimeButtonIndex = 0;
|
||||
|
||||
void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs) => _uiDirty = true;
|
||||
private AudioSystem _audioSystem;
|
||||
|
||||
private AppearanceComponent _appearance;
|
||||
private PowerDeviceComponent _powerDevice;
|
||||
|
||||
private BoundUserInterface _userInterface;
|
||||
|
||||
private Container _storage;
|
||||
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
@@ -109,7 +104,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
|
||||
private void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage message)
|
||||
{
|
||||
if (!Powered || _busy)
|
||||
if (!_powered || _busy)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -119,43 +114,74 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
case MicrowaveStartCookMessage msg :
|
||||
wzhzhzh();
|
||||
break;
|
||||
|
||||
case MicrowaveEjectMessage msg :
|
||||
if (HasContents)
|
||||
if (_hasContents)
|
||||
{
|
||||
VaporizeReagents();
|
||||
EjectSolids();
|
||||
ClickSound();
|
||||
UpdateUserInterface();
|
||||
_uiDirty = true;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MicrowaveEjectSolidIndexedMessage msg:
|
||||
if (HasContents)
|
||||
if (_hasContents)
|
||||
{
|
||||
EjectSolidWithIndex(msg.EntityID);
|
||||
EjectSolid(msg.EntityID);
|
||||
ClickSound();
|
||||
UpdateUserInterface();
|
||||
_uiDirty = true;
|
||||
}
|
||||
break;
|
||||
case MicrowaveVaporizeReagentIndexedMessage msg:
|
||||
if (HasContents)
|
||||
if (_hasContents)
|
||||
{
|
||||
VaporizeReagentWithReagentQuantity(msg.ReagentQuantity);
|
||||
VaporizeReagentQuantity(msg.ReagentQuantity);
|
||||
ClickSound();
|
||||
UpdateUserInterface();
|
||||
_uiDirty = true;
|
||||
}
|
||||
break;
|
||||
case MicrowaveSelectCookTimeMessage msg:
|
||||
_currentCookTimerTime = msg.newCookTime;
|
||||
_currentCookTimeButtonIndex = msg.ButtonIndex;
|
||||
_currentCookTimerTime = msg.NewCookTime;
|
||||
ClickSound();
|
||||
UpdateUserInterface();
|
||||
_uiDirty = true;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void OnUpdate()
|
||||
{
|
||||
|
||||
if (!_powered)
|
||||
{
|
||||
//TODO:If someone cuts power currently, microwave magically keeps going. FIX IT!
|
||||
SetAppearance(MicrowaveVisualState.Idle);
|
||||
}
|
||||
|
||||
if (_busy && !_powered)
|
||||
{
|
||||
//we lost power while we were cooking/busy!
|
||||
_lostPower = true;
|
||||
VaporizeReagents();
|
||||
EjectSolids();
|
||||
_busy = false;
|
||||
_uiDirty = true;
|
||||
}
|
||||
|
||||
if (_uiDirty)
|
||||
{
|
||||
_userInterface.SetState(new MicrowaveUpdateUserInterfaceState
|
||||
(
|
||||
_solution.Solution.Contents.ToArray(),
|
||||
_storage.ContainedEntities.Select(item => item.Uid).ToArray(),
|
||||
_busy,
|
||||
_currentCookTimeButtonIndex,
|
||||
_currentCookTimerTime
|
||||
));
|
||||
_uiDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetAppearance(MicrowaveVisualState state)
|
||||
{
|
||||
if (_appearance != null || Owner.TryGetComponent(out _appearance))
|
||||
@@ -165,42 +191,29 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
|
||||
}
|
||||
|
||||
private void UpdateUserInterface()
|
||||
{
|
||||
var solidsVisualList = new List<EntityUid>();
|
||||
foreach(var item in _storage.ContainedEntities)
|
||||
{
|
||||
solidsVisualList.Add(item.Uid);
|
||||
}
|
||||
|
||||
_userInterface.SetState(new MicrowaveUpdateUserInterfaceState(_solution.Solution.Contents, solidsVisualList, _busy));
|
||||
}
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.User.TryGetComponent(out IActorComponent actor) || !Powered)
|
||||
if (!eventArgs.User.TryGetComponent(out IActorComponent actor) || !_powered)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateUserInterface();
|
||||
_uiDirty = true;
|
||||
_userInterface.Open(actor.playerSession);
|
||||
|
||||
}
|
||||
|
||||
public bool InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (!_powered)
|
||||
{
|
||||
_notifyManager.PopupMessage(Owner.Transform.GridPosition, eventArgs.User,
|
||||
Loc.GetString("It has no power!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
var itemEntity = eventArgs.User.GetComponent<HandsComponent>().GetActiveHand.Owner;
|
||||
|
||||
if(itemEntity.TryGetComponent<PourableComponent>(out var attackPourable))
|
||||
{
|
||||
//Get target and check if it can be poured into
|
||||
if (!Owner.TryGetComponent<SolutionComponent>(out var mySolution)
|
||||
|| !mySolution.CanPourIn)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!itemEntity.TryGetComponent<SolutionComponent>(out var attackSolution)
|
||||
|| !attackSolution.CanPourOut)
|
||||
{
|
||||
@@ -208,7 +221,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
}
|
||||
|
||||
//Get transfer amount. May be smaller than _transferAmount if not enough room
|
||||
var realTransferAmount = ReagentUnit.Min(attackPourable.TransferAmount, mySolution.EmptyVolume);
|
||||
var realTransferAmount = ReagentUnit.Min(attackPourable.TransferAmount, _solution.EmptyVolume);
|
||||
if (realTransferAmount <= 0) //Special message if container is full
|
||||
{
|
||||
_notifyManager.PopupMessage(Owner.Transform.GridPosition, eventArgs.User,
|
||||
@@ -218,7 +231,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
|
||||
//Move units from attackSolution to targetSolution
|
||||
var removedSolution = attackSolution.SplitSolution(realTransferAmount);
|
||||
if (!mySolution.TryAddSolution(removedSolution))
|
||||
if (!_solution.TryAddSolution(removedSolution))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -228,24 +241,18 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!itemEntity.TryGetComponent(typeof(FoodComponent), out var food))
|
||||
{
|
||||
|
||||
_notifyManager.PopupMessage(Owner, eventArgs.User, "That won't work!");
|
||||
return false;
|
||||
}
|
||||
|
||||
itemEntity.TryGetComponent(typeof(ItemComponent), out var food);
|
||||
var ent = food.Owner; //Get the entity of the ItemComponent.
|
||||
_storage.Insert(ent);
|
||||
UpdateUserInterface();
|
||||
_uiDirty = true;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
//This is required. It's 'cook'.
|
||||
// ReSharper disable once InconsistentNaming
|
||||
// ReSharper disable once IdentifierTypo
|
||||
private void wzhzhzh()
|
||||
{
|
||||
if (!HasContents)
|
||||
if (!_hasContents)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -267,25 +274,23 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
|
||||
// Check recipes
|
||||
FoodRecipePrototype recipeToCook = null;
|
||||
foreach(var r in _recipeManager.Recipes)
|
||||
foreach (var r in _recipeManager.Recipes.Where(r => CanSatisfyRecipe(r, solidsDict)))
|
||||
{
|
||||
if (!CanSatisfyRecipe(r, solidsDict))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
recipeToCook = r;
|
||||
}
|
||||
|
||||
var goodMeal = (recipeToCook != null)
|
||||
&&
|
||||
(_currentCookTimerTime == (uint)recipeToCook.CookTime) ? true : false;
|
||||
(_currentCookTimerTime == (uint)recipeToCook.CookTime);
|
||||
|
||||
SetAppearance(MicrowaveVisualState.Cooking);
|
||||
_audioSystem.Play(_startCookingSound,Owner, AudioParams.Default);
|
||||
_audioSystem.Play(_startCookingSound, Owner, AudioParams.Default);
|
||||
Timer.Spawn((int)(_currentCookTimerTime * _cookTimeMultiplier), () =>
|
||||
{
|
||||
|
||||
if (_lostPower)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (goodMeal)
|
||||
{
|
||||
SubtractContents(recipeToCook);
|
||||
@@ -296,14 +301,19 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
VaporizeSolids();
|
||||
}
|
||||
|
||||
var entityToSpawn = goodMeal ? recipeToCook.Result : _badRecipeName;
|
||||
_entityManager.SpawnEntity(entityToSpawn, Owner.Transform.GridPosition);
|
||||
_audioSystem.Play(_cookingCompleteSound,Owner, AudioParams.Default);
|
||||
if (recipeToCook != null)
|
||||
{
|
||||
var entityToSpawn = goodMeal ? recipeToCook.Result : _badRecipeName;
|
||||
_entityManager.SpawnEntity(entityToSpawn, Owner.Transform.GridPosition);
|
||||
}
|
||||
_audioSystem.Play(_cookingCompleteSound, Owner, AudioParams.Default.WithVolume(-1f));
|
||||
SetAppearance(MicrowaveVisualState.Idle);
|
||||
_busy = false;
|
||||
UpdateUserInterface();
|
||||
|
||||
_uiDirty = true;
|
||||
});
|
||||
UpdateUserInterface();
|
||||
_lostPower = false;
|
||||
_uiDirty = true;
|
||||
}
|
||||
|
||||
private void VaporizeReagents()
|
||||
@@ -311,7 +321,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
_solution.RemoveAllSolution();
|
||||
}
|
||||
|
||||
private void VaporizeReagentWithReagentQuantity(Solution.ReagentQuantity reagentQuantity)
|
||||
private void VaporizeReagentQuantity(Solution.ReagentQuantity reagentQuantity)
|
||||
{
|
||||
_solution.TryRemoveReagent(reagentQuantity.ReagentId, reagentQuantity.Quantity);
|
||||
}
|
||||
@@ -335,7 +345,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
}
|
||||
}
|
||||
|
||||
private void EjectSolidWithIndex(EntityUid entityID)
|
||||
private void EjectSolid(EntityUid entityID)
|
||||
{
|
||||
if (_entityManager.EntityExists(entityID))
|
||||
{
|
||||
@@ -402,9 +412,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
|
||||
private void ClickSound()
|
||||
{
|
||||
|
||||
_audioSystem.Play("/Audio/machines/machine_switch.ogg",Owner, AudioParams.Default.WithVolume(-2f));
|
||||
|
||||
_audioSystem.Play("/Audio/machines/machine_switch.ogg",Owner,AudioParams.Default.WithVolume(-2f));
|
||||
}
|
||||
|
||||
public SuicideKind Suicide(IEntity victim, IChatManager chat)
|
||||
@@ -423,7 +431,7 @@ namespace Content.Server.GameObjects.Components.Kitchen
|
||||
chat.EntityMe(victim, Loc.GetPluralString("is trying to cook {0:their} head!", "is trying to cook {0:their} heads!", headCount, victim));
|
||||
_currentCookTimerTime = 10;
|
||||
ClickSound();
|
||||
UpdateUserInterface();
|
||||
_uiDirty = true;
|
||||
wzhzhzh();
|
||||
return SuicideKind.Heat;
|
||||
}
|
||||
Reference in New Issue
Block a user