Re-organize all projects (#4166)
This commit is contained in:
113
Content.Server/Radio/Components/HandheldRadioComponent.cs
Normal file
113
Content.Server/Radio/Components/HandheldRadioComponent.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Server.Radio.EntitySystems;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Notification;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Radio.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IRadio))]
|
||||
[ComponentReference(typeof(IListen))]
|
||||
public class HandheldRadioComponent : Component, IUse, IListen, IRadio, IActivate, IExamine
|
||||
{
|
||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||
public override string Name => "Radio";
|
||||
|
||||
private RadioSystem _radioSystem = default!;
|
||||
|
||||
private bool _radioOn;
|
||||
[DataField("channels")]
|
||||
private List<int> _channels = new(){1459};
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("broadcastChannel")]
|
||||
private int BroadcastFrequency { get; set; } = 1459;
|
||||
|
||||
[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();
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables] public IReadOnlyList<int> Channels => _channels;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_radioSystem = EntitySystem.Get<RadioSystem>();
|
||||
|
||||
RadioOn = false;
|
||||
}
|
||||
|
||||
public void Speak(string message)
|
||||
{
|
||||
_chatManager.EntitySay(Owner, message);
|
||||
}
|
||||
|
||||
public bool Use(IEntity user)
|
||||
{
|
||||
RadioOn = !RadioOn;
|
||||
|
||||
var message = Loc.GetString($"The radio is now {(RadioOn ? "on" : "off")}.");
|
||||
Owner.PopupMessage(user, message);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IUse.UseEntity(UseEntityEventArgs eventArgs)
|
||||
{
|
||||
return Use(eventArgs.User);
|
||||
}
|
||||
|
||||
public bool CanListen(string message, IEntity source)
|
||||
{
|
||||
return RadioOn &&
|
||||
Owner.Transform.Coordinates.TryDistance(Owner.EntityManager, source.Transform.Coordinates, out var distance) &&
|
||||
distance <= ListenRange;
|
||||
}
|
||||
|
||||
public void Receive(string message, int channel, IEntity speaker)
|
||||
{
|
||||
if (RadioOn)
|
||||
{
|
||||
Speak(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void Listen(string message, IEntity speaker)
|
||||
{
|
||||
Broadcast(message, speaker);
|
||||
}
|
||||
|
||||
public void Broadcast(string message, IEntity speaker)
|
||||
{
|
||||
_radioSystem.SpreadMessage(this, speaker, message, BroadcastFrequency);
|
||||
}
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
Use(eventArgs.User);
|
||||
}
|
||||
|
||||
public void Examine(FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
message.AddText(Loc.GetString("It is set to broadcast over the {0} frequency.", BroadcastFrequency));
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Content.Server/Radio/Components/IListen.cs
Normal file
17
Content.Server/Radio/Components/IListen.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
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, IEntity source);
|
||||
|
||||
void Listen(string message, IEntity speaker);
|
||||
}
|
||||
}
|
||||
14
Content.Server/Radio/Components/IRadio.cs
Normal file
14
Content.Server/Radio/Components/IRadio.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Radio.Components
|
||||
{
|
||||
public interface IRadio
|
||||
{
|
||||
IReadOnlyList<int> Channels { get; }
|
||||
|
||||
void Receive(string message, int channel, IEntity speaker);
|
||||
|
||||
void Broadcast(string message, IEntity speaker);
|
||||
}
|
||||
}
|
||||
22
Content.Server/Radio/EntitySystems/ListeningSystem.cs
Normal file
22
Content.Server/Radio/EntitySystems/ListeningSystem.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Content.Server.Radio.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Radio.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ListeningSystem : EntitySystem
|
||||
{
|
||||
public void PingListeners(IEntity source, string message)
|
||||
{
|
||||
foreach (var listener in ComponentManager.EntityQuery<IListen>(true))
|
||||
{
|
||||
// TODO: Map Position distance
|
||||
if (listener.CanListen(message, source))
|
||||
{
|
||||
listener.Listen(message, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Content.Server/Radio/EntitySystems/RadioSystem.cs
Normal file
32
Content.Server/Radio/EntitySystems/RadioSystem.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.Radio.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Radio.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class RadioSystem : EntitySystem
|
||||
{
|
||||
private readonly List<string> _messages = new();
|
||||
|
||||
public void SpreadMessage(IRadio source, IEntity speaker, string message, int channel)
|
||||
{
|
||||
if (_messages.Contains(message)) return;
|
||||
|
||||
_messages.Add(message);
|
||||
|
||||
foreach (var radio in ComponentManager.EntityQuery<IRadio>(true))
|
||||
{
|
||||
if (radio.Channels.Contains(channel))
|
||||
{
|
||||
//TODO: once voice identity gets added, pass into receiver via source.GetSpeakerVoice()
|
||||
radio.Receive(message, channel, speaker);
|
||||
}
|
||||
}
|
||||
|
||||
_messages.Remove(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user