]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Turn interaction related attempt events into structs (#29168)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Tue, 18 Jun 2024 14:30:41 +0000 (02:30 +1200)
committerGitHub <noreply@github.com>
Tue, 18 Jun 2024 14:30:41 +0000 (00:30 +1000)
* Turn InteractionAttemptEvent into a struct event

* readonly

* GettingInteractedWithAttemptEvent

* ConsciousAttemptEvent

13 files changed:
Content.Client/Interaction/DragDropSystem.cs
Content.Client/Replay/Spectator/ReplaySpectatorSystem.Blockers.cs
Content.Shared/ActionBlocker/ActionBlockerSystem.cs
Content.Shared/Administration/SharedAdminFrozenSystem.cs
Content.Shared/Bed/Sleep/SleepingSystem.cs
Content.Shared/Cuffs/SharedCuffableSystem.cs
Content.Shared/Ghost/SharedGhostSystem.cs
Content.Shared/Interaction/Events/InteractionAttemptEvent.cs
Content.Shared/Interaction/SharedInteractionSystem.Blocking.cs
Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs
Content.Shared/Puppet/SharedVentriloquistPuppetSystem.cs
Content.Shared/Stunnable/SharedStunSystem.cs
Content.Shared/SubFloor/SharedSubFloorHideSystem.cs

index 8baa4d15fe4b229d82a66cdab52de69334b857c8..d249766bbccaf46192c7d54540401dfdcd0d86b0 100644 (file)
@@ -495,7 +495,7 @@ public sealed class DragDropSystem : SharedDragDropSystem
         // CanInteract() doesn't support checking a second "target" entity.
         // Doing so manually:
         var ev = new GettingInteractedWithAttemptEvent(user, dragged);
-        RaiseLocalEvent(dragged, ev, true);
+        RaiseLocalEvent(dragged, ref ev);
 
         if (ev.Cancelled)
             return false;
index 2fa862f3df7f19067a99ca3a7b2140903f99c39e..99d85350b5e20586dc2dc6163f563742221658f1 100644 (file)
@@ -17,7 +17,7 @@ public sealed partial class ReplaySpectatorSystem
         SubscribeLocalEvent<ReplaySpectatorComponent, UseAttemptEvent>(OnAttempt);
         SubscribeLocalEvent<ReplaySpectatorComponent, PickupAttemptEvent>(OnAttempt);
         SubscribeLocalEvent<ReplaySpectatorComponent, ThrowAttemptEvent>(OnAttempt);
-        SubscribeLocalEvent<ReplaySpectatorComponent, InteractionAttemptEvent>(OnAttempt);
+        SubscribeLocalEvent<ReplaySpectatorComponent, InteractionAttemptEvent>(OnInteractAttempt);
         SubscribeLocalEvent<ReplaySpectatorComponent, AttackAttemptEvent>(OnAttempt);
         SubscribeLocalEvent<ReplaySpectatorComponent, DropAttemptEvent>(OnAttempt);
         SubscribeLocalEvent<ReplaySpectatorComponent, IsEquippingAttemptEvent>(OnAttempt);
@@ -27,6 +27,11 @@ public sealed partial class ReplaySpectatorSystem
         SubscribeLocalEvent<ReplaySpectatorComponent, PullAttemptEvent>(OnPullAttempt);
     }
 
+    private void OnInteractAttempt(Entity<ReplaySpectatorComponent> ent, ref InteractionAttemptEvent args)
+    {
+        args.Cancelled = true;
+    }
+
     private void OnAttempt(EntityUid uid, ReplaySpectatorComponent component, CancellableEntityEventArgs args)
     {
         args.Cancel();
index f1c77fda43b243831743e6f7e60e4a2651a2d090..005c7dc78ec75ef55779c9192bf67803cbe7e06e 100644 (file)
@@ -70,7 +70,7 @@ namespace Content.Shared.ActionBlocker
                 return false;
 
             var ev = new InteractionAttemptEvent(user, target);
-            RaiseLocalEvent(user, ev);
+            RaiseLocalEvent(user, ref ev);
 
             if (ev.Cancelled)
                 return false;
@@ -79,7 +79,7 @@ namespace Content.Shared.ActionBlocker
                 return true;
 
             var targetEv = new GettingInteractedWithAttemptEvent(user, target);
-            RaiseLocalEvent(target.Value, targetEv);
+            RaiseLocalEvent(target.Value, ref targetEv);
 
             return !targetEv.Cancelled;
         }
@@ -110,7 +110,7 @@ namespace Content.Shared.ActionBlocker
         public bool CanConsciouslyPerformAction(EntityUid user)
         {
             var ev = new ConsciousAttemptEvent(user);
-            RaiseLocalEvent(user, ev);
+            RaiseLocalEvent(user, ref ev);
 
             return !ev.Cancelled;
         }
index 2fa22e00052a154c89fecd365caa61f69d2bf0e6..259df2bdf2ac14359ee4d8de441104910b7b833b 100644 (file)
@@ -11,6 +11,7 @@ using Content.Shared.Throwing;
 
 namespace Content.Shared.Administration;
 
+// TODO deduplicate with BlockMovementComponent
 public abstract class SharedAdminFrozenSystem : EntitySystem
 {
     [Dependency] private readonly ActionBlockerSystem _blocker = default!;
@@ -23,7 +24,7 @@ public abstract class SharedAdminFrozenSystem : EntitySystem
         SubscribeLocalEvent<AdminFrozenComponent, UseAttemptEvent>(OnAttempt);
         SubscribeLocalEvent<AdminFrozenComponent, PickupAttemptEvent>(OnAttempt);
         SubscribeLocalEvent<AdminFrozenComponent, ThrowAttemptEvent>(OnAttempt);
-        SubscribeLocalEvent<AdminFrozenComponent, InteractionAttemptEvent>(OnAttempt);
+        SubscribeLocalEvent<AdminFrozenComponent, InteractionAttemptEvent>(OnInteractAttempt);
         SubscribeLocalEvent<AdminFrozenComponent, ComponentStartup>(OnStartup);
         SubscribeLocalEvent<AdminFrozenComponent, ComponentShutdown>(UpdateCanMove);
         SubscribeLocalEvent<AdminFrozenComponent, UpdateCanMoveEvent>(OnUpdateCanMove);
@@ -34,6 +35,11 @@ public abstract class SharedAdminFrozenSystem : EntitySystem
         SubscribeLocalEvent<AdminFrozenComponent, SpeakAttemptEvent>(OnSpeakAttempt);
     }
 
+    private void OnInteractAttempt(Entity<AdminFrozenComponent> ent, ref InteractionAttemptEvent args)
+    {
+        args.Cancelled = true;
+    }
+
     private void OnSpeakAttempt(EntityUid uid, AdminFrozenComponent component, SpeakAttemptEvent args)
     {
         if (!component.Muted)
index aac3e7bb18ccab15cb9b4e1e0df5edec0b82bf88..6008e301cfeef9efd14f07b8b27f58a5f0eb0e9b 100644 (file)
@@ -153,7 +153,7 @@ public sealed partial class SleepingSystem : EntitySystem
 
     private void OnConsciousAttempt(Entity<SleepingComponent> ent, ref ConsciousAttemptEvent args)
     {
-        args.Cancel();
+        args.Cancelled = true;
     }
 
     private void OnExamined(Entity<SleepingComponent> ent, ref ExaminedEvent args)
index 0e506f938e65af0f3fe37544a200f97f85b57276..be169deb0e5be7bd4d2a194584ec5114d96511e1 100644 (file)
@@ -79,7 +79,7 @@ namespace Content.Shared.Cuffs
             SubscribeLocalEvent<CuffableComponent, PickupAttemptEvent>(CheckAct);
             SubscribeLocalEvent<CuffableComponent, AttackAttemptEvent>(CheckAct);
             SubscribeLocalEvent<CuffableComponent, UseAttemptEvent>(CheckAct);
-            SubscribeLocalEvent<CuffableComponent, InteractionAttemptEvent>(CheckAct);
+            SubscribeLocalEvent<CuffableComponent, InteractionAttemptEvent>(CheckInteract);
 
             SubscribeLocalEvent<HandcuffComponent, AfterInteractEvent>(OnCuffAfterInteract);
             SubscribeLocalEvent<HandcuffComponent, MeleeHitEvent>(OnCuffMeleeHit);
@@ -87,6 +87,12 @@ namespace Content.Shared.Cuffs
             SubscribeLocalEvent<HandcuffComponent, VirtualItemDeletedEvent>(OnCuffVirtualItemDeleted);
         }
 
+        private void CheckInteract(Entity<CuffableComponent> ent, ref InteractionAttemptEvent args)
+        {
+            if (!ent.Comp.CanStillInteract)
+                args.Cancelled = true;
+        }
+
         private void OnUncuffAttempt(ref UncuffAttemptEvent args)
         {
             if (args.Cancelled)
index ad8b86f7ddab0b1fd29633d308d617ff5ee18002..6e62bee1310175a87bb49103de820f8d881b6226 100644 (file)
@@ -19,12 +19,18 @@ namespace Content.Shared.Ghost
         {
             base.Initialize();
             SubscribeLocalEvent<GhostComponent, UseAttemptEvent>(OnAttempt);
-            SubscribeLocalEvent<GhostComponent, InteractionAttemptEvent>(OnAttempt);
+            SubscribeLocalEvent<GhostComponent, InteractionAttemptEvent>(OnAttemptInteract);
             SubscribeLocalEvent<GhostComponent, EmoteAttemptEvent>(OnAttempt);
             SubscribeLocalEvent<GhostComponent, DropAttemptEvent>(OnAttempt);
             SubscribeLocalEvent<GhostComponent, PickupAttemptEvent>(OnAttempt);
         }
 
+        private void OnAttemptInteract(Entity<GhostComponent> ent, ref InteractionAttemptEvent args)
+        {
+            if (!ent.Comp.CanGhostInteract)
+                args.Cancelled = true;
+        }
+
         private void OnAttempt(EntityUid uid, GhostComponent component, CancellableEntityEventArgs args)
         {
             if (!component.CanGhostInteract)
index 0024811c369e53fcc1b267db8a729862b8833101..a04c0536354f0d43ce09dab528d970a98d9fde1c 100644 (file)
@@ -3,39 +3,33 @@
     /// <summary>
     ///     Event raised directed at a user to see if they can perform a generic interaction.
     /// </summary>
-    public sealed class InteractionAttemptEvent : CancellableEntityEventArgs
+    [ByRefEvent]
+    public struct InteractionAttemptEvent(EntityUid uid, EntityUid? target)
     {
-        public InteractionAttemptEvent(EntityUid uid, EntityUid? target)
-        {
-            Uid = uid;
-            Target = target;
-        }
-
-        public EntityUid Uid { get; }
-        public EntityUid? Target { get; }
+        public bool Cancelled;
+        public readonly EntityUid Uid = uid;
+        public readonly EntityUid? Target = target;
     }
 
     /// <summary>
     /// Raised to determine whether an entity is conscious to perform an action.
     /// </summary>
-    public sealed class ConsciousAttemptEvent(EntityUid Uid) : CancellableEntityEventArgs
+    [ByRefEvent]
+    public struct ConsciousAttemptEvent(EntityUid uid)
     {
-        public EntityUid Uid { get; } = Uid;
+        public bool Cancelled;
+        public readonly EntityUid Uid = uid;
     }
 
     /// <summary>
     ///     Event raised directed at the target entity of an interaction to see if the user is allowed to perform some
     ///     generic interaction.
     /// </summary>
-    public sealed class GettingInteractedWithAttemptEvent : CancellableEntityEventArgs
+    [ByRefEvent]
+    public struct GettingInteractedWithAttemptEvent(EntityUid uid, EntityUid? target)
     {
-        public GettingInteractedWithAttemptEvent(EntityUid uid, EntityUid? target)
-        {
-            Uid = uid;
-            Target = target;
-        }
-
-        public EntityUid Uid { get; }
-        public EntityUid? Target { get; }
+        public bool Cancelled;
+        public readonly EntityUid Uid = uid;
+        public readonly EntityUid? Target = target;
     }
 }
index 9a84789adfca125d1cf9d4f6a736a161a3c11fe3..a682bf981597c6bdaf1ae27c8d5639d57a2d0e90 100644 (file)
@@ -6,6 +6,7 @@ using Content.Shared.Movement.Events;
 
 namespace Content.Shared.Interaction;
 
+// TODO deduplicate with AdminFrozenComponent
 /// <summary>
 /// Handles <see cref="BlockMovementComponent"/>, which prevents various
 /// kinds of movement and interactions when attached to an entity.
@@ -16,7 +17,7 @@ public partial class SharedInteractionSystem
     {
         SubscribeLocalEvent<BlockMovementComponent, UpdateCanMoveEvent>(OnMoveAttempt);
         SubscribeLocalEvent<BlockMovementComponent, UseAttemptEvent>(CancelEvent);
-        SubscribeLocalEvent<BlockMovementComponent, InteractionAttemptEvent>(CancelEvent);
+        SubscribeLocalEvent<BlockMovementComponent, InteractionAttemptEvent>(CancelInteractEvent);
         SubscribeLocalEvent<BlockMovementComponent, DropAttemptEvent>(CancelEvent);
         SubscribeLocalEvent<BlockMovementComponent, PickupAttemptEvent>(CancelEvent);
         SubscribeLocalEvent<BlockMovementComponent, ChangeDirectionAttemptEvent>(CancelEvent);
@@ -25,6 +26,11 @@ public partial class SharedInteractionSystem
         SubscribeLocalEvent<BlockMovementComponent, ComponentShutdown>(OnBlockingShutdown);
     }
 
+    private void CancelInteractEvent(Entity<BlockMovementComponent> ent, ref InteractionAttemptEvent args)
+    {
+        args.Cancelled = true;
+    }
+
     private void OnMoveAttempt(EntityUid uid, BlockMovementComponent component, UpdateCanMoveEvent args)
     {
         if (component.LifeStage > ComponentLifeStage.Running)
index 08b351e61e85e7221dbf281bea1166d4d5e8c2a2..155cfede01578d1821c305f4f860461965374a4c 100644 (file)
@@ -31,7 +31,7 @@ public partial class MobStateSystem
         SubscribeLocalEvent<MobStateComponent, ChangeDirectionAttemptEvent>(CheckAct);
         SubscribeLocalEvent<MobStateComponent, UseAttemptEvent>(CheckAct);
         SubscribeLocalEvent<MobStateComponent, AttackAttemptEvent>(CheckAct);
-        SubscribeLocalEvent<MobStateComponent, ConsciousAttemptEvent>(CheckAct);
+        SubscribeLocalEvent<MobStateComponent, ConsciousAttemptEvent>(CheckConcious);
         SubscribeLocalEvent<MobStateComponent, ThrowAttemptEvent>(CheckAct);
         SubscribeLocalEvent<MobStateComponent, SpeakAttemptEvent>(OnSpeakAttempt);
         SubscribeLocalEvent<MobStateComponent, IsEquippingAttemptEvent>(OnEquipAttempt);
@@ -48,6 +48,17 @@ public partial class MobStateSystem
         SubscribeLocalEvent<MobStateComponent, AttemptPacifiedAttackEvent>(OnAttemptPacifiedAttack);
     }
 
+    private void CheckConcious(Entity<MobStateComponent> ent, ref ConsciousAttemptEvent args)
+    {
+        switch (ent.Comp.CurrentState)
+        {
+            case MobState.Dead:
+            case MobState.Critical:
+                args.Cancelled = true;
+                break;
+        }
+    }
+
     private void OnStateExitSubscribers(EntityUid target, MobStateComponent component, MobState state)
     {
         switch (state)
index 430c2b1b17d67516c5942dd4993471c8c89350e4..e3fa21ed3777e016b56cd461934b0585b41e306b 100644 (file)
@@ -7,6 +7,7 @@ using Content.Shared.Movement.Events;
 
 namespace Content.Shared.Puppet;
 
+// TODO deduplicate with BlockMovementComponent
 public abstract class SharedVentriloquistPuppetSystem : EntitySystem
 {
     [Dependency] private readonly ActionBlockerSystem _blocker = default!;
@@ -15,7 +16,7 @@ public abstract class SharedVentriloquistPuppetSystem : EntitySystem
     {
         base.Initialize();
         SubscribeLocalEvent<VentriloquistPuppetComponent, UseAttemptEvent>(Cancel);
-        SubscribeLocalEvent<VentriloquistPuppetComponent, InteractionAttemptEvent>(Cancel);
+        SubscribeLocalEvent<VentriloquistPuppetComponent, InteractionAttemptEvent>(CancelInteract);
         SubscribeLocalEvent<VentriloquistPuppetComponent, DropAttemptEvent>(Cancel);
         SubscribeLocalEvent<VentriloquistPuppetComponent, PickupAttemptEvent>(Cancel);
         SubscribeLocalEvent<VentriloquistPuppetComponent, UpdateCanMoveEvent>(Cancel);
@@ -24,6 +25,11 @@ public abstract class SharedVentriloquistPuppetSystem : EntitySystem
         SubscribeLocalEvent<VentriloquistPuppetComponent, ComponentStartup>(OnStartup);
     }
 
+    private void CancelInteract(Entity<VentriloquistPuppetComponent> ent, ref InteractionAttemptEvent args)
+    {
+        args.Cancelled = true;
+    }
+
     private void OnStartup(EntityUid uid, VentriloquistPuppetComponent component, ComponentStartup args)
     {
         _blocker.UpdateCanMove(uid);
@@ -33,4 +39,4 @@ public abstract class SharedVentriloquistPuppetSystem : EntitySystem
     {
         args.Cancel();
     }
-}
\ No newline at end of file
+}
index 9190427d3214860e0712032f0c2588f719cbee77..092da8fe5ab3960cfbfa7eed85b5f48393a57634 100644 (file)
@@ -54,7 +54,7 @@ public abstract class SharedStunSystem : EntitySystem
         // Attempt event subscriptions.
         SubscribeLocalEvent<StunnedComponent, ChangeDirectionAttemptEvent>(OnAttempt);
         SubscribeLocalEvent<StunnedComponent, UpdateCanMoveEvent>(OnMoveAttempt);
-        SubscribeLocalEvent<StunnedComponent, InteractionAttemptEvent>(OnAttempt);
+        SubscribeLocalEvent<StunnedComponent, InteractionAttemptEvent>(OnAttemptInteract);
         SubscribeLocalEvent<StunnedComponent, UseAttemptEvent>(OnAttempt);
         SubscribeLocalEvent<StunnedComponent, ThrowAttemptEvent>(OnAttempt);
         SubscribeLocalEvent<StunnedComponent, DropAttemptEvent>(OnAttempt);
@@ -65,7 +65,10 @@ public abstract class SharedStunSystem : EntitySystem
         SubscribeLocalEvent<MobStateComponent, MobStateChangedEvent>(OnMobStateChanged);
     }
 
-
+    private void OnAttemptInteract(Entity<StunnedComponent> ent, ref InteractionAttemptEvent args)
+    {
+        args.Cancelled = true;
+    }
 
     private void OnMobStateChanged(EntityUid uid, MobStateComponent component, MobStateChangedEvent args)
     {
index ba78ff651f59896a9cfee48ccf3f4d133384ead9..cebc84ecb93e615c883ee441d34995645f6effb0 100644 (file)
@@ -45,11 +45,11 @@ namespace Content.Shared.SubFloor
                 args.Cancelled = true;
         }
 
-        private void OnInteractionAttempt(EntityUid uid, SubFloorHideComponent component, GettingInteractedWithAttemptEvent args)
+        private void OnInteractionAttempt(EntityUid uid, SubFloorHideComponent component, ref GettingInteractedWithAttemptEvent args)
         {
             // No interactions with entities hidden under floor tiles.
             if (component.BlockInteractions && component.IsUnderCover)
-                args.Cancel();
+                args.Cancelled = true;
         }
 
         private void OnSubFloorStarted(EntityUid uid, SubFloorHideComponent component, ComponentStartup _)