2021-01-07 00:31:43 -06:00
|
|
|
#nullable enable
|
2020-08-22 22:29:20 +02:00
|
|
|
using System;
|
2020-08-13 14:40:27 +02:00
|
|
|
using System.Collections.Generic;
|
2020-05-02 01:29:20 -05:00
|
|
|
using System.Linq;
|
2020-08-18 14:39:08 +02:00
|
|
|
using System.Threading.Tasks;
|
2020-04-26 23:14:02 -05:00
|
|
|
using Content.Server.GameObjects.Components.Chemistry;
|
2020-07-25 15:11:16 +02:00
|
|
|
using Content.Server.GameObjects.Components.GUI;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Content.Server.GameObjects.Components.Items.Storage;
|
|
|
|
|
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
|
|
|
|
using Content.Server.Interfaces.Chat;
|
|
|
|
|
using Content.Server.Interfaces.GameObjects;
|
2020-08-24 20:47:17 +02:00
|
|
|
using Content.Server.Utility;
|
2020-04-26 23:14:02 -05:00
|
|
|
using Content.Shared.Chemistry;
|
2020-09-13 14:23:52 +02:00
|
|
|
using Content.Shared.GameObjects.Components.Body;
|
2020-10-10 15:25:13 +02:00
|
|
|
using Content.Shared.GameObjects.Components.Body.Part;
|
2021-02-03 14:05:31 +01:00
|
|
|
using Content.Shared.GameObjects.Components.Chemistry;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Content.Shared.GameObjects.Components.Power;
|
2021-01-07 00:31:43 -06:00
|
|
|
using Content.Shared.GameObjects.EntitySystems;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Content.Shared.Interfaces;
|
|
|
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
2020-04-26 23:14:02 -05:00
|
|
|
using Content.Shared.Kitchen;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Content.Shared.Prototypes.Kitchen;
|
2020-05-01 03:37:21 -05:00
|
|
|
using Robust.Server.GameObjects;
|
2020-05-04 13:54:54 -04:00
|
|
|
using Robust.Shared.Audio;
|
2020-09-13 14:23:52 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Robust.Shared.Localization;
|
|
|
|
|
using Robust.Shared.Serialization;
|
2020-09-13 14:23:52 +02:00
|
|
|
using Robust.Shared.ViewVariables;
|
2020-04-26 15:44:20 -05:00
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components.Kitchen
|
|
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2020-04-26 23:14:02 -05:00
|
|
|
[ComponentReference(typeof(IActivate))]
|
2020-06-07 12:00:05 -03:00
|
|
|
public class MicrowaveComponent : SharedMicrowaveComponent, IActivate, IInteractUsing, ISolutionChange, ISuicideAct
|
2020-04-26 15:44:20 -05:00
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
[Dependency] private readonly RecipeManager _recipeManager = default!;
|
2020-04-26 15:44:20 -05:00
|
|
|
|
2020-08-29 11:12:21 +00:00
|
|
|
#region YAMLSERIALIZE
|
2020-05-01 17:19:04 -05:00
|
|
|
private int _cookTimeDefault;
|
|
|
|
|
private int _cookTimeMultiplier; //For upgrades and stuff I guess?
|
2020-08-22 22:29:20 +02:00
|
|
|
private string _badRecipeName = "";
|
|
|
|
|
private string _startCookingSound = "";
|
|
|
|
|
private string _cookingCompleteSound = "";
|
2020-05-03 23:58:29 -05:00
|
|
|
#endregion
|
|
|
|
|
|
2020-08-22 22:29:20 +02:00
|
|
|
[ViewVariables]
|
2020-05-03 01:34:00 -05:00
|
|
|
private bool _busy = false;
|
2020-05-01 17:19:04 -05:00
|
|
|
|
2020-05-03 23:58:29 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// This is a fixed offset of 5.
|
|
|
|
|
/// The cook times for all recipes should be divisible by 5,with a minimum of 1 second.
|
|
|
|
|
/// For right now, I don't think any recipe cook time should be greater than 60 seconds.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables]
|
2020-05-28 15:28:35 -05:00
|
|
|
private uint _currentCookTimerTime = 1;
|
2020-05-03 23:58:29 -05:00
|
|
|
|
2020-08-22 22:29:20 +02:00
|
|
|
private bool Powered => !Owner.TryGetComponent(out PowerReceiverComponent? receiver) || receiver.Powered;
|
2020-09-09 18:32:31 -04:00
|
|
|
private bool _hasContents => Owner.TryGetComponent(out SolutionContainerComponent? solution) && (solution.ReagentList.Count > 0 || _storage.ContainedEntities.Count > 0);
|
2020-05-28 15:28:35 -05:00
|
|
|
private bool _uiDirty = true;
|
|
|
|
|
private bool _lostPower = false;
|
|
|
|
|
private int _currentCookTimeButtonIndex = 0;
|
2020-05-01 03:37:21 -05:00
|
|
|
|
2020-05-28 15:28:35 -05:00
|
|
|
void ISolutionChange.SolutionChanged(SolutionChangeEventArgs eventArgs) => _uiDirty = true;
|
2020-08-22 22:29:20 +02:00
|
|
|
private AudioSystem _audioSystem = default!;
|
|
|
|
|
private Container _storage = default!;
|
|
|
|
|
|
2020-08-24 20:47:17 +02:00
|
|
|
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(MicrowaveUiKey.Key);
|
2020-05-06 17:45:45 -05:00
|
|
|
|
2020-04-26 23:14:02 -05:00
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
|
|
|
{
|
|
|
|
|
base.ExposeData(serializer);
|
2020-05-01 03:37:21 -05:00
|
|
|
serializer.DataField(ref _badRecipeName, "failureResult", "FoodBadRecipe");
|
2020-05-01 17:19:04 -05:00
|
|
|
serializer.DataField(ref _cookTimeDefault, "cookTime", 5);
|
|
|
|
|
serializer.DataField(ref _cookTimeMultiplier, "cookTimeMultiplier", 1000);
|
2020-07-07 13:19:00 -04:00
|
|
|
serializer.DataField(ref _startCookingSound, "beginCookingSound","/Audio/Machines/microwave_start_beep.ogg" );
|
|
|
|
|
serializer.DataField(ref _cookingCompleteSound, "foodDoneSound","/Audio/Machines/microwave_done_beep.ogg" );
|
2020-04-26 23:14:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2020-08-22 22:29:20 +02:00
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
Owner.EnsureComponent<SolutionContainerComponent>();
|
2020-05-01 03:37:21 -05:00
|
|
|
|
2020-05-01 17:19:04 -05:00
|
|
|
_storage = ContainerManagerComponent.Ensure<Container>("microwave_entity_container", Owner, out var existed);
|
2020-05-31 12:40:36 -05:00
|
|
|
_audioSystem = EntitySystem.Get<AudioSystem>();
|
2020-08-22 22:29:20 +02:00
|
|
|
|
|
|
|
|
if (UserInterface != null)
|
|
|
|
|
{
|
|
|
|
|
UserInterface.OnReceiveMessage += UserInterfaceOnReceiveMessage;
|
|
|
|
|
}
|
2020-04-26 23:14:02 -05:00
|
|
|
}
|
|
|
|
|
|
2020-05-01 23:34:04 -05:00
|
|
|
private void UserInterfaceOnReceiveMessage(ServerBoundUserInterfaceMessage message)
|
2020-04-26 23:14:02 -05:00
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
if (!Powered || _busy)
|
2020-05-03 23:58:29 -05:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-05-01 17:19:04 -05:00
|
|
|
|
2020-05-01 23:34:04 -05:00
|
|
|
switch (message.Message)
|
2020-05-01 03:37:21 -05:00
|
|
|
{
|
2020-05-01 23:34:04 -05:00
|
|
|
case MicrowaveStartCookMessage msg :
|
2020-05-04 13:54:54 -04:00
|
|
|
wzhzhzh();
|
2020-05-01 23:34:04 -05:00
|
|
|
break;
|
|
|
|
|
case MicrowaveEjectMessage msg :
|
2020-05-28 15:28:35 -05:00
|
|
|
if (_hasContents)
|
2020-05-03 23:58:29 -05:00
|
|
|
{
|
|
|
|
|
VaporizeReagents();
|
|
|
|
|
EjectSolids();
|
2020-05-04 13:54:54 -04:00
|
|
|
ClickSound();
|
2020-05-28 15:28:35 -05:00
|
|
|
_uiDirty = true;
|
2020-05-03 23:58:29 -05:00
|
|
|
}
|
2020-05-01 23:34:04 -05:00
|
|
|
break;
|
2020-05-03 01:34:00 -05:00
|
|
|
case MicrowaveEjectSolidIndexedMessage msg:
|
2020-05-28 15:28:35 -05:00
|
|
|
if (_hasContents)
|
2020-05-03 23:58:29 -05:00
|
|
|
{
|
2020-05-28 15:28:35 -05:00
|
|
|
EjectSolid(msg.EntityID);
|
2020-05-04 13:54:54 -04:00
|
|
|
ClickSound();
|
2020-05-28 15:28:35 -05:00
|
|
|
_uiDirty = true;
|
2020-05-03 23:58:29 -05:00
|
|
|
}
|
|
|
|
|
break;
|
2020-05-04 15:16:16 -05:00
|
|
|
case MicrowaveVaporizeReagentIndexedMessage msg:
|
2020-05-28 15:28:35 -05:00
|
|
|
if (_hasContents)
|
2020-05-04 15:16:16 -05:00
|
|
|
{
|
2020-05-28 15:28:35 -05:00
|
|
|
VaporizeReagentQuantity(msg.ReagentQuantity);
|
2020-05-04 15:16:16 -05:00
|
|
|
ClickSound();
|
2020-05-28 15:28:35 -05:00
|
|
|
_uiDirty = true;
|
2020-05-04 15:16:16 -05:00
|
|
|
}
|
|
|
|
|
break;
|
2020-05-03 23:58:29 -05:00
|
|
|
case MicrowaveSelectCookTimeMessage msg:
|
2020-05-28 15:28:35 -05:00
|
|
|
_currentCookTimeButtonIndex = msg.ButtonIndex;
|
|
|
|
|
_currentCookTimerTime = msg.NewCookTime;
|
2020-05-04 13:54:54 -04:00
|
|
|
ClickSound();
|
2020-05-28 15:28:35 -05:00
|
|
|
_uiDirty = true;
|
2020-05-03 01:34:00 -05:00
|
|
|
break;
|
2020-05-01 03:37:21 -05:00
|
|
|
}
|
2020-05-01 23:34:04 -05:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 15:28:35 -05:00
|
|
|
public void OnUpdate()
|
2020-05-03 01:34:00 -05:00
|
|
|
{
|
2020-05-28 15:28:35 -05:00
|
|
|
|
2020-08-22 22:29:20 +02:00
|
|
|
if (!Powered)
|
2020-05-03 23:58:29 -05:00
|
|
|
{
|
2020-05-28 15:28:35 -05:00
|
|
|
//TODO:If someone cuts power currently, microwave magically keeps going. FIX IT!
|
|
|
|
|
SetAppearance(MicrowaveVisualState.Idle);
|
2020-05-03 23:58:29 -05:00
|
|
|
}
|
|
|
|
|
|
2020-08-22 22:29:20 +02:00
|
|
|
if (_busy && !Powered)
|
2020-05-28 15:28:35 -05:00
|
|
|
{
|
|
|
|
|
//we lost power while we were cooking/busy!
|
|
|
|
|
_lostPower = true;
|
|
|
|
|
VaporizeReagents();
|
|
|
|
|
EjectSolids();
|
|
|
|
|
_busy = false;
|
|
|
|
|
_uiDirty = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
if (_uiDirty && Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
2020-05-28 15:28:35 -05:00
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
UserInterface?.SetState(new MicrowaveUpdateUserInterfaceState
|
2020-05-28 15:28:35 -05:00
|
|
|
(
|
2020-08-22 22:29:20 +02:00
|
|
|
solution.Solution.Contents.ToArray(),
|
2020-05-28 15:28:35 -05:00
|
|
|
_storage.ContainedEntities.Select(item => item.Uid).ToArray(),
|
|
|
|
|
_busy,
|
|
|
|
|
_currentCookTimeButtonIndex,
|
|
|
|
|
_currentCookTimerTime
|
|
|
|
|
));
|
|
|
|
|
_uiDirty = false;
|
|
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 15:28:35 -05:00
|
|
|
private void SetAppearance(MicrowaveVisualState state)
|
2020-05-03 01:34:00 -05:00
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
2020-05-03 01:34:00 -05:00
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
appearance.SetData(PowerDeviceVisuals.VisualState, state);
|
2020-05-03 01:34:00 -05:00
|
|
|
}
|
|
|
|
|
}
|
2020-05-01 23:34:04 -05:00
|
|
|
|
|
|
|
|
void IActivate.Activate(ActivateEventArgs eventArgs)
|
|
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
if (!eventArgs.User.TryGetComponent(out IActorComponent? actor) || !Powered)
|
2020-05-03 23:58:29 -05:00
|
|
|
{
|
2020-05-01 23:34:04 -05:00
|
|
|
return;
|
2020-05-03 23:58:29 -05:00
|
|
|
}
|
2020-08-22 22:29:20 +02:00
|
|
|
|
2020-05-28 15:28:35 -05:00
|
|
|
_uiDirty = true;
|
2020-09-13 05:03:22 -07:00
|
|
|
UserInterface?.Toggle(actor.playerSession);
|
2020-05-01 17:19:04 -05:00
|
|
|
}
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
2020-05-02 01:29:20 -05:00
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
if (!Powered)
|
2020-05-28 15:28:35 -05:00
|
|
|
{
|
2020-09-01 12:34:53 +02:00
|
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("It has no power!"));
|
2020-05-28 15:28:35 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-25 15:11:16 +02:00
|
|
|
var itemEntity = eventArgs.User.GetComponent<HandsComponent>().GetActiveHand?.Owner;
|
|
|
|
|
|
|
|
|
|
if (itemEntity == null)
|
|
|
|
|
{
|
2020-09-01 12:34:53 +02:00
|
|
|
eventArgs.User.PopupMessage(Loc.GetString("You have no active hand!"));
|
2020-07-25 15:11:16 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
|
2021-02-03 14:05:31 +01:00
|
|
|
if (itemEntity.TryGetComponent<SolutionTransferComponent>(out var attackPourable))
|
2020-05-02 01:29:20 -05:00
|
|
|
{
|
2021-02-03 14:05:31 +01:00
|
|
|
if (!itemEntity.TryGetComponent<ISolutionInteractionsComponent>(out var attackSolution)
|
|
|
|
|
|| !attackSolution.CanDrain)
|
2020-05-02 01:29:20 -05:00
|
|
|
{
|
2020-05-03 01:34:00 -05:00
|
|
|
return false;
|
2020-05-02 01:29:20 -05:00
|
|
|
}
|
|
|
|
|
|
2020-09-09 18:32:31 -04:00
|
|
|
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
2020-08-22 22:29:20 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 01:34:00 -05:00
|
|
|
//Get transfer amount. May be smaller than _transferAmount if not enough room
|
2020-08-22 22:29:20 +02:00
|
|
|
var realTransferAmount = ReagentUnit.Min(attackPourable.TransferAmount, solution.EmptyVolume);
|
2020-05-03 01:34:00 -05:00
|
|
|
if (realTransferAmount <= 0) //Special message if container is full
|
|
|
|
|
{
|
2020-09-01 12:34:53 +02:00
|
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("Container is full"));
|
2020-05-03 01:34:00 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Move units from attackSolution to targetSolution
|
2021-02-03 14:05:31 +01:00
|
|
|
var removedSolution = attackSolution.Drain(realTransferAmount);
|
2020-08-22 22:29:20 +02:00
|
|
|
if (!solution.TryAddSolution(removedSolution))
|
2020-05-03 23:58:29 -05:00
|
|
|
{
|
2020-05-03 01:34:00 -05:00
|
|
|
return false;
|
2020-05-03 23:58:29 -05:00
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
|
2020-09-01 12:34:53 +02:00
|
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("Transferred {0}u", removedSolution.TotalVolume));
|
2020-05-02 01:29:20 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-29 15:50:23 -05:00
|
|
|
if (!itemEntity.TryGetComponent(typeof(ItemComponent), out var food))
|
|
|
|
|
{
|
|
|
|
|
|
2020-09-01 12:34:53 +02:00
|
|
|
Owner.PopupMessage(eventArgs.User, "That won't work!");
|
2020-05-29 15:50:23 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 23:58:29 -05:00
|
|
|
var ent = food.Owner; //Get the entity of the ItemComponent.
|
|
|
|
|
_storage.Insert(ent);
|
2020-05-28 15:28:35 -05:00
|
|
|
_uiDirty = true;
|
2020-05-03 23:58:29 -05:00
|
|
|
return true;
|
2020-05-02 01:29:20 -05:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 15:28:35 -05:00
|
|
|
// ReSharper disable once InconsistentNaming
|
|
|
|
|
// ReSharper disable once IdentifierTypo
|
2020-05-01 17:19:04 -05:00
|
|
|
private void wzhzhzh()
|
|
|
|
|
{
|
2020-05-28 15:28:35 -05:00
|
|
|
if (!_hasContents)
|
2020-05-04 13:54:54 -04:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-05-06 17:45:45 -05:00
|
|
|
|
2020-05-01 23:34:04 -05:00
|
|
|
_busy = true;
|
2020-05-03 01:34:00 -05:00
|
|
|
// Convert storage into Dictionary of ingredients
|
2020-05-04 18:35:36 -05:00
|
|
|
var solidsDict = new Dictionary<string, int>();
|
2020-05-03 23:58:29 -05:00
|
|
|
foreach(var item in _storage.ContainedEntities)
|
2020-05-03 01:34:00 -05:00
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
if (item.Prototype == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 18:35:36 -05:00
|
|
|
if(solidsDict.ContainsKey(item.Prototype.ID))
|
2020-05-03 01:34:00 -05:00
|
|
|
{
|
2020-05-04 18:35:36 -05:00
|
|
|
solidsDict[item.Prototype.ID]++;
|
2020-05-03 01:34:00 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-05-04 18:35:36 -05:00
|
|
|
solidsDict.Add(item.Prototype.ID, 1);
|
2020-05-03 01:34:00 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-05 11:46:34 -05:00
|
|
|
var failState = MicrowaveSuccessState.RecipeFail;
|
|
|
|
|
foreach(var id in solidsDict.Keys)
|
|
|
|
|
{
|
|
|
|
|
if(_recipeManager.SolidAppears(id))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
failState = MicrowaveSuccessState.UnwantedForeignObject;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 01:34:00 -05:00
|
|
|
// Check recipes
|
2020-08-22 22:29:20 +02:00
|
|
|
FoodRecipePrototype? recipeToCook = null;
|
2020-06-05 11:46:34 -05:00
|
|
|
foreach (var r in _recipeManager.Recipes.Where(r => CanSatisfyRecipe(r, solidsDict) == MicrowaveSuccessState.RecipePass))
|
2020-04-26 23:14:02 -05:00
|
|
|
{
|
2020-05-03 23:58:29 -05:00
|
|
|
recipeToCook = r;
|
2020-04-26 23:14:02 -05:00
|
|
|
}
|
2020-05-03 23:58:29 -05:00
|
|
|
|
|
|
|
|
var goodMeal = (recipeToCook != null)
|
|
|
|
|
&&
|
2020-05-28 15:28:35 -05:00
|
|
|
(_currentCookTimerTime == (uint)recipeToCook.CookTime);
|
2020-05-03 23:58:29 -05:00
|
|
|
SetAppearance(MicrowaveVisualState.Cooking);
|
2020-06-07 08:55:15 -05:00
|
|
|
_audioSystem.PlayFromEntity(_startCookingSound, Owner, AudioParams.Default);
|
2020-10-30 05:02:49 +01:00
|
|
|
Owner.SpawnTimer((int)(_currentCookTimerTime * _cookTimeMultiplier), (Action)(() =>
|
2020-05-03 23:58:29 -05:00
|
|
|
{
|
2020-05-28 15:28:35 -05:00
|
|
|
if (_lostPower)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-06-05 11:46:34 -05:00
|
|
|
|
|
|
|
|
if(failState == MicrowaveSuccessState.UnwantedForeignObject)
|
2020-05-03 23:58:29 -05:00
|
|
|
{
|
2020-06-05 11:46:34 -05:00
|
|
|
VaporizeReagents();
|
|
|
|
|
EjectSolids();
|
2020-05-03 23:58:29 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-06-05 11:46:34 -05:00
|
|
|
if (goodMeal)
|
|
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
SubtractContents(recipeToCook!);
|
2020-06-05 11:46:34 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
VaporizeReagents();
|
|
|
|
|
VaporizeSolids();
|
|
|
|
|
}
|
2020-05-03 23:58:29 -05:00
|
|
|
|
2020-06-05 11:46:34 -05:00
|
|
|
if (recipeToCook != null)
|
|
|
|
|
{
|
|
|
|
|
var entityToSpawn = goodMeal ? recipeToCook.Result : _badRecipeName;
|
2020-11-18 15:45:53 +01:00
|
|
|
Owner.EntityManager.SpawnEntity(entityToSpawn, Owner.Transform.Coordinates);
|
2020-06-05 11:46:34 -05:00
|
|
|
}
|
2020-05-28 15:28:35 -05:00
|
|
|
}
|
2020-06-07 08:55:15 -05:00
|
|
|
_audioSystem.PlayFromEntity(_cookingCompleteSound, Owner, AudioParams.Default.WithVolume(-1f));
|
2020-06-05 11:46:34 -05:00
|
|
|
|
2020-05-03 23:58:29 -05:00
|
|
|
SetAppearance(MicrowaveVisualState.Idle);
|
|
|
|
|
_busy = false;
|
2020-05-28 15:28:35 -05:00
|
|
|
|
|
|
|
|
_uiDirty = true;
|
2020-06-07 08:55:15 -05:00
|
|
|
}));
|
2020-05-28 15:28:35 -05:00
|
|
|
_lostPower = false;
|
|
|
|
|
_uiDirty = true;
|
2020-04-26 23:14:02 -05:00
|
|
|
}
|
2020-05-01 23:34:04 -05:00
|
|
|
|
2020-05-03 01:34:00 -05:00
|
|
|
private void VaporizeReagents()
|
2020-05-01 23:34:04 -05:00
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
2020-08-22 22:29:20 +02:00
|
|
|
{
|
|
|
|
|
solution.RemoveAllSolution();
|
|
|
|
|
}
|
2020-05-04 15:16:16 -05:00
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
|
2020-05-28 15:28:35 -05:00
|
|
|
private void VaporizeReagentQuantity(Solution.ReagentQuantity reagentQuantity)
|
2020-05-04 15:16:16 -05:00
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
if (Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
2020-08-22 22:29:20 +02:00
|
|
|
{
|
|
|
|
|
solution?.TryRemoveReagent(reagentQuantity.ReagentId, reagentQuantity.Quantity);
|
|
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void VaporizeSolids()
|
|
|
|
|
{
|
2020-05-04 14:39:33 -05:00
|
|
|
for(var i = _storage.ContainedEntities.Count-1; i>=0; i--)
|
2020-05-03 01:34:00 -05:00
|
|
|
{
|
2020-05-04 14:39:33 -05:00
|
|
|
var item = _storage.ContainedEntities.ElementAt(i);
|
2020-05-03 23:58:29 -05:00
|
|
|
_storage.Remove(item);
|
2020-05-03 01:34:00 -05:00
|
|
|
item.Delete();
|
|
|
|
|
}
|
2020-05-01 23:34:04 -05:00
|
|
|
}
|
2020-05-02 01:29:20 -05:00
|
|
|
|
|
|
|
|
private void EjectSolids()
|
|
|
|
|
{
|
|
|
|
|
|
2020-05-04 14:39:33 -05:00
|
|
|
for(var i = _storage.ContainedEntities.Count-1; i>=0; i--)
|
2020-05-02 01:29:20 -05:00
|
|
|
{
|
2020-05-04 14:39:33 -05:00
|
|
|
_storage.Remove(_storage.ContainedEntities.ElementAt(i));
|
2020-05-02 01:29:20 -05:00
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
}
|
2020-05-02 01:29:20 -05:00
|
|
|
|
2020-05-28 15:28:35 -05:00
|
|
|
private void EjectSolid(EntityUid entityID)
|
2020-05-03 01:34:00 -05:00
|
|
|
{
|
2020-11-18 15:45:53 +01:00
|
|
|
if (Owner.EntityManager.EntityExists(entityID))
|
2020-05-04 18:35:36 -05:00
|
|
|
{
|
2020-11-18 15:45:53 +01:00
|
|
|
_storage.Remove(Owner.EntityManager.GetEntity(entityID));
|
2020-05-04 18:35:36 -05:00
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void SubtractContents(FoodRecipePrototype recipe)
|
|
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
2020-08-22 22:29:20 +02:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 23:58:29 -05:00
|
|
|
foreach(var recipeReagent in recipe.IngredientsReagents)
|
2020-05-03 01:34:00 -05:00
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
solution?.TryRemoveReagent(recipeReagent.Key, ReagentUnit.New(recipeReagent.Value));
|
2020-05-02 01:29:20 -05:00
|
|
|
}
|
|
|
|
|
|
2020-05-03 23:58:29 -05:00
|
|
|
foreach (var recipeSolid in recipe.IngredientsSolids)
|
2020-05-03 01:34:00 -05:00
|
|
|
{
|
2020-05-03 23:58:29 -05:00
|
|
|
for (var i = 0; i < recipeSolid.Value; i++)
|
|
|
|
|
{
|
2020-05-04 13:54:54 -04:00
|
|
|
foreach (var item in _storage.ContainedEntities)
|
2020-05-03 23:58:29 -05:00
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
if (item.Prototype == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 23:58:29 -05:00
|
|
|
if (item.Prototype.ID == recipeSolid.Key)
|
|
|
|
|
{
|
|
|
|
|
_storage.Remove(item);
|
|
|
|
|
item.Delete();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
}
|
2020-05-03 23:58:29 -05:00
|
|
|
|
2020-05-02 01:29:20 -05:00
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
|
2020-06-05 11:46:34 -05:00
|
|
|
private MicrowaveSuccessState CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary<string,int> solids)
|
2020-04-26 23:14:02 -05:00
|
|
|
{
|
2020-09-09 18:32:31 -04:00
|
|
|
if (!Owner.TryGetComponent(out SolutionContainerComponent? solution))
|
2020-08-22 22:29:20 +02:00
|
|
|
{
|
|
|
|
|
return MicrowaveSuccessState.RecipeFail;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 01:34:00 -05:00
|
|
|
foreach (var reagent in recipe.IngredientsReagents)
|
2020-05-02 01:29:20 -05:00
|
|
|
{
|
2021-01-07 00:31:43 -06:00
|
|
|
if (!solution.Solution.ContainsReagent(reagent.Key, out var amount))
|
2020-05-02 01:29:20 -05:00
|
|
|
{
|
2020-06-05 11:46:34 -05:00
|
|
|
return MicrowaveSuccessState.RecipeFail;
|
2020-05-02 01:29:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (amount.Int() < reagent.Value)
|
|
|
|
|
{
|
2020-06-05 11:46:34 -05:00
|
|
|
return MicrowaveSuccessState.RecipeFail;
|
2020-05-02 01:29:20 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 01:34:00 -05:00
|
|
|
foreach (var solid in recipe.IngredientsSolids)
|
2020-04-26 23:14:02 -05:00
|
|
|
{
|
2020-05-04 18:35:36 -05:00
|
|
|
if (!solids.ContainsKey(solid.Key))
|
2020-04-27 00:27:25 -05:00
|
|
|
{
|
2020-06-05 11:46:34 -05:00
|
|
|
return MicrowaveSuccessState.RecipeFail;
|
2020-04-27 00:27:25 -05:00
|
|
|
}
|
2020-04-26 23:14:02 -05:00
|
|
|
|
2020-05-04 18:35:36 -05:00
|
|
|
if (solids[solid.Key] < solid.Value)
|
2020-04-30 23:07:27 -05:00
|
|
|
{
|
2020-06-05 11:46:34 -05:00
|
|
|
return MicrowaveSuccessState.RecipeFail;
|
2020-04-30 23:07:27 -05:00
|
|
|
}
|
2020-04-26 23:14:02 -05:00
|
|
|
}
|
2020-04-26 15:44:20 -05:00
|
|
|
|
2020-06-05 11:46:34 -05:00
|
|
|
|
|
|
|
|
return MicrowaveSuccessState.RecipePass;
|
2020-04-26 15:44:20 -05:00
|
|
|
}
|
2020-05-06 17:45:45 -05:00
|
|
|
|
2020-05-04 13:54:54 -04:00
|
|
|
private void ClickSound()
|
|
|
|
|
{
|
2020-07-07 13:19:00 -04:00
|
|
|
_audioSystem.PlayFromEntity("/Audio/Machines/machine_switch.ogg",Owner,AudioParams.Default.WithVolume(-2f));
|
2020-05-04 13:54:54 -04:00
|
|
|
}
|
2020-04-26 23:14:02 -05:00
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
SuicideKind ISuicideAct.Suicide(IEntity victim, IChatManager chat)
|
2020-05-27 20:05:12 -03:00
|
|
|
{
|
Bodysystem and damagesystem rework (#1544)
* Things and stuff with grids, unfinished w/ code debug changes.
* Updated submodule and also lost some progress cause I fucked it up xd
* First unfinished draft of the BodySystem. Doesn't compile.
* More changes to make it compile, but still just a framework. Doesn't do anything at the moment.
* Many cleanup changes.
* Revert "Merge branch 'master' of https://github.com/GlassEclipse/space-station-14 into body_system"
This reverts commit ddd4aebbc76cf2a0b7b102f72b93d55a0816c88c, reversing
changes made to 12d0dd752706bdda8879393bd8191a1199a0c978.
* Commit human.yml
* Updated a lot of things to be more classy, more progress overall, etc. etc.
* Latest update with many changes
* Minor changes
* Fixed Travis build bug
* Adds first draft of Body Scanner console, apparently I also forgot to tie Mechanisms into body parts so now a heart just sits in the Torso like a good boy :)
* Commit rest of stuff
* Latest changes
* Latest changes again
* 14 naked cowboys
* Yay!
* Latest changes (probably doesnt compile)
* Surgery!!!!!!!!!~1116y
* Cleaned some stuff up
* More cleanup
* Refactoring of code. Basic surgery path now done.
* Removed readme, has been added to HackMD
* Fixes typo (and thus test errors)
* WIP changes, committing so I can pull latest master changes
* Still working on that god awful merge
* Latest changes
* Latest changes!!
* Beginning of refactor to BoundUserInterface
* Surgery!
* Latest changes - fixes pr change requests and random fixes
* oops
* Fixes bodypart recursion
* Beginning of work on revamping the damage system.
* More latest changes
* Latest changes
* Finished merge
* Commit before removing old healthcode
* Almost done with removing speciescomponent...
* It compiles!!!
* yahoo more work
* Fixes to make it work
* Merge conflict fixes
* Deleting species visualizer was a mistake
* IDE warnings are VERBOTEN
* makes the server not kill itself on startup, some cleanup (#1)
* Namespaces, comments and exception fixes
* Fix conveyor and conveyor switch serialization
SS14 in reactive when
* Move damage, acts and body to shared
Damage cleanup
Comment cleanup
* Rename SpeciesComponent to RotationComponent and cleanup
Damage cleanup
Comment cleanup
* Fix nullable warnings
* Address old reviews
Fix off welder suicide damage type, deathmatch and suspicion
* Fix new test fail with units being able to accept items when unpowered
* Remove RotationComponent, change references to IBodyManagerComponent
* Add a bloodstream to humans
* More cleanups
* Add body conduits, connections, connectors substances and valves
* Revert "Add body conduits, connections, connectors substances and valves"
This reverts commit 9ab0b50e6b15fe98852d7b0836c0cdbf4bd76d20.
* Implement the heart mechanism behavior with the circulatory network
* Added network property to mechanism behaviors
* Changed human organ sprites and added missing ones
* Fix tests
* Add individual body part sprite rendering
* Fix error where dropped mechanisms are not initialized
* Implement client/server body damage
* Make DamageContainer take care of raising events
* Reimplement medical scanner with the new body system
* Improve the medical scanner ui
* Merge conflict fixes
* Fix crash when colliding with something
* Fix microwave suicides and eyes sprite rendering
* Fix nullable reference error
* Fix up surgery client side
* Fix missing using from merge conflict
* Add breathing
*inhale
* Merge conflict fixes
* Fix accumulatedframetime being reset to 0 instead of decreased by the threshold
https://github.com/space-wizards/space-station-14/pull/1617
* Use and add to the new AtmosHelpers
* Fix feet
* Add proper coloring to dropped body parts
* Fix Urist's lungs being too strong
* Merge conflict fixes
* Merge conflict fixes
* Merge conflict fixes
Co-authored-by: GlassEclipse <tsymall5@gmail.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com>
2020-08-17 01:42:42 +02:00
|
|
|
var headCount = 0;
|
2020-10-10 15:25:13 +02:00
|
|
|
|
|
|
|
|
if (victim.TryGetComponent<IBody>(out var body))
|
2020-05-27 20:05:12 -03:00
|
|
|
{
|
2020-10-10 15:25:13 +02:00
|
|
|
var heads = body.GetPartsOfType(BodyPartType.Head);
|
2020-05-27 20:05:12 -03:00
|
|
|
foreach (var head in heads)
|
|
|
|
|
{
|
2020-10-10 15:25:13 +02:00
|
|
|
if (!body.TryDropPart(head, out var dropped))
|
Bodysystem and damagesystem rework (#1544)
* Things and stuff with grids, unfinished w/ code debug changes.
* Updated submodule and also lost some progress cause I fucked it up xd
* First unfinished draft of the BodySystem. Doesn't compile.
* More changes to make it compile, but still just a framework. Doesn't do anything at the moment.
* Many cleanup changes.
* Revert "Merge branch 'master' of https://github.com/GlassEclipse/space-station-14 into body_system"
This reverts commit ddd4aebbc76cf2a0b7b102f72b93d55a0816c88c, reversing
changes made to 12d0dd752706bdda8879393bd8191a1199a0c978.
* Commit human.yml
* Updated a lot of things to be more classy, more progress overall, etc. etc.
* Latest update with many changes
* Minor changes
* Fixed Travis build bug
* Adds first draft of Body Scanner console, apparently I also forgot to tie Mechanisms into body parts so now a heart just sits in the Torso like a good boy :)
* Commit rest of stuff
* Latest changes
* Latest changes again
* 14 naked cowboys
* Yay!
* Latest changes (probably doesnt compile)
* Surgery!!!!!!!!!~1116y
* Cleaned some stuff up
* More cleanup
* Refactoring of code. Basic surgery path now done.
* Removed readme, has been added to HackMD
* Fixes typo (and thus test errors)
* WIP changes, committing so I can pull latest master changes
* Still working on that god awful merge
* Latest changes
* Latest changes!!
* Beginning of refactor to BoundUserInterface
* Surgery!
* Latest changes - fixes pr change requests and random fixes
* oops
* Fixes bodypart recursion
* Beginning of work on revamping the damage system.
* More latest changes
* Latest changes
* Finished merge
* Commit before removing old healthcode
* Almost done with removing speciescomponent...
* It compiles!!!
* yahoo more work
* Fixes to make it work
* Merge conflict fixes
* Deleting species visualizer was a mistake
* IDE warnings are VERBOTEN
* makes the server not kill itself on startup, some cleanup (#1)
* Namespaces, comments and exception fixes
* Fix conveyor and conveyor switch serialization
SS14 in reactive when
* Move damage, acts and body to shared
Damage cleanup
Comment cleanup
* Rename SpeciesComponent to RotationComponent and cleanup
Damage cleanup
Comment cleanup
* Fix nullable warnings
* Address old reviews
Fix off welder suicide damage type, deathmatch and suspicion
* Fix new test fail with units being able to accept items when unpowered
* Remove RotationComponent, change references to IBodyManagerComponent
* Add a bloodstream to humans
* More cleanups
* Add body conduits, connections, connectors substances and valves
* Revert "Add body conduits, connections, connectors substances and valves"
This reverts commit 9ab0b50e6b15fe98852d7b0836c0cdbf4bd76d20.
* Implement the heart mechanism behavior with the circulatory network
* Added network property to mechanism behaviors
* Changed human organ sprites and added missing ones
* Fix tests
* Add individual body part sprite rendering
* Fix error where dropped mechanisms are not initialized
* Implement client/server body damage
* Make DamageContainer take care of raising events
* Reimplement medical scanner with the new body system
* Improve the medical scanner ui
* Merge conflict fixes
* Fix crash when colliding with something
* Fix microwave suicides and eyes sprite rendering
* Fix nullable reference error
* Fix up surgery client side
* Fix missing using from merge conflict
* Add breathing
*inhale
* Merge conflict fixes
* Fix accumulatedframetime being reset to 0 instead of decreased by the threshold
https://github.com/space-wizards/space-station-14/pull/1617
* Use and add to the new AtmosHelpers
* Fix feet
* Add proper coloring to dropped body parts
* Fix Urist's lungs being too strong
* Merge conflict fixes
* Merge conflict fixes
* Merge conflict fixes
Co-authored-by: GlassEclipse <tsymall5@gmail.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com>
2020-08-17 01:42:42 +02:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-10 15:25:13 +02:00
|
|
|
var droppedHeads = dropped.Where(p => p.PartType == BodyPartType.Head);
|
|
|
|
|
|
|
|
|
|
foreach (var droppedHead in droppedHeads)
|
|
|
|
|
{
|
|
|
|
|
_storage.Insert(droppedHead.Owner);
|
|
|
|
|
headCount++;
|
|
|
|
|
}
|
2020-05-27 20:05:12 -03:00
|
|
|
}
|
|
|
|
|
}
|
2020-08-30 11:28:46 +02:00
|
|
|
|
2020-10-10 15:25:13 +02:00
|
|
|
var othersMessage = headCount > 1
|
|
|
|
|
? Loc.GetString("{0:theName} is trying to cook {0:their} heads!", victim)
|
|
|
|
|
: Loc.GetString("{0:theName} is trying to cook {0:their} head!", victim);
|
|
|
|
|
|
2020-08-30 11:28:46 +02:00
|
|
|
victim.PopupMessageOtherClients(othersMessage);
|
|
|
|
|
|
2020-10-10 15:25:13 +02:00
|
|
|
var selfMessage = headCount > 1
|
|
|
|
|
? Loc.GetString("You cook your heads!")
|
|
|
|
|
: Loc.GetString("You cook your head!");
|
|
|
|
|
|
2020-08-30 11:28:46 +02:00
|
|
|
victim.PopupMessage(selfMessage);
|
|
|
|
|
|
2020-05-27 20:05:12 -03:00
|
|
|
_currentCookTimerTime = 10;
|
|
|
|
|
ClickSound();
|
2020-05-28 15:28:35 -05:00
|
|
|
_uiDirty = true;
|
2020-05-27 20:05:12 -03:00
|
|
|
wzhzhzh();
|
|
|
|
|
return SuicideKind.Heat;
|
|
|
|
|
}
|
2020-04-26 15:44:20 -05:00
|
|
|
}
|
|
|
|
|
}
|