2022-04-08 17:17:25 -04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Content.Shared.Examine;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Server.Radio.Components;
|
2022-06-23 20:11:03 +10:00
|
|
|
|
using Content.Shared.Radio;
|
2020-10-07 14:02:12 +02:00
|
|
|
|
using JetBrains.Annotations;
|
2020-07-28 16:13:39 -06:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Server.Radio.EntitySystems
|
2020-07-28 16:13:39 -06:00
|
|
|
|
{
|
2020-10-07 14:02:12 +02:00
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class RadioSystem : EntitySystem
|
2020-07-28 16:13:39 -06:00
|
|
|
|
{
|
2021-03-16 15:50:20 +01:00
|
|
|
|
private readonly List<string> _messages = new();
|
2020-10-07 14:02:12 +02:00
|
|
|
|
|
2022-04-08 17:17:25 -04:00
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
SubscribeLocalEvent<HandheldRadioComponent, ExaminedEvent>(OnExamine);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnExamine(EntityUid uid, HandheldRadioComponent component, ExaminedEvent args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!args.IsInDetailsRange)
|
|
|
|
|
|
return;
|
|
|
|
|
|
args.PushMarkup(Loc.GetString("handheld-radio-component-on-examine",("frequency", component.BroadcastFrequency)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-23 20:11:03 +10:00
|
|
|
|
public void SpreadMessage(IRadio source, EntityUid speaker, string message, RadioChannelPrototype channel)
|
2020-10-07 14:02:12 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (_messages.Contains(message)) return;
|
2020-07-28 16:13:39 -06:00
|
|
|
|
|
|
|
|
|
|
_messages.Add(message);
|
|
|
|
|
|
|
2021-09-28 13:35:29 +02:00
|
|
|
|
foreach (var radio in EntityManager.EntityQuery<IRadio>(true))
|
2020-07-28 16:13:39 -06:00
|
|
|
|
{
|
2022-06-23 20:11:03 +10:00
|
|
|
|
//TODO: once voice identity gets added, pass into receiver via source.GetSpeakerVoice()
|
|
|
|
|
|
radio.Receive(message, channel, speaker);
|
2020-07-28 16:13:39 -06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_messages.Remove(message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|