IListener and IRadio purge (#11980)

This commit is contained in:
Leon Friedrich
2022-11-15 17:09:27 +13:00
committed by GitHub
parent bc525425da
commit 0b5a58001c
48 changed files with 946 additions and 643 deletions

View 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();
}

View File

@@ -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);
}
}
}

View 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;
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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
{
}

View File

@@ -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" };
}

View 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;
}

View 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;
}

View 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;
}