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 <milonpl.git@proton.me>
This commit is contained in:
beck-thompson
2025-04-13 08:51:35 -07:00
committed by GitHub
parent 022a383a58
commit 05f9e6d28e
4 changed files with 68 additions and 4 deletions

View 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
}

View 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.

View File

@@ -597,6 +597,9 @@
type: WiresBoundUserInterface
- type: CrewManifestViewer
ownerKey: enum.IdCardConsoleUiKey.Key
- type: Speech
speechVerb: Robotic
speechSounds: Pai
- type: Sprite
layers:
- map: ["computerLayerBody"]

View File

@@ -123,6 +123,9 @@
entity: !type:BoardNodeEntity { container: board }
edges:
- to: monitorUnsecured
completed:
- !type:RaiseEvent
event: !type:MachineDeconstructedEvent
steps:
- tool: Prying
doAfter: 1