From e9616e40f9fdc04d45851e5595d731ae0ec2ca7f Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Thu, 14 Jul 2022 22:29:29 +1200 Subject: [PATCH] Remove IActivate (#9705) * git mv * purge IActivate * File scoped NS --- .../Components/HandheldRadioComponent.cs | 8 +-- .../Radio/EntitySystems/RadioSystem.cs | 13 ++++- .../Interaction/ActivateInWorldEvent.cs | 26 +++++++++ Content.Shared/Interaction/IActivate.cs | 56 ------------------- .../Interaction/SharedInteractionSystem.cs | 22 +------- 5 files changed, 40 insertions(+), 85 deletions(-) create mode 100644 Content.Shared/Interaction/ActivateInWorldEvent.cs delete mode 100644 Content.Shared/Interaction/IActivate.cs diff --git a/Content.Server/Radio/Components/HandheldRadioComponent.cs b/Content.Server/Radio/Components/HandheldRadioComponent.cs index c914b575d6..66c2cefd3e 100644 --- a/Content.Server/Radio/Components/HandheldRadioComponent.cs +++ b/Content.Server/Radio/Components/HandheldRadioComponent.cs @@ -14,9 +14,8 @@ namespace Content.Server.Radio.Components [ComponentProtoName("Radio")] [ComponentReference(typeof(IRadio))] [ComponentReference(typeof(IListen))] - [ComponentReference(typeof(IActivate))] #pragma warning disable 618 - public sealed class HandheldRadioComponent : Component, IListen, IRadio, IActivate + public sealed class HandheldRadioComponent : Component, IListen, IRadio #pragma warning restore 618 { private ChatSystem _chatSystem = default!; @@ -98,10 +97,5 @@ namespace Content.Server.Radio.Components { _radioSystem.SpreadMessage(this, speaker, message, channel); } - - void IActivate.Activate(ActivateEventArgs eventArgs) - { - Use(eventArgs.User); - } } } diff --git a/Content.Server/Radio/EntitySystems/RadioSystem.cs b/Content.Server/Radio/EntitySystems/RadioSystem.cs index 8ce5460508..14b736791b 100644 --- a/Content.Server/Radio/EntitySystems/RadioSystem.cs +++ b/Content.Server/Radio/EntitySystems/RadioSystem.cs @@ -1,8 +1,9 @@ -using System.Linq; +using System.Linq; using Content.Shared.Examine; using Content.Server.Radio.Components; using Content.Shared.Radio; using JetBrains.Annotations; +using Content.Shared.Interaction; namespace Content.Server.Radio.EntitySystems { @@ -15,6 +16,16 @@ namespace Content.Server.Radio.EntitySystems { base.Initialize(); SubscribeLocalEvent(OnExamine); + SubscribeLocalEvent(OnActivate); + } + + private void OnActivate(EntityUid uid, HandheldRadioComponent component, ActivateInWorldEvent args) + { + if (args.Handled) + return; + + args.Handled = true; + component.Use(args.User); } private void OnExamine(EntityUid uid, HandheldRadioComponent component, ExaminedEvent args) diff --git a/Content.Shared/Interaction/ActivateInWorldEvent.cs b/Content.Shared/Interaction/ActivateInWorldEvent.cs new file mode 100644 index 0000000000..ea308f9b08 --- /dev/null +++ b/Content.Shared/Interaction/ActivateInWorldEvent.cs @@ -0,0 +1,26 @@ +using JetBrains.Annotations; + +namespace Content.Shared.Interaction; + +/// +/// Raised when an entity is activated in the world. +/// +[PublicAPI] +public sealed class ActivateInWorldEvent : HandledEntityEventArgs, ITargetedInteractEventArgs +{ + /// + /// Entity that activated the target world entity. + /// + public EntityUid User { get; } + + /// + /// Entity that was activated in the world. + /// + public EntityUid Target { get; } + + public ActivateInWorldEvent(EntityUid user, EntityUid target) + { + User = user; + Target = target; + } +} diff --git a/Content.Shared/Interaction/IActivate.cs b/Content.Shared/Interaction/IActivate.cs deleted file mode 100644 index c2bc023af0..0000000000 --- a/Content.Shared/Interaction/IActivate.cs +++ /dev/null @@ -1,56 +0,0 @@ -using JetBrains.Annotations; - -namespace Content.Shared.Interaction -{ - /// - /// This interface gives components behavior when being activated (by default, - /// this is done via the "E" key) when the user is in range and has unobstructed access to the target entity - /// (allows inside blockers). This includes activating an object in the world as well as activating an - /// object in inventory. Unlike IUse, this can be performed on entities that aren't in the active hand, - /// even when the active hand is currently holding something else. - /// - [RequiresExplicitImplementation] - public interface IActivate - { - /// - /// Called when this component is activated by another entity who is in range. - /// - [Obsolete("Use ActivateInWorldMessage instead")] - void Activate(ActivateEventArgs eventArgs); - } - - public sealed class ActivateEventArgs : EventArgs, ITargetedInteractEventArgs - { - public ActivateEventArgs(EntityUid user, EntityUid target) - { - User = user; - Target = target; - } - - public EntityUid User { get; } - public EntityUid Target { get; } - } - - /// - /// Raised when an entity is activated in the world. - /// - [PublicAPI] - public sealed class ActivateInWorldEvent : HandledEntityEventArgs, ITargetedInteractEventArgs - { - /// - /// Entity that activated the target world entity. - /// - public EntityUid User { get; } - - /// - /// Entity that was activated in the world. - /// - public EntityUid Target { get; } - - public ActivateInWorldEvent(EntityUid user, EntityUid target) - { - User = user; - Target = target; - } - } -} diff --git a/Content.Shared/Interaction/SharedInteractionSystem.cs b/Content.Shared/Interaction/SharedInteractionSystem.cs index 1d98bf8a7d..965f9cfe1b 100644 --- a/Content.Shared/Interaction/SharedInteractionSystem.cs +++ b/Content.Shared/Interaction/SharedInteractionSystem.cs @@ -649,15 +649,6 @@ namespace Content.Shared.Interaction if (afterInteractEvent.Handled) return; - var afterInteractEventArgs = new AfterInteractEventArgs(user, clickLocation, target, canReach); - var afterInteracts = AllComps(used).OrderByDescending(x => x.Priority).ToList(); - - foreach (var afterInteract in afterInteracts) - { - if (await afterInteract.AfterInteract(afterInteractEventArgs)) - return; - } - if (target == null) return; @@ -718,20 +709,9 @@ namespace Content.Shared.Interaction var activateMsg = new ActivateInWorldEvent(user, used); RaiseLocalEvent(used, activateMsg, true); - if (activateMsg.Handled) - { - _useDelay.BeginDelay(used, delayComponent); - _adminLogger.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}"); - return true; - } - - var activatable = AllComps(used).FirstOrDefault(); - if (activatable == null) + if (!activateMsg.Handled) return false; - activatable.Activate(new ActivateEventArgs(user, used)); - - // No way to check success. _useDelay.BeginDelay(used, delayComponent); _adminLogger.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}"); return true;