mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-09-29 23:57:29 +00:00
* Changed up how emoting works This was a long 10 hours just to get the chat to behave slightly different. At least we can now scream over radio! Will most definitely need some more work to get bugs out since this is the first implementation. * Not ok This was unmarked for some reason... I don't remember unmarking this. * DeltaV comments Added comments to explain changes. Moved localization files to the _DV folder. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Moved code Moved code to more suitable files and added some comments. * Rights for robots Now those with intrinsic radios can also emote! * Fixes up some small stuff Changes to fix some small issues with the code to align it more with modern standards. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix by-ref event Never worked with this event type before so gonna hope this works. * Update Content.Shared/Chat/SharedChatSystem.Emote.cs Signed-off-by: pathetic meowmeow <uhhadd@gmail.com> * Update Content.Shared/Chat/SharedChatSystem.cs Signed-off-by: pathetic meowmeow <uhhadd@gmail.com> * Update Content.Server/Chat/Systems/ChatSystem.cs Signed-off-by: pathetic meowmeow <uhhadd@gmail.com> * fix style nits * remove conflicting chatsan --------- Signed-off-by: pathetic meowmeow <uhhadd@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: pathetic meowmeow <uhhadd@gmail.com>
154 lines
5.8 KiB
C#
154 lines
5.8 KiB
C#
using Content.Shared.Cuffs; // DeltaV
|
|
using Content.Shared.Cuffs.Components; // DeltaV
|
|
using Content.Shared.Hands.Components; // DeltaV
|
|
using Content.Shared.Chat;
|
|
using Content.Shared.Inventory.Events;
|
|
using Content.Shared.Popups; // DeltaV
|
|
using Content.Shared.Radio;
|
|
using Content.Shared.Radio.Components;
|
|
using Content.Shared.Radio.EntitySystems;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Player;
|
|
using Content.Shared._DV.Chat;
|
|
|
|
namespace Content.Server.Radio.EntitySystems;
|
|
|
|
public sealed class HeadsetSystem : SharedHeadsetSystem
|
|
{
|
|
[Dependency] private readonly INetManager _netMan = default!;
|
|
[Dependency] private readonly RadioSystem _radio = default!;
|
|
[Dependency] private readonly SharedCuffableSystem _cuffable = default!; // DeltaV
|
|
[Dependency] private readonly SharedPopupSystem _popup = default!; // DeltaV
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<HeadsetComponent, RadioReceiveEvent>(OnHeadsetReceive);
|
|
SubscribeLocalEvent<HeadsetComponent, EncryptionChannelsChangedEvent>(OnKeysChanged);
|
|
|
|
SubscribeLocalEvent<WearingHeadsetComponent, EntitySpokeEvent>(OnSpeak);
|
|
SubscribeLocalEvent<WearingHeadsetComponent, EntityAudiblyEmotedEvent>(OnAudibleEmote); // DeltaV
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
// DeltaV
|
|
// WARNING - Be very careful when modifying this method.
|
|
// The implementation right now has null forgiving operatiors in OnSpeak() and OnAudibleEmote() since this only returns true if channel is not null
|
|
private bool CheckRadioCapable(EntityUid uid, WearingHeadsetComponent headset, RadioChannelPrototype? channel)
|
|
{
|
|
if (channel != null
|
|
&& TryComp(headset.Headset, out EncryptionKeyHolderComponent? keys)
|
|
&& keys.Channels.Contains(channel.ID))
|
|
{
|
|
if (!TryComp<HandsComponent>(uid, out var hands) || hands.Count < 1 ||
|
|
TryComp<CuffableComponent>(uid, out var cuffable) && _cuffable.IsCuffed((uid, cuffable)))
|
|
{
|
|
_popup.PopupEntity(Loc.GetString("headset-cant-reach"), uid, uid, PopupType.SmallCaution);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private void OnAudibleEmote(EntityUid uid, WearingHeadsetComponent component, EntityAudiblyEmotedEvent args)
|
|
{
|
|
if (CheckRadioCapable(uid, component, args.Channel))
|
|
{
|
|
_radio.SendRadioMessage(uid, args.Message, args.Channel!, component.Headset, emType: args.Type);
|
|
args.Channel = null;
|
|
}
|
|
}
|
|
// DeltaV - End
|
|
|
|
private void OnSpeak(EntityUid uid, WearingHeadsetComponent component, EntitySpokeEvent args)
|
|
{
|
|
if (CheckRadioCapable(uid, component, args.Channel)) // DeltaV - Put all the radio checks into the CheckRadioCapable() method.
|
|
{
|
|
_radio.SendRadioMessage(uid, args.Message, args.Channel!, component.Headset); // DeltaV - Made the args.Channel null ignorant as CheckRadioCapable() guarantees it not null.
|
|
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);
|
|
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;
|
|
|
|
component.Enabled = value;
|
|
Dirty(uid, component);
|
|
|
|
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);
|
|
}
|
|
}
|