Elimate most IInteractUsing (#7481)

This commit is contained in:
Rane
2022-04-15 17:20:20 -04:00
committed by GitHub
parent 569085ab5c
commit 70a26bf0c2
13 changed files with 431 additions and 485 deletions

View File

@@ -1,5 +1,13 @@
using Content.Server.AME.Components;
using System.Linq;
using Content.Server.AME.Components;
using Content.Server.Power.Components;
using Content.Server.Hands.Components;
using Content.Server.Popups;
using Content.Server.Tools;
using Content.Shared.Interaction;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Audio;
using JetBrains.Annotations;
namespace Content.Server.AME
@@ -7,6 +15,9 @@ namespace Content.Server.AME
[UsedImplicitly]
public sealed class AntimatterEngineSystem : EntitySystem
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly ToolSystem _toolSystem = default!;
private float _accumulatedFrameTime;
private const float UpdateCooldown = 10f;
@@ -15,6 +26,8 @@ namespace Content.Server.AME
{
base.Initialize();
SubscribeLocalEvent<AMEControllerComponent, PowerChangedEvent>(OnAMEPowerChange);
SubscribeLocalEvent<AMEControllerComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<AMEPartComponent, InteractUsingEvent>(OnPartInteractUsing);
}
public override void Update(float frameTime)
@@ -37,5 +50,61 @@ namespace Content.Server.AME
{
component.UpdateUserInterface();
}
private void OnInteractUsing(EntityUid uid, AMEControllerComponent component, InteractUsingEvent args)
{
if (!TryComp(args.User, out HandsComponent? hands))
{
_popupSystem.PopupEntity(Loc.GetString("ame-controller-component-interact-using-no-hands-text"), uid, Filter.Entities(args.User));
return;
}
if (HasComp<AMEFuelContainerComponent?>(args.Used))
{
if (component.HasJar)
{
_popupSystem.PopupEntity(Loc.GetString("ame-controller-component-interact-using-already-has-jar"), uid, Filter.Entities(args.User));
}
else
{
component.JarSlot.Insert(args.Used);
_popupSystem.PopupEntity(Loc.GetString("ame-controller-component-interact-using-success"), uid, Filter.Entities(args.User));
component.UpdateUserInterface();
}
}
else
{
_popupSystem.PopupEntity(Loc.GetString("ame-controller-component-interact-using-fail"), uid, Filter.Entities(args.User));
}
}
private void OnPartInteractUsing(EntityUid uid, AMEPartComponent component, InteractUsingEvent args)
{
if (!HasComp<HandsComponent>(args.User))
{
_popupSystem.PopupEntity(Loc.GetString("ame-part-component-interact-using-no-hands"), uid, Filter.Entities(args.User));
return;
}
if (!_toolSystem.HasQuality(args.Used, component.QualityNeeded))
return;
if (!_mapManager.TryGetGrid(args.ClickLocation.GetGridId(EntityManager), out var mapGrid))
return; // No AME in space.
var snapPos = mapGrid.TileIndicesFor(args.ClickLocation);
if (mapGrid.GetAnchoredEntities(snapPos).Any(sc => HasComp<AMEShieldComponent>(sc)))
{
_popupSystem.PopupEntity(Loc.GetString("ame-part-component-shielding-already-present"), uid, Filter.Entities(args.User));
return;
}
var ent = EntityManager.SpawnEntity("AMEShielding", mapGrid.GridTileToLocal(snapPos));
SoundSystem.Play(Filter.Pvs(uid), component.UnwrapSound.GetSound(), uid);
EntityManager.QueueDeleteEntity(uid);
}
}
}