Remove IActivate (#9705)

* git mv

* purge IActivate

* File scoped NS
This commit is contained in:
Leon Friedrich
2022-07-14 22:29:29 +12:00
committed by GitHub
parent bad837fb85
commit e9616e40f9
5 changed files with 40 additions and 85 deletions

View File

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

View File

@@ -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<HandheldRadioComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<HandheldRadioComponent, ActivateInWorldEvent>(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)

View File

@@ -0,0 +1,26 @@
using JetBrains.Annotations;
namespace Content.Shared.Interaction;
/// <summary>
/// Raised when an entity is activated in the world.
/// </summary>
[PublicAPI]
public sealed class ActivateInWorldEvent : HandledEntityEventArgs, ITargetedInteractEventArgs
{
/// <summary>
/// Entity that activated the target world entity.
/// </summary>
public EntityUid User { get; }
/// <summary>
/// Entity that was activated in the world.
/// </summary>
public EntityUid Target { get; }
public ActivateInWorldEvent(EntityUid user, EntityUid target)
{
User = user;
Target = target;
}
}

View File

@@ -1,56 +0,0 @@
using JetBrains.Annotations;
namespace Content.Shared.Interaction
{
/// <summary>
/// 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.
/// </summary>
[RequiresExplicitImplementation]
public interface IActivate
{
/// <summary>
/// Called when this component is activated by another entity who is in range.
/// </summary>
[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; }
}
/// <summary>
/// Raised when an entity is activated in the world.
/// </summary>
[PublicAPI]
public sealed class ActivateInWorldEvent : HandledEntityEventArgs, ITargetedInteractEventArgs
{
/// <summary>
/// Entity that activated the target world entity.
/// </summary>
public EntityUid User { get; }
/// <summary>
/// Entity that was activated in the world.
/// </summary>
public EntityUid Target { get; }
public ActivateInWorldEvent(EntityUid user, EntityUid target)
{
User = user;
Target = target;
}
}
}

View File

@@ -649,15 +649,6 @@ namespace Content.Shared.Interaction
if (afterInteractEvent.Handled)
return;
var afterInteractEventArgs = new AfterInteractEventArgs(user, clickLocation, target, canReach);
var afterInteracts = AllComps<IAfterInteract>(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<IActivate>(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;