2020-12-16 13:31:47 +00:00
|
|
|
using System.Linq;
|
2021-06-09 22:19:39 +02:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Content.Server.Hands.Components;
|
2021-10-29 13:42:18 +01:00
|
|
|
using Content.Server.Tools;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Interaction;
|
2021-09-26 15:18:45 +02:00
|
|
|
using Content.Shared.Popups;
|
2021-07-10 17:35:33 +02:00
|
|
|
using Content.Shared.Sound;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.GameObjects;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Audio;
|
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;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Player;
|
2021-10-07 13:01:27 +02:00
|
|
|
using Robust.Shared.Prototypes;
|
2021-07-10 17:35:33 +02:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-10-07 13:01:27 +02:00
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
2020-08-29 06:05:44 -05:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.AME.Components
|
2020-08-29 06:05:44 -05:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
[ComponentReference(typeof(IInteractUsing))]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class AMEPartComponent : Component, IInteractUsing
|
2020-08-29 06:05:44 -05:00
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
|
|
|
|
[Dependency] private readonly IServerEntityManager _serverEntityManager = default!;
|
2020-09-01 12:34:53 +02:00
|
|
|
|
2021-10-07 13:01:27 +02:00
|
|
|
[DataField("unwrapSound")]
|
|
|
|
|
private SoundSpecifier _unwrapSound = new SoundPathSpecifier("/Audio/Effects/unwrap.ogg");
|
|
|
|
|
|
|
|
|
|
[DataField("qualityNeeded", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
|
|
|
|
|
private string _qualityNeeded = "Pulsing";
|
2020-08-29 06:05:44 -05:00
|
|
|
|
|
|
|
|
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs args)
|
|
|
|
|
{
|
2021-12-08 17:04:21 +01:00
|
|
|
if (!_serverEntityManager.HasComponent<HandsComponent>(args.User))
|
2020-08-29 06:05:44 -05:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
Owner.PopupMessage(args.User, Loc.GetString("ame-part-component-interact-using-no-hands"));
|
2021-10-07 13:01:27 +02:00
|
|
|
return false;
|
2020-08-29 06:05:44 -05:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 15:53:09 +01:00
|
|
|
if (!EntitySystem.Get<ToolSystem>().HasQuality(args.Using, _qualityNeeded))
|
2021-10-07 13:01:27 +02:00
|
|
|
return false;
|
2020-08-29 06:05:44 -05:00
|
|
|
|
2021-03-04 16:57:09 +01:00
|
|
|
if (!_mapManager.TryGetGrid(args.ClickLocation.GetGridId(_serverEntityManager), out var mapGrid))
|
|
|
|
|
return false; // No AME in space.
|
2020-08-29 06:05:44 -05:00
|
|
|
|
2021-04-28 10:49:37 -07:00
|
|
|
var snapPos = mapGrid.TileIndicesFor(args.ClickLocation);
|
2021-09-28 13:35:29 +02:00
|
|
|
if (mapGrid.GetAnchoredEntities(snapPos).Any(sc => _serverEntityManager.HasComponent<AMEShieldComponent>(sc)))
|
2021-03-04 16:57:09 +01:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
Owner.PopupMessage(args.User, Loc.GetString("ame-part-component-shielding-already-present"));
|
2021-03-04 16:57:09 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2020-08-29 06:05:44 -05:00
|
|
|
|
2021-03-04 16:57:09 +01:00
|
|
|
var ent = _serverEntityManager.SpawnEntity("AMEShielding", mapGrid.GridTileToLocal(snapPos));
|
2020-12-27 02:11:52 +00:00
|
|
|
|
2021-07-31 19:52:33 +02:00
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), _unwrapSound.GetSound(), Owner);
|
2021-03-04 16:57:09 +01:00
|
|
|
|
2021-12-08 17:04:21 +01:00
|
|
|
_serverEntityManager.QueueDeleteEntity(Owner);
|
2020-08-29 06:05:44 -05:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|