Listener fix for speech (#10240)

This commit is contained in:
Flipp Syder
2022-08-11 02:25:29 -07:00
committed by GitHub
parent 29ce4ead84
commit 0f9e31c988
5 changed files with 32 additions and 12 deletions

View File

@@ -266,6 +266,7 @@ public sealed partial class ChatSystem : SharedChatSystem
("entityName", Name(source)));
SendInVoiceRange(ChatChannel.Local, message, messageWrap, source, hideChat);
_listener.PingListeners(source, message, null);
var ev = new EntitySpokeEvent(message);
RaiseLocalEvent(source, ev);

View File

@@ -45,9 +45,9 @@ namespace Content.Server.Headset
_radioSystem = EntitySystem.Get<RadioSystem>();
}
public bool CanListen(string message, EntityUid source, RadioChannelPrototype prototype)
public bool CanListen(string message, EntityUid source, RadioChannelPrototype? prototype)
{
return Channels.Contains(prototype.ID) && RadioRequested;
return prototype != null && Channels.Contains(prototype.ID) && RadioRequested;
}
public void Receive(string message, RadioChannelPrototype channel, EntityUid source)
@@ -73,8 +73,13 @@ namespace Content.Server.Headset
_netManager.ServerSendMessage(msg, playerChannel);
}
public void Listen(string message, EntityUid speaker, RadioChannelPrototype channel)
public void Listen(string message, EntityUid speaker, RadioChannelPrototype? channel)
{
if (channel == null)
{
return;
}
Broadcast(message, speaker, channel);
}

View File

@@ -1,3 +1,4 @@
using System.Linq;
using Content.Server.Chat;
using Content.Server.Chat.Systems;
using Content.Server.Radio.EntitySystems;
@@ -20,6 +21,7 @@ namespace Content.Server.Radio.Components
{
private ChatSystem _chatSystem = default!;
private RadioSystem _radioSystem = default!;
private IPrototypeManager _prototypeManager = default!;
private bool _radioOn;
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
@@ -52,6 +54,7 @@ namespace Content.Server.Radio.Components
_radioSystem = EntitySystem.Get<RadioSystem>();
_chatSystem = EntitySystem.Get<ChatSystem>();
IoCManager.Resolve(ref _prototypeManager);
RadioOn = false;
}
@@ -72,12 +75,16 @@ namespace Content.Server.Radio.Components
return true;
}
public bool CanListen(string message, EntityUid source, RadioChannelPrototype prototype)
public bool CanListen(string message, EntityUid source, RadioChannelPrototype? prototype)
{
if (!_channels.Contains(prototype.ID)) return false;
if (prototype != null && !_channels.Contains(prototype.ID)
|| !_prototypeManager.HasIndex<RadioChannelPrototype>(BroadcastChannel))
{
return false;
}
return RadioOn &&
EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(Owner, source, range: ListenRange);
return RadioOn
&& EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(Owner, source, range: ListenRange);
}
public void Receive(string message, RadioChannelPrototype channel, EntityUid speaker)
@@ -88,9 +95,16 @@ namespace Content.Server.Radio.Components
}
}
public void Listen(string message, EntityUid speaker, RadioChannelPrototype channel)
public void Listen(string message, EntityUid speaker, RadioChannelPrototype? prototype)
{
Broadcast(message, speaker, channel);
// if we can't get the channel, we need to just use the broadcast frequency
if (prototype == null
&& !_prototypeManager.TryIndex(BroadcastChannel, out prototype))
{
return;
}
Broadcast(message, speaker, prototype);
}
public void Broadcast(string message, EntityUid speaker, RadioChannelPrototype channel)

View File

@@ -10,8 +10,8 @@ namespace Content.Server.Radio.Components
{
int ListenRange { get; }
bool CanListen(string message, EntityUid source, RadioChannelPrototype channelPrototype);
bool CanListen(string message, EntityUid source, RadioChannelPrototype? channelPrototype);
void Listen(string message, EntityUid speaker, RadioChannelPrototype channel);
void Listen(string message, EntityUid speaker, RadioChannelPrototype? channel);
}
}

View File

@@ -7,7 +7,7 @@ namespace Content.Server.Radio.EntitySystems
[UsedImplicitly]
public sealed class ListeningSystem : EntitySystem
{
public void PingListeners(EntityUid source, string message, RadioChannelPrototype channel)
public void PingListeners(EntityUid source, string message, RadioChannelPrototype? channel)
{
foreach (var listener in EntityManager.EntityQuery<IListen>(true))
{