IListener and IRadio purge (#11980)
This commit is contained in:
17
Content.Server/Radio/Components/ActiveRadioComponent.cs
Normal file
17
Content.Server/Radio/Components/ActiveRadioComponent.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Content.Shared.Radio;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
|
||||
namespace Content.Server.Radio.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This component is required to receive radio message events.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class ActiveRadioComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The channels that this radio is listening on.
|
||||
/// </summary>
|
||||
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
|
||||
public HashSet<string> Channels = new();
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Chat;
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Server.Radio.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Popups;
|
||||
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;
|
||||
|
||||
namespace Content.Server.Radio.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentProtoName("Radio")]
|
||||
[ComponentReference(typeof(IRadio))]
|
||||
[ComponentReference(typeof(IListen))]
|
||||
#pragma warning disable 618
|
||||
public sealed class HandheldRadioComponent : Component, IListen, IRadio
|
||||
#pragma warning restore 618
|
||||
{
|
||||
private ChatSystem? _chatSystem;
|
||||
private RadioSystem? _radioSystem;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
|
||||
private bool _radioOn;
|
||||
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
|
||||
private HashSet<string> _channels = new();
|
||||
|
||||
public int BroadcastFrequency => IoCManager.Resolve<IPrototypeManager>()
|
||||
.Index<RadioChannelPrototype>(BroadcastChannel).Frequency;
|
||||
|
||||
// TODO: Assert in componentinit that channels has this.
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("broadcastChannel", customTypeSerializer: typeof(PrototypeIdSerializer<RadioChannelPrototype>))]
|
||||
public string BroadcastChannel { get; set; } = "Common";
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("listenRange")] public int ListenRange { get; private set; } = 7;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool RadioOn
|
||||
{
|
||||
get => _radioOn;
|
||||
private set
|
||||
{
|
||||
_radioOn = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_radioSystem = EntitySystem.Get<RadioSystem>();
|
||||
_chatSystem = EntitySystem.Get<ChatSystem>();
|
||||
|
||||
RadioOn = false;
|
||||
}
|
||||
|
||||
public void Speak(string message)
|
||||
{
|
||||
_chatSystem?.TrySendInGameICMessage(Owner, message, InGameICChatType.Speak, false);
|
||||
}
|
||||
|
||||
public bool Use(EntityUid user)
|
||||
{
|
||||
RadioOn = !RadioOn;
|
||||
|
||||
var message = Loc.GetString("handheld-radio-component-on-use",
|
||||
("radioState", Loc.GetString(RadioOn ? "handheld-radio-component-on-state" : "handheld-radio-component-off-state")));
|
||||
Owner.PopupMessage(user, message);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanListen(string message, EntityUid source, RadioChannelPrototype? prototype)
|
||||
{
|
||||
if (prototype != null && !_channels.Contains(prototype.ID)
|
||||
|| !_prototypeManager.HasIndex<RadioChannelPrototype>(BroadcastChannel))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return RadioOn
|
||||
&& EntitySystem.Get<SharedInteractionSystem>().InRangeUnobstructed(Owner, source, range: ListenRange);
|
||||
}
|
||||
|
||||
public void Receive(string message, RadioChannelPrototype channel, EntityUid speaker)
|
||||
{
|
||||
if (_channels.Contains(channel.ID) && RadioOn)
|
||||
{
|
||||
Speak(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void Listen(string message, EntityUid speaker, RadioChannelPrototype? prototype)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
_radioSystem?.SpreadMessage(this, speaker, message, channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
Content.Server/Radio/Components/HeadsetComponent.cs
Normal file
25
Content.Server/Radio/Components/HeadsetComponent.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Content.Server.Radio.EntitySystems;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Radio;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
|
||||
namespace Content.Server.Radio.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This component relays radio messages to the parent entity's chat when equipped.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[Access(typeof(HeadsetSystem))]
|
||||
public sealed class HeadsetComponent : Component
|
||||
{
|
||||
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
|
||||
public readonly HashSet<string> Channels = new() { "Common" };
|
||||
|
||||
[DataField("enabled")]
|
||||
public bool Enabled = true;
|
||||
|
||||
public bool IsEquipped = false;
|
||||
|
||||
[DataField("requiredSlot")]
|
||||
public SlotFlags RequiredSlot = SlotFlags.EARS;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using Content.Shared.Radio;
|
||||
|
||||
namespace Content.Server.Radio.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for objects such as radios meant to have an effect when speech is
|
||||
/// heard. Requires component reference.
|
||||
/// </summary>
|
||||
public interface IListen : IComponent
|
||||
{
|
||||
int ListenRange { get; }
|
||||
|
||||
bool CanListen(string message, EntityUid source, RadioChannelPrototype? channelPrototype);
|
||||
|
||||
void Listen(string message, EntityUid speaker, RadioChannelPrototype? channel);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using Content.Shared.Radio;
|
||||
|
||||
namespace Content.Server.Radio.Components
|
||||
{
|
||||
public interface IRadio : IComponent
|
||||
{
|
||||
void Receive(string message, RadioChannelPrototype channel, EntityUid speaker);
|
||||
|
||||
void Broadcast(string message, EntityUid speaker, RadioChannelPrototype channel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Content.Server.Radio.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This component allows an entity to directly translate radio messages into chat messages. Note that this does not
|
||||
/// automatically add an <see cref="ActiveRadioComponent"/>, which is required to receive radio messages on specific
|
||||
/// channels.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class IntrinsicRadioReceiverComponent : Component
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Content.Shared.Radio;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
|
||||
namespace Content.Server.Radio.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This component allows an entity to directly translate spoken text into radio messages (effectively an intrinsic
|
||||
/// radio headset).
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class IntrinsicRadioTransmitterComponent : Component
|
||||
{
|
||||
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
|
||||
public readonly HashSet<string> Channels = new() { "Common" };
|
||||
}
|
||||
24
Content.Server/Radio/Components/RadioMicrophoneComponent.cs
Normal file
24
Content.Server/Radio/Components/RadioMicrophoneComponent.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Content.Server.Radio.EntitySystems;
|
||||
using Content.Shared.Radio;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Radio.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Listens for local chat messages and relays them to some radio frequency
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[Access(typeof(RadioDeviceSystem))]
|
||||
public sealed class RadioMicrophoneComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("broadcastChannel", customTypeSerializer: typeof(PrototypeIdSerializer<RadioChannelPrototype>))]
|
||||
public string BroadcastChannel = "Common";
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("listenRange")]
|
||||
public int ListenRange = 4;
|
||||
|
||||
[DataField("enabled")]
|
||||
public bool Enabled = false;
|
||||
}
|
||||
19
Content.Server/Radio/Components/RadioSpeakerComponent.cs
Normal file
19
Content.Server/Radio/Components/RadioSpeakerComponent.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Content.Server.Radio.EntitySystems;
|
||||
using Content.Shared.Radio;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
|
||||
namespace Content.Server.Radio.Components;
|
||||
|
||||
/// <summary>
|
||||
/// Listens for radio messages and relays them to local chat.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[Access(typeof(RadioDeviceSystem))]
|
||||
public sealed class RadioSpeakerComponent : Component
|
||||
{
|
||||
[DataField("channels", customTypeSerializer: typeof(PrototypeIdHashSetSerializer<RadioChannelPrototype>))]
|
||||
public HashSet<string> Channels = new () { "Common" };
|
||||
|
||||
[DataField("enabled")]
|
||||
public bool Enabled;
|
||||
}
|
||||
13
Content.Server/Radio/Components/WearingHeadsetComponent.cs
Normal file
13
Content.Server/Radio/Components/WearingHeadsetComponent.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using Content.Server.Radio.EntitySystems;
|
||||
|
||||
namespace Content.Server.Radio.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This component is used to tag players that are currently wearing an ACTIVE headset.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class WearingHeadsetComponent : Component
|
||||
{
|
||||
[DataField("headset")]
|
||||
public EntityUid Headset;
|
||||
}
|
||||
Reference in New Issue
Block a user