]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add microwave-nukedisk interaction (#36114)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Wed, 21 May 2025 18:06:58 +0000 (04:06 +1000)
committerGitHub <noreply@github.com>
Wed, 21 May 2025 18:06:58 +0000 (11:06 -0700)
* Add microwave-nukedisk interaction

* popup

* Fix UninitializedSaveTest

Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs
Content.Server/Nuke/NukeComponent.cs
Content.Server/Nuke/NukeSystem.cs
Content.Shared/Nuke/NukeDiskComponent.cs
Resources/Locale/en-US/nuke/nuke-component.ftl

index f0bd0c2127c098641fd725deef017e6c7c616c07..6d36f7457b95c8db9157fa78ae91cbb0a2a3635d 100644 (file)
@@ -547,6 +547,10 @@ namespace Content.Server.Kitchen.EntitySystems
                 var ev = new BeingMicrowavedEvent(uid, user);
                 RaiseLocalEvent(item, ev);
 
+                // TODO MICROWAVE SPARKS & EFFECTS
+                // Various microwaveable entities should probably spawn a spark, play a sound, and generate a pop=up.
+                // This should probably be handled by the microwave system, with fields in BeingMicrowavedEvent.
+
                 if (ev.Handled)
                 {
                     UpdateUserInterfaceState(uid, component);
index e1a117f4bdbe556ddcbd7de422cdd50b8d09679d..b14ad9c1654e574b2ad49a05d463223863e4d328 100644 (file)
@@ -21,8 +21,7 @@ namespace Content.Server.Nuke
         /// <summary>
         ///     Default bomb timer value in seconds.
         /// </summary>
-        [DataField("timer")]
-        [ViewVariables(VVAccess.ReadWrite)]
+        [DataField]
         public int Timer = 300;
 
         /// <summary>
@@ -36,7 +35,7 @@ namespace Content.Server.Nuke
         ///     How long until the bomb can arm again after deactivation.
         ///     Used to prevent announcements spam.
         /// </summary>
-        [DataField("cooldown")]
+        [DataField]
         public int Cooldown = 30;
 
         /// <summary>
@@ -143,32 +142,32 @@ namespace Content.Server.Nuke
         /// </summary>
         public (MapId, EntityUid?)? OriginMapGrid;
 
-        [DataField("codeLength")] public int CodeLength = 6;
-        [ViewVariables] public string Code = string.Empty;
+        [DataField] public int CodeLength = 6;
+        [DataField] public string Code = string.Empty;
 
         /// <summary>
         ///     Time until explosion in seconds.
         /// </summary>
-        [ViewVariables(VVAccess.ReadWrite)]
+        [DataField]
         public float RemainingTime;
 
         /// <summary>
         ///     Time until bomb cooldown will expire in seconds.
         /// </summary>
-        [ViewVariables]
+        [DataField]
         public float CooldownTime;
 
         /// <summary>
         ///     Current nuclear code buffer. Entered manually by players.
         ///     If valid it will allow arm/disarm bomb.
         /// </summary>
-        [ViewVariables]
+        [DataField]
         public string EnteredCode = "";
 
         /// <summary>
         ///     Current status of a nuclear bomb.
         /// </summary>
-        [ViewVariables]
+        [DataField]
         public NukeStatus Status = NukeStatus.AWAIT_DISK;
 
         /// <summary>
index aa1fe3240102756f002031479ab1f122931ef1fc..77be71f7bcba5e60337414f31b1f51d163e48022 100644 (file)
@@ -2,6 +2,7 @@ using Content.Server.AlertLevel;
 using Content.Server.Audio;
 using Content.Server.Chat.Systems;
 using Content.Server.Explosion.EntitySystems;
+using Content.Server.Kitchen.Components;
 using Content.Server.Pinpointer;
 using Content.Server.Popups;
 using Content.Server.Station.Systems;
@@ -79,11 +80,12 @@ public sealed class NukeSystem : EntitySystem
 
         // Doafter events
         SubscribeLocalEvent<NukeComponent, NukeDisarmDoAfterEvent>(OnDoAfter);
+
+        SubscribeLocalEvent<NukeDiskComponent, BeingMicrowavedEvent>(OnMicrowaved);
     }
 
     private void OnInit(EntityUid uid, NukeComponent component, ComponentInit args)
     {
-        component.RemainingTime = component.Timer;
         _itemSlots.AddItemSlot(uid, SharedNukeComponent.NukeDiskSlotId, component.DiskSlot);
 
         UpdateStatus(uid, component);
@@ -111,11 +113,13 @@ public sealed class NukeSystem : EntitySystem
 
     private void OnMapInit(EntityUid uid, NukeComponent nuke, MapInitEvent args)
     {
+        nuke.RemainingTime = nuke.Timer;
         var originStation = _station.GetOwningStation(uid);
 
         if (originStation != null)
+        {
             nuke.OriginStation = originStation;
-
+        }
         else
         {
             var transform = Transform(uid);
@@ -125,6 +129,19 @@ public sealed class NukeSystem : EntitySystem
         nuke.Code = GenerateRandomNumberString(nuke.CodeLength);
     }
 
+    /// <summary>
+    /// Slightly randomize nuke countdown timer
+    /// </summary>
+    private void OnMicrowaved(Entity<NukeDiskComponent> ent, ref BeingMicrowavedEvent args)
+    {
+        if (ent.Comp.TimeModifier != null)
+            return;
+
+        var seconds = _random.NextGaussian(ent.Comp.MicrowaveMean.TotalSeconds, ent.Comp.MicrowaveStd.TotalSeconds);
+        ent.Comp.TimeModifier = TimeSpan.FromSeconds(seconds);
+        _popups.PopupEntity(Loc.GetString("nuke-disk-component-microwave"), ent.Owner, PopupType.Medium);
+    }
+
     private void OnRemove(EntityUid uid, NukeComponent component, ComponentRemove args)
     {
         _itemSlots.RemoveItemSlot(uid, component.DiskSlot);
@@ -346,11 +363,11 @@ public sealed class NukeSystem : EntitySystem
                     break;
                 }
 
-                // var isValid = _codes.IsCodeValid(uid, component.EnteredCode);
                 if (component.EnteredCode == component.Code)
                 {
                     component.Status = NukeStatus.AWAIT_ARM;
-                    component.RemainingTime = component.Timer;
+                    var modifier = CompOrNull<NukeDiskComponent>(component.DiskSlot.Item)?.TimeModifier ?? TimeSpan.Zero;
+                    component.RemainingTime = MathF.Max(component.Timer + (float)modifier.TotalSeconds, component.MinimumTime);
                     _audio.PlayPvs(component.AccessGrantedSound, uid);
                 }
                 else
index 2f99d68918c3ffed09995756af60c2ea013d1ed7..8185b15f31bc3872218fd211305b14a157dac5b4 100644 (file)
@@ -8,5 +8,16 @@ namespace Content.Shared.Nuke;
 [RegisterComponent, NetworkedComponent]
 public sealed partial class NukeDiskComponent : Component
 {
+    /// <summary>
+    /// Used to modify the nuke's countdown timer.
+    /// </summary>
+    [DataField]
+    public TimeSpan? TimeModifier;
 
+    [DataField]
+    public TimeSpan MicrowaveMean = TimeSpan.Zero;
+
+    [DataField]
+    public TimeSpan MicrowaveStd = TimeSpan.FromSeconds(27.35);
+    // STD of 27.36s means theres an 90% chance the time is between +-45s, and a ~99% chance its between +-70s
 }
index dfd56347ca33bb84af377a24cc87cc5ac74e2acb..64c67e2e04a7af8c722ebcf33cc91e249a880086 100644 (file)
@@ -6,6 +6,8 @@ nuke-component-announcement-unarmed = The station's self-destruct was deactivate
 nuke-component-announcement-send-codes = Attention! Self-destruction codes have been sent to designated fax machines.
 nuke-component-doafter-warning = You start fiddling with wires and knobs in order to disarm the nuke.. This may take a while.
 
+nuke-disk-component-microwave = The disk sparks and fizzles a bit, but seems mostly unharmed?
+
 # Nuke UI
 nuke-user-interface-title = Nuclear Fission Explosive
 nuke-user-interface-arm-button = ARM