From b4046bc2bb498bd525b8a40c7839a543c92ca18c Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Tue, 23 Jan 2024 17:12:18 -0500 Subject: [PATCH] Fix sloshing electricity & enable SpeechVerb masking (#24238) * Implemented electricity speech verb masking * Handle speech verb override elsewhere in the system, even though we're not using it * Fix that protoId business * No nullable component fields * Use ProtoId, and try going back to a nullable. Specifiy DataFields on VoiceMaskComponent. --- Content.Server/Chat/Systems/ChatSystem.cs | 11 +++++++++-- .../Radio/EntitySystems/RadioSystem.cs | 13 ++++++++++++- .../Speech/Components/ListenWireAction.cs | 17 ++++++++++++----- Content.Server/VoiceMask/VoiceMaskComponent.cs | 18 ++++++++++++++++-- Content.Server/VoiceMask/VoiceMaskSystem.cs | 2 ++ .../en-US/chat/managers/chat-manager.ftl | 4 ++++ Resources/Prototypes/Voice/speech_verbs.yml | 7 +++++++ 7 files changed, 62 insertions(+), 10 deletions(-) diff --git a/Content.Server/Chat/Systems/ChatSystem.cs b/Content.Server/Chat/Systems/ChatSystem.cs index 81656d29d7..7a8446be8a 100644 --- a/Content.Server/Chat/Systems/ChatSystem.cs +++ b/Content.Server/Chat/Systems/ChatSystem.cs @@ -19,6 +19,7 @@ using Content.Shared.Interaction; using Content.Shared.Mobs.Systems; using Content.Shared.Players; using Content.Shared.Radio; +using Content.Shared.Speech; using Robust.Server.Player; using Robust.Shared.Audio; using Robust.Shared.Audio.Systems; @@ -389,6 +390,8 @@ public sealed partial class ChatSystem : SharedChatSystem if (message.Length == 0) return; + var speech = GetSpeechVerb(source, message); + // get the entity's apparent name (if no override provided). string name; if (nameOverride != null) @@ -400,10 +403,12 @@ public sealed partial class ChatSystem : SharedChatSystem var nameEv = new TransformSpeakerNameEvent(source, Name(source)); RaiseLocalEvent(source, nameEv); name = nameEv.Name; + // Check for a speech verb override + if (nameEv.SpeechVerb != null && _prototypeManager.TryIndex(nameEv.SpeechVerb, out var proto)) + speech = proto; } name = FormattedMessage.EscapeText(name); - var speech = GetSpeechVerb(source, message); var wrappedMessage = Loc.GetString(speech.Bold ? "chat-manager-entity-say-bold-wrap-message" : "chat-manager-entity-say-wrap-message", ("entityName", name), ("verb", Loc.GetString(_random.Pick(speech.SpeechVerbStrings))), @@ -872,11 +877,13 @@ public sealed class TransformSpeakerNameEvent : EntityEventArgs { public EntityUid Sender; public string Name; + public string? SpeechVerb; - public TransformSpeakerNameEvent(EntityUid sender, string name) + public TransformSpeakerNameEvent(EntityUid sender, string name, string? speechVerb = null) { Sender = sender; Name = name; + SpeechVerb = speechVerb; } } diff --git a/Content.Server/Radio/EntitySystems/RadioSystem.cs b/Content.Server/Radio/EntitySystems/RadioSystem.cs index 8569d51d59..5d3074b06b 100644 --- a/Content.Server/Radio/EntitySystems/RadioSystem.cs +++ b/Content.Server/Radio/EntitySystems/RadioSystem.cs @@ -7,6 +7,7 @@ using Content.Shared.Chat; using Content.Shared.Database; using Content.Shared.Radio; using Content.Shared.Radio.Components; +using Content.Shared.Speech; using Robust.Shared.Map; using Robust.Shared.Network; using Robust.Shared.Player; @@ -79,7 +80,17 @@ public sealed class RadioSystem : EntitySystem name = FormattedMessage.EscapeText(name); - var speech = _chat.GetSpeechVerb(messageSource, message); + SpeechVerbPrototype speech; + if (mask != null + && mask.Enabled + && mask.SpeechVerb != null + && _prototype.TryIndex(mask.SpeechVerb, out var proto)) + { + speech = proto; + } + else + speech = _chat.GetSpeechVerb(messageSource, message); + var content = escapeMarkup ? FormattedMessage.EscapeText(message) : message; diff --git a/Content.Server/Speech/Components/ListenWireAction.cs b/Content.Server/Speech/Components/ListenWireAction.cs index 1748ab3d6d..68d2201862 100644 --- a/Content.Server/Speech/Components/ListenWireAction.cs +++ b/Content.Server/Speech/Components/ListenWireAction.cs @@ -1,8 +1,5 @@ -using System.Text; - using Content.Server.Speech.Components; using Content.Server.Chat.Systems; -using Content.Server.Speech.EntitySystems; using Content.Server.VoiceMask; using Content.Server.Wires; using Content.Shared.Speech; @@ -18,7 +15,13 @@ public sealed partial class ListenWireAction : BaseToggleWireAction /// /// Length of the gibberish string sent when pulsing the wire /// - private int _noiseLength = 16; + private const int NoiseLength = 16; + + /// + /// Identifier of the SpeechVerbPrototype to use when pulsing the wire + /// + [ValidatePrototypeId] + private const string SpeechVerb = "Electricity"; public override Color Color { get; set; } = Color.Green; public override string Name { get; set; } = "wire-name-listen"; @@ -75,19 +78,22 @@ public sealed partial class ListenWireAction : BaseToggleWireAction // Save the user's existing voicemask if they have one var oldEnabled = true; var oldVoiceName = Loc.GetString("wire-listen-pulse-error-name"); + string? oldSpeechVerb = null; if (EntityManager.TryGetComponent(user, out var oldMask)) { oldEnabled = oldMask.Enabled; oldVoiceName = oldMask.VoiceName; + oldSpeechVerb = oldMask.SpeechVerb; } // Give the user a temporary voicemask component var mask = EntityManager.EnsureComponent(user); mask.Enabled = true; mask.VoiceName = Loc.GetString("wire-listen-pulse-identifier"); + mask.SpeechVerb = SpeechVerb; var chars = Loc.GetString("wire-listen-pulse-characters").ToCharArray(); - var noiseMsg = _chat.BuildGibberishString(chars, _noiseLength); + var noiseMsg = _chat.BuildGibberishString(chars, NoiseLength); var attemptEv = new ListenAttemptEvent(wire.Owner); EntityManager.EventBus.RaiseLocalEvent(wire.Owner, attemptEv); @@ -104,6 +110,7 @@ public sealed partial class ListenWireAction : BaseToggleWireAction { mask.Enabled = oldEnabled; mask.VoiceName = oldVoiceName; + mask.SpeechVerb = oldSpeechVerb; } base.Pulse(user, wire); diff --git a/Content.Server/VoiceMask/VoiceMaskComponent.cs b/Content.Server/VoiceMask/VoiceMaskComponent.cs index edf38b39d4..d0c9200300 100644 --- a/Content.Server/VoiceMask/VoiceMaskComponent.cs +++ b/Content.Server/VoiceMask/VoiceMaskComponent.cs @@ -1,9 +1,23 @@ +using Content.Shared.Speech; +using Robust.Shared.Prototypes; + namespace Content.Server.VoiceMask; [RegisterComponent] public sealed partial class VoiceMaskComponent : Component { - [ViewVariables(VVAccess.ReadWrite)] public bool Enabled = true; + [DataField] + [ViewVariables(VVAccess.ReadWrite)] + public bool Enabled = true; - [ViewVariables(VVAccess.ReadWrite)] public string VoiceName = "Unknown"; + [DataField] + [ViewVariables(VVAccess.ReadWrite)] + public string VoiceName = "Unknown"; + + /// + /// If EnableSpeechVerbModification is true, overrides the speech verb used when this entity speaks. + /// + [DataField] + [ViewVariables(VVAccess.ReadWrite)] + public ProtoId? SpeechVerb; } diff --git a/Content.Server/VoiceMask/VoiceMaskSystem.cs b/Content.Server/VoiceMask/VoiceMaskSystem.cs index 8e1c2c66f2..380eb7e701 100644 --- a/Content.Server/VoiceMask/VoiceMaskSystem.cs +++ b/Content.Server/VoiceMask/VoiceMaskSystem.cs @@ -66,6 +66,8 @@ public sealed partial class VoiceMaskSystem : EntitySystem */ args.Name = component.VoiceName; + if (component.SpeechVerb != null) + args.SpeechVerb = component.SpeechVerb; } } diff --git a/Resources/Locale/en-US/chat/managers/chat-manager.ftl b/Resources/Locale/en-US/chat/managers/chat-manager.ftl index 9eeb39a0f0..6bbb3cd449 100644 --- a/Resources/Locale/en-US/chat/managers/chat-manager.ftl +++ b/Resources/Locale/en-US/chat/managers/chat-manager.ftl @@ -113,3 +113,7 @@ chat-speech-verb-ghost-1 = complains chat-speech-verb-ghost-2 = breathes chat-speech-verb-ghost-3 = hums chat-speech-verb-ghost-4 = mutters + +chat-speech-verb-electricity-1 = crackles +chat-speech-verb-electricity-2 = buzzes +chat-speech-verb-electricity-3 = screeches diff --git a/Resources/Prototypes/Voice/speech_verbs.yml b/Resources/Prototypes/Voice/speech_verbs.yml index 29e6d750af..b849a32a54 100644 --- a/Resources/Prototypes/Voice/speech_verbs.yml +++ b/Resources/Prototypes/Voice/speech_verbs.yml @@ -121,3 +121,10 @@ - chat-speech-verb-ghost-3 - chat-speech-verb-ghost-4 - chat-speech-verb-mumble + +- type: speechVerb + id: Electricity + speechVerbStrings: + - chat-speech-verb-electricity-1 + - chat-speech-verb-electricity-2 + - chat-speech-verb-electricity-3