From 1d6f31c7b7034436dc5f4d89d2dc32fa2fac19a5 Mon Sep 17 00:00:00 2001 From: Stalen <33173619+stalengd@users.noreply.github.com> Date: Sat, 28 Dec 2024 21:21:37 +0300 Subject: [PATCH] Block telepathy on death (#2419) * Block telepathy on death * Return BOM --- .../SS220/Telepathy/TelepathySystem.cs | 16 ++++++++++++++-- .../Administration/SharedAdminFrozenSystem.cs | 10 ++++++++++ Content.Shared/Bed/Sleep/SleepingSystem.cs | 9 +++++++++ .../Mobs/Systems/MobStateSystem.Subscribers.cs | 15 +++++++++++++++ .../SS220/Telepathy/TelepathyComponent.cs | 3 +++ 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/Content.Server/SS220/Telepathy/TelepathySystem.cs b/Content.Server/SS220/Telepathy/TelepathySystem.cs index eaae1cf2082819..7c29a49978a50a 100644 --- a/Content.Server/SS220/Telepathy/TelepathySystem.cs +++ b/Content.Server/SS220/Telepathy/TelepathySystem.cs @@ -50,8 +50,13 @@ private void OnTelepathyAnnouncementSend(Entity ent, ref Tel private void OnTelepathySend(Entity ent, ref TelepathySendEvent args) { - if (ent.Comp.TelepathyChannelPrototype is { } telepathyChannel) - SendMessageToEveryoneWithRightChannel(telepathyChannel, args.Message, ent); + if (ent.Comp.TelepathyChannelPrototype is not { } telepathyChannel) + return; + + if (!CanSendTelepathy(ent)) + return; + + SendMessageToEveryoneWithRightChannel(telepathyChannel, args.Message, ent); } /// @@ -166,4 +171,11 @@ private string GetSenderName(EntityUid? senderUid) var name = Name(nameEv.Sender); return name; } + + private bool CanSendTelepathy(EntityUid sender) + { + var args = new TelepathySendAttemptEvent(sender, false); + RaiseLocalEvent(sender, ref args); + return !args.Cancelled; + } } diff --git a/Content.Shared/Administration/SharedAdminFrozenSystem.cs b/Content.Shared/Administration/SharedAdminFrozenSystem.cs index 259df2bdf2ac14..beca070ffb162b 100644 --- a/Content.Shared/Administration/SharedAdminFrozenSystem.cs +++ b/Content.Shared/Administration/SharedAdminFrozenSystem.cs @@ -7,6 +7,7 @@ using Content.Shared.Movement.Pulling.Events; using Content.Shared.Movement.Pulling.Systems; using Content.Shared.Speech; +using Content.Shared.SS220.Telepathy; using Content.Shared.Throwing; namespace Content.Shared.Administration; @@ -33,6 +34,7 @@ public override void Initialize() SubscribeLocalEvent(OnAttempt); SubscribeLocalEvent(OnEmoteAttempt); SubscribeLocalEvent(OnSpeakAttempt); + SubscribeLocalEvent(OnTelepathyAttempt); // SS220 Block telepathy on death } private void OnInteractAttempt(Entity ent, ref InteractionAttemptEvent args) @@ -86,4 +88,12 @@ private void OnEmoteAttempt(EntityUid uid, AdminFrozenComponent component, Emote if (component.Muted) args.Cancel(); } + + // SS220 Block telepathy on death begin + private void OnTelepathyAttempt(Entity entity, ref TelepathySendAttemptEvent args) + { + if (entity.Comp.Muted) + args.Cancelled = true; + } + // SS220 Block telepathy on death end } diff --git a/Content.Shared/Bed/Sleep/SleepingSystem.cs b/Content.Shared/Bed/Sleep/SleepingSystem.cs index 3c863520c4c7b0..8f62cceed9b8a1 100644 --- a/Content.Shared/Bed/Sleep/SleepingSystem.cs +++ b/Content.Shared/Bed/Sleep/SleepingSystem.cs @@ -23,6 +23,7 @@ using Robust.Shared.Prototypes; using Robust.Shared.Timing; using Content.Shared.Emoting; +using Content.Shared.SS220.Telepathy; namespace Content.Shared.Bed.Sleep; @@ -64,6 +65,7 @@ public override void Initialize() SubscribeLocalEvent(OnInit); SubscribeLocalEvent(OnUnbuckleAttempt); SubscribeLocalEvent(OnEmoteAttempt); + SubscribeLocalEvent(OnTelepathyAttempt); // SS220 Block telepathy on death } private void OnUnbuckleAttempt(Entity ent, ref UnbuckleAttemptEvent args) @@ -318,6 +320,13 @@ public void OnEmoteAttempt(Entity ent, ref EmoteAttemptEvent { args.Cancel(); } + + // SS220 Block telepathy on death begin + public void OnTelepathyAttempt(Entity ent, ref TelepathySendAttemptEvent args) + { + args.Cancelled = true; + } + // SS220 Block telepathy on death end } diff --git a/Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs b/Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs index f99bd43febccbe..2b714aebed0b8e 100644 --- a/Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs +++ b/Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs @@ -13,6 +13,7 @@ using Content.Shared.Pointing; using Content.Shared.Pulling.Events; using Content.Shared.Speech; +using Content.Shared.SS220.Telepathy; using Content.Shared.Standing; using Content.Shared.Strip.Components; using Content.Shared.Throwing; @@ -32,6 +33,7 @@ private void SubscribeEvents() SubscribeLocalEvent(CheckConcious); SubscribeLocalEvent(CheckAct); SubscribeLocalEvent(OnSpeakAttempt); + SubscribeLocalEvent(OnTelepathyAttempt); // SS220 Block telepathy on death SubscribeLocalEvent(OnEquipAttempt); SubscribeLocalEvent(CheckAct); SubscribeLocalEvent(OnUnequipAttempt); @@ -148,6 +150,19 @@ private void OnSpeakAttempt(EntityUid uid, MobStateComponent component, SpeakAtt CheckAct(uid, component, args); } + // SS220 Block telepathy on death begin + private void OnTelepathyAttempt(Entity entity, ref TelepathySendAttemptEvent args) + { + switch (entity.Comp.CurrentState) + { + case MobState.Dead: + case MobState.Critical: + args.Cancelled = true; + break; + } + } + // SS220 Block telepathy on death end + private void CheckAct(EntityUid target, MobStateComponent component, CancellableEntityEventArgs args) { switch (component.CurrentState) diff --git a/Content.Shared/SS220/Telepathy/TelepathyComponent.cs b/Content.Shared/SS220/Telepathy/TelepathyComponent.cs index 0a85aa8f152ba6..b8a55779f7d92f 100644 --- a/Content.Shared/SS220/Telepathy/TelepathyComponent.cs +++ b/Content.Shared/SS220/Telepathy/TelepathyComponent.cs @@ -42,3 +42,6 @@ public TelepathyAnnouncementSendEvent(string message, string telepathyChannel) TelepathyChannel = telepathyChannel; } } + +[ByRefEvent] +public record struct TelepathySendAttemptEvent(EntityUid Sender, bool Cancelled);