From c0b657ca185aa73dc78b138b9f39bdfe17f6a2b9 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Wed, 26 Oct 2022 14:15:48 +1300 Subject: [PATCH] Remove InteractedWithEvent and friends. (#11939) --- Content.Client/Verbs/VerbSystem.cs | 15 ------- Content.Server/Cuffs/CuffableSystem.cs | 1 + Content.Server/Disease/DiseaseSystem.cs | 17 ++------ .../Unit/EntitySystems/DisposalUnitSystem.cs | 1 + .../Fluids/EntitySystems/SpillableSystem.cs | 1 + .../Forensics/Systems/ForensicsSystem.cs | 8 ++-- .../PneumaticCannon/PneumaticCannonSystem.cs | 1 + Content.Server/Rotatable/RotatableSystem.cs | 2 + Content.Server/Sticky/Systems/StickySystem.cs | 3 +- Content.Server/Verbs/VerbSystem.cs | 12 +----- .../Weapons/Melee/MeleeWeaponSystem.cs | 17 ++++++++ .../ActionBlocker/ActionBlockerSystem.cs | 15 ------- .../Events/ContactInteractionEvent.cs | 17 ++++++++ .../Interaction/SharedInteractionSystem.cs | 43 ++++++++++++++++++- .../Item/ItemInteractedWithEvent.cs | 17 -------- Content.Shared/Item/SharedItemSystem.cs | 9 ++-- .../Item/UserInteractedWithItemEvent.cs | 17 -------- .../Systems/SharedPullingSystem.Actions.cs | 4 ++ .../Pulling/Systems/SharedPullingSystem.cs | 2 + Content.Shared/Verbs/SharedVerbSystem.cs | 19 +++++++- Content.Shared/Verbs/Verb.cs | 13 ++++++ 21 files changed, 133 insertions(+), 101 deletions(-) create mode 100644 Content.Shared/Interaction/Events/ContactInteractionEvent.cs delete mode 100644 Content.Shared/Item/ItemInteractedWithEvent.cs delete mode 100644 Content.Shared/Item/UserInteractedWithItemEvent.cs diff --git a/Content.Client/Verbs/VerbSystem.cs b/Content.Client/Verbs/VerbSystem.cs index 99a28040a9..ce158af506 100644 --- a/Content.Client/Verbs/VerbSystem.cs +++ b/Content.Client/Verbs/VerbSystem.cs @@ -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) diff --git a/Content.Server/Cuffs/CuffableSystem.cs b/Content.Server/Cuffs/CuffableSystem.cs index 50410f44f0..fae5113d20 100644 --- a/Content.Server/Cuffs/CuffableSystem.cs +++ b/Content.Server/Cuffs/CuffableSystem.cs @@ -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? diff --git a/Content.Server/Disease/DiseaseSystem.cs b/Content.Server/Disease/DiseaseSystem.cs index c3ad5389e5..8d6f1b37fb 100644 --- a/Content.Server/Disease/DiseaseSystem.cs +++ b/Content.Server/Disease/DiseaseSystem.cs @@ -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(OnInit); SubscribeLocalEvent(OnTryCureDisease); SubscribeLocalEvent(OnRejuvenate); - SubscribeLocalEvent(OnUserInteractDiseased); - SubscribeLocalEvent(OnTargetInteractDiseased); + SubscribeLocalEvent(OnContactInteraction); SubscribeLocalEvent(OnEntitySpeak); SubscribeLocalEvent(OnEquipped); SubscribeLocalEvent(OnUnequipped); @@ -256,17 +255,9 @@ namespace Content.Server.Disease /// /// When a diseased person interacts with something, check infection. /// - private void OnUserInteractDiseased(EntityUid uid, DiseasedComponent component, UserInteractedWithItemEvent args) + private void OnContactInteraction(EntityUid uid, DiseasedComponent component, ContactInteractionEvent args) { - InteractWithDiseased(args.User, args.Item); - } - - /// - /// When a diseased person is interacted with, check infection. - /// - 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) diff --git a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs index 6b8488cb08..3b1543dc2b 100644 --- a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs +++ b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs @@ -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 diff --git a/Content.Server/Fluids/EntitySystems/SpillableSystem.cs b/Content.Server/Fluids/EntitySystems/SpillableSystem.cs index b862678e29..963e0dd8e0 100644 --- a/Content.Server/Fluids/EntitySystems/SpillableSystem.cs +++ b/Content.Server/Fluids/EntitySystems/SpillableSystem.cs @@ -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); } diff --git a/Content.Server/Forensics/Systems/ForensicsSystem.cs b/Content.Server/Forensics/Systems/ForensicsSystem.cs index b1b67fb476..e122ea4555 100644 --- a/Content.Server/Forensics/Systems/ForensicsSystem.cs +++ b/Content.Server/Forensics/Systems/ForensicsSystem.cs @@ -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(OnInteract); + SubscribeLocalEvent(OnInteract); SubscribeLocalEvent(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) diff --git a/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs b/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs index e7b808f5b9..02bbae9316 100644 --- a/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs +++ b/Content.Server/PneumaticCannon/PneumaticCannonSystem.cs @@ -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); } diff --git a/Content.Server/Rotatable/RotatableSystem.cs b/Content.Server/Rotatable/RotatableSystem.cs index 2db571a27b..abfa4c53b3 100644 --- a/Content.Server/Rotatable/RotatableSystem.cs +++ b/Content.Server/Rotatable/RotatableSystem.cs @@ -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(component.Owner).LocalRotation = Angle.Zero, Category = VerbCategory.Rotate, IconTexture = "/Textures/Interface/VerbIcons/refresh.svg.192dpi.png", diff --git a/Content.Server/Sticky/Systems/StickySystem.cs b/Content.Server/Sticky/Systems/StickySystem.cs index 4905c797b3..50f873a183 100644 --- a/Content.Server/Sticky/Systems/StickySystem.cs +++ b/Content.Server/Sticky/Systems/StickySystem.cs @@ -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) diff --git a/Content.Server/Verbs/VerbSystem.cs b/Content.Server/Verbs/VerbSystem.cs index fbc8b5e4f9..f00a0f60c1 100644 --- a/Content.Server/Verbs/VerbSystem.cs +++ b/Content.Server/Verbs/VerbSystem.cs @@ -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) diff --git a/Content.Server/Weapons/Melee/MeleeWeaponSystem.cs b/Content.Server/Weapons/Melee/MeleeWeaponSystem.cs index eeb2bd4947..b9ba62da4b 100644 --- a/Content.Server/Weapons/Melee/MeleeWeaponSystem.cs +++ b/Content.Server/Weapons/Melee/MeleeWeaponSystem.cs @@ -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) diff --git a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs index b875ba0260..de6eb0e5b2 100644 --- a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs +++ b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs @@ -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); - } } } diff --git a/Content.Shared/Interaction/Events/ContactInteractionEvent.cs b/Content.Shared/Interaction/Events/ContactInteractionEvent.cs new file mode 100644 index 0000000000..c9d5fba2ed --- /dev/null +++ b/Content.Shared/Interaction/Events/ContactInteractionEvent.cs @@ -0,0 +1,17 @@ +namespace Content.Shared.Interaction.Events; + +/// +/// Raised directed at two entities to indicate that they came into contact, usually as a result of some other interaction. +/// +/// +/// This is currently used by the forensics and disease systems to perform on-contact interactions. +/// +public sealed class ContactInteractionEvent : HandledEntityEventArgs +{ + public readonly EntityUid Other; + + public ContactInteractionEvent(EntityUid other) + { + Other = other; + } +} diff --git a/Content.Shared/Interaction/SharedInteractionSystem.cs b/Content.Shared/Interaction/SharedInteractionSystem.cs index 701a24dfc7..6be9761a9e 100644 --- a/Content.Shared/Interaction/SharedInteractionSystem.cs +++ b/Content.Shared/Interaction/SharedInteractionSystem.cs @@ -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; } + + /// + /// Simple convenience function to raise contact events (disease, forensics, etc). + /// + 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)); + } } /// diff --git a/Content.Shared/Item/ItemInteractedWithEvent.cs b/Content.Shared/Item/ItemInteractedWithEvent.cs deleted file mode 100644 index 28611d291a..0000000000 --- a/Content.Shared/Item/ItemInteractedWithEvent.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Content.Shared.Item; - -/// -/// 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. -/// -public sealed class ItemInteractedWithEvent : EntityEventArgs -{ - public EntityUid User; - public EntityUid Item; - public ItemInteractedWithEvent(EntityUid user, EntityUid item) - { - User = user; - Item = item; - } -} diff --git a/Content.Shared/Item/SharedItemSystem.cs b/Content.Shared/Item/SharedItemSystem.cs index d779e8028e..648ce1a31d 100644 --- a/Content.Shared/Item/SharedItemSystem.cs +++ b/Content.Shared/Item/SharedItemSystem.cs @@ -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. diff --git a/Content.Shared/Item/UserInteractedWithItemEvent.cs b/Content.Shared/Item/UserInteractedWithItemEvent.cs deleted file mode 100644 index 0d88348727..0000000000 --- a/Content.Shared/Item/UserInteractedWithItemEvent.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Content.Shared.Item; - -/// -/// 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. -/// -public sealed class UserInteractedWithItemEvent : EntityEventArgs -{ - public EntityUid User; - public EntityUid Item; - public UserInteractedWithItemEvent(EntityUid user, EntityUid item) - { - User = user; - Item = item; - } -} diff --git a/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs b/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs index bdd3767119..52bd4fb059 100644 --- a/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs +++ b/Content.Shared/Pulling/Systems/SharedPullingSystem.Actions.cs @@ -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; diff --git a/Content.Shared/Pulling/Systems/SharedPullingSystem.cs b/Content.Shared/Pulling/Systems/SharedPullingSystem.cs index 9835525b78..c655687a7c 100644 --- a/Content.Shared/Pulling/Systems/SharedPullingSystem.cs +++ b/Content.Shared/Pulling/Systems/SharedPullingSystem.cs @@ -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); } } diff --git a/Content.Shared/Verbs/SharedVerbSystem.cs b/Content.Shared/Verbs/SharedVerbSystem.cs index 3e470a00a2..36d3055ff5 100644 --- a/Content.Shared/Verbs/SharedVerbSystem.cs +++ b/Content.Shared/Verbs/SharedVerbSystem.cs @@ -154,6 +154,23 @@ namespace Content.Shared.Verbs /// /// This will try to call the action delegates and raise the local events for the given verb. /// - 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); + } } } diff --git a/Content.Shared/Verbs/Verb.cs b/Content.Shared/Verbs/Verb.cs index 587b1ea122..a47af80856 100644 --- a/Content.Shared/Verbs/Verb.cs +++ b/Content.Shared/Verbs/Verb.cs @@ -146,6 +146,15 @@ namespace Content.Shared.Verbs /// public bool ConfirmationPopup = false; + /// + /// If true, this verb will raise s when executed. If not explicitly + /// specified, this will just default to raising the event if is + /// true and the user is in range. + /// + public bool? DoContactInteraction; + + public virtual bool DefaultDoContactInteraction => false; + /// /// Compares two verbs based on their , , , /// and . @@ -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() {