* Add department-specific radio channels
This commit adds working department-specific radio channels, while
minimizing damage to the current codebase. It is expected that a future
refactor will clean this up a bit.
ChatSystem now has a RadioPrefix() method that recognizes
department-specific channels (e.g. ":e" and ":m") in addition to the
global channel (";"). It strips the prefix from the message and assigns
messages an integer representing the destination channel, if any.
IListen and IRadio now accept optional 'channel' arguments with this
channel in mind.
The ugly is that the integer channel number is hard-coded and also shows
up in chat.
Comms are not modeled at this time. You cannot break comms (yet).
All headsets have channels soldered into them. You cannot change
encryption keys to hop on new channels. Steal a headset instead.
* Remove debugging print
* Convert to prototypes
* Use prototype names in headset prototype
* Adjust list style
* Document prototype fields
* cringe
* some cleanup
* colours
* Remove alphas at least
* cc
Co-authored-by: Kevin Zheng <kevinz5000@gmail.com>
90 lines
2.7 KiB
C#
90 lines
2.7 KiB
C#
using Content.Server.Chat;
|
|
using Content.Server.Chat.Systems;
|
|
using Content.Server.Communications;
|
|
using Content.Server.Station.Systems;
|
|
using Content.Shared.GameTicking;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Server.Nuke
|
|
{
|
|
/// <summary>
|
|
/// Nuclear code is generated once per round
|
|
/// One code works for all nukes
|
|
/// </summary>
|
|
public sealed class NukeCodeSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly ChatSystem _chatSystem = default!;
|
|
[Dependency] private readonly StationSystem _stationSystem = default!;
|
|
|
|
private const int CodeLength = 6;
|
|
public string Code { get; private set; } = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
GenerateNewCode();
|
|
|
|
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRestart);
|
|
}
|
|
|
|
private void OnRestart(RoundRestartCleanupEvent ev)
|
|
{
|
|
GenerateNewCode();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if code is equal to current bombs code
|
|
/// </summary>
|
|
public bool IsCodeValid(string code)
|
|
{
|
|
return code == Code;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Generate a new nuclear bomb code. Replacing old one.
|
|
/// </summary>
|
|
public void GenerateNewCode()
|
|
{
|
|
var ret = "";
|
|
for (var i = 0; i < CodeLength; i++)
|
|
{
|
|
var c = (char) _random.Next('0', '9' + 1);
|
|
ret += c;
|
|
}
|
|
|
|
Code = ret;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Send a nuclear code to all communication consoles
|
|
/// </summary>
|
|
/// <returns>True if at least one console received codes</returns>
|
|
public bool SendNukeCodes()
|
|
{
|
|
// todo: this should probably be handled by fax system
|
|
var wasSent = false;
|
|
var consoles = EntityManager.EntityQuery<CommunicationsConsoleComponent>();
|
|
foreach (var console in consoles)
|
|
{
|
|
if (!EntityManager.TryGetComponent((console).Owner, out TransformComponent? transform))
|
|
continue;
|
|
|
|
var consolePos = transform.MapPosition;
|
|
EntityManager.SpawnEntity("NukeCodePaper", consolePos);
|
|
|
|
wasSent = true;
|
|
}
|
|
|
|
// TODO: Allow selecting a station for nuke codes
|
|
if (wasSent)
|
|
{
|
|
var msg = Loc.GetString("nuke-component-announcement-send-codes");
|
|
_chatSystem.DispatchGlobalStationAnnouncement(msg, colorOverride: Color.Red);
|
|
}
|
|
|
|
return wasSent;
|
|
}
|
|
}
|
|
}
|