Voice mask (#10458)
This commit is contained in:
9
Content.Server/VoiceMask/VoiceMaskComponent.cs
Normal file
9
Content.Server/VoiceMask/VoiceMaskComponent.cs
Normal 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";
|
||||
}
|
||||
48
Content.Server/VoiceMask/VoiceMaskSystem.Equip.cs
Normal file
48
Content.Server/VoiceMask/VoiceMaskSystem.Equip.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
88
Content.Server/VoiceMask/VoiceMaskSystem.cs
Normal file
88
Content.Server/VoiceMask/VoiceMaskSystem.cs
Normal 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
|
||||
{
|
||||
}
|
||||
13
Content.Server/VoiceMask/VoiceMaskerComponent.cs
Normal file
13
Content.Server/VoiceMask/VoiceMaskerComponent.cs
Normal 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";
|
||||
}
|
||||
Reference in New Issue
Block a user