Files
tbd-station-14/Content.Server/GameObjects/Components/Power/AME/AMEPartComponent.cs
collinlunn b51b8cb182 Some Power nullable & ComponentDependency (#3050)
* Power nullability

* AME nullability

* re-adds EnsureComponents

* conflict fix

* Update Content.Server/GameObjects/Components/Power/PowerNetComponents/RadiationCollectorComponent.cs

Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>

* Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs

Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>

* Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryStorageComponent.cs

Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>

* Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs

Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>

* Update Content.Server/GameObjects/Components/Power/PowerNetComponents/BatteryDischargerComponent.cs

Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>

* removes duplicate component assignment

Co-authored-by: py01 <pyronetics01@gmail.com>
Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com>
2021-02-01 17:19:43 +01:00

61 lines
2.4 KiB
C#

#nullable enable
using System.Threading.Tasks;
using System.Linq;
using Content.Server.GameObjects.Components.Interactable;
using Content.Server.Interfaces.GameObjects.Components.Items;
using Content.Shared.GameObjects.Components.Interactable;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects.Systems;
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!;
public override string Name => "AMEPart";
private string _unwrap = "/Audio/Effects/unwrap.ogg";
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs args)
{
if (!args.User.TryGetComponent<IHandsComponent>(out var hands))
{
Owner.PopupMessage(args.User, Loc.GetString("You have no hands."));
return true;
}
if (args.Using.TryGetComponent<ToolComponent>(out var multitool) && multitool.Qualities == ToolQuality.Multitool)
{
var mapGrid = _mapManager.GetGrid(args.ClickLocation.GetGridId(_serverEntityManager));
var snapPos = mapGrid.SnapGridCellFor(args.ClickLocation, SnapGridOffset.Center);
if (mapGrid.GetSnapGridCell(snapPos, SnapGridOffset.Center).Any(sc => sc.Owner.HasComponent<AMEShieldComponent>()))
{
Owner.PopupMessage(args.User, Loc.GetString("Shielding is already there!"));
return true;
}
var ent = _serverEntityManager.SpawnEntity("AMEShielding", mapGrid.GridTileToLocal(snapPos));
ent.Transform.LocalRotation = Owner.Transform.LocalRotation;
EntitySystem.Get<AudioSystem>().PlayFromEntity(_unwrap, Owner);
Owner.Delete();
}
return true;
}
}
}