From 05f9e6d28e06cc0974071d772a3a39fd3a9271ad Mon Sep 17 00:00:00 2001 From: beck-thompson <107373427+beck-thompson@users.noreply.github.com> Date: Sun, 13 Apr 2025 08:51:35 -0700 Subject: [PATCH] ID card computer bug fixed (And made it more fun!) (#32308) * First commit * More feature yay * comments * good * silly me * review --------- Co-authored-by: Milon --- .../Access/Systems/IdCardConsoleSystem.cs | 65 +++++++++++++++++-- .../components/id-card-console-component.ftl | 1 + .../Machines/Computers/computers.yml | 3 + .../Construction/Graphs/machines/computer.yml | 3 + 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/Content.Server/Access/Systems/IdCardConsoleSystem.cs b/Content.Server/Access/Systems/IdCardConsoleSystem.cs index a9e5d9a6d3..2d6e8a1238 100644 --- a/Content.Server/Access/Systems/IdCardConsoleSystem.cs +++ b/Content.Server/Access/Systems/IdCardConsoleSystem.cs @@ -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(UpdateUserInterface); SubscribeLocalEvent(UpdateUserInterface); SubscribeLocalEvent(UpdateUserInterface); + SubscribeLocalEvent(OnDamageChanged); + + // Intercept the event before anyone can do anything with it! + SubscribeLocalEvent(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 entity, ref MachineDeconstructedEvent args) + { + TryDropAndThrowIds(entity.AsNullable()); + } + + private void OnDamageChanged(Entity entity, ref DamageChangedEvent args) + { + if (TryDropAndThrowIds(entity.AsNullable())) + _chat.TrySendInGameICMessage(entity, Loc.GetString("id-card-console-damaged"), InGameICChatType.Speak, true); + } + + #region PublicAPI + + /// + /// 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. + /// + public bool TryDropAndThrowIds(Entity 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 } diff --git a/Resources/Locale/en-US/access/components/id-card-console-component.ftl b/Resources/Locale/en-US/access/components/id-card-console-component.ftl index be5d3f0bc3..7793b34846 100644 --- a/Resources/Locale/en-US/access/components/id-card-console-component.ftl +++ b/Resources/Locale/en-US/access/components/id-card-console-component.ftl @@ -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. diff --git a/Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml b/Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml index 4ee4c0de0a..0f502e83f0 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/Computers/computers.yml @@ -597,6 +597,9 @@ type: WiresBoundUserInterface - type: CrewManifestViewer ownerKey: enum.IdCardConsoleUiKey.Key + - type: Speech + speechVerb: Robotic + speechSounds: Pai - type: Sprite layers: - map: ["computerLayerBody"] diff --git a/Resources/Prototypes/Recipes/Construction/Graphs/machines/computer.yml b/Resources/Prototypes/Recipes/Construction/Graphs/machines/computer.yml index b3c9cac926..4530cef1b2 100644 --- a/Resources/Prototypes/Recipes/Construction/Graphs/machines/computer.yml +++ b/Resources/Prototypes/Recipes/Construction/Graphs/machines/computer.yml @@ -123,6 +123,9 @@ entity: !type:BoardNodeEntity { container: board } edges: - to: monitorUnsecured + completed: + - !type:RaiseEvent + event: !type:MachineDeconstructedEvent steps: - tool: Prying doAfter: 1 -- 2.51.2