Skip to content

Commit

Permalink
Listener fix for speech (#10240)
Browse files Browse the repository at this point in the history
  • Loading branch information
vulppine authored Aug 11, 2022
1 parent 29ce4ea commit 0f9e31c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions Content.Server/Chat/Systems/ChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ private void SendEntitySpeak(EntityUid source, string originalMessage, bool hide
("entityName", Name(source)));

SendInVoiceRange(ChatChannel.Local, message, messageWrap, source, hideChat);
_listener.PingListeners(source, message, null);

var ev = new EntitySpokeEvent(message);
RaiseLocalEvent(source, ev);
Expand Down
11 changes: 8 additions & 3 deletions Content.Server/Headset/HeadsetComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ protected override void Initialize()
_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)
Expand All @@ -73,8 +73,13 @@ public void Receive(string message, RadioChannelPrototype channel, EntityUid sou
_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);
}

Expand Down
26 changes: 20 additions & 6 deletions Content.Server/Radio/Components/HandheldRadioComponent.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using Content.Server.Chat;
using Content.Server.Chat.Systems;
using Content.Server.Radio.EntitySystems;
Expand All @@ -20,6 +21,7 @@ public sealed class HandheldRadioComponent : Component, IListen, IRadio
{
private ChatSystem _chatSystem = default!;
private RadioSystem _radioSystem = default!;
private IPrototypeManager _prototypeManager = default!;

private bool _radioOn;
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
Expand Down Expand Up @@ -52,6 +54,7 @@ protected override void Initialize()

_radioSystem = EntitySystem.Get<RadioSystem>();
_chatSystem = EntitySystem.Get<ChatSystem>();
IoCManager.Resolve(ref _prototypeManager);

RadioOn = false;
}
Expand All @@ -72,12 +75,16 @@ public bool Use(EntityUid user)
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)
Expand All @@ -88,9 +95,16 @@ public void Receive(string message, RadioChannelPrototype channel, EntityUid spe
}
}

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)
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Radio/Components/IListen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public interface IListen : IComponent
{
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);
}
}
2 changes: 1 addition & 1 deletion Content.Server/Radio/EntitySystems/ListeningSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down

0 comments on commit 0f9e31c

Please sign in to comment.