Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Syrinx implant #2055

Merged
merged 5 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions Content.Server/DeltaV/Implants/SyrinxImplantComponent.cs

This file was deleted.

108 changes: 8 additions & 100 deletions Content.Server/DeltaV/Implants/SyrinxImplantSystem.cs
Original file line number Diff line number Diff line change
@@ -1,115 +1,23 @@
using Content.Server.Administration.Logs;
using Content.Server.Implants;
using Content.Server.Speech.Components;
using Content.Shared.Database;
using Content.Shared.DeltaV.Implants;
using Content.Server.VoiceMask;
using Content.Shared.Implants;
using Content.Shared.Inventory;
using Content.Shared.Popups;
using Content.Shared.Preferences;
using Content.Shared.Speech;
using Content.Shared.VoiceMask;
using Robust.Shared.Prototypes;

namespace Content.Server.DeltaV.Implants;
namespace Content.Server.Implants;

public sealed class SyrinxImplantSystem : EntitySystem
public sealed class SubdermalBionicSyrinxImplantSystem : EntitySystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedUserInterfaceSystem _ui = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<SyrinxImplantComponent, ImplantImplantedEvent>(OnImplanted);
SubscribeLocalEvent<SyrinxImplantComponent, ImplantRemovedEvent>(OnRemoved);
SubscribeLocalEvent<SyrinxImplantComponent, VoiceMaskChangeNameMessage>(OnChangeName);
SubscribeLocalEvent<SyrinxImplantComponent, VoiceMaskChangeVerbMessage>(OnChangeVerb);
SubscribeLocalEvent<SyrinxImplantSetNameEvent>(OpenUI);
}

private void OnImplanted(Entity<SyrinxImplantComponent> ent, ref ImplantImplantedEvent args)
{
if (args.Implanted is not {} user)
return;

ent.Comp.Existing = HasComp<VoiceOverrideComponent>(user);

var voice = EnsureComp<VoiceOverrideComponent>(user);
voice.NameOverride = Name(user);
}

private void OnRemoved(Entity<SyrinxImplantComponent> ent, ref ImplantRemovedEvent args)
{
if (args.Implanted is not {} user)
return;

if (ent.Comp.Existing && TryComp<VoiceOverrideComponent>(user, out var voice))
voice.NameOverride = Name(user);
else
RemComp<VoiceOverrideComponent>(user);
}

private void OnChangeVerb(Entity<SyrinxImplantComponent> ent, ref VoiceMaskChangeVerbMessage msg)
{
var user = msg.Actor;
if (!TryComp<VoiceOverrideComponent>(user, out var voice))
return;

if (msg.Verb is {} id && !_proto.HasIndex<SpeechVerbPrototype>(id))
return;

voice.SpeechVerbOverride = msg.Verb;
// verb is only important to metagamers so no need to log as opposed to name

_popup.PopupEntity(Loc.GetString("voice-mask-popup-success"), ent, user);

UpdateUI(ent, voice);
}

/// <summary>
/// Copy from VoiceMaskSystem, adapted to work with SyrinxImplantComponent.
/// </summary>
private void OnChangeName(Entity<SyrinxImplantComponent> ent, ref VoiceMaskChangeNameMessage msg)
{
var user = msg.Actor;
if (!TryComp<VoiceOverrideComponent>(user, out var voice))
return;

if (msg.Name.Length > HumanoidCharacterProfile.MaxNameLength || msg.Name.Length <= 0)
{
_popup.PopupEntity(Loc.GetString("voice-mask-popup-failure"), user, user, PopupType.SmallCaution);
return;
}

voice.NameOverride = msg.Name.Trim();
_adminLogger.Add(LogType.Action, LogImpact.Medium, $"{ToPrettyString(user):player} set voice of {ToPrettyString(ent):mask}: {voice.NameOverride}");

_popup.PopupEntity(Loc.GetString("voice-mask-popup-success"), user, user);

UpdateUI(ent, voice);
}

/// <summary>
/// Copy from VoiceMaskSystem, adapted to work with SyrinxImplantComponent.
/// </summary>
private void UpdateUI(EntityUid uid, VoiceOverrideComponent voice)
{
var state = new VoiceMaskBuiState(voice.NameOverride ?? Loc.GetString("voice-mask-default-name-override"), voice.SpeechVerbOverride);
_ui.SetUiState(uid, VoiceMaskUIKey.Key, state);
SubscribeLocalEvent<VoiceMaskComponent, ImplantImplantedEvent>(OnInsert);
}

private void OpenUI(SyrinxImplantSetNameEvent args)
private void OnInsert(Entity<VoiceMaskComponent> ent, ref ImplantImplantedEvent args)
{
var user = args.Performer;
if (!TryComp<VoiceOverrideComponent>(user, out var voice))
if (!args.Implanted.HasValue)
return;

var uid = args.Action.Comp.Container!.Value;
_ui.TryOpenUi(uid, VoiceMaskUIKey.Key, user);
UpdateUI(uid, voice);
// Update the name so it's the entities default name. You can't take it off like a voice mask so it's important!
ent.Comp.VoiceMaskName = Name(args.Implanted.Value);
}
}
9 changes: 9 additions & 0 deletions Content.Server/VoiceMask/VoiceMaskSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Content.Shared.Chat;
using Content.Shared.Clothing;
using Content.Shared.Database;
using Content.Shared.Implants;
using Content.Shared.Inventory;
using Content.Shared.Popups;
using Content.Shared.Preferences;
Expand All @@ -24,6 +25,7 @@ public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<VoiceMaskComponent, InventoryRelayedEvent<TransformSpeakerNameEvent>>(OnTransformSpeakerName);
SubscribeLocalEvent<VoiceMaskComponent, ImplantRelayEvent<TransformSpeakerNameEvent>>(OnTransformSpeakerNameImplant);
SubscribeLocalEvent<VoiceMaskComponent, VoiceMaskChangeNameMessage>(OnChangeName);
SubscribeLocalEvent<VoiceMaskComponent, VoiceMaskChangeVerbMessage>(OnChangeVerb);
SubscribeLocalEvent<VoiceMaskComponent, ClothingGotEquippedEvent>(OnEquip);
Expand All @@ -36,6 +38,13 @@ private void OnTransformSpeakerName(Entity<VoiceMaskComponent> entity, ref Inven
args.Args.SpeechVerb = entity.Comp.VoiceMaskSpeechVerb ?? args.Args.SpeechVerb;
}

// Delta-v specific for implants
private void OnTransformSpeakerNameImplant(Entity<VoiceMaskComponent> entity, ref ImplantRelayEvent<TransformSpeakerNameEvent> args)
{
args.Event.VoiceName = GetCurrentVoiceName(entity);
args.Event.SpeechVerb = entity.Comp.VoiceMaskSpeechVerb ?? args.Event.SpeechVerb;
}

#region User inputs from UI
private void OnChangeVerb(Entity<VoiceMaskComponent> entity, ref VoiceMaskChangeVerbMessage msg)
{
Expand Down
8 changes: 0 additions & 8 deletions Content.Shared/DeltaV/Implants/SyrinxImplantSetNameEvent.cs

This file was deleted.

2 changes: 2 additions & 0 deletions Content.Shared/Implants/SharedSubdermalImplantSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using Content.Shared.Actions;
using Content.Shared.Chat; // Delta-v
using Content.Shared.Implants.Components;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
Expand Down Expand Up @@ -29,6 +30,7 @@ public override void Initialize()
SubscribeLocalEvent<ImplantedComponent, MobStateChangedEvent>(RelayToImplantEvent);
SubscribeLocalEvent<ImplantedComponent, AfterInteractUsingEvent>(RelayToImplantEvent);
SubscribeLocalEvent<ImplantedComponent, SuicideEvent>(RelayToImplantEvent);
SubscribeLocalEvent<ImplantedComponent, TransformSpeakerNameEvent>(RelayToImplantEvent); // Delta-v
}

private void OnInsert(EntityUid uid, SubdermalImplantComponent component, EntGotInsertedIntoContainerMessage args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,4 @@
- type: InstantAction
icon: DeltaV/Interface/Actions/harpy_syrinx.png
itemIconStyle: BigAction
event: !type:SyrinxImplantSetNameEvent
event: !type:VoiceMaskSetNameEvent
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
implantAction: ActionSyrinxChangeVoiceMask
whitelist:
components:
- HarpySinger
- HarpySinger # Ensure this is only for harpies and if this component gets renamed, CHANGE IT TO THE NEW VALUE!!!
- type: VoiceMask
- type: UserInterface
interfaces:
enum.VoiceMaskUIKey.Key:
type: VoiceMaskBoundUserInterface
- type: SyrinxImplant

- type: entity
categories: [ HideSpawnMenu, Spawner ]
Expand Down
2 changes: 1 addition & 1 deletion Resources/Prototypes/DeltaV/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

- type: Tag
id: HidesHarpyWings
beck-thompson marked this conversation as resolved.
Show resolved Hide resolved

- type: Tag
id: HudMedicalSecurity #Craftable Corpsman Glasses

Expand Down
Loading