* add headset component

* add basic headset logic

* fix formatting in listening component, add dependency to headset

* test function for headset

* implement headset as listener

* ANNIHILATES ListeningComponent, refactor of radio/listener sys

* basic headset functionality

* rename RadioComponent to HandheldRadioComponent

* change channel to list of channels

* basic headset implementation complete

* message now always excludes ';'

* add radio color; state channel freq. and source name

* undocumented game breaking bug commit (DO NOT RESEARCH)
actually just changes frequency from 1457 (what signalers are set to by default) to 1459, the actual frequency for common

* Add more sprites

* Reorganizes

* Added job headsets

* Adds headset as an ignored component

* Jobs now spawn with headsets

* remove system.tracing

* Catchup commits

* Add headset property serialization

* Turn GetChannels into a property

* ListenRange property and serializatioon

* Adjust interfaces

* Address reviews

* Cleanup

* Address reviews

* Update rsi

* Fix licenses and copyright

* Fix missing textures

* Merge fixes

* Move headset textures from objects/devices to clothing/ears

* Fix rsi state names and add equipped states

* Fix headsets not working

* Add missing brackets to channel number in chat

* heck

* Fix broken rsi

* Fix radio id and names

* Put quotes around headset messages

* Fix method names

* Fix handheld radios

* Fix capitalization when using radio channels and trim

* Remove unnecessary dependency

* Indent that

* Separate this part

* Goodbye icons

* Implement IActivate in HandheldRadioComponent

* Add examine tooltip to radios and headsets

* Rename IListen methods

Co-authored-by: Bright <nsmoak10@yahoo.com>
Co-authored-by: Swept <jamesurquhartwebb@gmail.com>
Co-authored-by: Bright0 <55061890+Bright0@users.noreply.github.com>
This commit is contained in:
DrSmugleaf
2020-10-07 14:02:12 +02:00
committed by GitHub
parent 20eac0de84
commit a984076574
104 changed files with 1313 additions and 172 deletions

View File

@@ -0,0 +1,104 @@
using System.Collections.Generic;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces;
using Content.Shared.Chat;
using Content.Shared.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Network;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Headset
{
[RegisterComponent]
[ComponentReference(typeof(IRadio))]
[ComponentReference(typeof(IListen))]
public class HeadsetComponent : Component, IListen, IRadio, IExamine
{
[Dependency] private readonly IServerNetManager _netManager = default!;
public override string Name => "Headset";
private RadioSystem _radioSystem = default!;
private List<int> _channels = new List<int>();
[ViewVariables(VVAccess.ReadWrite)]
private int BroadcastFrequency { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public int ListenRange { get; private set; }
public IReadOnlyList<int> Channels => _channels;
public bool RadioRequested { get; set; }
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
// Only listens to speech in exact same position
serializer.DataField(this, h => h.ListenRange, "listenRange", 0);
serializer.DataField(ref _channels, "channels", new List<int> {1459});
serializer.DataField(this, h => h.BroadcastFrequency, "broadcastChannel", 1459);
}
public override void Initialize()
{
base.Initialize();
_radioSystem = EntitySystem.Get<RadioSystem>();
}
public bool CanListen(string message, IEntity source)
{
return RadioRequested;
}
public void Receive(string message, int channel, IEntity source)
{
if (ContainerHelpers.TryGetContainer(Owner, out var container))
{
if (!container.Owner.TryGetComponent(out IActorComponent actor))
return;
var playerChannel = actor.playerSession.ConnectedClient;
var msg = _netManager.CreateNetMessage<MsgChatMessage>();
msg.Channel = ChatChannel.Radio;
msg.Message = message;
msg.MessageWrap = Loc.GetString("[{0}] {1} says, \"{{0}}\"", channel, source.Name);
_netManager.ServerSendMessage(msg, playerChannel);
}
}
public void Listen(string message, IEntity speaker)
{
Broadcast(message, speaker);
}
public void Broadcast(string message, IEntity speaker)
{
_radioSystem.SpreadMessage(this, speaker, message, BroadcastFrequency);
RadioRequested = false;
}
public void Examine(FormattedMessage message, bool inDetailsRange)
{
message.AddText(Loc.GetString("It is set to broadcast over the {0} frequency.", BroadcastFrequency));
message.AddText(Loc.GetString("A small screen on the headset displays the following available frequencies:"));
message.AddText("\n");
message.AddText(Loc.GetString("Use {0} for the currently tuned frequency.", ";"));
}
}
}

View File

@@ -1,23 +0,0 @@
using Content.Server.Interfaces;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
namespace Content.Server.GameObjects.Components
{
[RegisterComponent]
public class ListeningComponent : Component
{
public override string Name => "Listening";
public void PassSpeechData(string speech, IEntity source, float distance)
{
foreach (var listener in Owner.GetAllComponents<IListen>())
{
if (distance > listener.GetListenRange()) { continue; }
listener.HeardSpeech(speech, source);
}
}
}
}

View File

@@ -0,0 +1,126 @@
using System.Collections.Generic;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces;
using Content.Server.Interfaces.Chat;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Radio
{
[RegisterComponent]
[ComponentReference(typeof(IRadio))]
[ComponentReference(typeof(IListen))]
public class HandheldRadioComponent : Component, IUse, IListen, IRadio, IActivate, IExamine
{
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Name => "Radio";
private RadioSystem _radioSystem = default!;
private bool _radioOn;
private List<int> _channels = new List<int>();
[ViewVariables(VVAccess.ReadWrite)]
private int BroadcastFrequency { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public int ListenRange { get; private set; }
[ViewVariables(VVAccess.ReadWrite)]
public bool RadioOn
{
get => _radioOn;
private set
{
_radioOn = value;
Dirty();
}
}
[ViewVariables] public IReadOnlyList<int> Channels => _channels;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(this, h => h.ListenRange, "listenRange", 7);
serializer.DataField(ref _channels, "channels", new List<int> {1459});
serializer.DataField(this, h => h.BroadcastFrequency, "broadcastChannel", 1459);
}
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;
}
public bool UseEntity(UseEntityEventArgs eventArgs)
{
return Use(eventArgs.User);
}
public bool CanListen(string message, IEntity source)
{
return RadioOn &&
Owner.Transform.Coordinates.TryDistance(_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);
}
public void 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));
}
}
}

View File

@@ -1,82 +0,0 @@
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces;
using Content.Server.Interfaces.Chat;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components
{
[RegisterComponent]
class RadioComponent : Component, IUse, IListen
{
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
public override string Name => "Radio";
private bool _radioOn;
private int _listenRange = 7;
private RadioSystem _radioSystem = default!;
[ViewVariables]
public bool RadioOn
{
get => _radioOn;
private set
{
_radioOn = value;
Dirty();
}
}
public override void Initialize()
{
base.Initialize();
_radioSystem = _entitySystemManager.GetEntitySystem<RadioSystem>();
RadioOn = false;
}
public void PassOnMessage(string message)
{
if(RadioOn)
{
_radioSystem.SpreadMessage(Owner, message);
}
}
public void Speaker(string message)
{
_chatManager.EntitySay(Owner, message);
}
public bool UseEntity(UseEntityEventArgs eventArgs)
{
RadioOn = !RadioOn;
if(RadioOn)
{
Owner.PopupMessage(eventArgs.User, "The radio is now on.");
}
else
{
Owner.PopupMessage(eventArgs.User, "The radio is now off.");
}
return true;
}
public void HeardSpeech(string speech, IEntity source)
{
PassOnMessage(speech);
}
public int GetListenRange()
{
return _listenRange;
}
}
}