Files
tbd-station-14/Content.Server/GameObjects/EntitySystems/DisassembleOnActivateSystem.cs
ShadowCommander a98c0dadd4 Implement inflatable wall (#3703)
* Implement inflatable wall

* Actually block atmos

* Fix naming and add description

* Add requested changes

* Change prototype to field

* Refactor checks to use existing methods

* Fix PrototypeIdSerializer imports

* Fix mass in yaml
2021-04-01 00:04:56 -07:00

69 lines
2.3 KiB
C#

using Content.Server.GameObjects.Components.Engineering;
using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Items.Storage;
using Content.Server.GameObjects.Components.Stack;
using Content.Server.GameObjects.EntitySystems.DoAfter;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Utility;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using System.Threading;
namespace Content.Server.GameObjects.EntitySystems
{
[UsedImplicitly]
public class DisassembleOnActivateSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DisassembleOnActivateComponent, ActivateInWorldMessage>(HandleActivateInWorld);
}
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<DisassembleOnActivateComponent, ActivateInWorldMessage>(HandleActivateInWorld);
}
private async void HandleActivateInWorld(EntityUid uid, DisassembleOnActivateComponent component, ActivateInWorldMessage args)
{
if (string.IsNullOrEmpty(component.Prototype))
return;
if (!args.User.InRangeUnobstructed(args.Activated))
return;
if (component.DoAfterTime > 0 && TryGet<DoAfterSystem>(out var doAfterSystem))
{
var doAfterArgs = new DoAfterEventArgs(args.User, component.DoAfterTime, component.TokenSource.Token)
{
BreakOnUserMove = true,
BreakOnStun = true,
};
var result = await doAfterSystem.DoAfter(doAfterArgs);
if (result != DoAfterStatus.Finished)
return;
component.TokenSource.Cancel();
}
if (component.Deleted || component.Owner.Deleted)
return;
var entity = EntityManager.SpawnEntity(component.Prototype, component.Owner.Transform.Coordinates);
if (args.User.TryGetComponent<HandsComponent>(out var hands)
&& entity.TryGetComponent<ItemComponent>(out var item))
{
hands.PutInHandOrDrop(item);
}
component.Owner.Delete();
return;
}
}
}