2020-05-02 01:29:20 -05:00
|
|
|
using System.Linq;
|
2020-08-18 14:39:08 +02:00
|
|
|
using System.Threading.Tasks;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Act;
|
|
|
|
|
using Content.Server.Chat.Managers;
|
2022-02-12 17:53:54 -07:00
|
|
|
using Content.Server.Chemistry.Components.SolutionManager;
|
2021-10-29 13:40:15 +01:00
|
|
|
using Content.Server.Chemistry.EntitySystems;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Hands.Components;
|
2021-09-26 15:18:45 +02:00
|
|
|
using Content.Server.Popups;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Power.Components;
|
2022-02-12 17:53:54 -07:00
|
|
|
using Content.Server.Temperature.Components;
|
|
|
|
|
using Content.Server.Temperature.Systems;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.UserInterface;
|
2021-06-19 19:34:01 +00:00
|
|
|
using Content.Shared.Acts;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Body.Components;
|
|
|
|
|
using Content.Shared.Body.Part;
|
2021-11-03 16:48:03 -07:00
|
|
|
using Content.Shared.FixedPoint;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Interaction;
|
2021-12-30 22:56:10 +01:00
|
|
|
using Content.Shared.Item;
|
2020-04-26 23:14:02 -05:00
|
|
|
using Content.Shared.Kitchen;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Kitchen.Components;
|
2021-09-26 15:18:45 +02:00
|
|
|
using Content.Shared.Popups;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Power;
|
2021-07-10 17:35:33 +02:00
|
|
|
using Content.Shared.Sound;
|
2022-02-12 17:53:54 -07:00
|
|
|
using Content.Shared.Tag;
|
2020-05-01 03:37:21 -05:00
|
|
|
using Robust.Server.GameObjects;
|
2020-05-04 13:54:54 -04:00
|
|
|
using Robust.Shared.Audio;
|
2021-03-01 15:24:46 -08:00
|
|
|
using Robust.Shared.Containers;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Player;
|
2020-04-26 15:44:20 -05:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Kitchen.Components
|
2020-04-26 15:44:20 -05:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2022-03-12 13:26:06 -05:00
|
|
|
public sealed class MicrowaveComponent : SharedMicrowaveComponent, IInteractUsing, ISuicideAct, IBreakAct
|
2020-04-26 15:44:20 -05:00
|
|
|
{
|
2021-12-05 21:02:04 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entities = default!;
|
|
|
|
|
|
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
|
2021-09-06 15:49:44 +02:00
|
|
|
|
|
|
|
|
[DataField("cookTime")] private uint _cookTimeDefault = 5;
|
|
|
|
|
[DataField("cookTimeMultiplier")] private int _cookTimeMultiplier = 1000; //For upgrades and stuff I guess?
|
|
|
|
|
[DataField("failureResult")] private string _badRecipeName = "FoodBadRecipe";
|
|
|
|
|
|
|
|
|
|
[DataField("beginCookingSound")] private SoundSpecifier _startCookingSound =
|
|
|
|
|
new SoundPathSpecifier("/Audio/Machines/microwave_start_beep.ogg");
|
|
|
|
|
|
|
|
|
|
[DataField("foodDoneSound")] private SoundSpecifier _cookingCompleteSound =
|
|
|
|
|
new SoundPathSpecifier("/Audio/Machines/microwave_done_beep.ogg");
|
|
|
|
|
|
2021-07-10 17:35:33 +02:00
|
|
|
[DataField("clickSound")]
|
|
|
|
|
private SoundSpecifier _clickSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg");
|
2021-09-06 15:49:44 +02:00
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
public SoundSpecifier ItemBreakSound = new SoundPathSpecifier("/Audio/Effects/clang.ogg");
|
|
|
|
|
|
2021-07-10 17:35:33 +02:00
|
|
|
#endregion YAMLSERIALIZE
|
2020-05-03 23:58:29 -05:00
|
|
|
|
2021-09-06 15:49:44 +02:00
|
|
|
[ViewVariables] private bool _busy = false;
|
2021-06-19 19:34:01 +00:00
|
|
|
private bool _broken;
|
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>
|
2021-09-06 15:49:44 +02:00
|
|
|
[ViewVariables] private uint _currentCookTimerTime = 1;
|
2020-05-03 23:58:29 -05:00
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// The max temperature that this microwave can heat objects to.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("temperatureUpperThreshold")]
|
|
|
|
|
public float TemperatureUpperThreshold = 373.15f;
|
|
|
|
|
|
2021-12-05 21:02:04 +01:00
|
|
|
private bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
2021-09-06 15:49:44 +02:00
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
private bool HasContents => _storage.ContainedEntities.Count > 0;
|
2021-09-06 15:49:44 +02:00
|
|
|
|
2022-03-12 13:26:06 -05:00
|
|
|
public bool UIDirty = true;
|
2021-09-06 15:49:44 +02:00
|
|
|
private bool _lostPower;
|
|
|
|
|
private int _currentCookTimeButtonIndex;
|
|
|
|
|
|
|
|
|
|
public void DirtyUi()
|
|
|
|
|
{
|
2022-03-12 13:26:06 -05:00
|
|
|
UIDirty = true;
|
2021-09-06 15:49:44 +02:00
|
|
|
}
|
2020-05-01 03:37:21 -05:00
|
|
|
|
2020-08-22 22:29:20 +02:00
|
|
|
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
|
|
|
|
2021-06-19 19:41:26 -07:00
|
|
|
protected override void Initialize()
|
2020-04-26 23:14:02 -05:00
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2020-08-22 22:29:20 +02:00
|
|
|
|
2021-03-31 12:41:23 -07:00
|
|
|
_currentCookTimerTime = _cookTimeDefault;
|
|
|
|
|
|
2021-09-06 15:49:44 +02:00
|
|
|
_storage = ContainerHelpers.EnsureContainer<Container>(Owner, "microwave_entity_container",
|
|
|
|
|
out _);
|
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
|
|
|
{
|
2021-09-06 15:49:44 +02:00
|
|
|
case MicrowaveStartCookMessage:
|
2021-03-31 12:41:23 -07:00
|
|
|
Wzhzhzh();
|
2020-05-01 23:34:04 -05:00
|
|
|
break;
|
2021-09-06 15:49:44 +02:00
|
|
|
case MicrowaveEjectMessage:
|
|
|
|
|
if (HasContents)
|
2020-05-03 23:58:29 -05:00
|
|
|
{
|
|
|
|
|
EjectSolids();
|
2020-05-04 13:54:54 -04:00
|
|
|
ClickSound();
|
2022-03-12 13:26:06 -05:00
|
|
|
UIDirty = true;
|
2020-05-03 23:58:29 -05:00
|
|
|
}
|
2021-09-06 15:49:44 +02:00
|
|
|
|
2020-05-01 23:34:04 -05:00
|
|
|
break;
|
2020-05-03 01:34:00 -05:00
|
|
|
case MicrowaveEjectSolidIndexedMessage msg:
|
2021-09-06 15:49:44 +02: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();
|
2022-03-12 13:26:06 -05:00
|
|
|
UIDirty = true;
|
2020-05-03 23:58:29 -05:00
|
|
|
}
|
|
|
|
|
break;
|
2021-09-06 15:49:44 +02:00
|
|
|
|
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();
|
2022-03-12 13:26:06 -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-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;
|
|
|
|
|
EjectSolids();
|
|
|
|
|
_busy = false;
|
2022-03-12 13:26:06 -05:00
|
|
|
UIDirty = true;
|
2020-05-28 15:28:35 -05:00
|
|
|
}
|
|
|
|
|
|
2021-06-19 19:34:01 +00:00
|
|
|
if (_busy && _broken)
|
|
|
|
|
{
|
|
|
|
|
SetAppearance(MicrowaveVisualState.Broken);
|
|
|
|
|
//we broke while we were cooking/busy!
|
|
|
|
|
_lostPower = true;
|
|
|
|
|
EjectSolids();
|
|
|
|
|
_busy = false;
|
2022-03-12 13:26:06 -05:00
|
|
|
UIDirty = true;
|
2021-06-19 19:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-12 13:26:06 -05:00
|
|
|
if (UIDirty)
|
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
|
|
|
(
|
2021-12-05 18:09:01 +01:00
|
|
|
_storage.ContainedEntities.Select(item => item).ToArray(),
|
2020-05-28 15:28:35 -05:00
|
|
|
_busy,
|
|
|
|
|
_currentCookTimeButtonIndex,
|
|
|
|
|
_currentCookTimerTime
|
|
|
|
|
));
|
2022-03-12 13:26:06 -05:00
|
|
|
UIDirty = false;
|
2020-05-28 15:28:35 -05:00
|
|
|
}
|
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
|
|
|
{
|
2021-06-19 19:34:01 +00:00
|
|
|
var finalState = state;
|
|
|
|
|
if (_broken)
|
|
|
|
|
{
|
|
|
|
|
finalState = MicrowaveVisualState.Broken;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 21:02:04 +01:00
|
|
|
if (_entities.TryGetComponent(Owner, out AppearanceComponent? appearance))
|
2020-05-03 01:34:00 -05:00
|
|
|
{
|
2021-06-19 19:34:01 +00:00
|
|
|
appearance.SetData(PowerDeviceVisuals.VisualState, finalState);
|
2020-05-03 01:34:00 -05:00
|
|
|
}
|
|
|
|
|
}
|
2020-05-01 23:34:04 -05:00
|
|
|
|
2021-06-19 19:34:01 +00:00
|
|
|
public void OnBreak(BreakageEventArgs eventArgs)
|
|
|
|
|
{
|
|
|
|
|
_broken = true;
|
|
|
|
|
SetAppearance(MicrowaveVisualState.Broken);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("microwave-component-interact-using-no-power"));
|
2020-05-28 15:28:35 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-19 19:34:01 +00:00
|
|
|
if (_broken)
|
|
|
|
|
{
|
2021-07-10 10:14:06 +02:00
|
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("microwave-component-interact-using-broken"));
|
2021-06-19 19:34:01 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-17 20:13:31 +13:00
|
|
|
if (_entities.GetComponent<HandsComponent>(eventArgs.User).ActiveHandEntity is not {Valid: true} itemEntity)
|
2020-07-25 15:11:16 +02:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
eventArgs.User.PopupMessage(Loc.GetString("microwave-component-interact-using-no-active-hand"));
|
2020-07-25 15:11:16 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
if (!_entities.TryGetComponent(itemEntity, typeof(SharedItemComponent), out var food))
|
2020-05-29 15:50:23 -05:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
Owner.PopupMessage(eventArgs.User, "microwave-component-interact-using-transfer-fail");
|
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);
|
2022-03-12 13:26:06 -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
|
2021-03-31 12:41:23 -07:00
|
|
|
private void Wzhzhzh()
|
2020-05-01 17:19:04 -05:00
|
|
|
{
|
2021-09-06 15:49:44 +02: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>();
|
2022-02-12 17:53:54 -07:00
|
|
|
var reagentDict = new Dictionary<string, FixedPoint2>();
|
2021-07-31 19:52:33 +02:00
|
|
|
foreach (var item in _storage.ContainedEntities)
|
2020-05-03 01:34:00 -05:00
|
|
|
{
|
2022-02-12 17:53:54 -07:00
|
|
|
// special behavior when being microwaved ;)
|
|
|
|
|
var ev = new BeingMicrowavedEvent(Owner);
|
|
|
|
|
_entities.EventBus.RaiseLocalEvent(item, ev, false);
|
|
|
|
|
|
|
|
|
|
if (ev.Handled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var tagSys = EntitySystem.Get<TagSystem>();
|
|
|
|
|
|
|
|
|
|
if (tagSys.HasTag(item, "MicrowaveMachineUnsafe")
|
|
|
|
|
|| tagSys.HasTag(item, "Metal"))
|
|
|
|
|
{
|
|
|
|
|
// destroy microwave
|
|
|
|
|
_broken = true;
|
|
|
|
|
SetAppearance(MicrowaveVisualState.Broken);
|
|
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), ItemBreakSound.GetSound(), Owner);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tagSys.HasTag(item, "MicrowaveSelfUnsafe")
|
|
|
|
|
|| tagSys.HasTag(item, "Plastic"))
|
|
|
|
|
{
|
|
|
|
|
_entities.SpawnEntity(_badRecipeName,
|
|
|
|
|
_entities.GetComponent<TransformComponent>(Owner).Coordinates);
|
|
|
|
|
_entities.QueueDeleteEntity(item);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 21:02:04 +01:00
|
|
|
var metaData = _entities.GetComponent<MetaDataComponent>(item);
|
|
|
|
|
if (metaData.EntityPrototype == null)
|
2020-08-22 22:29:20 +02:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 21:02:04 +01:00
|
|
|
if (solidsDict.ContainsKey(metaData.EntityPrototype.ID))
|
2020-05-03 01:34:00 -05:00
|
|
|
{
|
2021-12-05 21:02:04 +01:00
|
|
|
solidsDict[metaData.EntityPrototype.ID]++;
|
2020-05-03 01:34:00 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-05 21:02:04 +01:00
|
|
|
solidsDict.Add(metaData.EntityPrototype.ID, 1);
|
2020-05-03 01:34:00 -05:00
|
|
|
}
|
|
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
if (!_entities.TryGetComponent<SolutionContainerManagerComponent>(item, out var solMan))
|
2020-06-05 11:46:34 -05:00
|
|
|
continue;
|
|
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
foreach (var (_, solution) in solMan.Solutions)
|
|
|
|
|
{
|
|
|
|
|
foreach (var reagent in solution.Contents)
|
|
|
|
|
{
|
|
|
|
|
if (reagentDict.ContainsKey(reagent.ReagentId))
|
|
|
|
|
reagentDict[reagent.ReagentId] += reagent.Quantity;
|
|
|
|
|
else
|
|
|
|
|
reagentDict.Add(reagent.ReagentId, reagent.Quantity);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-05 11:46:34 -05:00
|
|
|
}
|
|
|
|
|
|
2020-05-03 01:34:00 -05:00
|
|
|
// Check recipes
|
2020-08-22 22:29:20 +02:00
|
|
|
FoodRecipePrototype? recipeToCook = null;
|
2021-09-06 15:49:44 +02:00
|
|
|
foreach (var r in _recipeManager.Recipes.Where(r =>
|
2022-02-12 17:53:54 -07:00
|
|
|
CanSatisfyRecipe(r, solidsDict, reagentDict)))
|
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
|
|
|
|
|
|
|
|
SetAppearance(MicrowaveVisualState.Cooking);
|
2022-02-12 17:53:54 -07:00
|
|
|
var time = _currentCookTimerTime * _cookTimeMultiplier;
|
2021-07-31 19:52:33 +02:00
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), _startCookingSound.GetSound(), Owner, AudioParams.Default);
|
2021-09-06 15:49:44 +02:00
|
|
|
Owner.SpawnTimer((int) (_currentCookTimerTime * _cookTimeMultiplier), () =>
|
2021-08-10 15:39:24 -07:00
|
|
|
{
|
|
|
|
|
if (_lostPower)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
AddTemperature(time);
|
|
|
|
|
|
|
|
|
|
if (recipeToCook != null)
|
2021-08-10 15:39:24 -07:00
|
|
|
{
|
2022-02-12 17:53:54 -07:00
|
|
|
SubtractContents(recipeToCook);
|
|
|
|
|
_entities.SpawnEntity(recipeToCook.Result,
|
|
|
|
|
_entities.GetComponent<TransformComponent>(Owner).Coordinates);
|
2021-08-10 15:39:24 -07:00
|
|
|
}
|
|
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
EjectSolids();
|
|
|
|
|
|
2021-08-10 15:39:24 -07:00
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), _cookingCompleteSound.GetSound(), Owner,
|
|
|
|
|
AudioParams.Default.WithVolume(-1f));
|
|
|
|
|
|
|
|
|
|
SetAppearance(MicrowaveVisualState.Idle);
|
|
|
|
|
_busy = false;
|
|
|
|
|
|
2022-03-12 13:26:06 -05:00
|
|
|
UIDirty = true;
|
2021-09-06 15:49:44 +02:00
|
|
|
});
|
2020-05-28 15:28:35 -05:00
|
|
|
_lostPower = false;
|
2022-03-12 13:26:06 -05:00
|
|
|
UIDirty = true;
|
2020-04-26 23:14:02 -05:00
|
|
|
}
|
2020-05-01 23:34:04 -05:00
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Adds temperature to every item in the microwave,
|
|
|
|
|
/// based on the time it took to microwave.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="time">The time on the microwave, in seconds.</param>
|
|
|
|
|
public void AddTemperature(float time)
|
2020-05-01 23:34:04 -05:00
|
|
|
{
|
2022-02-12 17:53:54 -07:00
|
|
|
var solutionContainerSystem = EntitySystem.Get<SolutionContainerSystem>();
|
|
|
|
|
foreach (var entity in _storage.ContainedEntities)
|
2020-08-22 22:29:20 +02:00
|
|
|
{
|
2022-02-12 17:53:54 -07:00
|
|
|
if (_entities.TryGetComponent(entity, out TemperatureComponent? temp))
|
|
|
|
|
{
|
|
|
|
|
EntitySystem.Get<TemperatureSystem>().ChangeHeat(entity, time / 10, false, temp);
|
|
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
if (_entities.TryGetComponent(entity, out SolutionContainerManagerComponent? solutions))
|
|
|
|
|
{
|
|
|
|
|
foreach (var (_, solution) in solutions.Solutions)
|
|
|
|
|
{
|
|
|
|
|
if (solution.Temperature > TemperatureUpperThreshold)
|
|
|
|
|
continue;
|
2020-05-03 01:34:00 -05:00
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
solutionContainerSystem.AddThermalEnergy(entity, solution, time / 10);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
}
|
2020-05-01 23:34:04 -05:00
|
|
|
}
|
2020-05-02 01:29:20 -05:00
|
|
|
|
|
|
|
|
private void EjectSolids()
|
|
|
|
|
{
|
2021-07-31 19:52:33 +02: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
|
|
|
|
2021-09-06 15:49:44 +02:00
|
|
|
private void EjectSolid(EntityUid entityId)
|
2020-05-03 01:34:00 -05:00
|
|
|
{
|
2021-12-05 21:02:04 +01:00
|
|
|
if (_entities.EntityExists(entityId))
|
2020-05-04 18:35:36 -05:00
|
|
|
{
|
2021-12-05 21:02:04 +01:00
|
|
|
_storage.Remove(entityId);
|
2020-05-04 18:35:36 -05:00
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SubtractContents(FoodRecipePrototype recipe)
|
|
|
|
|
{
|
2022-02-12 17:53:54 -07:00
|
|
|
var totalReagentsToRemove = new Dictionary<string, FixedPoint2>(recipe.IngredientsReagents);
|
|
|
|
|
var solutionContainerSystem = EntitySystem.Get<SolutionContainerSystem>();
|
2020-08-22 22:29:20 +02:00
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
// this is spaghetti ngl
|
|
|
|
|
foreach (var item in _storage.ContainedEntities)
|
2020-05-03 01:34:00 -05:00
|
|
|
{
|
2022-02-12 17:53:54 -07:00
|
|
|
if (!_entities.TryGetComponent<SolutionContainerManagerComponent>(item, out var solMan))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// go over every solution
|
|
|
|
|
foreach (var (_, solution) in solMan.Solutions)
|
|
|
|
|
{
|
|
|
|
|
foreach (var (reagent, _) in recipe.IngredientsReagents)
|
|
|
|
|
{
|
|
|
|
|
// removed everything
|
|
|
|
|
if (!totalReagentsToRemove.ContainsKey(reagent))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!solution.ContainsReagent(reagent))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var quant = solution.GetReagentQuantity(reagent);
|
|
|
|
|
|
|
|
|
|
if (quant >= totalReagentsToRemove[reagent])
|
|
|
|
|
{
|
|
|
|
|
quant = totalReagentsToRemove[reagent];
|
|
|
|
|
totalReagentsToRemove.Remove(reagent);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
totalReagentsToRemove[reagent] -= quant;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
solutionContainerSystem.TryRemoveReagent(item, solution, reagent, quant);
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
{
|
2021-12-05 21:02:04 +01:00
|
|
|
var metaData = _entities.GetComponent<MetaDataComponent>(item);
|
|
|
|
|
if (metaData.EntityPrototype == null)
|
2020-08-22 22:29:20 +02:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 21:02:04 +01:00
|
|
|
if (metaData.EntityPrototype.ID == recipeSolid.Key)
|
2020-05-03 23:58:29 -05:00
|
|
|
{
|
|
|
|
|
_storage.Remove(item);
|
2021-12-05 21:02:04 +01:00
|
|
|
_entities.DeleteEntity(item);
|
2020-05-03 23:58:29 -05:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
}
|
2020-05-02 01:29:20 -05:00
|
|
|
}
|
2020-05-03 01:34:00 -05:00
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
private bool CanSatisfyRecipe(FoodRecipePrototype recipe, Dictionary<string, int> solids, Dictionary<string, FixedPoint2> reagents)
|
2020-04-26 23:14:02 -05:00
|
|
|
{
|
2021-12-05 18:09:01 +01:00
|
|
|
if (_currentCookTimerTime != recipe.CookTime)
|
2021-02-25 06:03:20 +01:00
|
|
|
{
|
2022-02-12 17:53:54 -07:00
|
|
|
return false;
|
2020-08-22 22:29:20 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
foreach (var solid in recipe.IngredientsSolids)
|
2020-05-02 01:29:20 -05:00
|
|
|
{
|
2022-02-12 17:53:54 -07:00
|
|
|
if (!solids.ContainsKey(solid.Key))
|
|
|
|
|
return false;
|
2020-05-02 01:29:20 -05:00
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
if (solids[solid.Key] < solid.Value)
|
|
|
|
|
return false;
|
2020-05-02 01:29:20 -05:00
|
|
|
}
|
|
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
foreach (var reagent in recipe.IngredientsReagents)
|
2020-04-26 23:14:02 -05:00
|
|
|
{
|
2022-02-12 17:53:54 -07:00
|
|
|
if (!reagents.ContainsKey(reagent.Key))
|
|
|
|
|
return false;
|
2020-04-26 23:14:02 -05:00
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
if (reagents[reagent.Key] < reagent.Value)
|
|
|
|
|
return false;
|
2020-04-26 23:14:02 -05:00
|
|
|
}
|
2020-04-26 15:44:20 -05:00
|
|
|
|
2022-02-12 17:53:54 -07:00
|
|
|
return true;
|
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()
|
|
|
|
|
{
|
2021-07-31 19:52:33 +02:00
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), _clickSound.GetSound(), Owner, AudioParams.Default.WithVolume(-2f));
|
2020-05-04 13:54:54 -04:00
|
|
|
}
|
2020-04-26 23:14:02 -05:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
SuicideKind ISuicideAct.Suicide(EntityUid 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
|
|
|
|
2021-12-05 21:02:04 +01:00
|
|
|
if (_entities.TryGetComponent<SharedBodyComponent?>(victim, out var body))
|
2020-05-27 20:05:12 -03:00
|
|
|
{
|
2021-04-05 14:54:51 +02:00
|
|
|
var headSlots = body.GetSlotsOfType(BodyPartType.Head);
|
|
|
|
|
|
|
|
|
|
foreach (var slot in headSlots)
|
2020-05-27 20:05:12 -03:00
|
|
|
{
|
2021-04-05 14:54:51 +02:00
|
|
|
var part = slot.Part;
|
|
|
|
|
|
|
|
|
|
if (part == null ||
|
|
|
|
|
!body.TryDropPart(slot, 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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-05 14:54:51 +02:00
|
|
|
foreach (var droppedPart in dropped.Values)
|
2020-10-10 15:25:13 +02:00
|
|
|
{
|
2021-04-05 14:54:51 +02:00
|
|
|
if (droppedPart.PartType != BodyPartType.Head)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_storage.Insert(droppedPart.Owner);
|
2020-10-10 15:25:13 +02:00
|
|
|
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
|
2021-06-21 02:13:54 +02:00
|
|
|
? Loc.GetString("microwave-component-suicide-multi-head-others-message", ("victim", victim))
|
2021-07-31 19:52:33 +02:00
|
|
|
: Loc.GetString("microwave-component-suicide-others-message", ("victim", victim));
|
2020-10-10 15:25:13 +02:00
|
|
|
|
2020-08-30 11:28:46 +02:00
|
|
|
victim.PopupMessageOtherClients(othersMessage);
|
|
|
|
|
|
2020-10-10 15:25:13 +02:00
|
|
|
var selfMessage = headCount > 1
|
2021-06-21 02:13:54 +02:00
|
|
|
? Loc.GetString("microwave-component-suicide-multi-head-message")
|
|
|
|
|
: Loc.GetString("microwave-component-suicide-message");
|
2020-10-10 15:25:13 +02:00
|
|
|
|
2020-08-30 11:28:46 +02:00
|
|
|
victim.PopupMessage(selfMessage);
|
|
|
|
|
|
2020-05-27 20:05:12 -03:00
|
|
|
_currentCookTimerTime = 10;
|
|
|
|
|
ClickSound();
|
2022-03-12 13:26:06 -05:00
|
|
|
UIDirty = true;
|
2021-03-31 12:41:23 -07:00
|
|
|
Wzhzhzh();
|
2020-05-27 20:05:12 -03:00
|
|
|
return SuicideKind.Heat;
|
|
|
|
|
}
|
2020-04-26 15:44:20 -05:00
|
|
|
}
|
2022-02-12 17:53:54 -07:00
|
|
|
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class BeingMicrowavedEvent : HandledEntityEventArgs
|
2022-02-12 17:53:54 -07:00
|
|
|
{
|
|
|
|
|
public EntityUid Microwave;
|
|
|
|
|
|
|
|
|
|
public BeingMicrowavedEvent(EntityUid microwave)
|
|
|
|
|
{
|
|
|
|
|
Microwave = microwave;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-26 15:44:20 -05:00
|
|
|
}
|