Elimate most IInteractUsing (#7481)
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Act;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Server.Chemistry.Components.SolutionManager;
|
||||
using Content.Server.Chemistry.EntitySystems;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Temperature.Components;
|
||||
@@ -14,8 +12,6 @@ using Content.Shared.Acts;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Part;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Kitchen;
|
||||
using Content.Shared.Kitchen.Components;
|
||||
using Content.Shared.Popups;
|
||||
@@ -30,7 +26,7 @@ using Robust.Shared.Player;
|
||||
namespace Content.Server.Kitchen.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class MicrowaveComponent : SharedMicrowaveComponent, IInteractUsing, ISuicideAct, IBreakAct
|
||||
public sealed class MicrowaveComponent : SharedMicrowaveComponent, ISuicideAct, IBreakAct
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
@@ -56,7 +52,7 @@ namespace Content.Server.Kitchen.Components
|
||||
#endregion YAMLSERIALIZE
|
||||
|
||||
[ViewVariables] private bool _busy = false;
|
||||
private bool _broken;
|
||||
public bool Broken;
|
||||
|
||||
/// <summary>
|
||||
/// This is a fixed offset of 5.
|
||||
@@ -71,9 +67,9 @@ namespace Content.Server.Kitchen.Components
|
||||
[DataField("temperatureUpperThreshold")]
|
||||
public float TemperatureUpperThreshold = 373.15f;
|
||||
|
||||
private bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
||||
public bool Powered => !_entities.TryGetComponent(Owner, out ApcPowerReceiverComponent? receiver) || receiver.Powered;
|
||||
|
||||
private bool HasContents => _storage.ContainedEntities.Count > 0;
|
||||
private bool HasContents => Storage.ContainedEntities.Count > 0;
|
||||
|
||||
public bool UIDirty = true;
|
||||
private bool _lostPower;
|
||||
@@ -84,7 +80,7 @@ namespace Content.Server.Kitchen.Components
|
||||
UIDirty = true;
|
||||
}
|
||||
|
||||
private Container _storage = default!;
|
||||
public Container Storage = default!;
|
||||
|
||||
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(MicrowaveUiKey.Key);
|
||||
|
||||
@@ -94,7 +90,7 @@ namespace Content.Server.Kitchen.Components
|
||||
|
||||
_currentCookTimerTime = _cookTimeDefault;
|
||||
|
||||
_storage = ContainerHelpers.EnsureContainer<Container>(Owner, "microwave_entity_container",
|
||||
Storage = ContainerHelpers.EnsureContainer<Container>(Owner, "microwave_entity_container",
|
||||
out _);
|
||||
|
||||
if (UserInterface != null)
|
||||
@@ -159,7 +155,7 @@ namespace Content.Server.Kitchen.Components
|
||||
UIDirty = true;
|
||||
}
|
||||
|
||||
if (_busy && _broken)
|
||||
if (_busy && Broken)
|
||||
{
|
||||
SetAppearance(MicrowaveVisualState.Broken);
|
||||
//we broke while we were cooking/busy!
|
||||
@@ -173,7 +169,7 @@ namespace Content.Server.Kitchen.Components
|
||||
{
|
||||
UserInterface?.SetState(new MicrowaveUpdateUserInterfaceState
|
||||
(
|
||||
_storage.ContainedEntities.Select(item => item).ToArray(),
|
||||
Storage.ContainedEntities.Select(item => item).ToArray(),
|
||||
_busy,
|
||||
_currentCookTimeButtonIndex,
|
||||
_currentCookTimerTime
|
||||
@@ -185,7 +181,7 @@ namespace Content.Server.Kitchen.Components
|
||||
private void SetAppearance(MicrowaveVisualState state)
|
||||
{
|
||||
var finalState = state;
|
||||
if (_broken)
|
||||
if (Broken)
|
||||
{
|
||||
finalState = MicrowaveVisualState.Broken;
|
||||
}
|
||||
@@ -198,42 +194,9 @@ namespace Content.Server.Kitchen.Components
|
||||
|
||||
public void OnBreak(BreakageEventArgs eventArgs)
|
||||
{
|
||||
_broken = true;
|
||||
Broken = true;
|
||||
SetAppearance(MicrowaveVisualState.Broken);
|
||||
}
|
||||
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (!Powered)
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("microwave-component-interact-using-no-power"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_broken)
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, Loc.GetString("microwave-component-interact-using-broken"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_entities.GetComponent<HandsComponent>(eventArgs.User).ActiveHandEntity is not {Valid: true} itemEntity)
|
||||
{
|
||||
eventArgs.User.PopupMessage(Loc.GetString("microwave-component-interact-using-no-active-hand"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_entities.TryGetComponent(itemEntity, typeof(SharedItemComponent), out var food))
|
||||
{
|
||||
Owner.PopupMessage(eventArgs.User, "microwave-component-interact-using-transfer-fail");
|
||||
return false;
|
||||
}
|
||||
|
||||
var ent = food.Owner; //Get the entity of the ItemComponent.
|
||||
_storage.Insert(ent);
|
||||
UIDirty = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
// ReSharper disable once IdentifierTypo
|
||||
private void Wzhzhzh()
|
||||
@@ -247,7 +210,7 @@ namespace Content.Server.Kitchen.Components
|
||||
// Convert storage into Dictionary of ingredients
|
||||
var solidsDict = new Dictionary<string, int>();
|
||||
var reagentDict = new Dictionary<string, FixedPoint2>();
|
||||
foreach (var item in _storage.ContainedEntities)
|
||||
foreach (var item in Storage.ContainedEntities)
|
||||
{
|
||||
// special behavior when being microwaved ;)
|
||||
var ev = new BeingMicrowavedEvent(Owner);
|
||||
@@ -262,7 +225,7 @@ namespace Content.Server.Kitchen.Components
|
||||
|| tagSys.HasTag(item, "Metal"))
|
||||
{
|
||||
// destroy microwave
|
||||
_broken = true;
|
||||
Broken = true;
|
||||
SetAppearance(MicrowaveVisualState.Broken);
|
||||
SoundSystem.Play(Filter.Pvs(Owner), ItemBreakSound.GetSound(), Owner);
|
||||
return;
|
||||
@@ -355,7 +318,7 @@ namespace Content.Server.Kitchen.Components
|
||||
public void AddTemperature(float time)
|
||||
{
|
||||
var solutionContainerSystem = EntitySystem.Get<SolutionContainerSystem>();
|
||||
foreach (var entity in _storage.ContainedEntities)
|
||||
foreach (var entity in Storage.ContainedEntities)
|
||||
{
|
||||
if (_entities.TryGetComponent(entity, out TemperatureComponent? temp))
|
||||
{
|
||||
@@ -377,9 +340,9 @@ namespace Content.Server.Kitchen.Components
|
||||
|
||||
private void EjectSolids()
|
||||
{
|
||||
for (var i = _storage.ContainedEntities.Count - 1; i >= 0; i--)
|
||||
for (var i = Storage.ContainedEntities.Count - 1; i >= 0; i--)
|
||||
{
|
||||
_storage.Remove(_storage.ContainedEntities.ElementAt(i));
|
||||
Storage.Remove(Storage.ContainedEntities.ElementAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,7 +350,7 @@ namespace Content.Server.Kitchen.Components
|
||||
{
|
||||
if (_entities.EntityExists(entityId))
|
||||
{
|
||||
_storage.Remove(entityId);
|
||||
Storage.Remove(entityId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,7 +360,7 @@ namespace Content.Server.Kitchen.Components
|
||||
var solutionContainerSystem = EntitySystem.Get<SolutionContainerSystem>();
|
||||
|
||||
// this is spaghetti ngl
|
||||
foreach (var item in _storage.ContainedEntities)
|
||||
foreach (var item in Storage.ContainedEntities)
|
||||
{
|
||||
if (!_entities.TryGetComponent<SolutionContainerManagerComponent>(item, out var solMan))
|
||||
continue;
|
||||
@@ -435,7 +398,7 @@ namespace Content.Server.Kitchen.Components
|
||||
{
|
||||
for (var i = 0; i < recipeSolid.Value; i++)
|
||||
{
|
||||
foreach (var item in _storage.ContainedEntities)
|
||||
foreach (var item in Storage.ContainedEntities)
|
||||
{
|
||||
var metaData = _entities.GetComponent<MetaDataComponent>(item);
|
||||
if (metaData.EntityPrototype == null)
|
||||
@@ -445,7 +408,7 @@ namespace Content.Server.Kitchen.Components
|
||||
|
||||
if (metaData.EntityPrototype.ID == recipeSolid.Key)
|
||||
{
|
||||
_storage.Remove(item);
|
||||
Storage.Remove(item);
|
||||
_entities.DeleteEntity(item);
|
||||
break;
|
||||
}
|
||||
@@ -512,7 +475,7 @@ namespace Content.Server.Kitchen.Components
|
||||
continue;
|
||||
}
|
||||
|
||||
_storage.Insert(droppedPart.Owner);
|
||||
Storage.Insert(droppedPart.Owner);
|
||||
headCount++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user