Make department radio messages work in default radio (#12834)

This commit is contained in:
Tom Richardson
2022-12-14 12:24:49 +11:00
committed by GitHub
parent df6faaec12
commit 49183abef2
2 changed files with 41 additions and 41 deletions

View File

@@ -43,34 +43,37 @@ public sealed partial class ChatSystem
private (string, RadioChannelPrototype?) GetRadioPrefix(EntityUid source, string message)
{
// TODO: Turn common into a true frequency and support multiple aliases.
var channelMessage = message.StartsWith(':') || message.StartsWith('.');
var radioMessage = message.StartsWith(';') || channelMessage;
if (!radioMessage) return (message, null);
var isRadioMessage = false;
RadioChannelPrototype? channel = null;
// First check if this is a message to the base radio frequency
if (message.StartsWith(';'))
{
// First Remove semicolon
channel = _prototypeManager.Index<RadioChannelPrototype>("Common");
message = message[1..].TrimStart();
isRadioMessage = true;
}
// Check now if the remaining message is a targeted radio message
if ((message.StartsWith(':') || message.StartsWith('.')) && message.Length >= 2)
{
// Strip remaining message prefix.
_keyCodes.TryGetValue(message[1], out channel);
message = message[2..].TrimStart();
isRadioMessage = true;
}
// If not a radio message at all
if (!isRadioMessage) return (message, null);
// Special case for empty messages
if (message.Length <= 1)
return (string.Empty, null);
// Look for a prefix indicating a destination radio channel.
RadioChannelPrototype? chan;
if (channelMessage && message.Length >= 2)
if (channel == null)
{
_keyCodes.TryGetValue(message[1], out chan);
if (chan == null)
{
_popup.PopupEntity(Loc.GetString("chat-manager-no-such-channel"), source, Filter.Entities(source));
chan = null;
}
// Strip message prefix.
message = message[2..].TrimStart();
}
else
{
// Remove semicolon
message = message[1..].TrimStart();
chan = _prototypeManager.Index<RadioChannelPrototype>("Common");
_popup.PopupEntity(Loc.GetString("chat-manager-no-such-channel"), source, Filter.Entities(source));
channel = null;
}
// Re-capitalize message since we removed the prefix.
@@ -83,6 +86,6 @@ public sealed partial class ChatSystem
_popup.PopupEntity(Loc.GetString("chat-manager-no-headset-on-message"), source, Filter.Entities(source));
}
return (message, chan);
return (message, channel);
}
}

View File

@@ -151,11 +151,22 @@ public sealed partial class ChatSystem : SharedChatSystem
if (string.IsNullOrEmpty(message))
return;
// This message may have a radio prefix, and should then be whispered to the resolved radio channel
if (checkRadioPrefix)
{
var (radioMessage, channel) = GetRadioPrefix(source, message);
if (channel != null)
{
SendEntityWhisper(source, radioMessage, hideChat, hideGlobalGhostChat, channel, nameOverride);
return;
}
}
// Otherwise, send whatever type.
switch (desiredType)
{
case InGameICChatType.Speak:
SendEntitySpeak(source, message, hideChat, hideGlobalGhostChat, nameOverride, checkRadioPrefix);
SendEntitySpeak(source, message, hideChat, hideGlobalGhostChat, nameOverride);
break;
case InGameICChatType.Whisper:
SendEntityWhisper(source, message, hideChat, hideGlobalGhostChat, null, nameOverride);
@@ -255,26 +266,12 @@ public sealed partial class ChatSystem : SharedChatSystem
#region Private API
private void SendEntitySpeak(EntityUid source, string originalMessage, bool hideChat, bool hideGlobalGhostChat, string? nameOverride, bool checkRadioPrefix)
private void SendEntitySpeak(EntityUid source, string originalMessage, bool hideChat, bool hideGlobalGhostChat, string? nameOverride)
{
if (!_actionBlocker.CanSpeak(source))
return;
RadioChannelPrototype? channel = null;
string message;
if (checkRadioPrefix)
(message, channel) = GetRadioPrefix(source, originalMessage);
else
message = originalMessage;
if (channel != null)
{
SendEntityWhisper(source, message, hideChat, hideGlobalGhostChat, channel, nameOverride);
return;
}
message = TransformSpeech(source, message);
var message = TransformSpeech(source, originalMessage);
if (message.Length == 0)
return;
@@ -297,7 +294,7 @@ public sealed partial class ChatSystem : SharedChatSystem
SendInVoiceRange(ChatChannel.Local, message, wrappedMessage, source, hideChat, hideGlobalGhostChat);
var ev = new EntitySpokeEvent(source, message, channel, null);
var ev = new EntitySpokeEvent(source, message, null, null);
RaiseLocalEvent(source, ev, true);
// To avoid logging any messages sent by entities that are not players, like vendors, cloning, etc.