From 930d0976165842abc202ecef483f316589365f14 Mon Sep 17 00:00:00 2001
From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
Date: Sun, 26 Mar 2023 12:58:57 -0400
Subject: [PATCH] NukeOps start with either station codes or their codes
(#14025)
* NukeOps start with all nuke codes
* make it pick a random code
* clarify this
---
Content.Server/Nuke/NukeCodePaperComponent.cs | 7 +++
Content.Server/Nuke/NukeCodePaperSystem.cs | 44 +++++++++++++------
.../Locale/en-US/nuke/nuke-component.ftl | 2 +-
.../Entities/Objects/Misc/paper.yml | 12 ++++-
4 files changed, 48 insertions(+), 17 deletions(-)
diff --git a/Content.Server/Nuke/NukeCodePaperComponent.cs b/Content.Server/Nuke/NukeCodePaperComponent.cs
index c57f5b1885..0056503698 100644
--- a/Content.Server/Nuke/NukeCodePaperComponent.cs
+++ b/Content.Server/Nuke/NukeCodePaperComponent.cs
@@ -7,5 +7,12 @@ namespace Content.Server.Nuke
[RegisterComponent]
public sealed class NukeCodePaperComponent : Component
{
+ ///
+ /// 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.
+ ///
+ [DataField("allNukesAvailable")]
+ public bool AllNukesAvailable;
}
}
diff --git a/Content.Server/Nuke/NukeCodePaperSystem.cs b/Content.Server/Nuke/NukeCodePaperSystem.cs
index 28467e1e3a..e764135201 100644
--- a/Content.Server/Nuke/NukeCodePaperSystem.cs
+++ b/Content.Server/Nuke/NukeCodePaperSystem.cs
@@ -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();
+ var faxes = EntityQueryEnumerator();
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())
+ var query = EntityQuery().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;
}
}
}
diff --git a/Resources/Locale/en-US/nuke/nuke-component.ftl b/Resources/Locale/en-US/nuke/nuke-component.ftl
index 200c3bf415..319fc33e15 100644
--- a/Resources/Locale/en-US/nuke/nuke-component.ftl
+++ b/Resources/Locale/en-US/nuke/nuke-component.ftl
@@ -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
diff --git a/Resources/Prototypes/Entities/Objects/Misc/paper.yml b/Resources/Prototypes/Entities/Objects/Misc/paper.yml
index 56916ad697..4dbe14d202 100644
--- a/Resources/Prototypes/Entities/Objects/Misc/paper.yml
+++ b/Resources/Prototypes/Entities/Objects/Misc/paper.yml
@@ -155,8 +155,16 @@
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
--
2.51.2