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.
This commit is contained in:
Tayrtahn
2024-01-23 17:12:18 -05:00
committed by GitHub
parent 1fb9d79c62
commit b4046bc2bb
7 changed files with 62 additions and 10 deletions

View 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);