2021-02-01 10:19:43 -06:00
|
|
|
#nullable enable
|
2020-12-27 02:11:52 +00:00
|
|
|
using System.Threading.Tasks;
|
2020-12-16 13:31:47 +00:00
|
|
|
using System.Linq;
|
2020-09-13 14:23:52 +02:00
|
|
|
using Content.Server.GameObjects.Components.Interactable;
|
2020-08-29 06:05:44 -05:00
|
|
|
using Content.Server.Interfaces.GameObjects.Components.Items;
|
|
|
|
|
using Content.Shared.GameObjects.Components.Interactable;
|
2020-09-13 14:23:52 +02:00
|
|
|
using Content.Shared.Interfaces;
|
2020-08-29 06:05:44 -05:00
|
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.GameObjects;
|
2020-08-29 06:05:44 -05:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Localization;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.Map;
|
2020-08-29 06:05:44 -05:00
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components.Power.AME
|
|
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
[ComponentReference(typeof(IInteractUsing))]
|
|
|
|
|
public class AMEPartComponent : Component, IInteractUsing
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
|
|
|
|
[Dependency] private readonly IServerEntityManager _serverEntityManager = default!;
|
2020-09-01 12:34:53 +02:00
|
|
|
|
2020-08-29 06:05:44 -05:00
|
|
|
public override string Name => "AMEPart";
|
2020-12-27 02:11:52 +00:00
|
|
|
private string _unwrap = "/Audio/Effects/unwrap.ogg";
|
2020-08-29 06:05:44 -05:00
|
|
|
|
|
|
|
|
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs args)
|
|
|
|
|
{
|
2021-02-01 10:19:43 -06:00
|
|
|
if (!args.User.TryGetComponent<IHandsComponent>(out var hands))
|
2020-08-29 06:05:44 -05:00
|
|
|
{
|
2020-09-01 12:34:53 +02:00
|
|
|
Owner.PopupMessage(args.User, Loc.GetString("You have no hands."));
|
2020-08-29 06:05:44 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-01 10:19:43 -06:00
|
|
|
if (args.Using.TryGetComponent<ToolComponent>(out var multitool) && multitool.Qualities == ToolQuality.Multitool)
|
2020-08-29 06:05:44 -05:00
|
|
|
{
|
|
|
|
|
|
2020-09-06 16:11:53 +02:00
|
|
|
var mapGrid = _mapManager.GetGrid(args.ClickLocation.GetGridId(_serverEntityManager));
|
2020-08-29 06:05:44 -05:00
|
|
|
var snapPos = mapGrid.SnapGridCellFor(args.ClickLocation, SnapGridOffset.Center);
|
2020-12-16 13:31:47 +00:00
|
|
|
if (mapGrid.GetSnapGridCell(snapPos, SnapGridOffset.Center).Any(sc => sc.Owner.HasComponent<AMEShieldComponent>()))
|
|
|
|
|
{
|
|
|
|
|
Owner.PopupMessage(args.User, Loc.GetString("Shielding is already there!"));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-08-29 06:05:44 -05:00
|
|
|
|
|
|
|
|
var ent = _serverEntityManager.SpawnEntity("AMEShielding", mapGrid.GridTileToLocal(snapPos));
|
|
|
|
|
ent.Transform.LocalRotation = Owner.Transform.LocalRotation;
|
|
|
|
|
|
2020-12-27 02:11:52 +00:00
|
|
|
EntitySystem.Get<AudioSystem>().PlayFromEntity(_unwrap, Owner);
|
|
|
|
|
|
2020-08-29 06:05:44 -05:00
|
|
|
Owner.Delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|