Skip to content

Commit

Permalink
[Add+Fix] Deaf Trait & Fixes (#270)
Browse files Browse the repository at this point in the history
* let-looc-hear

* whispering

* IsBlockedByDeafness

* trait

* fix fix fix

* fix thanks rabbit

---------

Co-authored-by: vanx <discord@vanxxxx>
  • Loading branch information
Vaaankas and vanx authored Mar 4, 2025
1 parent bac2492 commit 3ab89f1
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 33 deletions.
39 changes: 7 additions & 32 deletions Content.Server/Chat/Systems/ChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public sealed partial class ChatSystem : SharedChatSystem
[Dependency] private readonly IReplayRecordingManager _replay = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly HearingSystem _hearing = default!;
[Dependency] private readonly IChatSanitizationManager _sanitizer = default!;
[Dependency] private readonly IAdminManager _adminManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
Expand Down Expand Up @@ -521,6 +522,11 @@ private void SendEntityWhisper(
if (MessageRangeCheck(session, data, range) != MessageRangeCheckResult.Full)
continue; // Won't get logged to chat, and ghosts are too far away to see the pop-up, so we just won't send it to them.

// WWDP Deafening
if (_hearing.IsBlockedByDeafness(session, ChatChannel.Whisper, language))
continue;
// WWDP end

var canUnderstandLanguage = _language.CanUnderstand(listener, language.ID);
// How the entity perceives the message depends on whether it can understand its language
var perceivedMessage = canUnderstandLanguage ? message : languageObfuscatedMessage;
Expand All @@ -547,25 +553,6 @@ private void SendEntityWhisper(
wrappedMessage = WrapWhisperMessage(source, "chat-manager-entity-whisper-unknown-wrap-message", string.Empty, result, language);
}

// WWDP Deafening
if (TryComp<MobStateComponent>(session.AttachedEntity, out var playermobstate))
{
if (playermobstate.CurrentState == MobState.Dead)
{
continue;
}
}

if (TryComp<DeafComponent>(session.AttachedEntity, out var deafComp))
{
var canthearmessage = Loc.GetString(deafComp.DeafChatMessage);
var wrappedcanthearmessage = $"{canthearmessage}";

_chatManager.ChatMessageToOne(ChatChannel.Local, canthearmessage, wrappedcanthearmessage, EntityUid.Invalid, false, session.Channel);
continue;
}
// WWDP end

_chatManager.ChatMessageToOne(ChatChannel.Whisper, result, wrappedMessage, source, false, session.Channel);
}

Expand Down Expand Up @@ -755,20 +742,8 @@ private void SendInVoiceRange(ChatChannel channel, string name, string message,
var entHideChat = entRange == MessageRangeCheckResult.HideChat;

// WWDP Deafening
if (TryComp<MobStateComponent>(session.AttachedEntity, out var playermobstate))
{
if (playermobstate.CurrentState == MobState.Dead)
continue;
}

if (TryComp<DeafComponent>(session.AttachedEntity, out var deafComp))
{
var canthearmessage = Loc.GetString(deafComp.DeafChatMessage);
var wrappedcanthearmessage = $"{canthearmessage}";

_chatManager.ChatMessageToOne(channel, canthearmessage, wrappedcanthearmessage, EntityUid.Invalid, false, session.Channel);
if (_hearing.IsBlockedByDeafness(session, channel, language))
continue;
}
// WWDP end

if (session.AttachedEntity is not { Valid: true } playerEntity)
Expand Down
7 changes: 7 additions & 0 deletions Content.Server/Radio/EntitySystems/HeadsetSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server._White.Hearing;
using Content.Server.Chat.Systems;
using Content.Server.Emp;
using Content.Server.Language;
Expand All @@ -17,6 +18,7 @@ public sealed class HeadsetSystem : SharedHeadsetSystem
{
[Dependency] private readonly INetManager _netMan = default!;
[Dependency] private readonly RadioSystem _radio = default!;
[Dependency] private readonly HearingSystem _hearing = default!;
[Dependency] private readonly LanguageSystem _language = default!;

public override void Initialize()
Expand Down Expand Up @@ -106,6 +108,11 @@ private void OnHeadsetReceive(EntityUid uid, HeadsetComponent component, ref Rad
var parent = Transform(uid).ParentUid;
if (TryComp(parent, out ActorComponent? actor))
{
// WWDP Deafening
if (_hearing.IsBlockedByDeafness(actor.PlayerSession, ChatChannel.Radio, args.Language))
return;
// WWDP end

var canUnderstand = _language.CanUnderstand(parent, args.Language.ID);
var msg = new MsgChatMessage
{
Expand Down
7 changes: 7 additions & 0 deletions Content.Server/Radio/EntitySystems/RadioSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Server._White.Hearing;
using Content.Server.Administration.Logs;
using Content.Server.Chat.Systems;
using Content.Server.Language;
Expand Down Expand Up @@ -33,6 +34,7 @@ public sealed class RadioSystem : EntitySystem
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly HearingSystem _hearing = default!;
[Dependency] private readonly LanguageSystem _language = default!;

// set used to prevent radio feedback loops.
Expand Down Expand Up @@ -74,6 +76,11 @@ private void OnIntrinsicReceive(EntityUid uid, IntrinsicRadioReceiverComponent c
{
if (TryComp(uid, out ActorComponent? actor))
{
// WWDP Deafening
if (_hearing.IsBlockedByDeafness(actor.PlayerSession, ChatChannel.Radio, args.Language))
return;
// WWDP end

// Einstein-Engines - languages mechanic
var listener = component.Owner;
var msg = args.OriginalChatMsg;
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/_White/Hearing/DeafComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed partial class DeafComponent : Component
public LocId DeafChatMessage = "deaf-chat-message";

[DataField]
public bool Permanent = false;
public bool Permanent = true;

[DataField]
public float Duration = 0f; // In seconds
Expand Down
29 changes: 29 additions & 0 deletions Content.Server/_White/Hearing/HearingSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System.Threading;
using Content.Server.Chat.Managers;
using Content.Shared.Bed.Sleep;
using Content.Shared.Chat;
using Content.Shared.Language;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Systems;
using Robust.Shared.Player;


namespace Content.Server._White.Hearing;
Expand All @@ -10,6 +14,7 @@ public sealed class HearingSystem : EntitySystem
{
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly EntityManager _entityManager = default!;
[Dependency] private readonly IChatManager _chatManager = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -75,6 +80,7 @@ private void OnHearingChanged(EntityUid uid, HearingComponent component, Hearing
}

EnsureComp<DeafComponent>(uid, out var deafComponent);
deafComponent.Permanent = false;
deafComponent.DeafChatMessage = args.DeafChatMessage;

deafComponent.TokenSource?.Cancel();
Expand All @@ -88,4 +94,27 @@ private void OnTimerFired(EntityUid uid, DeafComponent deafComponent)
if (!deafComponent.Permanent)
RemComp<DeafComponent>(uid);
}

// Public API
// Returns true if the message can not be heard
// If true, sends a DeafChatMessage in player's chat
public bool IsBlockedByDeafness(ICommonSession session, ChatChannel channel, LanguagePrototype language)
{
if (channel is not (ChatChannel.Local or ChatChannel.Whisper or ChatChannel.Radio or ChatChannel.Notifications))
return false;

if (!language.SpeechOverride.RequireSpeech) // Non-verbal languages e.g. sign language
return false;

if (TryComp<DeafComponent>(session.AttachedEntity, out var deafComp))
{
var canthearmessage = Loc.GetString(deafComp.DeafChatMessage);
var wrappedcanthearmessage = $"{canthearmessage}";

_chatManager.ChatMessageToOne(ChatChannel.Local, canthearmessage, wrappedcanthearmessage, EntityUid.Invalid, false, session.Channel);
return true;
}

return false;
}
}
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/_white/traits/traits.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trait-name-Deaf = Deaf
trait-description-Deaf = You can not hear anything anyone says! Luckily, you seem to know how to communicate in the sign language.
2 changes: 2 additions & 0 deletions Resources/Locale/ru-RU/_white/traits/traits.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trait-name-Deaf = Глухой
trait-description-Deaf = Вы совершенно ничего не слышите! К вашему счастью, вы всё ещё можете общаться на языке жестов.
19 changes: 19 additions & 0 deletions Resources/Prototypes/_White/Traits/traits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- type: trait
id: Deaf
category: Auditory
points: 4
requirements:
- !type:CharacterJobRequirement
inverted: true
jobs:
- Borg
- MedicalBorg
functions:
- !type:TraitAddComponent
components:
- type: Deaf
- !type:TraitModifyLanguages
languagesSpoken:
- Sign
languagesUnderstood:
- Sign

0 comments on commit 3ab89f1

Please sign in to comment.