Voice mask (#10458)

This commit is contained in:
Flipp Syder
2022-09-28 19:22:27 -07:00
committed by GitHub
parent 336e9ee609
commit 0385f1387c
18 changed files with 357 additions and 7 deletions

View File

@@ -259,12 +259,15 @@ public sealed partial class ChatSystem : SharedChatSystem
return;
}
var nameEv = new TransformSpeakerNameEvent(source, Name(source));
RaiseLocalEvent(source, nameEv);
message = TransformSpeech(source, message);
if (message.Length == 0)
return;
var messageWrap = Loc.GetString("chat-manager-entity-say-wrap-message",
("entityName", Name(source)));
("entityName", nameEv.Name));
SendInVoiceRange(ChatChannel.Local, message, messageWrap, source, hideChat);
_listener.PingListeners(source, message, null);
@@ -295,8 +298,12 @@ public sealed partial class ChatSystem : SharedChatSystem
var transformSource = Transform(source);
var sourceCoords = transformSource.Coordinates;
var nameEv = new TransformSpeakerNameEvent(source, Name(source));
RaiseLocalEvent(source, nameEv);
var messageWrap = Loc.GetString("chat-manager-entity-whisper-wrap-message",
("entityName", Name(source)));
("entityName", nameEv.Name));
var xforms = GetEntityQuery<TransformComponent>();
var ghosts = GetEntityQuery<GhostComponent>();
@@ -530,6 +537,18 @@ public sealed partial class ChatSystem : SharedChatSystem
#endregion
}
public sealed class TransformSpeakerNameEvent : EntityEventArgs
{
public EntityUid Sender;
public string Name;
public TransformSpeakerNameEvent(EntityUid sender, string name)
{
Sender = sender;
Name = name;
}
}
/// <summary>
/// Raised broadcast in order to transform speech.
/// </summary>

View File

@@ -13,6 +13,7 @@ using Content.Server.Disease.Components;
using Content.Server.IdentityManagement;
using Content.Server.Nutrition.EntitySystems;
using Content.Server.Popups;
using Content.Server.VoiceMask;
using Content.Shared.Clothing.EntitySystems;
using Content.Shared.IdentityManagement.Components;
using Robust.Shared.Player;
@@ -87,6 +88,8 @@ namespace Content.Server.Clothing
_clothing.SetEquippedPrefix(uid, mask.IsToggled ? "toggled" : null, clothing);
}
// shouldn't this be an event?
// toggle ingestion blocking
if (TryComp<IngestionBlockerComponent>(uid, out var blocker))
blocker.Enabled = !mask.IsToggled;
@@ -99,6 +102,10 @@ namespace Content.Server.Clothing
if (TryComp<IdentityBlockerComponent>(uid, out var identity))
identity.Enabled = !mask.IsToggled;
// toggle voice masking
if (TryComp<VoiceMaskComponent>(uid, out var voiceMask))
voiceMask.Enabled = !mask.IsToggled;
// toggle breath tool connection (skip during equip since that is handled in LungSystem)
if (isEquip || !TryComp<BreathToolComponent>(uid, out var breathTool))
return;

View File

@@ -1,5 +1,7 @@
using Content.Server.Radio.Components;
using Content.Server.VoiceMask;
using Content.Shared.Chat;
using Content.Shared.IdentityManagement;
using Content.Shared.Radio;
using Robust.Server.GameObjects;
using Robust.Shared.Network;
@@ -28,12 +30,19 @@ namespace Content.Server.Ghost.Components
var playerChannel = actor.PlayerSession.ConnectedClient;
var name = _entMan.GetComponent<MetaDataComponent>(speaker).EntityName;
if (_entMan.TryGetComponent(speaker, out VoiceMaskComponent? mask) && mask.Enabled)
{
name = Identity.Name(speaker, _entMan);
}
var msg = new MsgChatMessage
{
Channel = ChatChannel.Radio,
Message = message,
//Square brackets are added here to avoid issues with escaping
MessageWrap = Loc.GetString("chat-radio-message-wrap", ("color", channel.Color), ("channel", $"\\[{channel.LocalizedName}\\]"), ("name", _entMan.GetComponent<MetaDataComponent>(speaker).EntityName))
MessageWrap = Loc.GetString("chat-radio-message-wrap", ("color", channel.Color), ("channel", $"\\[{channel.LocalizedName}\\]"), ("name", name))
};
_netManager.ServerSendMessage(msg, playerChannel);

View File

@@ -1,7 +1,9 @@
using Content.Server.Chat.Systems;
using Content.Server.Radio.Components;
using Content.Server.Radio.EntitySystems;
using Content.Server.VoiceMask;
using Content.Shared.Chat;
using Content.Shared.IdentityManagement;
using Content.Shared.Radio;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
@@ -58,6 +60,13 @@ namespace Content.Server.Headset
var playerChannel = actor.PlayerSession.ConnectedClient;
var name = _entMan.GetComponent<MetaDataComponent>(source).EntityName;
if (_entMan.TryGetComponent(source, out VoiceMaskComponent? mask) && mask.Enabled)
{
name = Identity.Name(source, _entMan);
}
message = _chatSystem.TransformSpeech(source, message);
if (message.Length == 0)
return;
@@ -67,7 +76,7 @@ namespace Content.Server.Headset
Channel = ChatChannel.Radio,
Message = message,
//Square brackets are added here to avoid issues with escaping
MessageWrap = Loc.GetString("chat-radio-message-wrap", ("color", channel.Color), ("channel", $"\\[{channel.LocalizedName}\\]"), ("name", _entMan.GetComponent<MetaDataComponent>(source).EntityName))
MessageWrap = Loc.GetString("chat-radio-message-wrap", ("color", channel.Color), ("channel", $"\\[{channel.LocalizedName}\\]"), ("name", name))
};
_netManager.ServerSendMessage(msg, playerChannel);

View File

@@ -43,7 +43,6 @@ namespace Content.Server.Radio.EntitySystems
foreach (var radio in EntityManager.EntityQuery<IRadio>(true))
{
//TODO: once voice identity gets added, pass into receiver via source.GetSpeakerVoice()
radio.Receive(message, channel, speaker);
}

View File

@@ -0,0 +1,9 @@
namespace Content.Server.VoiceMask;
[RegisterComponent]
public sealed class VoiceMaskComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)] public bool Enabled = true;
[ViewVariables(VVAccess.ReadWrite)] public string VoiceName = "Unknown";
}

View File

@@ -0,0 +1,48 @@
using Content.Server.Actions;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Content.Shared.Speech;
using Robust.Shared.Prototypes;
namespace Content.Server.VoiceMask;
// This partial deals with equipment, i.e., the syndicate voice mask.
public sealed partial class VoiceMaskSystem
{
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly ActionsSystem _actions = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private const string MaskSlot = "mask";
private void OnEquip(EntityUid uid, VoiceMaskerComponent component, GotEquippedEvent args)
{
var comp = EnsureComp<VoiceMaskComponent>(args.Equipee);
comp.VoiceName = component.LastSetName;
if (!_prototypeManager.TryIndex<InstantActionPrototype>(component.Action, out var action))
{
throw new ArgumentException("Could not get voice masking prototype.");
}
_actions.AddAction(args.Equipee, (InstantAction) action.Clone(), uid);
}
private void OnUnequip(EntityUid uid, VoiceMaskerComponent compnent, GotUnequippedEvent args)
{
RemComp<VoiceMaskComponent>(args.Equipee);
}
private void TrySetLastKnownName(EntityUid maskWearer, string lastName)
{
if (!HasComp<VoiceMaskComponent>(maskWearer)
|| !_inventory.TryGetSlotEntity(maskWearer, MaskSlot, out var maskEntity)
|| !TryComp<VoiceMaskerComponent>(maskEntity, out var maskComp))
{
return;
}
maskComp.LastSetName = lastName;
}
}

View File

@@ -0,0 +1,88 @@
using Content.Server.Chat.Systems;
using Content.Server.Popups;
using Content.Shared.Actions;
using Content.Shared.Inventory.Events;
using Content.Shared.Preferences;
using Content.Shared.Verbs;
using Content.Shared.VoiceMask;
using Robust.Server.GameObjects;
using Robust.Shared.Player;
namespace Content.Server.VoiceMask;
public sealed partial class VoiceMaskSystem : EntitySystem
{
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
public override void Initialize()
{
SubscribeLocalEvent<VoiceMaskComponent, TransformSpeakerNameEvent>(OnSpeakerNameTransform);
SubscribeLocalEvent<VoiceMaskComponent, VoiceMaskChangeNameMessage>(OnChangeName);
SubscribeLocalEvent<VoiceMaskerComponent, GotEquippedEvent>(OnEquip);
SubscribeLocalEvent<VoiceMaskerComponent, GotUnequippedEvent>(OnUnequip);
SubscribeLocalEvent<VoiceMaskSetNameEvent>(OnSetName);
// SubscribeLocalEvent<VoiceMaskerComponent, GetVerbsEvent<AlternativeVerb>>(GetVerbs);
}
private void OnSetName(VoiceMaskSetNameEvent ev)
{
OpenUI(ev.Performer);
}
private void OnChangeName(EntityUid uid, VoiceMaskComponent component, VoiceMaskChangeNameMessage message)
{
if (message.Name.Length > HumanoidCharacterProfile.MaxNameLength || message.Name.Length <= 0)
{
_popupSystem.PopupCursor(Loc.GetString("voice-mask-popup-failure"), Filter.SinglePlayer(message.Session));
return;
}
component.VoiceName = message.Name;
_popupSystem.PopupCursor(Loc.GetString("voice-mask-popup-success"), Filter.SinglePlayer(message.Session));
TrySetLastKnownName(uid, message.Name);
UpdateUI(uid, component);
}
private void OnSpeakerNameTransform(EntityUid uid, VoiceMaskComponent component, TransformSpeakerNameEvent args)
{
if (component.Enabled)
{
/*
args.Name = _idCard.TryGetIdCard(uid, out var card) && !string.IsNullOrEmpty(card.FullName)
? card.FullName
: Loc.GetString("voice-mask-unknown");
*/
args.Name = component.VoiceName;
}
}
private void OpenUI(EntityUid player, ActorComponent? actor = null)
{
if (!Resolve(player, ref actor))
{
return;
}
_uiSystem.GetUiOrNull(player, VoiceMaskUIKey.Key)?.Open(actor.PlayerSession);
UpdateUI(player);
}
private void UpdateUI(EntityUid owner, VoiceMaskComponent? component = null)
{
if (!Resolve(owner, ref component))
{
return;
}
_uiSystem.GetUiOrNull(owner, VoiceMaskUIKey.Key)?.SetState(new VoiceMaskBuiState(component.VoiceName));
}
}
public sealed class VoiceMaskSetNameEvent : InstantActionEvent
{
}

View File

@@ -0,0 +1,13 @@
using Content.Shared.Actions.ActionTypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.VoiceMask;
[RegisterComponent]
public sealed class VoiceMaskerComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)] public string LastSetName = "Unknown";
[DataField("action", customTypeSerializer: typeof(PrototypeIdSerializer<InstantActionPrototype>))]
public string Action = "ChangeVoiceMask";
}