2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.DoAfter;
|
|
|
|
|
using Content.Server.Engineering.Components;
|
|
|
|
|
using Content.Server.Hands.Components;
|
|
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Shared.Interaction.Helpers;
|
2021-12-30 22:56:10 +01:00
|
|
|
using Content.Shared.Item;
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-09 12:29:27 +01:00
|
|
|
if (component.Deleted || Deleted(component.Owner))
|
2021-04-01 00:04:56 -07:00
|
|
|
return;
|
|
|
|
|
|
2021-12-08 13:00:43 +01:00
|
|
|
var entity = EntityManager.SpawnEntity(component.Prototype, EntityManager.GetComponent<TransformComponent>(component.Owner).Coordinates);
|
2021-04-01 00:04:56 -07:00
|
|
|
|
2021-12-08 13:00:43 +01:00
|
|
|
if (EntityManager.TryGetComponent<HandsComponent?>(args.User, out var hands)
|
2021-12-30 22:56:10 +01:00
|
|
|
&& EntityManager.TryGetComponent<SharedItemComponent?>(entity, out var item))
|
2021-04-01 00:04:56 -07:00
|
|
|
{
|
|
|
|
|
hands.PutInHandOrDrop(item);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 13:00:43 +01:00
|
|
|
EntityManager.DeleteEntity(component.Owner);
|
2021-04-01 00:04:56 -07:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|