]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
UseInHandEvent cleanup (#35231)
authorslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Tue, 18 Feb 2025 12:27:30 +0000 (13:27 +0100)
committerGitHub <noreply@github.com>
Tue, 18 Feb 2025 12:27:30 +0000 (23:27 +1100)
Content.Server/Atmos/EntitySystems/GasAnalyzerSystem.cs
Content.Server/Holiday/Christmas/RandomGiftSystem.cs
Content.Server/Mousetrap/MousetrapSystem.cs
Content.Server/PAI/PAISystem.cs
Content.Server/Storage/EntitySystems/SpawnItemsOnUseSystem.cs
Content.Server/Storage/EntitySystems/SpawnTableOnUseSystem.cs
Content.Server/Teleportation/HandTeleporterSystem.cs
Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Magazine.cs
Content.Shared/Whistle/WhistleSystem.cs

index 81f0b96d0255adcc4e96595569a8d4a8f0b091f6..cc541e35e9a16399ae81f28026153b6874209c28 100644 (file)
@@ -76,14 +76,13 @@ public sealed class GasAnalyzerSystem : EntitySystem
     /// </summary>
     private void OnUseInHand(Entity<GasAnalyzerComponent> entity, ref UseInHandEvent args)
     {
+        // Not checking for Handled because ActivatableUISystem already marks it as such.
+
         if (!entity.Comp.Enabled)
-        {
             ActivateAnalyzer(entity, args.User);
-        }
         else
-        {
             DisableAnalyzer(entity, args.User);
-        }
+
         args.Handled = true;
     }
 
index 0816c2c36ce4c3430188e3ee81340d24c03716f0..559dc9856ebf1a7cc6a61061efae4d43b22cda61 100644 (file)
@@ -6,7 +6,6 @@ using Content.Shared.Interaction.Events;
 using Content.Shared.Item;
 using Content.Shared.Whitelist;
 using Robust.Server.Audio;
-using Robust.Server.GameObjects;
 using Robust.Shared.Map.Components;
 using Robust.Shared.Physics.Components;
 using Robust.Shared.Prototypes;
@@ -26,6 +25,7 @@ public sealed class RandomGiftSystem : EntitySystem
     [Dependency] private readonly IRobustRandom _random = default!;
     [Dependency] private readonly IAdminLogManager _adminLogger = default!;
     [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
+    [Dependency] private readonly SharedTransformSystem _transform = default!;
 
     private readonly List<string> _possibleGiftsSafe = new();
     private readonly List<string> _possibleGiftsUnsafe = new();
@@ -63,11 +63,16 @@ public sealed class RandomGiftSystem : EntitySystem
         if (component.Wrapper is not null)
             Spawn(component.Wrapper, coords);
 
-        args.Handled = true;
         _audio.PlayPvs(component.Sound, args.User);
-        Del(uid);
+
+        // Don't delete the entity in the event bus, so we queue it for deletion.
+        // We need the free hand for the new item, so we send it to nullspace.
+        _transform.DetachEntity(uid, Transform(uid));
+        QueueDel(uid);
+
         _hands.PickupOrDrop(args.User, handsEnt);
 
+        args.Handled = true;
     }
 
     private void OnGiftMapInit(EntityUid uid, RandomGiftComponent component, MapInitEvent args)
index e3aaab364dd8c94f12f7071853fbcbf68cfa83be..3afe858ce02415e1fd35c1ae694673953bc87f5c 100644 (file)
@@ -27,6 +27,9 @@ public sealed class MousetrapSystem : EntitySystem
 
     private void OnUseInHand(EntityUid uid, MousetrapComponent component, UseInHandEvent args)
     {
+        if (args.Handled)
+            return;
+
         component.IsActive = !component.IsActive;
         _popupSystem.PopupEntity(component.IsActive
             ? Loc.GetString("mousetrap-on-activate")
@@ -35,6 +38,8 @@ public sealed class MousetrapSystem : EntitySystem
             args.User);
 
         UpdateVisuals(uid);
+
+        args.Handled = true;
     }
 
     private void OnStepTriggerAttempt(EntityUid uid, MousetrapComponent component, ref StepTriggerAttemptEvent args)
index 0cdb0bc29a2dff7e6e19f5c7e5bf18dc1381bbbe..b0f4f2476d8a76c936d3eb5236be0c4731d7cccb 100644 (file)
@@ -37,6 +37,8 @@ public sealed class PAISystem : SharedPAISystem
 
     private void OnUseInHand(EntityUid uid, PAIComponent component, UseInHandEvent args)
     {
+        // Not checking for Handled because ToggleableGhostRoleSystem already marks it as such.
+
         if (!TryComp<MindContainerComponent>(uid, out var mind) || !mind.HasMind)
             component.LastUser = args.User;
     }
index 4c533ede3ad7ce01c4b36aada390b59e69b52f00..1fd617c539fb69d12875a33449c59dcffabc549b 100644 (file)
@@ -4,10 +4,8 @@ using Content.Server.Storage.Components;
 using Content.Shared.Database;
 using Content.Shared.Hands.EntitySystems;
 using Content.Shared.Interaction.Events;
-using Robust.Shared.Audio;
 using Robust.Shared.Audio.Systems;
 using Robust.Shared.Map;
-using Robust.Shared.Player;
 using Robust.Shared.Random;
 using static Content.Shared.Storage.EntitySpawnCollection;
 
@@ -20,6 +18,7 @@ namespace Content.Server.Storage.EntitySystems
         [Dependency] private readonly SharedHandsSystem _hands = default!;
         [Dependency] private readonly PricingSystem _pricing = default!;
         [Dependency] private readonly SharedAudioSystem _audio = default!;
+        [Dependency] private readonly SharedTransformSystem _transform = default!;
 
         public override void Initialize()
         {
@@ -80,26 +79,25 @@ namespace Content.Server.Storage.EntitySystems
                 _adminLogger.Add(LogType.EntitySpawn, LogImpact.Low, $"{ToPrettyString(args.User)} used {ToPrettyString(uid)} which spawned {ToPrettyString(entityToPlaceInHands.Value)}");
             }
 
+            // The entity is often deleted, so play the sound at its position rather than parenting
             if (component.Sound != null)
-            {
-                // The entity is often deleted, so play the sound at its position rather than parenting
-                var coordinates = Transform(uid).Coordinates;
-                _audio.PlayPvs(component.Sound, coordinates);
-            }
+                _audio.PlayPvs(component.Sound, coords);
 
             component.Uses--;
 
             // Delete entity only if component was successfully used
             if (component.Uses <= 0)
             {
-                args.Handled = true;
-                EntityManager.DeleteEntity(uid);
+                // Don't delete the entity in the event bus, so we queue it for deletion.
+                // We need the free hand for the new item, so we send it to nullspace.
+                _transform.DetachEntity(uid, Transform(uid));
+                QueueDel(uid);
             }
 
             if (entityToPlaceInHands != null)
-            {
                 _hands.PickupOrDrop(args.User, entityToPlaceInHands.Value);
-            }
+
+            args.Handled = true;
         }
     }
 }
index 96556ed7b25624a1d04e317a773b2fc2f493ce16..1f96b39a4e93ac0233b7d8205fc58686be6d33fc 100644 (file)
@@ -12,6 +12,7 @@ public sealed class SpawnTableOnUseSystem : EntitySystem
     [Dependency] private readonly EntityTableSystem _entityTable = default!;
     [Dependency] private readonly IAdminLogManager _adminLogger = default!;
     [Dependency] private readonly SharedHandsSystem _hands = default!;
+    [Dependency] private readonly SharedTransformSystem _transform = default!;
 
     public override void Initialize()
     {
@@ -25,17 +26,21 @@ public sealed class SpawnTableOnUseSystem : EntitySystem
         if (args.Handled)
             return;
 
-        args.Handled = true;
-
         var coords = Transform(ent).Coordinates;
         var spawns = _entityTable.GetSpawns(ent.Comp.Table);
+
+        // Don't delete the entity in the event bus, so we queue it for deletion.
+        // We need the free hand for the new item, so we send it to nullspace.
+        _transform.DetachEntity(ent, Transform(ent));
+        QueueDel(ent);
+
         foreach (var id in spawns)
         {
             var spawned = Spawn(id, coords);
             _adminLogger.Add(LogType.EntitySpawn, LogImpact.Low, $"{ToPrettyString(args.User):user} used {ToPrettyString(ent):spawner} which spawned {ToPrettyString(spawned)}");
-            _hands.TryPickupAnyHand(args.User, spawned);
+            _hands.PickupOrDrop(args.User, spawned);
         }
 
-        Del(ent);
+        args.Handled = true;
     }
 }
index 1cd2e1d8c25ce33eb45171de4defaf034ce6e4f9..78e881d76a05f4dc92c0ef575aba3657607b53ef 100644 (file)
@@ -41,6 +41,9 @@ public sealed class HandTeleporterSystem : EntitySystem
 
     private void OnUseInHand(EntityUid uid, HandTeleporterComponent component, UseInHandEvent args)
     {
+        if (args.Handled)
+            return;
+
         if (Deleted(component.FirstPortal))
             component.FirstPortal = null;
 
@@ -67,6 +70,8 @@ public sealed class HandTeleporterSystem : EntitySystem
 
             _doafter.TryStartDoAfter(doafterArgs);
         }
+
+        args.Handled = true;
     }
 
 
index 61a4820e5b3c76e9c5ce494e49dc4d6c6e6a7657..2876851d2d8df9bbd8a760dd10c69a32d34889aa 100644 (file)
@@ -38,6 +38,8 @@ public abstract partial class SharedGunSystem
 
     private void OnMagazineUse(EntityUid uid, MagazineAmmoProviderComponent component, UseInHandEvent args)
     {
+        // not checking for args.Handled or marking as such because we only relay the event to the magazine entity
+
         var magEnt = GetMagazineEntity(uid);
 
         if (magEnt == null)
index 9db7ffa0bf0b7943cea2d71054e7b7e1c1d046da..bbedffd8ecc448d2cd1d2ae30d00da1ce393a6a0 100644 (file)
@@ -27,11 +27,10 @@ public sealed class WhistleSystem : EntitySystem
 
     public void OnUseInHand(EntityUid uid, WhistleComponent component, UseInHandEvent args)
     {
-        if (!_timing.IsFirstTimePredicted)
+        if (args.Handled || !_timing.IsFirstTimePredicted)
             return;
 
-        TryMakeLoudWhistle(uid, args.User, component);
-        args.Handled = true;
+        args.Handled = TryMakeLoudWhistle(uid, args.User, component);
     }
 
     public bool TryMakeLoudWhistle(EntityUid uid, EntityUid owner, WhistleComponent? component = null)