]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
ID card computer bug fixed (And made it more fun!) (#32308)
authorbeck-thompson <107373427+beck-thompson@users.noreply.github.com>
Sun, 13 Apr 2025 15:51:35 +0000 (08:51 -0700)
committerGitHub <noreply@github.com>
Sun, 13 Apr 2025 15:51:35 +0000 (17:51 +0200)
* First commit

* More feature yay

* comments

* good

* silly me

* review

---------

Co-authored-by: Milon <milonpl.git@proton.me>
Content.Server/Access/Systems/IdCardConsoleSystem.cs
Resources/Locale/en-US/access/components/id-card-console-component.ftl
Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml
Resources/Prototypes/Recipes/Construction/Graphs/machines/computer.yml

index a9e5d9a6d3ef2c43ac42306fe2366001860f8ca3..2d6e8a1238c66ff3e51ed4c6451a7c2a467b7b39 100644 (file)
@@ -1,18 +1,24 @@
+using System.Linq;
+using Content.Server.Chat.Systems;
+using Content.Server.Containers;
 using Content.Server.StationRecords.Systems;
 using Content.Shared.Access.Components;
+using static Content.Shared.Access.Components.IdCardConsoleComponent;
 using Content.Shared.Access.Systems;
+using Content.Shared.Access;
 using Content.Shared.Administration.Logs;
+using Content.Shared.Construction;
+using Content.Shared.Containers.ItemSlots;
+using Content.Shared.Damage;
 using Content.Shared.Database;
 using Content.Shared.Roles;
 using Content.Shared.StationRecords;
-using Content.Shared.StatusIcon;
+using Content.Shared.Throwing;
 using JetBrains.Annotations;
 using Robust.Server.GameObjects;
 using Robust.Shared.Containers;
 using Robust.Shared.Prototypes;
-using System.Linq;
-using static Content.Shared.Access.Components.IdCardConsoleComponent;
-using Content.Shared.Access;
+using Robust.Shared.Random;
 
 namespace Content.Server.Access.Systems;
 
@@ -26,6 +32,10 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
     [Dependency] private readonly AccessSystem _access = default!;
     [Dependency] private readonly IdCardSystem _idCard = default!;
     [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
+    [Dependency] private readonly SharedContainerSystem _container = default!;
+    [Dependency] private readonly ThrowingSystem _throwing = default!;
+    [Dependency] private readonly IRobustRandom _random = default!;
+    [Dependency] private readonly ChatSystem _chat = default!;
 
     public override void Initialize()
     {
@@ -37,6 +47,11 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
         SubscribeLocalEvent<IdCardConsoleComponent, ComponentStartup>(UpdateUserInterface);
         SubscribeLocalEvent<IdCardConsoleComponent, EntInsertedIntoContainerMessage>(UpdateUserInterface);
         SubscribeLocalEvent<IdCardConsoleComponent, EntRemovedFromContainerMessage>(UpdateUserInterface);
+        SubscribeLocalEvent<IdCardConsoleComponent, DamageChangedEvent>(OnDamageChanged);
+
+        // Intercept the event before anyone can do anything with it!
+        SubscribeLocalEvent<IdCardConsoleComponent, MachineDeconstructedEvent>(OnMachineDeconstructed,
+            before: [typeof(EmptyOnMachineDeconstructSystem), typeof(ItemSlotsSystem)]);
     }
 
     private void OnWriteToTargetIdMessage(EntityUid uid, IdCardConsoleComponent component, WriteToTargetIdMessage args)
@@ -210,4 +225,46 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem
 
         _record.Synchronize(key);
     }
+
+    private void OnMachineDeconstructed(Entity<IdCardConsoleComponent> entity, ref MachineDeconstructedEvent args)
+    {
+        TryDropAndThrowIds(entity.AsNullable());
+    }
+
+    private void OnDamageChanged(Entity<IdCardConsoleComponent> entity, ref DamageChangedEvent args)
+    {
+        if (TryDropAndThrowIds(entity.AsNullable()))
+            _chat.TrySendInGameICMessage(entity, Loc.GetString("id-card-console-damaged"), InGameICChatType.Speak, true);
+    }
+
+    #region PublicAPI
+
+    /// <summary>
+    ///     Tries to drop any IDs stored in the console, and then tries to throw them away.
+    ///     Returns true if anything was ejected and false otherwise.
+    /// </summary>
+    public bool TryDropAndThrowIds(Entity<IdCardConsoleComponent?, ItemSlotsComponent?> ent)
+    {
+        if (!Resolve(ent, ref ent.Comp1, ref ent.Comp2))
+            return false;
+
+        var didEject = false;
+
+        foreach (var slot in ent.Comp2.Slots.Values)
+        {
+            if (slot.Item == null || slot.ContainerSlot == null)
+                continue;
+
+            var item = slot.Item.Value;
+            if (_container.Remove(item, slot.ContainerSlot))
+            {
+                _throwing.TryThrow(item, _random.NextVector2(), baseThrowSpeed: 5f);
+                didEject = true;
+            }
+        }
+
+        return didEject;
+    }
+
+    #endregion
 }
index be5d3f0bc3ac9f12320b51502088134cdd794195..7793b34846ba4f9923ae2a074fa698e782a21743 100644 (file)
@@ -10,3 +10,4 @@ id-card-console-window-job-selection-label = Job presets (sets department and jo
 access-id-card-console-component-no-hands-error = You have no hands.
 id-card-console-privileged-id = Privileged ID
 id-card-console-target-id = Target ID
+id-card-console-damaged = Structural integrity compromised, ejecting contents.
index 4ee4c0de0a03d6f803aa9e98a20073ca7ed7a144..0f502e83f0af88ccf408d0c89a210048a5d7d085 100644 (file)
         type: WiresBoundUserInterface
   - type: CrewManifestViewer
     ownerKey: enum.IdCardConsoleUiKey.Key
+  - type: Speech
+    speechVerb: Robotic
+    speechSounds: Pai
   - type: Sprite
     layers:
     - map: ["computerLayerBody"]
index b3c9cac926226d53900f0a0d4a59d430b4440261..4530cef1b2c43300d866f4b342b6e262861c02dd 100644 (file)
       entity: !type:BoardNodeEntity { container: board }
       edges:
         - to: monitorUnsecured
+          completed:
+            - !type:RaiseEvent
+                event: !type:MachineDeconstructedEvent
           steps:
             - tool: Prying
               doAfter: 1