Files
Delta-v/Content.Server/Nuke/NukeCodePaperSystem.cs
T
13ccf597c2 Add hostage ops (Nuke ops alternative objective) (#2545)
* first commit

* Some fixes

* final fixes

* Partly working

* More fixes + you can now win

* More fixes

* Forget

* Final fixes

* Update the number of hostages to 4

* Add feedback popups

* Use mind rolls like a cool person

* bruh

* NOW I'm mad

* Bruh

* :trollface:

Signed-off-by: deltanedas <39013340+deltanedas@users.noreply.github.com>

* :trollface:

Signed-off-by: deltanedas <39013340+deltanedas@users.noreply.github.com>

* Bruh I forget

---------

Signed-off-by: deltanedas <39013340+deltanedas@users.noreply.github.com>
Co-authored-by: deltanedas <@deltanedas:kde.org>
Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com>
2025-01-25 01:29:41 +00:00

148 lines
5.3 KiB
C#

using System.Diagnostics.CodeAnalysis;
using Content.Server._DV.Antag; // DeltaV
using Content.Server.Chat.Systems;
using Content.Server.Fax;
using Content.Shared.Fax.Components;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Paper;
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!;
[Dependency] private readonly FaxSystem _faxSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NukeCodePaperComponent, MapInitEvent>(OnMapInit,
after: new []{ typeof(NukeLabelSystem) });
}
private void OnMapInit(EntityUid uid, NukeCodePaperComponent component, MapInitEvent args)
{
SetupPaper(uid, component);
}
private void SetupPaper(EntityUid uid, NukeCodePaperComponent? component = null, EntityUid? station = null)
{
if (!Resolve(uid, ref component))
return;
// DeltaV - Not the best way of doing this
var evnt = new GetNukeCodePaperWriting();
RaiseLocalEvent(ref evnt);
if (evnt.ToWrite != null)
{
if (TryComp<PaperComponent>(uid, out var deltavpaperComp))
_paper.SetContent((uid, deltavpaperComp), evnt.ToWrite);
return;
}
// DeltaV - End
if (TryGetRelativeNukeCode(uid, out var paperContent, station, onlyCurrentStation: component.AllNukesAvailable))
{
if (TryComp<PaperComponent>(uid, out var paperComp))
_paper.SetContent((uid, paperComp), paperContent);
}
}
/// <summary>
/// Send a nuclear code to all faxes on that station which are authorized to receive nuke codes.
/// </summary>
/// <returns>True if at least one fax received codes</returns>
public bool SendNukeCodes(EntityUid station)
{
if (!HasComp<StationDataComponent>(station))
{
return false;
}
var faxes = EntityQueryEnumerator<FaxMachineComponent>();
var wasSent = false;
while (faxes.MoveNext(out var faxEnt, out var fax))
{
if (!fax.ReceiveNukeCodes || !TryGetRelativeNukeCode(faxEnt, out var paperContent, station))
{
continue;
}
var printout = new FaxPrintout(
paperContent,
Loc.GetString("nuke-codes-fax-paper-name"),
null,
null,
"paper_stamp-centcom",
new List<StampDisplayInfo>
{
new StampDisplayInfo { StampedName = Loc.GetString("stamp-component-stamped-name-centcom"), StampedColor = Color.FromHex("#BB3232") },
}
);
_faxSystem.Receive(faxEnt, printout, null, fax);
wasSent = true;
}
if (wasSent)
{
var msg = Loc.GetString("nuke-component-announcement-send-codes");
_chatSystem.DispatchStationAnnouncement(station, msg, colorOverride: Color.Red);
}
return wasSent;
}
private bool TryGetRelativeNukeCode(
EntityUid uid,
[NotNullWhen(true)] out string? nukeCode,
EntityUid? station = null,
TransformComponent? transform = null,
bool onlyCurrentStation = false)
{
nukeCode = null;
if (!Resolve(uid, ref transform))
{
return false;
}
var owningStation = station ?? _station.GetOwningStation(uid);
var codesMessage = new FormattedMessage();
// Find the first nuke that matches the passed location.
var nukes = new List<Entity<NukeComponent>>();
var query = EntityQueryEnumerator<NukeComponent>();
while (query.MoveNext(out var nukeUid, out var nuke))
{
nukes.Add((nukeUid, nuke));
}
_random.Shuffle(nukes);
foreach (var (nukeUid, nuke) in nukes)
{
if (!onlyCurrentStation &&
(owningStation == null &&
nuke.OriginMapGrid != (transform.MapID, transform.GridUid) ||
nuke.OriginStation != owningStation))
{
continue;
}
codesMessage.PushNewline();
codesMessage.AddMarkupOrThrow(Loc.GetString("nuke-codes-list", ("name", MetaData(nukeUid).EntityName), ("code", nuke.Code)));
break;
}
if (!codesMessage.IsEmpty)
nukeCode = Loc.GetString("nuke-codes-message")+codesMessage;
return !codesMessage.IsEmpty;
}
}
}