2022-03-30 22:21:58 -07:00
|
|
|
using Content.Server.Chat;
|
2022-06-23 20:11:03 +10:00
|
|
|
using Content.Server.Chat.Systems;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Radio.EntitySystems;
|
|
|
|
|
using Content.Shared.Interaction;
|
2021-09-26 15:18:45 +02:00
|
|
|
using Content.Shared.Popups;
|
2022-06-23 20:11:03 +10:00
|
|
|
using Content.Shared.Radio;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
|
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
2020-10-07 14:02:12 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Radio.Components
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2022-02-01 19:35:40 -08:00
|
|
|
[ComponentProtoName("Radio")]
|
2020-10-07 14:02:12 +02:00
|
|
|
[ComponentReference(typeof(IRadio))]
|
|
|
|
|
[ComponentReference(typeof(IListen))]
|
2022-01-05 02:23:01 +13:00
|
|
|
[ComponentReference(typeof(IActivate))]
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2022-04-08 17:17:25 -04:00
|
|
|
public sealed class HandheldRadioComponent : Component, IListen, IRadio, IActivate
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
2022-03-30 22:21:58 -07:00
|
|
|
private ChatSystem _chatSystem = default!;
|
2020-10-07 14:02:12 +02:00
|
|
|
private RadioSystem _radioSystem = default!;
|
|
|
|
|
|
|
|
|
|
private bool _radioOn;
|
2022-06-23 20:11:03 +10:00
|
|
|
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
|
|
|
|
|
private HashSet<string> _channels = new();
|
2020-10-07 14:02:12 +02:00
|
|
|
|
2022-06-23 20:11:03 +10:00
|
|
|
public int BroadcastFrequency => IoCManager.Resolve<IPrototypeManager>()
|
|
|
|
|
.Index<RadioChannelPrototype>(BroadcastChannel).Frequency;
|
|
|
|
|
|
|
|
|
|
// TODO: Assert in componentinit that channels has this.
|
2020-10-07 14:02:12 +02:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2022-06-23 20:11:03 +10:00
|
|
|
[DataField("broadcastChannel", customTypeSerializer: typeof(PrototypeIdSerializer<RadioChannelPrototype>))]
|
|
|
|
|
public string BroadcastChannel { get; set; } = "Common";
|
2020-10-07 14:02:12 +02:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)] [DataField("listenRange")] public int ListenRange { get; private set; } = 7;
|
2020-10-07 14:02:12 +02:00
|
|
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public bool RadioOn
|
|
|
|
|
{
|
|
|
|
|
get => _radioOn;
|
|
|
|
|
private set
|
|
|
|
|
{
|
|
|
|
|
_radioOn = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-19 19:41:26 -07:00
|
|
|
protected override void Initialize()
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
_radioSystem = EntitySystem.Get<RadioSystem>();
|
2022-03-30 22:21:58 -07:00
|
|
|
_chatSystem = EntitySystem.Get<ChatSystem>();
|
2020-10-07 14:02:12 +02:00
|
|
|
|
|
|
|
|
RadioOn = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Speak(string message)
|
|
|
|
|
{
|
2022-03-30 22:21:58 -07:00
|
|
|
_chatSystem.TrySendInGameICMessage(Owner, message, InGameICChatType.Speak, false);
|
2020-10-07 14:02:12 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-05 10:56:17 -08:00
|
|
|
public bool Use(EntityUid user)
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
|
|
|
|
RadioOn = !RadioOn;
|
|
|
|
|
|
2021-06-21 02:13:54 +02:00
|
|
|
var message = Loc.GetString("handheld-radio-component-on-use",
|
|
|
|
|
("radioState", Loc.GetString(RadioOn ? "handheld-radio-component-on-state" : "handheld-radio-component-off-state")));
|
2020-10-07 14:02:12 +02:00
|
|
|
Owner.PopupMessage(user, message);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-23 20:11:03 +10:00
|
|
|
public bool CanListen(string message, EntityUid source, RadioChannelPrototype prototype)
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
2022-06-23 20:11:03 +10:00
|
|
|
if (!_channels.Contains(prototype.ID)) return false;
|
|
|
|
|
|
2020-10-07 14:02:12 +02:00
|
|
|
return RadioOn &&
|
2022-02-17 15:40:03 +13:00
|
|
|
EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(Owner, source, range: ListenRange);
|
2020-10-07 14:02:12 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-23 20:11:03 +10:00
|
|
|
public void Receive(string message, RadioChannelPrototype channel, EntityUid speaker)
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
2022-06-23 20:11:03 +10:00
|
|
|
if (_channels.Contains(channel.ID) && RadioOn)
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
|
|
|
|
Speak(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-23 20:11:03 +10:00
|
|
|
public void Listen(string message, EntityUid speaker, RadioChannelPrototype channel)
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
2022-06-23 20:11:03 +10:00
|
|
|
Broadcast(message, speaker, channel);
|
2020-10-07 14:02:12 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-23 20:11:03 +10:00
|
|
|
public void Broadcast(string message, EntityUid speaker, RadioChannelPrototype channel)
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
2022-06-23 20:11:03 +10:00
|
|
|
_radioSystem.SpreadMessage(this, speaker, message, channel);
|
2020-10-07 14:02:12 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
void IActivate.Activate(ActivateEventArgs eventArgs)
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
|
|
|
|
Use(eventArgs.User);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|