* parrots have ears. add poly * high tech parrot functionality * adjust times * add accent to radio message * don't spam everything all at once probably * learn about the existence of prob(float) * actually use Prob(float) correctly * newline * add pet spawner for poly * move chance to talk on radio to component * missing comment * minor edits and doc additions * the reviewerrrrrrr * parrot can't learn when crit or dead * increase default memory * rename poly to polly * crude way to ignore whispers. chatcode please * This is Polly. It is set to broadcast over the engineering frequency * add missing initialize * add displacement map for parrot ears * review comments - Errant * minor things * large rework * fix attempting to talk when entity has no channels * use list of active radios again to track channels * fix bad return, some comments * fix long learn cooldown * minor adjustments * use FromMinutes * the voices told me to make these changes * remove default reassignment * Review changes * remove polly's accent * decouple radio stuff from parrotsystem * minor stuff * split vocalization and parroting * minor review work * re-add missing check * add admin verb for clearing parrot messages * minor action icon update * oops * increase icon number text size * Admin erase parrot messages associated with players * part 1 beck review * add whitelist and blacklist for parrots * Downgrade missing component error to warning * Add comment * add some missing comments * Remove active radio entity tracking, use all inventory slots * Minor changes * small review stuff * review radio stuff * swap ears displacement to invisible death displacement * remove syncsprite * vscode why do yo have to hurt my feelings * review changes * use checkboth
127 lines
4.4 KiB
C#
127 lines
4.4 KiB
C#
using Content.Server.Chat.Systems;
|
|
using Content.Server.Emp;
|
|
using Content.Server.Radio.Components;
|
|
using Content.Shared.Inventory.Events;
|
|
using Content.Shared.Radio;
|
|
using Content.Shared.Radio.Components;
|
|
using Content.Shared.Radio.EntitySystems;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Content.Server.Radio.EntitySystems;
|
|
|
|
public sealed class HeadsetSystem : SharedHeadsetSystem
|
|
{
|
|
[Dependency] private readonly INetManager _netMan = default!;
|
|
[Dependency] private readonly RadioSystem _radio = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<HeadsetComponent, RadioReceiveEvent>(OnHeadsetReceive);
|
|
SubscribeLocalEvent<HeadsetComponent, EncryptionChannelsChangedEvent>(OnKeysChanged);
|
|
|
|
SubscribeLocalEvent<WearingHeadsetComponent, EntitySpokeEvent>(OnSpeak);
|
|
|
|
SubscribeLocalEvent<HeadsetComponent, EmpPulseEvent>(OnEmpPulse);
|
|
}
|
|
|
|
private void OnKeysChanged(EntityUid uid, HeadsetComponent component, EncryptionChannelsChangedEvent args)
|
|
{
|
|
UpdateRadioChannels(uid, component, args.Component);
|
|
}
|
|
|
|
private void UpdateRadioChannels(EntityUid uid, HeadsetComponent headset, EncryptionKeyHolderComponent? keyHolder = null)
|
|
{
|
|
// make sure to not add ActiveRadioComponent when headset is being deleted
|
|
if (!headset.Enabled || MetaData(uid).EntityLifeStage >= EntityLifeStage.Terminating)
|
|
return;
|
|
|
|
if (!Resolve(uid, ref keyHolder))
|
|
return;
|
|
|
|
if (keyHolder.Channels.Count == 0)
|
|
RemComp<ActiveRadioComponent>(uid);
|
|
else
|
|
EnsureComp<ActiveRadioComponent>(uid).Channels = new(keyHolder.Channels);
|
|
}
|
|
|
|
private void OnSpeak(EntityUid uid, WearingHeadsetComponent component, EntitySpokeEvent args)
|
|
{
|
|
if (args.Channel != null
|
|
&& TryComp(component.Headset, out EncryptionKeyHolderComponent? keys)
|
|
&& keys.Channels.Contains(args.Channel.ID))
|
|
{
|
|
_radio.SendRadioMessage(uid, args.Message, args.Channel, component.Headset);
|
|
args.Channel = null; // prevent duplicate messages from other listeners.
|
|
}
|
|
}
|
|
|
|
protected override void OnGotEquipped(EntityUid uid, HeadsetComponent component, GotEquippedEvent args)
|
|
{
|
|
base.OnGotEquipped(uid, component, args);
|
|
if (component.IsEquipped && component.Enabled)
|
|
{
|
|
EnsureComp<WearingHeadsetComponent>(args.Equipee).Headset = uid;
|
|
UpdateRadioChannels(uid, component);
|
|
}
|
|
}
|
|
|
|
protected override void OnGotUnequipped(EntityUid uid, HeadsetComponent component, GotUnequippedEvent args)
|
|
{
|
|
base.OnGotUnequipped(uid, component, args);
|
|
component.IsEquipped = false;
|
|
RemComp<ActiveRadioComponent>(uid);
|
|
RemComp<WearingHeadsetComponent>(args.Equipee);
|
|
}
|
|
|
|
public void SetEnabled(EntityUid uid, bool value, HeadsetComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
if (component.Enabled == value)
|
|
return;
|
|
|
|
if (!value)
|
|
{
|
|
RemCompDeferred<ActiveRadioComponent>(uid);
|
|
|
|
if (component.IsEquipped)
|
|
RemCompDeferred<WearingHeadsetComponent>(Transform(uid).ParentUid);
|
|
}
|
|
else if (component.IsEquipped)
|
|
{
|
|
EnsureComp<WearingHeadsetComponent>(Transform(uid).ParentUid).Headset = uid;
|
|
UpdateRadioChannels(uid, component);
|
|
}
|
|
}
|
|
|
|
private void OnHeadsetReceive(EntityUid uid, HeadsetComponent component, ref RadioReceiveEvent args)
|
|
{
|
|
// TODO: change this when a code refactor is done
|
|
// this is currently done this way because receiving radio messages on an entity otherwise requires that entity
|
|
// to have an ActiveRadioComponent
|
|
|
|
var parent = Transform(uid).ParentUid;
|
|
|
|
if (parent.IsValid())
|
|
{
|
|
var relayEvent = new HeadsetRadioReceiveRelayEvent(args);
|
|
RaiseLocalEvent(parent, ref relayEvent);
|
|
}
|
|
|
|
if (TryComp(parent, out ActorComponent? actor))
|
|
_netMan.ServerSendMessage(args.ChatMsg, actor.PlayerSession.Channel);
|
|
}
|
|
|
|
private void OnEmpPulse(EntityUid uid, HeadsetComponent component, ref EmpPulseEvent args)
|
|
{
|
|
if (component.Enabled)
|
|
{
|
|
args.Affected = true;
|
|
args.Disabled = true;
|
|
}
|
|
}
|
|
}
|