]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix borg chassis gibbing not dropping items (#37276)
authorKrunklehorn <42424291+Krunklehorn@users.noreply.github.com>
Thu, 8 May 2025 14:28:11 +0000 (10:28 -0400)
committerGitHub <noreply@github.com>
Thu, 8 May 2025 14:28:11 +0000 (10:28 -0400)
BeingGibbedEvent and TryEjectPowerCell

Content.Server/Silicons/Borgs/BorgSystem.Ui.cs
Content.Server/Silicons/Borgs/BorgSystem.cs

index 9f9977cddc29abd1666803470241cabf26dc1b65..191b2264211d65232182b11ac5021d807208f11d 100644 (file)
@@ -40,15 +40,8 @@ public sealed partial class BorgSystem
 
     private void OnEjectBatteryBuiMessage(EntityUid uid, BorgChassisComponent component, BorgEjectBatteryBuiMessage args)
     {
-        if (!TryComp<PowerCellSlotComponent>(uid, out var slotComp) ||
-            !Container.TryGetContainer(uid, slotComp.CellSlotId, out var container) ||
-            !container.ContainedEntities.Any())
-        {
-            return;
-        }
-
-        var ents = Container.EmptyContainer(container);
-        _hands.TryPickupAnyHand(args.Actor, ents.First());
+        if (TryEjectPowerCell(uid, component, out var ents))
+            _hands.TryPickupAnyHand(args.Actor, ents.First());
     }
 
     private void OnSetNameBuiMessage(EntityUid uid, BorgChassisComponent component, BorgSetNameBuiMessage args)
index 7c096f17299a11f898cb87c04d1ea0610da582ff..e9d8a08c6f8df781fe7f16932feb3a5cadd19db3 100644 (file)
@@ -1,11 +1,13 @@
 using Content.Server.Actions;
 using Content.Server.Administration.Logs;
 using Content.Server.Administration.Managers;
+using Content.Server.Body.Components;
 using Content.Server.DeviceNetwork.Systems;
 using Content.Server.Explosion.EntitySystems;
 using Content.Server.Hands.Systems;
 using Content.Server.PowerCell;
 using Content.Shared.Alert;
+using Content.Shared.Containers.ItemSlots;
 using Content.Shared.Database;
 using Content.Shared.IdentityManagement;
 using Content.Shared.Interaction;
@@ -29,6 +31,8 @@ using Robust.Shared.Containers;
 using Robust.Shared.Player;
 using Robust.Shared.Random;
 using Robust.Shared.Timing;
+using System.Diagnostics.CodeAnalysis;
+using System.Linq;
 
 namespace Content.Server.Silicons.Borgs;
 
@@ -45,6 +49,7 @@ public sealed partial class BorgSystem : SharedBorgSystem
     [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
     [Dependency] private readonly TriggerSystem _trigger = default!;
     [Dependency] private readonly HandsSystem _hands = default!;
+    [Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
     [Dependency] private readonly MetaDataSystem _metaData = default!;
     [Dependency] private readonly SharedMindSystem _mind = default!;
     [Dependency] private readonly MobStateSystem _mobState = default!;
@@ -69,6 +74,7 @@ public sealed partial class BorgSystem : SharedBorgSystem
         SubscribeLocalEvent<BorgChassisComponent, MindAddedMessage>(OnMindAdded);
         SubscribeLocalEvent<BorgChassisComponent, MindRemovedMessage>(OnMindRemoved);
         SubscribeLocalEvent<BorgChassisComponent, MobStateChangedEvent>(OnMobStateChanged);
+        SubscribeLocalEvent<BorgChassisComponent, BeingGibbedEvent>(OnBeingGibbed);
         SubscribeLocalEvent<BorgChassisComponent, PowerCellChangedEvent>(OnPowerCellChanged);
         SubscribeLocalEvent<BorgChassisComponent, PowerCellSlotEmptyEvent>(OnPowerCellSlotEmpty);
         SubscribeLocalEvent<BorgChassisComponent, GetCharactedDeadIcEvent>(OnGetDeadIC);
@@ -195,6 +201,14 @@ public sealed partial class BorgSystem : SharedBorgSystem
         }
     }
 
+    private void OnBeingGibbed(EntityUid uid, BorgChassisComponent component, ref BeingGibbedEvent args)
+    {
+        TryEjectPowerCell(uid, component, out var _);
+
+        _container.EmptyContainer(component.BrainContainer);
+        _container.EmptyContainer(component.ModuleContainer);
+    }
+
     private void OnPowerCellChanged(EntityUid uid, BorgChassisComponent component, PowerCellChangedEvent args)
     {
         UpdateBatteryAlert((uid, component));
@@ -294,6 +308,20 @@ public sealed partial class BorgSystem : SharedBorgSystem
         _alerts.ShowAlert(ent, ent.Comp.BatteryAlert, chargePercent);
     }
 
+    public bool TryEjectPowerCell(EntityUid uid, BorgChassisComponent component, [NotNullWhen(true)] out List<EntityUid>? ents)
+    {
+        ents = null;
+
+        if (!TryComp<PowerCellSlotComponent>(uid, out var slotComp) ||
+            !Container.TryGetContainer(uid, slotComp.CellSlotId, out var container) ||
+            !container.ContainedEntities.Any())
+                return false;
+
+        ents = Container.EmptyContainer(container);
+
+        return true;
+    }
+
     /// <summary>
     /// Activates a borg when a player occupies it
     /// </summary>