mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* Scope creep my ass * why was this shit not pushed???? * gone... * fix that * review plus buildd * asfsafsafsafsafas * grug * burber * I'll fix this later * shrimply die * also this * it's snerf or snuthin * assaads * round snend * aaaa * fix this shit for real * actually, don't start GameRules until MapInit now that I think aboot it. * forgot u * don't actually need this part nullable * Deffer comp removal * one liner * do that too * chungus * Honestly makes more sense here, plus WHY are we doing all that shit on "GameRuleAdded" rather than GameRuleStarted(?) * deferred removal :V * aaaaaaaaaaaaaaa * whhop * Whoop * better * landmine that I placed for myself then forgot about lmao * cleanup * FUCKING `!` * gotovo * amogus * please don't check by metadata I beg * waawsasfdfsasfa * sfafsasfafsas * fdsaasffsasfa * code * fix * fasasffasfasfsad * chungaas * I may be stupid * gra * graaaaaaaaaaaaaaaaa * comment * gra * clearing is not predicted and would require major refactors, so don't cache on client. * lame shit :P * last holes * nukeopsfsafsasafsfafsa * why was that shit public bruh * bubrbgwahrghfaka * dynamic * revert change that did nothing lmao
136 lines
4.8 KiB
C#
136 lines
4.8 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using Content.Server.Chat.Systems;
|
|
using Content.Server.Fax;
|
|
using Content.Shared.Fax.Components;
|
|
using Content.Server.Station.Systems;
|
|
using Content.Shared.Paper;
|
|
using Content.Shared.Station.Components;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Server.Nuke
|
|
{
|
|
public sealed partial class NukeCodePaperSystem : EntitySystem
|
|
{
|
|
[Dependency] private IRobustRandom _random = default!;
|
|
[Dependency] private ChatSystem _chatSystem = default!;
|
|
[Dependency] private ServerStationSystem _station = default!;
|
|
[Dependency] private PaperSystem _paper = default!;
|
|
[Dependency] private 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;
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|