Remove InteractedWithEvent and friends. (#11939)

This commit is contained in:
Leon Friedrich
2022-10-26 14:15:48 +13:00
committed by GitHub
parent b03f17bda2
commit c0b657ca18
21 changed files with 133 additions and 101 deletions

View File

@@ -78,9 +78,6 @@ namespace Content.Shared.ActionBlocker
var targetEv = new GettingInteractedWithAttemptEvent(user, target);
RaiseLocalEvent(target.Value, targetEv);
if (!targetEv.Cancelled)
InteractWithItem(user, target.Value);
return !targetEv.Cancelled;
}
@@ -136,11 +133,7 @@ namespace Content.Shared.ActionBlocker
var itemEv = new GettingPickedUpAttemptEvent(user, item);
RaiseLocalEvent(item, itemEv);
if (!itemEv.Cancelled)
InteractWithItem(user, item);
return !itemEv.Cancelled;
}
public bool CanEmote(EntityUid uid)
@@ -186,13 +179,5 @@ namespace Content.Shared.ActionBlocker
return !ev.Cancelled;
}
private void InteractWithItem(EntityUid user, EntityUid item)
{
var userEvent = new UserInteractedWithItemEvent(user, item);
RaiseLocalEvent(user, userEvent);
var itemEvent = new ItemInteractedWithEvent(user, item);
RaiseLocalEvent(item, itemEvent);
}
}
}

View File

@@ -0,0 +1,17 @@
namespace Content.Shared.Interaction.Events;
/// <summary>
/// Raised directed at two entities to indicate that they came into contact, usually as a result of some other interaction.
/// </summary>
/// <remarks>
/// This is currently used by the forensics and disease systems to perform on-contact interactions.
/// </remarks>
public sealed class ContactInteractionEvent : HandledEntityEventArgs
{
public readonly EntityUid Other;
public ContactInteractionEvent(EntityUid other)
{
Other = other;
}
}

View File

@@ -261,7 +261,8 @@ namespace Content.Shared.Interaction
if (target != null)
{
var ev = new InteractNoHandEvent(user, target.Value);
RaiseLocalEvent(user, ev, true);
RaiseLocalEvent(user, ev);
DoContactInteraction(user, target.Value, ev);
}
return;
}
@@ -316,6 +317,7 @@ namespace Content.Shared.Interaction
var message = new InteractHandEvent(user, target);
RaiseLocalEvent(target, message, true);
_adminLogger.Add(LogType.InteractHand, LogImpact.Low, $"{ToPrettyString(user):user} interacted with {ToPrettyString(target):target}");
DoContactInteraction(user, target, message);
if (message.Handled)
return;
@@ -337,6 +339,9 @@ namespace Content.Shared.Interaction
var rangedMsg = new RangedInteractEvent(user, used, target.Value, clickLocation);
RaiseLocalEvent(target.Value, rangedMsg, true);
// We contact the USED entity, but not the target.
DoContactInteraction(user, used, rangedMsg);
if (rangedMsg.Handled)
return;
}
@@ -722,6 +727,9 @@ namespace Content.Shared.Interaction
{
var ev = new BeforeRangedInteractEvent(user, used, target, clickLocation, canReach);
RaiseLocalEvent(used, ev);
// We contact the USED entity, but not the target.
DoContactInteraction(user, used, ev);
return ev.Handled;
}
@@ -750,6 +758,9 @@ namespace Content.Shared.Interaction
// all interactions should only happen when in range / unobstructed, so no range check is needed
var interactUsingEvent = new InteractUsingEvent(user, used, target, clickLocation);
RaiseLocalEvent(target, interactUsingEvent, true);
DoContactInteraction(user, used, interactUsingEvent);
DoContactInteraction(user, target, interactUsingEvent);
DoContactInteraction(used, target, interactUsingEvent);
if (interactUsingEvent.Handled)
return;
@@ -765,7 +776,14 @@ namespace Content.Shared.Interaction
target = null;
var afterInteractEvent = new AfterInteractEvent(user, used, target, clickLocation, canReach);
RaiseLocalEvent(used, afterInteractEvent, false);
RaiseLocalEvent(used, afterInteractEvent);
DoContactInteraction(user, used, afterInteractEvent);
if (canReach)
{
DoContactInteraction(user, target, afterInteractEvent);
DoContactInteraction(used, target, afterInteractEvent);
}
if (afterInteractEvent.Handled)
return;
@@ -774,6 +792,13 @@ namespace Content.Shared.Interaction
var afterInteractUsingEvent = new AfterInteractUsingEvent(user, used, target, clickLocation, canReach);
RaiseLocalEvent(target.Value, afterInteractUsingEvent);
DoContactInteraction(user, used, afterInteractUsingEvent);
if (canReach)
{
DoContactInteraction(user, target, afterInteractUsingEvent);
DoContactInteraction(used, target, afterInteractUsingEvent);
}
}
#region ActivateItemInWorld
@@ -832,6 +857,7 @@ namespace Content.Shared.Interaction
if (!activateMsg.Handled)
return false;
DoContactInteraction(user, used, activateMsg);
_useDelay.BeginDelay(used, delayComponent);
_adminLogger.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}");
return true;
@@ -869,6 +895,7 @@ namespace Content.Shared.Interaction
RaiseLocalEvent(used, useMsg, true);
if (useMsg.Handled)
{
DoContactInteraction(user, used, useMsg);
_useDelay.BeginDelay(used, delayComponent);
return true;
}
@@ -977,6 +1004,18 @@ namespace Content.Shared.Interaction
return true;
}
/// <summary>
/// Simple convenience function to raise contact events (disease, forensics, etc).
/// </summary>
public void DoContactInteraction(EntityUid uidA, EntityUid? uidB, HandledEntityEventArgs? args = null)
{
if (uidB == null || args?.Handled == false)
return;
RaiseLocalEvent(uidA, new ContactInteractionEvent(uidB.Value));
RaiseLocalEvent(uidB.Value, new ContactInteractionEvent(uidA));
}
}
/// <summary>

View File

@@ -1,17 +0,0 @@
namespace Content.Shared.Item;
/// <summary>
/// Raised on the item after they do any sort of interaction with an item,
/// useful for when you want a component on the user to do something to the user
/// E.g. forensics, disease, etc.
/// </summary>
public sealed class ItemInteractedWithEvent : EntityEventArgs
{
public EntityUid User;
public EntityUid Item;
public ItemInteractedWithEvent(EntityUid user, EntityUid item)
{
User = user;
Item = item;
}
}

View File

@@ -111,14 +111,13 @@ public abstract class SharedItemSystem : EntitySystem
if (args.Hands == null ||
args.Using != null ||
!args.CanAccess ||
!args.CanInteract) //||
//!_handsSystem.CanPickupAnyHand(args.User, args.Target, handsComp: args.Hands, item: component))
!args.CanInteract ||
!_handsSystem.CanPickupAnyHand(args.User, args.Target, handsComp: args.Hands, item: component))
return;
InteractionVerb verb = new();
// TODO ITEM
//verb.Act = () => _handsSystem.TryPickupAnyHand(args.User, args.Target, checkActionBlocker: false,
// handsComp: args.Hands, item: component);
verb.Act = () => _handsSystem.TryPickupAnyHand(args.User, args.Target, checkActionBlocker: false,
handsComp: args.Hands, item: component);
verb.IconTexture = "/Textures/Interface/VerbIcons/pickup.svg.192dpi.png";
// if the item already in a container (that is not the same as the user's), then change the text.

View File

@@ -1,17 +0,0 @@
namespace Content.Shared.Item;
/// <summary>
/// Raised on the user after they do any sort of interaction with an item,
/// useful for when you want a component on the user to do something to the item.
/// E.g. forensics, disease, etc.
/// </summary>
public sealed class UserInteractedWithItemEvent : EntityEventArgs
{
public EntityUid User;
public EntityUid Item;
public UserInteractedWithItemEvent(EntityUid user, EntityUid item)
{
User = user;
Item = item;
}
}

View File

@@ -1,6 +1,7 @@
using Content.Shared.ActionBlocker;
using Content.Shared.Buckle.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Physics.Pull;
using Content.Shared.Pulling.Components;
using Content.Shared.Pulling.Events;
@@ -16,6 +17,7 @@ namespace Content.Shared.Pulling
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
public bool CanPull(EntityUid puller, EntityUid pulled)
{
@@ -189,6 +191,8 @@ namespace Content.Shared.Pulling
if (pullAttempt.Cancelled)
return false;
_interaction.DoContactInteraction(pullable.Owner, puller.Owner);
_pullSm.ForceRelationship(puller, pullable);
pullable.PrevFixedRotation = pullablePhysics.FixedRotation;
pullablePhysics.FixedRotation = pullable.FixedRotationOnPull;

View File

@@ -93,6 +93,7 @@ namespace Content.Shared.Pulling
Verb verb = new();
verb.Text = Loc.GetString("pulling-verb-get-data-text-stop-pulling");
verb.Act = () => TryStopPull(component, args.User);
verb.DoContactInteraction = false; // pulling handle its own contact interaction.
args.Verbs.Add(verb);
}
else if (CanPull(args.User, args.Target))
@@ -100,6 +101,7 @@ namespace Content.Shared.Pulling
Verb verb = new();
verb.Text = Loc.GetString("pulling-verb-get-data-text");
verb.Act = () => TryStartPull(args.User, args.Target);
verb.DoContactInteraction = false; // pulling handle its own contact interaction.
args.Verbs.Add(verb);
}
}

View File

@@ -154,6 +154,23 @@ namespace Content.Shared.Verbs
/// <remarks>
/// This will try to call the action delegates and raise the local events for the given verb.
/// </remarks>
public abstract void ExecuteVerb(Verb verb, EntityUid user, EntityUid target, bool forced = false);
public virtual void ExecuteVerb(Verb verb, EntityUid user, EntityUid target, bool forced = false)
{
// invoke any relevant actions
verb.Act?.Invoke();
// Maybe raise a local event
if (verb.ExecutionEventArgs != null)
{
if (verb.EventTarget.IsValid())
RaiseLocalEvent(verb.EventTarget, verb.ExecutionEventArgs);
else
RaiseLocalEvent(verb.ExecutionEventArgs);
}
// Perform any contact interactions
if (verb.DoContactInteraction ?? (verb.DefaultDoContactInteraction && _interactionSystem.InRangeUnobstructed(user, target)))
_interactionSystem.DoContactInteraction(user, target);
}
}
}

View File

@@ -146,6 +146,15 @@ namespace Content.Shared.Verbs
/// </summary>
public bool ConfirmationPopup = false;
/// <summary>
/// If true, this verb will raise <see cref="ContactInteractionEvent"/>s when executed. If not explicitly
/// specified, this will just default to raising the event if <see cref="DefaultDoContactInteraction"/> is
/// true and the user is in range.
/// </summary>
public bool? DoContactInteraction;
public virtual bool DefaultDoContactInteraction => false;
/// <summary>
/// Compares two verbs based on their <see cref="Priority"/>, <see cref="Category"/>, <see cref="Text"/>,
/// and <see cref="IconTexture"/>.
@@ -235,6 +244,7 @@ namespace Content.Shared.Verbs
{
public new static string DefaultTextStyleClass = "InteractionVerb";
public override int TypePriority => 4;
public override bool DefaultDoContactInteraction => true;
public InteractionVerb() : base()
{
@@ -256,6 +266,7 @@ namespace Content.Shared.Verbs
public sealed class UtilityVerb : Verb
{
public override int TypePriority => 3;
public override bool DefaultDoContactInteraction => true;
public UtilityVerb() : base()
{
@@ -293,6 +304,7 @@ namespace Content.Shared.Verbs
{
public override int TypePriority => 2;
public new static string DefaultTextStyleClass = "AlternativeVerb";
public override bool DefaultDoContactInteraction => true;
public AlternativeVerb() : base()
{
@@ -314,6 +326,7 @@ namespace Content.Shared.Verbs
{
public override int TypePriority => 1;
public new static string DefaultTextStyleClass = "ActivationVerb";
public override bool DefaultDoContactInteraction => true;
public ActivationVerb() : base()
{