2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.DoAfter;
|
|
|
|
|
using Content.Server.Engineering.Components;
|
|
|
|
|
using Content.Server.Hands.Components;
|
|
|
|
|
using Content.Server.Items;
|
|
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Shared.Interaction.Helpers;
|
2021-04-01 00:04:56 -07:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Engineering.EntitySystems
|
2021-04-01 00:04:56 -07:00
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
public class DisassembleOnActivateSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2021-05-22 21:06:40 -07:00
|
|
|
SubscribeLocalEvent<DisassembleOnActivateComponent, ActivateInWorldEvent>(HandleActivateInWorld);
|
2021-04-01 00:04:56 -07:00
|
|
|
}
|
|
|
|
|
|
2021-05-22 21:06:40 -07:00
|
|
|
private async void HandleActivateInWorld(EntityUid uid, DisassembleOnActivateComponent component, ActivateInWorldEvent args)
|
2021-04-01 00:04:56 -07:00
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(component.Prototype))
|
|
|
|
|
return;
|
2021-05-22 21:06:40 -07:00
|
|
|
if (!args.User.InRangeUnobstructed(args.Target))
|
2021-04-01 00:04:56 -07:00
|
|
|
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,
|
|
|
|
|
};
|
2021-07-04 13:32:24 +02:00
|
|
|
var result = await doAfterSystem.WaitDoAfter(doAfterArgs);
|
2021-04-01 00:04:56 -07:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|