]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix sloshing electricity & enable SpeechVerb masking (#24238)
authorTayrtahn <tayrtahn@gmail.com>
Tue, 23 Jan 2024 22:12:18 +0000 (17:12 -0500)
committerGitHub <noreply@github.com>
Tue, 23 Jan 2024 22:12:18 +0000 (17:12 -0500)
* 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
Content.Server/Radio/EntitySystems/RadioSystem.cs
Content.Server/Speech/Components/ListenWireAction.cs
Content.Server/VoiceMask/VoiceMaskComponent.cs
Content.Server/VoiceMask/VoiceMaskSystem.cs
Resources/Locale/en-US/chat/managers/chat-manager.ftl
Resources/Prototypes/Voice/speech_verbs.yml

index 81656d29d7da9738659eab49a22a5217e00d057f..7a8446be8a2d041bf241919269bd8c745e304f8b 100644 (file)
@@ -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<SpeechVerbPrototype>(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;
     }
 }
 
index 8569d51d590bec85a29cefe4de4bf6283a938329..5d3074b06b61dbe522b5835c5d40dd37554ac8e0 100644 (file)
@@ -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<SpeechVerbPrototype>(mask.SpeechVerb, out var proto))
+        {
+            speech = proto;
+        }
+        else
+            speech = _chat.GetSpeechVerb(messageSource, message);
+
         var content = escapeMarkup
             ? FormattedMessage.EscapeText(message)
             : message;
index 1748ab3d6de835932df023ffbbf8d4383be72689..68d2201862ca79014802056aba46dedf97fafd48 100644 (file)
@@ -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
     /// <summary>
     /// Length of the gibberish string sent when pulsing the wire
     /// </summary>
-    private int _noiseLength = 16;
+    private const int NoiseLength = 16;
+
+    /// <summary>
+    /// Identifier of the SpeechVerbPrototype to use when pulsing the wire
+    /// </summary>
+    [ValidatePrototypeId<SpeechVerbPrototype>]
+    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<VoiceMaskComponent>(user, out var oldMask))
         {
             oldEnabled = oldMask.Enabled;
             oldVoiceName = oldMask.VoiceName;
+            oldSpeechVerb = oldMask.SpeechVerb;
         }
 
         // Give the user a temporary voicemask component
         var mask = EntityManager.EnsureComponent<VoiceMaskComponent>(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);
index edf38b39d482c68a20180bc7e8e2bcc3023bf255..d0c920030063db9c760ba743e7ae06f0e10bf76d 100644 (file)
@@ -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;
+
+    [DataField]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public string VoiceName = "Unknown";
 
-    [ViewVariables(VVAccess.ReadWrite)] public string VoiceName = "Unknown";
+    /// <summary>
+    /// If EnableSpeechVerbModification is true, overrides the speech verb used when this entity speaks.
+    /// </summary>
+    [DataField]
+    [ViewVariables(VVAccess.ReadWrite)]
+    public ProtoId<SpeechVerbPrototype>? SpeechVerb;
 }
index 8e1c2c66f2f7d5d414d84280f52dd80d09c9ca16..380eb7e7013478c80f97ec7aa8ac58f27b74ab4b 100644 (file)
@@ -66,6 +66,8 @@ public sealed partial class VoiceMaskSystem : EntitySystem
                 */
 
             args.Name = component.VoiceName;
+            if (component.SpeechVerb != null)
+                args.SpeechVerb = component.SpeechVerb;
         }
     }
 
index 9eeb39a0f0b7ec651a488dbbbd516dc0a2e201b5..6bbb3cd449b9dbd82afba7797fd7e8e180042a5c 100644 (file)
@@ -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
index 29e6d750af91d61ffb5f8b06df791d1f60c8f295..b849a32a5487cb288a4b6f3f1a2952c7935bd174 100644 (file)
   - 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