Intercom buffs and fixes (#29580)
* Intercom buffs and fixes * remove unused bui state * mild sec intercom buff * reinforce sec intercoms
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Server.Interaction;
|
||||
using Content.Server.Popups;
|
||||
@@ -6,13 +7,10 @@ using Content.Server.Power.EntitySystems;
|
||||
using Content.Server.Radio.Components;
|
||||
using Content.Server.Speech;
|
||||
using Content.Server.Speech.Components;
|
||||
using Content.Shared.UserInterface;
|
||||
using Content.Shared.Chat;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Radio;
|
||||
using Content.Shared.Radio.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Radio.EntitySystems;
|
||||
@@ -28,7 +26,6 @@ public sealed class RadioDeviceSystem : EntitySystem
|
||||
[Dependency] private readonly RadioSystem _radio = default!;
|
||||
[Dependency] private readonly InteractionSystem _interaction = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
||||
|
||||
// Used to prevent a shitter from using a bunch of radios to spam chat.
|
||||
private HashSet<(string, EntityUid)> _recentlySent = new();
|
||||
@@ -47,7 +44,7 @@ public sealed class RadioDeviceSystem : EntitySystem
|
||||
SubscribeLocalEvent<RadioSpeakerComponent, ActivateInWorldEvent>(OnActivateSpeaker);
|
||||
SubscribeLocalEvent<RadioSpeakerComponent, RadioReceiveEvent>(OnReceiveRadio);
|
||||
|
||||
SubscribeLocalEvent<IntercomComponent, BeforeActivatableUIOpenEvent>(OnBeforeIntercomUiOpen);
|
||||
SubscribeLocalEvent<IntercomComponent, EncryptionChannelsChangedEvent>(OnIntercomEncryptionChannelsChanged);
|
||||
SubscribeLocalEvent<IntercomComponent, ToggleIntercomMicMessage>(OnToggleIntercomMic);
|
||||
SubscribeLocalEvent<IntercomComponent, ToggleIntercomSpeakerMessage>(OnToggleIntercomSpeaker);
|
||||
SubscribeLocalEvent<IntercomComponent, SelectIntercomChannelMessage>(OnSelectIntercomChannel);
|
||||
@@ -150,18 +147,18 @@ public sealed class RadioDeviceSystem : EntitySystem
|
||||
SetSpeakerEnabled(uid, user, !component.Enabled, quiet, component);
|
||||
}
|
||||
|
||||
public void SetSpeakerEnabled(EntityUid uid, EntityUid user, bool enabled, bool quiet = false, RadioSpeakerComponent? component = null)
|
||||
public void SetSpeakerEnabled(EntityUid uid, EntityUid? user, bool enabled, bool quiet = false, RadioSpeakerComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
|
||||
component.Enabled = enabled;
|
||||
|
||||
if (!quiet)
|
||||
if (!quiet && user != null)
|
||||
{
|
||||
var state = Loc.GetString(component.Enabled ? "handheld-radio-component-on-state" : "handheld-radio-component-off-state");
|
||||
var message = Loc.GetString("handheld-radio-component-on-use", ("radioState", state));
|
||||
_popup.PopupEntity(message, user, user);
|
||||
_popup.PopupEntity(message, user.Value, user.Value);
|
||||
}
|
||||
|
||||
_appearance.SetData(uid, RadioDeviceVisuals.Speaker, component.Enabled);
|
||||
@@ -213,61 +210,74 @@ public sealed class RadioDeviceSystem : EntitySystem
|
||||
var nameEv = new TransformSpeakerNameEvent(args.MessageSource, Name(args.MessageSource));
|
||||
RaiseLocalEvent(args.MessageSource, nameEv);
|
||||
|
||||
var name = Loc.GetString("speech-name-relay", ("speaker", Name(uid)),
|
||||
var name = Loc.GetString("speech-name-relay",
|
||||
("speaker", Name(uid)),
|
||||
("originalName", nameEv.Name));
|
||||
|
||||
// log to chat so people can identity the speaker/source, but avoid clogging ghost chat if there are many radios
|
||||
_chat.TrySendInGameICMessage(uid, args.Message, InGameICChatType.Whisper, ChatTransmitRange.GhostRangeLimit, nameOverride: name, checkRadioPrefix: false);
|
||||
}
|
||||
|
||||
private void OnBeforeIntercomUiOpen(EntityUid uid, IntercomComponent component, BeforeActivatableUIOpenEvent args)
|
||||
private void OnIntercomEncryptionChannelsChanged(Entity<IntercomComponent> ent, ref EncryptionChannelsChangedEvent args)
|
||||
{
|
||||
UpdateIntercomUi(uid, component);
|
||||
ent.Comp.SupportedChannels = args.Component.Channels.Select(p => new ProtoId<RadioChannelPrototype>(p)).ToList();
|
||||
|
||||
var channel = args.Component.DefaultChannel;
|
||||
if (ent.Comp.CurrentChannel != null && ent.Comp.SupportedChannels.Contains(ent.Comp.CurrentChannel.Value))
|
||||
channel = ent.Comp.CurrentChannel;
|
||||
|
||||
SetIntercomChannel(ent, channel);
|
||||
}
|
||||
|
||||
private void OnToggleIntercomMic(EntityUid uid, IntercomComponent component, ToggleIntercomMicMessage args)
|
||||
private void OnToggleIntercomMic(Entity<IntercomComponent> ent, ref ToggleIntercomMicMessage args)
|
||||
{
|
||||
if (component.RequiresPower && !this.IsPowered(uid, EntityManager))
|
||||
if (ent.Comp.RequiresPower && !this.IsPowered(ent, EntityManager))
|
||||
return;
|
||||
|
||||
SetMicrophoneEnabled(uid, args.Actor, args.Enabled, true);
|
||||
UpdateIntercomUi(uid, component);
|
||||
SetMicrophoneEnabled(ent, args.Actor, args.Enabled, true);
|
||||
ent.Comp.MicrophoneEnabled = args.Enabled;
|
||||
Dirty(ent);
|
||||
}
|
||||
|
||||
private void OnToggleIntercomSpeaker(EntityUid uid, IntercomComponent component, ToggleIntercomSpeakerMessage args)
|
||||
private void OnToggleIntercomSpeaker(Entity<IntercomComponent> ent, ref ToggleIntercomSpeakerMessage args)
|
||||
{
|
||||
if (component.RequiresPower && !this.IsPowered(uid, EntityManager))
|
||||
if (ent.Comp.RequiresPower && !this.IsPowered(ent, EntityManager))
|
||||
return;
|
||||
|
||||
SetSpeakerEnabled(uid, args.Actor, args.Enabled, true);
|
||||
UpdateIntercomUi(uid, component);
|
||||
SetSpeakerEnabled(ent, args.Actor, args.Enabled, true);
|
||||
ent.Comp.SpeakerEnabled = args.Enabled;
|
||||
Dirty(ent);
|
||||
}
|
||||
|
||||
private void OnSelectIntercomChannel(EntityUid uid, IntercomComponent component, SelectIntercomChannelMessage args)
|
||||
private void OnSelectIntercomChannel(Entity<IntercomComponent> ent, ref SelectIntercomChannelMessage args)
|
||||
{
|
||||
if (component.RequiresPower && !this.IsPowered(uid, EntityManager))
|
||||
if (ent.Comp.RequiresPower && !this.IsPowered(ent, EntityManager))
|
||||
return;
|
||||
|
||||
if (!_protoMan.TryIndex<RadioChannelPrototype>(args.Channel, out _) || !component.SupportedChannels.Contains(args.Channel))
|
||||
if (!_protoMan.HasIndex<RadioChannelPrototype>(args.Channel) || !ent.Comp.SupportedChannels.Contains(args.Channel))
|
||||
return;
|
||||
|
||||
if (TryComp<RadioMicrophoneComponent>(uid, out var mic))
|
||||
mic.BroadcastChannel = args.Channel;
|
||||
if (TryComp<RadioSpeakerComponent>(uid, out var speaker))
|
||||
speaker.Channels = new(){ args.Channel };
|
||||
UpdateIntercomUi(uid, component);
|
||||
SetIntercomChannel(ent, args.Channel);
|
||||
}
|
||||
|
||||
private void UpdateIntercomUi(EntityUid uid, IntercomComponent component)
|
||||
private void SetIntercomChannel(Entity<IntercomComponent> ent, ProtoId<RadioChannelPrototype>? channel)
|
||||
{
|
||||
var micComp = CompOrNull<RadioMicrophoneComponent>(uid);
|
||||
var speakerComp = CompOrNull<RadioSpeakerComponent>(uid);
|
||||
ent.Comp.CurrentChannel = channel;
|
||||
|
||||
var micEnabled = micComp?.Enabled ?? false;
|
||||
var speakerEnabled = speakerComp?.Enabled ?? false;
|
||||
var availableChannels = component.SupportedChannels;
|
||||
var selectedChannel = micComp?.BroadcastChannel ?? SharedChatSystem.CommonChannel;
|
||||
var state = new IntercomBoundUIState(micEnabled, speakerEnabled, availableChannels, selectedChannel);
|
||||
_ui.SetUiState(uid, IntercomUiKey.Key, state);
|
||||
if (channel == null)
|
||||
{
|
||||
SetSpeakerEnabled(ent, null, false);
|
||||
SetMicrophoneEnabled(ent, null, false);
|
||||
ent.Comp.MicrophoneEnabled = false;
|
||||
ent.Comp.SpeakerEnabled = false;
|
||||
Dirty(ent);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryComp<RadioMicrophoneComponent>(ent, out var mic))
|
||||
mic.BroadcastChannel = channel;
|
||||
if (TryComp<RadioSpeakerComponent>(ent, out var speaker))
|
||||
speaker.Channels = new(){ channel };
|
||||
Dirty(ent);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user