Disposal drop their contents if they're destroyed or unanchored. Fixes #4114 (#4269)

* Fixes #4114

Disposals now drop their contents if destroyed or if unwrenched

* Update DisposalUnitSystem.cs

* Update DisposalUnitSystem.cs
This commit is contained in:
Fiftyllama
2021-07-16 05:22:29 +02:00
committed by GitHub
parent fc9a15b288
commit eb7d65ad5b
2 changed files with 19 additions and 8 deletions

View File

@@ -14,6 +14,7 @@ using Content.Server.Interfaces;
using Content.Server.Power.Components; using Content.Server.Power.Components;
using Content.Server.UserInterface; using Content.Server.UserInterface;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
using Content.Shared.Acts;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.Disposal.Components; using Content.Shared.Disposal.Components;
using Content.Shared.DragDrop; using Content.Shared.DragDrop;
@@ -42,7 +43,7 @@ namespace Content.Server.Disposal.Unit.Components
[ComponentReference(typeof(SharedDisposalUnitComponent))] [ComponentReference(typeof(SharedDisposalUnitComponent))]
[ComponentReference(typeof(IActivate))] [ComponentReference(typeof(IActivate))]
[ComponentReference(typeof(IInteractUsing))] [ComponentReference(typeof(IInteractUsing))]
public class DisposalUnitComponent : SharedDisposalUnitComponent, IInteractHand, IActivate, IInteractUsing, IThrowCollide, IGasMixtureHolder public class DisposalUnitComponent : SharedDisposalUnitComponent, IInteractHand, IActivate, IInteractUsing, IThrowCollide, IGasMixtureHolder, IDestroyAct
{ {
[Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IMapManager _mapManager = default!;
@@ -304,7 +305,7 @@ namespace Content.Server.Disposal.Unit.Components
return true; return true;
} }
private void TryEjectContents() public void TryEjectContents()
{ {
foreach (var entity in _container.ContainedEntities.ToArray()) foreach (var entity in _container.ContainedEntities.ToArray())
{ {
@@ -690,5 +691,10 @@ namespace Content.Server.Disposal.Unit.Components
component.TryFlush(); component.TryFlush();
} }
} }
void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs)
{
TryEjectContents();
}
} }
} }

View File

@@ -1,4 +1,5 @@
using Content.Server.Disposal.Unit.Components; using Content.Server.Disposal.Unit.Components;
using Content.Server.Construction.Components;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
namespace Content.Server.Disposal.Unit.EntitySystems namespace Content.Server.Disposal.Unit.EntitySystems
@@ -9,15 +10,19 @@ namespace Content.Server.Disposal.Unit.EntitySystems
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<DisposalUnitComponent, PhysicsBodyTypeChangedEvent>(BodyTypeChanged); SubscribeLocalEvent<DisposalUnitComponent, AnchoredEvent>(OnAnchored);
SubscribeLocalEvent<DisposalUnitComponent, UnanchoredEvent>(OnUnanchored);
} }
private static void BodyTypeChanged( private static void OnAnchored(EntityUid uid, DisposalUnitComponent component, AnchoredEvent args)
EntityUid uid,
DisposalUnitComponent component,
PhysicsBodyTypeChangedEvent args)
{ {
component.UpdateVisualState(); component.UpdateVisualState();
} }
private static void OnUnanchored(EntityUid uid, DisposalUnitComponent component, UnanchoredEvent args)
{
component.UpdateVisualState();
component.TryEjectContents();
}
} }
} }