]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix uncuffing for zombies (#21021)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Mon, 16 Oct 2023 05:31:03 +0000 (01:31 -0400)
committerGitHub <noreply@github.com>
Mon, 16 Oct 2023 05:31:03 +0000 (23:31 -0600)
Content.Shared/Cuffs/SharedCuffableSystem.cs

index d64e15799dcc40288d975a6af989c1da7a8eff84..4951bb7f1cb410b92aae53dbb7e79b5cfa3eb12e 100644 (file)
@@ -3,6 +3,7 @@ using Content.Shared.ActionBlocker;
 using Content.Shared.Administration.Components;
 using Content.Shared.Administration.Logs;
 using Content.Shared.Alert;
+using Content.Shared.Atmos.Piping.Unary.Components;
 using Content.Shared.Buckle.Components;
 using Content.Shared.Cuffs.Components;
 using Content.Shared.Damage;
@@ -85,6 +86,7 @@ namespace Content.Shared.Cuffs
             SubscribeLocalEvent<HandcuffComponent, AfterInteractEvent>(OnCuffAfterInteract);
             SubscribeLocalEvent<HandcuffComponent, MeleeHitEvent>(OnCuffMeleeHit);
             SubscribeLocalEvent<HandcuffComponent, AddCuffDoAfterEvent>(OnAddCuffDoAfter);
+            SubscribeLocalEvent<HandcuffComponent, VirtualItemDeletedEvent>(OnCuffVirtualItemDeleted);
         }
 
         private void OnUncuffAttempt(ref UncuffAttemptEvent args)
@@ -163,7 +165,7 @@ namespace Content.Shared.Cuffs
                 return;
 
             component.CanStillInteract = canInteract;
-            Dirty(component);
+            Dirty(uid, component);
             _actionBlocker.UpdateCanMove(uid);
 
             if (component.CanStillInteract)
@@ -350,7 +352,11 @@ namespace Content.Shared.Cuffs
                         ("otherName", Identity.Name(user, EntityManager, target))), target, target);
                 }
             }
+        }
 
+        private void OnCuffVirtualItemDeleted(EntityUid uid, HandcuffComponent component, VirtualItemDeletedEvent args)
+        {
+            Uncuff(args.User, null, uid, cuff: component);
         }
 
         /// <summary>
@@ -543,7 +549,7 @@ namespace Content.Shared.Cuffs
             {
                 if (!cuffable.Container.ContainedEntities.Contains(cuffsToRemove.Value))
                 {
-                    Logger.Warning("A user is trying to remove handcuffs that aren't in the owner's container. This should never happen!");
+                    Log.Warning("A user is trying to remove handcuffs that aren't in the owner's container. This should never happen!");
                 }
             }
 
@@ -608,21 +614,23 @@ namespace Content.Shared.Cuffs
             _audio.PlayPredicted(isOwner ? cuff.StartBreakoutSound : cuff.StartUncuffSound, target, user);
         }
 
-        public void Uncuff(EntityUid target, EntityUid user, EntityUid cuffsToRemove, CuffableComponent? cuffable = null, HandcuffComponent? cuff = null)
+        public void Uncuff(EntityUid target, EntityUid? user, EntityUid cuffsToRemove, CuffableComponent? cuffable = null, HandcuffComponent? cuff = null)
         {
             if (!Resolve(target, ref cuffable) || !Resolve(cuffsToRemove, ref cuff))
                 return;
 
-            var attempt = new UncuffAttemptEvent(user, target);
-            RaiseLocalEvent(user, ref attempt);
-            if (attempt.Cancelled)
-                return;
+            if (user != null)
+            {
+                var attempt = new UncuffAttemptEvent(user.Value, target);
+                RaiseLocalEvent(user.Value, ref attempt);
+                if (attempt.Cancelled)
+                    return;
+            }
 
             _audio.PlayPredicted(cuff.EndUncuffSound, target, user);
 
             cuffable.Container.Remove(cuffsToRemove);
 
-
             if (_net.IsServer)
             {
                 // Handles spawning broken cuffs on server to avoid client misprediction
@@ -640,12 +648,13 @@ namespace Content.Shared.Cuffs
                 // Only play popups on server because popups suck
                 if (cuffable.CuffedHandCount == 0)
                 {
-                    _popup.PopupEntity(Loc.GetString("cuffable-component-remove-cuffs-success-message"), user, user);
+                    if (user != null)
+                        _popup.PopupEntity(Loc.GetString("cuffable-component-remove-cuffs-success-message"), user.Value, user.Value);
 
-                    if (target != user)
+                    if (target != user && user != null)
                     {
                         _popup.PopupEntity(Loc.GetString("cuffable-component-remove-cuffs-by-other-success-message",
-                            ("otherName", Identity.Name(user, EntityManager, user))), target, target);
+                            ("otherName", Identity.Name(user.Value, EntityManager, user))), target, target);
                         _adminLog.Add(LogType.Action, LogImpact.Medium,
                             $"{ToPrettyString(user):player} has successfully uncuffed {ToPrettyString(target):player}");
                     }
@@ -655,22 +664,22 @@ namespace Content.Shared.Cuffs
                             $"{ToPrettyString(user):player} has successfully uncuffed themselves");
                     }
                 }
-                else
+                else if (user != null)
                 {
                     if (user != target)
                     {
                         _popup.PopupEntity(Loc.GetString("cuffable-component-remove-cuffs-partial-success-message",
                             ("cuffedHandCount", cuffable.CuffedHandCount),
-                            ("otherName", Identity.Name(user, EntityManager, user))), user, user);
+                            ("otherName", Identity.Name(user.Value, EntityManager, user.Value))), user.Value, user.Value);
                         _popup.PopupEntity(Loc.GetString(
                             "cuffable-component-remove-cuffs-by-other-partial-success-message",
-                            ("otherName", Identity.Name(user, EntityManager, user)),
+                            ("otherName", Identity.Name(user.Value, EntityManager, user.Value)),
                             ("cuffedHandCount", cuffable.CuffedHandCount)), target, target);
                     }
                     else
                     {
                         _popup.PopupEntity(Loc.GetString("cuffable-component-remove-cuffs-partial-success-message",
-                            ("cuffedHandCount", cuffable.CuffedHandCount)), user, user);
+                            ("cuffedHandCount", cuffable.CuffedHandCount)), user.Value, user.Value);
                     }
                 }
             }