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);
}
}
}

View File

@@ -1,16 +1,9 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Content.Server.Hands.Components;
using Content.Server.NodeContainer;
using Content.Server.Power.Components;
using Content.Server.UserInterface;
using Content.Shared.ActionBlocker;
using Content.Shared.AME;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Item;
using Content.Shared.Popups;
using Content.Shared.Sound;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
@@ -20,8 +13,7 @@ using Robust.Shared.Player;
namespace Content.Server.AME.Components
{
[RegisterComponent]
[ComponentReference(typeof(IInteractUsing))]
public sealed class AMEControllerComponent : SharedAMEControllerComponent, IInteractUsing
public sealed class AMEControllerComponent : SharedAMEControllerComponent
{
[Dependency] private readonly IEntityManager _entities = default!;
[Dependency] private readonly IEntitySystemManager _sysMan = default!;
@@ -41,8 +33,8 @@ namespace Content.Server.AME.Components
[ViewVariables]
private int _stability = 100;
private ContainerSlot _jarSlot = default!;
[ViewVariables] private bool HasJar => _jarSlot.ContainedEntity != null;
public ContainerSlot JarSlot = default!;
[ViewVariables] public bool HasJar => JarSlot.ContainedEntity != null;
protected override void Initialize()
{
@@ -59,7 +51,7 @@ namespace Content.Server.AME.Components
_injecting = false;
InjectionAmount = 2;
_jarSlot = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-fuelJarContainer");
JarSlot = ContainerHelpers.EnsureContainer<ContainerSlot>(Owner, $"{Name}-fuelJarContainer");
}
internal void OnUpdate(float frameTime)
@@ -76,7 +68,7 @@ namespace Content.Server.AME.Components
return;
}
if (_jarSlot.ContainedEntity is not {Valid: true} jar)
if (JarSlot.ContainedEntity is not {Valid: true} jar)
return;
_entities.TryGetComponent<AMEFuelContainerComponent?>(jar, out var fuelJar);
@@ -105,7 +97,7 @@ namespace Content.Server.AME.Components
private AMEControllerBoundUserInterfaceState GetUserInterfaceState()
{
if (_jarSlot.ContainedEntity is not {Valid: true} jar)
if (JarSlot.ContainedEntity is not {Valid: true} jar)
{
return new AMEControllerBoundUserInterfaceState(Powered, IsMasterController(), false, HasJar, 0, InjectionAmount, GetCoreCount());
}
@@ -187,10 +179,10 @@ namespace Content.Server.AME.Components
if (!HasJar || _injecting)
return;
if (_jarSlot.ContainedEntity is not {Valid: true} jar)
if (JarSlot.ContainedEntity is not {Valid: true} jar)
return;
_jarSlot.Remove(jar);
JarSlot.Remove(jar);
UpdateUserInterface();
_sysMan.GetEntitySystem<SharedHandsSystem>().PickupOrDrop(user, jar);
@@ -277,43 +269,6 @@ namespace Content.Server.AME.Components
{
SoundSystem.Play(Filter.Pvs(Owner), _injectSound.GetSound(), Owner, AudioParams.Default.WithVolume(overloading ? 10f : 0f));
}
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs args)
{
if (!_entities.TryGetComponent(args.User, out HandsComponent? hands))
{
Owner.PopupMessage(args.User, Loc.GetString("ame-controller-component-interact-using-no-hands-text"));
return true;
}
if (hands.ActiveHandEntity == null)
{
Owner.PopupMessage(args.User, Loc.GetString("ame-controller-component-interact-using-nothing-in-hands-text"));
return false;
}
var activeHandEntity = hands.ActiveHandEntity;
if (_entities.HasComponent<AMEFuelContainerComponent?>(activeHandEntity))
{
if (HasJar)
{
Owner.PopupMessage(args.User, Loc.GetString("ame-controller-component-interact-using-already-has-jar"));
}
else
{
_jarSlot.Insert(activeHandEntity.Value);
Owner.PopupMessage(args.User, Loc.GetString("ame-controller-component-interact-using-success"));
UpdateUserInterface();
}
}
else
{
Owner.PopupMessage(args.User, Loc.GetString("ame-controller-component-interact-using-fail"));
}
return true;
}
}
}

View File

@@ -1,64 +1,16 @@
using System.Linq;
using System.Threading.Tasks;
using Content.Server.Hands.Components;
using Content.Server.Tools;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Sound;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.AME.Components
{
[RegisterComponent]
[ComponentReference(typeof(IInteractUsing))]
public sealed class AMEPartComponent : Component, IInteractUsing
public sealed class AMEPartComponent : Component
{
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IServerEntityManager _serverEntityManager = default!;
[DataField("unwrapSound")]
private SoundSpecifier _unwrapSound = new SoundPathSpecifier("/Audio/Effects/unwrap.ogg");
public SoundSpecifier UnwrapSound = new SoundPathSpecifier("/Audio/Effects/unwrap.ogg");
[DataField("qualityNeeded", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
private string _qualityNeeded = "Pulsing";
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs args)
{
if (!_serverEntityManager.HasComponent<HandsComponent>(args.User))
{
Owner.PopupMessage(args.User, Loc.GetString("ame-part-component-interact-using-no-hands"));
return false;
}
if (!EntitySystem.Get<ToolSystem>().HasQuality(args.Using, _qualityNeeded))
return false;
if (!_mapManager.TryGetGrid(args.ClickLocation.GetGridId(_serverEntityManager), out var mapGrid))
return false; // No AME in space.
var snapPos = mapGrid.TileIndicesFor(args.ClickLocation);
if (mapGrid.GetAnchoredEntities(snapPos).Any(sc => _serverEntityManager.HasComponent<AMEShieldComponent>(sc)))
{
Owner.PopupMessage(args.User, Loc.GetString("ame-part-component-shielding-already-present"));
return true;
}
var ent = _serverEntityManager.SpawnEntity("AMEShielding", mapGrid.GridTileToLocal(snapPos));
SoundSystem.Play(Filter.Pvs(Owner), _unwrapSound.GetSound(), Owner);
_serverEntityManager.QueueDeleteEntity(Owner);
return true;
}
public string QualityNeeded = "Pulsing";
}
}