Add GhostRadio to allow ghosts to hear radio messages (#4896)

* Add GhostRadio to allow ghosts to hear radio messages

* Add GhostRadio to ignored components
This commit is contained in:
ShadowCommander
2021-10-16 12:04:35 -07:00
committed by GitHub
parent 66dc8f5df5
commit 9da81ea85f
3 changed files with 49 additions and 2 deletions

View File

@@ -0,0 +1,45 @@
using System.Collections.Generic;
using Content.Server.Radio.Components;
using Content.Shared.Chat;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Network;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Ghost.Components
{
[RegisterComponent]
[ComponentReference(typeof(IRadio))]
public class GhostRadioComponent : Component, IRadio
{
[Dependency] private readonly IServerNetManager _netManager = default!;
public override string Name => "GhostRadio";
[DataField("channels")]
private List<int> _channels = new(){1459};
public IReadOnlyList<int> Channels => _channels;
public void Receive(string message, int channel, IEntity speaker)
{
if (!Owner.TryGetComponent(out ActorComponent? actor))
return;
var playerChannel = actor.PlayerSession.ConnectedClient;
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
msg.Channel = ChatChannel.Radio;
msg.Message = message;
//Square brackets are added here to avoid issues with escaping
msg.MessageWrap = Loc.GetString("chat-radio-message-wrap", ("channel", $"\\[{channel}\\]"), ("name", speaker.Name));
_netManager.ServerSendMessage(msg, playerChannel);
}
public void Broadcast(string message, IEntity speaker) { }
}
}