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

@@ -263,21 +263,6 @@ namespace Content.Client.Verbs
EntityManager.RaisePredictiveEvent(new ExecuteVerbEvent(target, verb));
}
public override 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, true);
else
RaiseLocalEvent(verb.ExecutionEventArgs);
}
}
private void HandleVerbResponse(VerbsResponseEvent msg)
{
if (!VerbMenu.RootMenu.Visible || VerbMenu.CurrentTarget != msg.Entity)

View File

@@ -56,6 +56,7 @@ namespace Content.Server.Cuffs
Verb verb = new()
{
Act = () => component.TryUncuff(args.User),
DoContactInteraction = true,
Text = Loc.GetString("uncuff-verb-get-data-text")
};
//TODO VERB ICON add uncuffing symbol? may re-use the alert symbol showing that you are currently cuffed?

View File

@@ -11,9 +11,9 @@ using Content.Shared.Disease.Components;
using Content.Shared.Examine;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Content.Shared.Item;
using Content.Shared.MobState.Components;
using Content.Shared.Rejuvenate;
using Robust.Shared.Player;
@@ -46,8 +46,7 @@ namespace Content.Server.Disease
SubscribeLocalEvent<DiseaseCarrierComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<DiseaseCarrierComponent, CureDiseaseAttemptEvent>(OnTryCureDisease);
SubscribeLocalEvent<DiseaseCarrierComponent, RejuvenateEvent>(OnRejuvenate);
SubscribeLocalEvent<DiseasedComponent, UserInteractedWithItemEvent>(OnUserInteractDiseased);
SubscribeLocalEvent<DiseasedComponent, ItemInteractedWithEvent>(OnTargetInteractDiseased);
SubscribeLocalEvent<DiseasedComponent, ContactInteractionEvent>(OnContactInteraction);
SubscribeLocalEvent<DiseasedComponent, EntitySpokeEvent>(OnEntitySpeak);
SubscribeLocalEvent<DiseaseProtectionComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<DiseaseProtectionComponent, GotUnequippedEvent>(OnUnequipped);
@@ -256,17 +255,9 @@ namespace Content.Server.Disease
/// <summary>
/// When a diseased person interacts with something, check infection.
/// </summary>
private void OnUserInteractDiseased(EntityUid uid, DiseasedComponent component, UserInteractedWithItemEvent args)
private void OnContactInteraction(EntityUid uid, DiseasedComponent component, ContactInteractionEvent args)
{
InteractWithDiseased(args.User, args.Item);
}
/// <summary>
/// When a diseased person is interacted with, check infection.
/// </summary>
private void OnTargetInteractDiseased(EntityUid uid, DiseasedComponent component, ItemInteractedWithEvent args)
{
InteractWithDiseased(args.Item, args.User);
InteractWithDiseased(uid, args.Other);
}
private void OnEntitySpeak(EntityUid uid, DiseasedComponent component, EntitySpokeEvent args)

View File

@@ -123,6 +123,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
Verb verb = new()
{
Act = () => TryInsert(component.Owner, args.User, args.User),
DoContactInteraction = true,
Text = Loc.GetString("disposal-self-insert-verb-get-data-text")
};
// TODO VERN ICON

View File

@@ -159,6 +159,7 @@ public sealed class SpillableSystem : EntitySystem
};
}
verb.Impact = LogImpact.Medium; // dangerous reagent reaction are logged separately.
verb.DoContactInteraction = true;
args.Verbs.Add(verb);
}

View File

@@ -1,5 +1,5 @@
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory;
using Content.Shared.Item;
using Robust.Shared.Random;
namespace Content.Server.Forensics
@@ -10,13 +10,13 @@ namespace Content.Server.Forensics
[Dependency] private readonly InventorySystem _inventory = default!;
public override void Initialize()
{
SubscribeLocalEvent<FingerprintComponent, UserInteractedWithItemEvent>(OnInteract);
SubscribeLocalEvent<FingerprintComponent, ContactInteractionEvent>(OnInteract);
SubscribeLocalEvent<FingerprintComponent, ComponentInit>(OnInit);
}
private void OnInteract(EntityUid uid, FingerprintComponent component, UserInteractedWithItemEvent args)
private void OnInteract(EntityUid uid, FingerprintComponent component, ContactInteractionEvent args)
{
ApplyEvidence(args.User, args.Item);
ApplyEvidence(uid, args.Other);
}
private void OnInit(EntityUid uid, FingerprintComponent component, ComponentInit args)

View File

@@ -303,6 +303,7 @@ namespace Content.Server.PneumaticCannon
Verb ejectItems = new();
ejectItems.Act = () => TryEjectAllItems(component, args.User);
ejectItems.Text = Loc.GetString("pneumatic-cannon-component-verb-eject-items-name");
ejectItems.DoContactInteraction = true;
args.Verbs.Add(ejectItems);
}

View File

@@ -24,6 +24,7 @@ namespace Content.Server.Rotatable
Verb verb = new();
verb.Act = () => TryFlip(component, args.User);
verb.Text = Loc.GetString("flippable-verb-get-data-text");
verb.DoContactInteraction = true;
// TODO VERB ICONS Add Uno reverse card style icon?
args.Verbs.Add(verb);
}
@@ -43,6 +44,7 @@ namespace Content.Server.Rotatable
Verb resetRotation = new ()
{
DoContactInteraction = true,
Act = () => EntityManager.GetComponent<TransformComponent>(component.Owner).LocalRotation = Angle.Zero,
Category = VerbCategory.Rotate,
IconTexture = "/Textures/Interface/VerbIcons/refresh.svg.192dpi.png",

View File

@@ -1,4 +1,4 @@
using Content.Server.DoAfter;
using Content.Server.DoAfter;
using Content.Server.Popups;
using Content.Server.Sticky.Components;
using Content.Server.Sticky.Events;
@@ -53,6 +53,7 @@ public sealed class StickySystem : EntitySystem
args.Verbs.Add(new Verb
{
DoContactInteraction = true,
Text = Loc.GetString("comp-sticky-unstick-verb-text"),
IconTexture = "/Textures/Interface/VerbIcons/eject.svg.192dpi.png",
Act = () => StartUnsticking(uid, args.User, component)

View File

@@ -84,17 +84,7 @@ namespace Content.Server.Verbs
// first, lets log the verb. Just in case it ends up crashing the server or something.
LogVerb(verb, user, target, forced);
// then 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, true);
else
RaiseLocalEvent(verb.ExecutionEventArgs);
}
base.ExecuteVerb(verb, user, target, forced);
}
public void LogVerb(Verb verb, EntityUid user, EntityUid target, bool forced)

View File

@@ -150,6 +150,13 @@ public sealed class MeleeWeaponSystem : SharedMeleeWeaponSystem
ev.Target.Value
};
_interaction.DoContactInteraction(ev.Weapon, ev.Target);
_interaction.DoContactInteraction(user, ev.Weapon);
// If the user is using a long-range weapon, this probably shouldn't be happening? But I'll interpret melee as a
// somewhat messy scuffle. See also, heavy attacks.
_interaction.DoContactInteraction(user, ev.Target);
// For stuff that cares about it being attacked.
RaiseLocalEvent(ev.Target.Value, new AttackedEvent(component.Owner, user, targetXform.Coordinates));
@@ -249,9 +256,17 @@ public sealed class MeleeWeaponSystem : SharedMeleeWeaponSystem
var modifiers = itemDamage.ModifiersList;
modifiers.AddRange(hitEvent.ModifiersList);
_interaction.DoContactInteraction(user, ev.Weapon);
// For stuff that cares about it being attacked.
foreach (var target in targets)
{
_interaction.DoContactInteraction(ev.Weapon, target);
// If the user is using a long-range weapon, this probably shouldn't be happening? But I'll interpret melee as a
// somewhat messy scuffle. See also, light attacks.
_interaction.DoContactInteraction(user, target);
RaiseLocalEvent(target, new AttackedEvent(component.Owner, user, Transform(target).Coordinates));
}
@@ -338,6 +353,8 @@ public sealed class MeleeWeaponSystem : SharedMeleeWeaponSystem
inTargetHand = targetHandsComponent.ActiveHand.HeldEntity!.Value;
}
_interaction.DoContactInteraction(user, ev.Target);
var attemptEvent = new DisarmAttemptEvent(target, user, inTargetHand);
if (inTargetHand != null)

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()
{