Fix gas tank and other hand-interaction bugs (#9700)
This commit is contained in:
@@ -45,7 +45,7 @@ namespace Content.IntegrationTests.Tests.Disposal
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
Assert.That(system.CanInsert(unit, entity), Is.EqualTo(result));
|
||||
system.TryInsert(unit.Owner, entity, entity);
|
||||
system.TryInsert(unit.Owner, entity, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,17 @@ namespace Content.Server.Atmos.Components
|
||||
/// <summary>
|
||||
/// Tank is connected to internals.
|
||||
/// </summary>
|
||||
[ViewVariables] public bool IsConnected { get; set; }
|
||||
[ViewVariables] public bool IsConnected => User != null;
|
||||
|
||||
[ViewVariables]
|
||||
public EntityUid? User;
|
||||
|
||||
/// <summary>
|
||||
/// True if this entity was recently moved out of a container. This might have been a hand -> inventory
|
||||
/// transfer, or it might have been the user dropping the tank. This indicates the tank needs to be checked.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public bool CheckUser;
|
||||
|
||||
/// <summary>
|
||||
/// Pressure at which tanks start leaking.
|
||||
|
||||
@@ -41,8 +41,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
SubscribeLocalEvent<GasTankComponent, GetItemActionsEvent>(OnGetActions);
|
||||
SubscribeLocalEvent<GasTankComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<GasTankComponent, ToggleActionEvent>(OnActionToggle);
|
||||
SubscribeLocalEvent<GasTankComponent, DroppedEvent>(OnDropped);
|
||||
|
||||
SubscribeLocalEvent<GasTankComponent, EntParentChangedMessage>(OnParentChange);
|
||||
SubscribeLocalEvent<GasTankComponent, GasTankSetPressureMessage>(OnGasTankSetPressure);
|
||||
SubscribeLocalEvent<GasTankComponent, GasTankToggleInternalsMessage>(OnGasTankToggleInternals);
|
||||
}
|
||||
@@ -84,9 +83,12 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
UpdateUserInterface(component, true);
|
||||
}
|
||||
|
||||
private void OnDropped(EntityUid uid, GasTankComponent component, DroppedEvent args)
|
||||
private void OnParentChange(EntityUid uid, GasTankComponent component, ref EntParentChangedMessage args)
|
||||
{
|
||||
DisconnectFromInternals(component, args.User);
|
||||
// When an item is moved from hands -> pockets, the container removal briefly dumps the item on the floor.
|
||||
// So this is a shitty fix, where the parent check is just delayed. But this really needs to get fixed
|
||||
// properly at some point.
|
||||
component.CheckUser = true;
|
||||
}
|
||||
|
||||
private void OnGetActions(EntityUid uid, GasTankComponent component, GetItemActionsEvent args)
|
||||
@@ -122,6 +124,16 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
|
||||
foreach (var gasTank in EntityManager.EntityQuery<GasTankComponent>())
|
||||
{
|
||||
if (gasTank.CheckUser)
|
||||
{
|
||||
gasTank.CheckUser = false;
|
||||
if (Transform(gasTank.Owner).ParentUid != gasTank.User)
|
||||
{
|
||||
DisconnectFromInternals(gasTank);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
_atmosphereSystem.React(gasTank.Air, gasTank);
|
||||
CheckStatus(gasTank);
|
||||
if (_ui.IsUiOpen(gasTank.Owner, SharedGasTankUiKey.Key))
|
||||
@@ -184,7 +196,10 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
if (!CanConnectToInternals(component)) return;
|
||||
var internals = GetInternalsComponent(component);
|
||||
if (internals == null) return;
|
||||
component.IsConnected = _internals.TryConnectTank(internals, component.Owner);
|
||||
|
||||
if (_internals.TryConnectTank(internals, component.Owner))
|
||||
component.User = internals.Owner;
|
||||
|
||||
_actions.SetToggled(component.ToggleAction, component.IsConnected);
|
||||
|
||||
// Couldn't toggle!
|
||||
@@ -201,7 +216,7 @@ namespace Content.Server.Atmos.EntitySystems
|
||||
public void DisconnectFromInternals(GasTankComponent component, EntityUid? owner = null)
|
||||
{
|
||||
if (!component.IsConnected) return;
|
||||
component.IsConnected = false;
|
||||
component.User = null;
|
||||
_actions.SetToggled(component.ToggleAction, false);
|
||||
|
||||
_internals.DisconnectTank(GetInternalsComponent(component, owner));
|
||||
|
||||
@@ -181,10 +181,10 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
return;
|
||||
}
|
||||
|
||||
if (!unit.Container.Insert(toInsert))
|
||||
{
|
||||
if (ev.User != null && !_handsSystem.TryDropIntoContainer(ev.User.Value, ev.ToInsert, unit.Container))
|
||||
return;
|
||||
}
|
||||
else
|
||||
unit.Container.Insert(toInsert);
|
||||
|
||||
AfterInsert(unit, toInsert);
|
||||
}
|
||||
@@ -466,7 +466,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
return state == SharedDisposalUnitComponent.PressureState.Ready && component.RecentlyEjected.Count == 0;
|
||||
}
|
||||
|
||||
public bool TryInsert(EntityUid unitId, EntityUid toInsertId, EntityUid userId, DisposalUnitComponent? unit = null)
|
||||
public bool TryInsert(EntityUid unitId, EntityUid toInsertId, EntityUid? userId, DisposalUnitComponent? unit = null)
|
||||
{
|
||||
if (!Resolve(unitId, ref unit))
|
||||
return false;
|
||||
@@ -477,7 +477,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
var delay = userId == toInsertId ? unit.EntryDelay : unit.DraggedEntryDelay;
|
||||
var ev = new DoInsertDisposalUnitEvent(userId, toInsertId, unitId);
|
||||
|
||||
if (delay <= 0)
|
||||
if (delay <= 0 || userId == null)
|
||||
{
|
||||
DoInsertDisposalUnit(ev);
|
||||
return true;
|
||||
@@ -485,7 +485,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
|
||||
// Can't check if our target AND disposals moves currently so we'll just check target.
|
||||
// if you really want to check if disposals moves then add a predicate.
|
||||
var doAfterArgs = new DoAfterEventArgs(userId, delay, default, toInsertId)
|
||||
var doAfterArgs = new DoAfterEventArgs(userId.Value, delay, default, toInsertId)
|
||||
{
|
||||
BreakOnDamage = true,
|
||||
BreakOnStun = true,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
{
|
||||
public record DoInsertDisposalUnitEvent(EntityUid User, EntityUid ToInsert, EntityUid Unit);
|
||||
public record DoInsertDisposalUnitEvent(EntityUid? User, EntityUid ToInsert, EntityUid Unit);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Part;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Server.Hands.Systems;
|
||||
|
||||
namespace Content.Server.Kitchen.EntitySystems
|
||||
{
|
||||
@@ -19,6 +20,8 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
internal sealed class MicrowaveSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly HandsSystem _handsSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -114,8 +117,7 @@ namespace Content.Server.Kitchen.EntitySystems
|
||||
}
|
||||
|
||||
args.Handled = true;
|
||||
|
||||
component.Storage.Insert(args.Used);
|
||||
_handsSystem.TryDropIntoContainer(args.User, args.Used, component.Storage);
|
||||
component.DirtyUi();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user