2021-06-21 02:13:54 +02:00
|
|
|
using System.Collections.Generic;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Chat.Managers;
|
|
|
|
|
using Content.Server.Radio.EntitySystems;
|
|
|
|
|
using Content.Shared.Examine;
|
|
|
|
|
using Content.Shared.Interaction;
|
2021-07-25 01:07:28 -07:00
|
|
|
using Content.Shared.Interaction.Helpers;
|
2021-09-26 15:18:45 +02:00
|
|
|
using Content.Shared.Popups;
|
2020-10-07 14:02:12 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Localization;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-10-07 14:02:12 +02:00
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
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-02-16 00:23:23 -07:00
|
|
|
public sealed class HandheldRadioComponent : Component, IListen, IRadio, IActivate, IExamine
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
|
|
|
|
private RadioSystem _radioSystem = default!;
|
|
|
|
|
|
|
|
|
|
private bool _radioOn;
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("channels")]
|
|
|
|
|
private List<int> _channels = new(){1459};
|
2020-10-07 14:02:12 +02:00
|
|
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("broadcastChannel")]
|
|
|
|
|
private int BroadcastFrequency { get; set; } = 1459;
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ViewVariables] public IReadOnlyList<int> Channels => _channels;
|
|
|
|
|
|
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>();
|
|
|
|
|
|
|
|
|
|
RadioOn = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Speak(string message)
|
|
|
|
|
{
|
|
|
|
|
_chatManager.EntitySay(Owner, message);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 10:56:17 -08:00
|
|
|
public bool CanListen(string message, EntityUid source)
|
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
|
|
|
}
|
|
|
|
|
|
2021-12-05 10:56:17 -08:00
|
|
|
public void Receive(string message, int channel, EntityUid speaker)
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
|
|
|
|
if (RadioOn)
|
|
|
|
|
{
|
|
|
|
|
Speak(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 10:56:17 -08:00
|
|
|
public void Listen(string message, EntityUid speaker)
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
|
|
|
|
Broadcast(message, speaker);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 10:56:17 -08:00
|
|
|
public void Broadcast(string message, EntityUid speaker)
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
|
|
|
|
_radioSystem.SpreadMessage(this, speaker, message, BroadcastFrequency);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
void IActivate.Activate(ActivateEventArgs eventArgs)
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
|
|
|
|
Use(eventArgs.User);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-20 12:42:42 +01:00
|
|
|
public void Examine(FormattedMessage message, bool inDetailsRange)
|
2020-10-07 14:02:12 +02:00
|
|
|
{
|
2021-06-21 02:13:54 +02:00
|
|
|
message.AddText(Loc.GetString("handheld-radio-component-on-examine",("frequency", BroadcastFrequency)));
|
2020-10-07 14:02:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|