]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Can emag artifact crusher (#23957)
authorSpeltIncorrectyl <66873282+SpeltIncorrectyl@users.noreply.github.com>
Fri, 19 Jan 2024 15:35:02 +0000 (15:35 +0000)
committerGitHub <noreply@github.com>
Fri, 19 Jan 2024 15:35:02 +0000 (10:35 -0500)
* initial commit

* made it emaggable

* removed OnAttemptEmagEvent

* moved emagging to shared

* added local file to git

Content.Server/Xenoarchaeology/Equipment/Systems/ArtifactCrusherSystem.cs
Content.Shared/Xenoarchaeology/Equipment/ArtifactCrusherComponent.cs
Content.Shared/Xenoarchaeology/Equipment/SharedArtifactCrusherSystem.cs
Resources/Locale/en-US/artifacts/artifact-crusher.ftl [new file with mode: 0644]

index 7d6f2785c67f1cc69ecfde798c301da255f3a5b0..09fdc260d7cd4ee0c1784b9f5b9b94bddd3f68d0 100644 (file)
@@ -1,4 +1,5 @@
 using Content.Server.Body.Systems;
+using Content.Server.Popups;
 using Content.Server.Power.Components;
 using Content.Server.Power.EntitySystems;
 using Content.Server.Stack;
@@ -23,6 +24,7 @@ public sealed class ArtifactCrusherSystem : SharedArtifactCrusherSystem
     [Dependency] private readonly BodySystem _body = default!;
     [Dependency] private readonly DamageableSystem _damageable = default!;
     [Dependency] private readonly StackSystem _stack = default!;
+    [Dependency] private readonly PopupSystem _popup = default!;
 
     /// <inheritdoc/>
     public override void Initialize()
@@ -38,7 +40,8 @@ public sealed class ArtifactCrusherSystem : SharedArtifactCrusherSystem
         if (!args.CanAccess || !args.CanInteract || args.Hands == null || ent.Comp.Crushing)
             return;
 
-        if (!TryComp<EntityStorageComponent>(ent, out var entityStorageComp) || entityStorageComp.Contents.ContainedEntities.Count == 0)
+        if (!TryComp<EntityStorageComponent>(ent, out var entityStorageComp) ||
+            entityStorageComp.Contents.ContainedEntities.Count == 0)
             return;
 
         if (!this.IsPowered(ent, EntityManager))
@@ -61,11 +64,14 @@ public sealed class ArtifactCrusherSystem : SharedArtifactCrusherSystem
 
     public void StartCrushing(Entity<ArtifactCrusherComponent, EntityStorageComponent> ent)
     {
-        var (_, crusher, _) = ent;
+        var (uid, crusher, _) = ent;
 
         if (crusher.Crushing)
             return;
 
+        if (crusher.AutoLock)
+            _popup.PopupEntity(Loc.GetString("artifact-crusher-autolocks-enable"), uid);
+
         crusher.Crushing = true;
         crusher.NextSecond = _timing.CurTime + TimeSpan.FromSeconds(1);
         crusher.CrushEndTime = _timing.CurTime + crusher.CrushDuration;
index 687b29f2083381558735e2783a57075040657b6c..e21cedb6f9a7a9b262e05e2854427fe8ed0af922 100644 (file)
@@ -101,6 +101,12 @@ public sealed partial class ArtifactCrusherComponent : Component
     /// </summary>
     [DataField]
     public (EntityUid, AudioComponent)? CrushingSoundEntity;
+
+    /// <summary>
+    /// When enabled, stops the artifact crusher from being opened when it is being crushed.
+    /// </summary>
+    [DataField, AutoNetworkedField, ViewVariables(VVAccess.ReadWrite)]
+    public bool AutoLock = false;
 }
 
 [Serializable, NetSerializable]
index 44e1b91a90639fd1aa3386416d9b62cbcb502d8c..da253ba80afc4c1508da2a5cc5e70e9af017a4bb 100644 (file)
@@ -1,6 +1,8 @@
+using Content.Shared.Examine;
 using Content.Shared.Storage.Components;
 using Robust.Shared.Audio.Systems;
 using Robust.Shared.Containers;
+using Content.Shared.Emag.Systems;
 
 namespace Content.Shared.Xenoarchaeology.Equipment;
 
@@ -20,6 +22,9 @@ public abstract class SharedArtifactCrusherSystem : EntitySystem
 
         SubscribeLocalEvent<ArtifactCrusherComponent, ComponentInit>(OnInit);
         SubscribeLocalEvent<ArtifactCrusherComponent, StorageAfterOpenEvent>(OnStorageAfterOpen);
+        SubscribeLocalEvent<ArtifactCrusherComponent, StorageOpenAttemptEvent>(OnStorageOpenAttempt);
+        SubscribeLocalEvent<ArtifactCrusherComponent, ExaminedEvent>(OnExamine);
+        SubscribeLocalEvent<ArtifactCrusherComponent, GotEmaggedEvent>(OnEmagged);
     }
 
     private void OnInit(Entity<ArtifactCrusherComponent> ent, ref ComponentInit args)
@@ -33,6 +38,23 @@ public abstract class SharedArtifactCrusherSystem : EntitySystem
         ContainerSystem.EmptyContainer(ent.Comp.OutputContainer);
     }
 
+    private void OnEmagged(Entity<ArtifactCrusherComponent> ent, ref GotEmaggedEvent args)
+    {
+        ent.Comp.AutoLock = true;
+        args.Handled = true;
+    }
+
+    private void OnStorageOpenAttempt(Entity<ArtifactCrusherComponent> ent, ref StorageOpenAttemptEvent args)
+    {
+        if (ent.Comp.AutoLock && ent.Comp.Crushing)
+            args.Cancelled = true;
+    }
+
+    private void OnExamine(Entity<ArtifactCrusherComponent> ent, ref ExaminedEvent args)
+    {
+        args.PushMarkup(ent.Comp.AutoLock ? Loc.GetString("artifact-crusher-examine-autolocks") : Loc.GetString("artifact-crusher-examine-no-autolocks"));
+    }
+
     public void StopCrushing(Entity<ArtifactCrusherComponent> ent, bool early = true)
     {
         var (_, crusher) = ent;
diff --git a/Resources/Locale/en-US/artifacts/artifact-crusher.ftl b/Resources/Locale/en-US/artifacts/artifact-crusher.ftl
new file mode 100644 (file)
index 0000000..d9f10f4
--- /dev/null
@@ -0,0 +1,3 @@
+artifact-crusher-examine-no-autolocks = The machine's autolocks are [color=green]disabled[/color].
+artifact-crusher-examine-autolocks = The machine's autolocks are [color=red]enabled[/color].
+artifact-crusher-autolocks-enable = The machine's locks snap shut!