NukeOps start with either station codes or their codes (#14025)
* NukeOps start with all nuke codes * make it pick a random code * clarify this
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user