]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
NukeOps start with either station codes or their codes (#14025)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Sun, 26 Mar 2023 16:58:57 +0000 (12:58 -0400)
committerGitHub <noreply@github.com>
Sun, 26 Mar 2023 16:58:57 +0000 (11:58 -0500)
* NukeOps start with all nuke codes

* make it pick a random code

* clarify this

Content.Server/Nuke/NukeCodePaperComponent.cs
Content.Server/Nuke/NukeCodePaperSystem.cs
Resources/Locale/en-US/nuke/nuke-component.ftl
Resources/Prototypes/Entities/Objects/Misc/paper.yml

index c57f5b1885c157a91da520b3b27facaa338c81ab..00565036984ab11e08721803d49b31607cda6a32 100644 (file)
@@ -7,5 +7,12 @@ namespace Content.Server.Nuke
     [RegisterComponent]
     public sealed class NukeCodePaperComponent : Component
     {
+        /// <summary>
+        /// Whether or not paper will contain a code for a nuke on the same
+        /// station as the paper, or if it will get a random code from all
+        /// possible nukes.
+        /// </summary>
+        [DataField("allNukesAvailable")]
+        public bool AllNukesAvailable;
     }
 }
index 28467e1e3a5b1105161049e165917c123ce50704..e764135201026f386c01880ba510825f14bebb68 100644 (file)
@@ -1,14 +1,18 @@
 using System.Diagnostics.CodeAnalysis;
+using System.Linq;
 using Content.Server.Chat.Systems;
 using Content.Server.Fax;
 using Content.Server.Paper;
 using Content.Server.Station.Components;
 using Content.Server.Station.Systems;
+using Robust.Shared.Random;
+using Robust.Shared.Utility;
 
 namespace Content.Server.Nuke
 {
     public sealed class NukeCodePaperSystem : EntitySystem
     {
+        [Dependency] private readonly IRobustRandom _random = default!;
         [Dependency] private readonly ChatSystem _chatSystem = default!;
         [Dependency] private readonly StationSystem _station = default!;
         [Dependency] private readonly PaperSystem _paper = default!;
@@ -23,12 +27,15 @@ namespace Content.Server.Nuke
 
         private void OnMapInit(EntityUid uid, NukeCodePaperComponent component, MapInitEvent args)
         {
-            SetupPaper(uid);
+            SetupPaper(uid, component);
         }
 
-        private void SetupPaper(EntityUid uid, EntityUid? station = null)
+        private void SetupPaper(EntityUid uid, NukeCodePaperComponent? component = null, EntityUid? station = null)
         {
-            if (TryGetRelativeNukeCode(uid, out var paperContent, station))
+            if (!Resolve(uid, ref component))
+                return;
+
+            if (TryGetRelativeNukeCode(uid, out var paperContent, station, onlyCurrentStation: component.AllNukesAvailable))
             {
                 _paper.SetContent(uid, paperContent);
             }
@@ -45,11 +52,11 @@ namespace Content.Server.Nuke
                 return false;
             }
 
-            var faxes = EntityManager.EntityQuery<FaxMachineComponent>();
+            var faxes = EntityQueryEnumerator<FaxMachineComponent>();
             var wasSent = false;
-            foreach (var fax in faxes)
+            while (faxes.MoveNext(out var faxEnt, out var fax))
             {
-                if (!fax.ReceiveNukeCodes || !TryGetRelativeNukeCode(fax.Owner, out var paperContent, station))
+                if (!fax.ReceiveNukeCodes || !TryGetRelativeNukeCode(faxEnt, out var paperContent, station))
                 {
                     continue;
                 }
@@ -60,7 +67,7 @@ namespace Content.Server.Nuke
                     null,
                     "paper_stamp-cent",
                     new() { Loc.GetString("stamp-component-stamped-name-centcom") });
-                _faxSystem.Receive(fax.Owner, printout, null, fax);
+                _faxSystem.Receive(faxEnt, printout, null, fax);
 
                 wasSent = true;
             }
@@ -78,7 +85,8 @@ namespace Content.Server.Nuke
             EntityUid uid,
             [NotNullWhen(true)] out string? nukeCode,
             EntityUid? station = null,
-            TransformComponent? transform = null)
+            TransformComponent? transform = null,
+            bool onlyCurrentStation = false)
         {
             nukeCode = null;
             if (!Resolve(uid, ref transform))
@@ -88,20 +96,28 @@ namespace Content.Server.Nuke
 
             var owningStation = station ?? _station.GetOwningStation(uid);
 
+            var codesMessage = new FormattedMessage();
             // Find the first nuke that matches the passed location.
-            foreach (var nuke in EntityQuery<NukeComponent>())
+            var query = EntityQuery<NukeComponent>().ToList();
+            _random.Shuffle(query);
+            foreach (var nuke in query)
             {
-                if (owningStation == null && nuke.OriginMapGrid != (transform.MapID, transform.GridUid)
-                    || nuke.OriginStation != owningStation)
+                if (!onlyCurrentStation &&
+                    (owningStation == null &&
+                    nuke.OriginMapGrid != (transform.MapID, transform.GridUid) ||
+                    nuke.OriginStation != owningStation))
                 {
                     continue;
                 }
 
-                nukeCode = Loc.GetString("nuke-codes-message", ("name", MetaData(nuke.Owner).EntityName), ("code", nuke.Code));
-                return true;
+                codesMessage.PushNewline();
+                codesMessage.AddMarkup(Loc.GetString("nuke-codes-list", ("name", MetaData(nuke.Owner).EntityName), ("code", nuke.Code)));
+                break;
             }
 
-            return false;
+            if (!codesMessage.IsEmpty)
+                nukeCode = Loc.GetString("nuke-codes-message")+codesMessage;
+            return !codesMessage.IsEmpty;
         }
     }
 }
index 200c3bf4157b02818eb7ed361a16aa83768698d6..319fc33e15f67fe1ac16f9531fcb760c3eff08c9 100644 (file)
@@ -35,5 +35,5 @@ nuke-label-syndicate = SYN-{$serial}
 
 # Codes
 nuke-codes-message = [color=red]TOP SECRET![/color]
- Nuclear device activation code: {$name} - {$code}
+nuke-codes-list = {$name} code: {$code}
 nuke-codes-fax-paper-name = nuclear authentication codes
index 56916ad69731b6b521e7f56099917ad2332883ec..4dbe14d20298bd4bef55142b9e9b162692b92e13 100644 (file)
   id: NukeCodePaper
   name: nuclear authentication codes
   components:
-    - type: NukeCodePaper
-    - type: Paper
+  - type: NukeCodePaper
+    allNukesAvailable: true
+  - type: Paper
+
+- type: entity
+  parent: NukeCodePaper
+  id: NukeCodePaperStation
+  suffix: Station Only
+  components:
+  - type: NukeCodePaper
 
 - type: entity
   name: pen