Make department radio messages work in default radio (#12834)
This commit is contained in:
@@ -43,34 +43,37 @@ public sealed partial class ChatSystem
|
|||||||
private (string, RadioChannelPrototype?) GetRadioPrefix(EntityUid source, string message)
|
private (string, RadioChannelPrototype?) GetRadioPrefix(EntityUid source, string message)
|
||||||
{
|
{
|
||||||
// TODO: Turn common into a true frequency and support multiple aliases.
|
// TODO: Turn common into a true frequency and support multiple aliases.
|
||||||
var channelMessage = message.StartsWith(':') || message.StartsWith('.');
|
var isRadioMessage = false;
|
||||||
var radioMessage = message.StartsWith(';') || channelMessage;
|
RadioChannelPrototype? channel = null;
|
||||||
if (!radioMessage) return (message, 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
|
// Special case for empty messages
|
||||||
if (message.Length <= 1)
|
if (message.Length <= 1)
|
||||||
return (string.Empty, null);
|
return (string.Empty, null);
|
||||||
|
|
||||||
// Look for a prefix indicating a destination radio channel.
|
if (channel == null)
|
||||||
RadioChannelPrototype? chan;
|
|
||||||
if (channelMessage && message.Length >= 2)
|
|
||||||
{
|
{
|
||||||
_keyCodes.TryGetValue(message[1], out chan);
|
_popup.PopupEntity(Loc.GetString("chat-manager-no-such-channel"), source, Filter.Entities(source));
|
||||||
|
channel = null;
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-capitalize message since we removed the prefix.
|
// 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));
|
_popup.PopupEntity(Loc.GetString("chat-manager-no-headset-on-message"), source, Filter.Entities(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (message, chan);
|
return (message, channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -151,11 +151,22 @@ public sealed partial class ChatSystem : SharedChatSystem
|
|||||||
if (string.IsNullOrEmpty(message))
|
if (string.IsNullOrEmpty(message))
|
||||||
return;
|
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.
|
// Otherwise, send whatever type.
|
||||||
switch (desiredType)
|
switch (desiredType)
|
||||||
{
|
{
|
||||||
case InGameICChatType.Speak:
|
case InGameICChatType.Speak:
|
||||||
SendEntitySpeak(source, message, hideChat, hideGlobalGhostChat, nameOverride, checkRadioPrefix);
|
SendEntitySpeak(source, message, hideChat, hideGlobalGhostChat, nameOverride);
|
||||||
break;
|
break;
|
||||||
case InGameICChatType.Whisper:
|
case InGameICChatType.Whisper:
|
||||||
SendEntityWhisper(source, message, hideChat, hideGlobalGhostChat, null, nameOverride);
|
SendEntityWhisper(source, message, hideChat, hideGlobalGhostChat, null, nameOverride);
|
||||||
@@ -255,26 +266,12 @@ public sealed partial class ChatSystem : SharedChatSystem
|
|||||||
|
|
||||||
#region Private API
|
#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))
|
if (!_actionBlocker.CanSpeak(source))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RadioChannelPrototype? channel = null;
|
var message = TransformSpeech(source, originalMessage);
|
||||||
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);
|
|
||||||
if (message.Length == 0)
|
if (message.Length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -297,7 +294,7 @@ public sealed partial class ChatSystem : SharedChatSystem
|
|||||||
|
|
||||||
SendInVoiceRange(ChatChannel.Local, message, wrappedMessage, source, hideChat, hideGlobalGhostChat);
|
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);
|
RaiseLocalEvent(source, ev, true);
|
||||||
|
|
||||||
// To avoid logging any messages sent by entities that are not players, like vendors, cloning, etc.
|
// To avoid logging any messages sent by entities that are not players, like vendors, cloning, etc.
|
||||||
|
|||||||
Reference in New Issue
Block a user