Files
tbd-station-14/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs
2025-05-20 01:08:55 -04:00

47 lines
1.6 KiB
C#

using Content.Server.Speech.Components;
using Content.Shared.Clothing;
namespace Content.Server.Speech.EntitySystems;
public sealed class AddAccentClothingSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AddAccentClothingComponent, ClothingGotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<AddAccentClothingComponent, ClothingGotUnequippedEvent>(OnGotUnequipped);
}
// TODO: Turn this into a relay event.
private void OnGotEquipped(EntityUid uid, AddAccentClothingComponent component, ref ClothingGotEquippedEvent args)
{
// does the user already has this accent?
var componentType = Factory.GetRegistration(component.Accent).Type;
if (HasComp(args.Wearer, componentType))
return;
// add accent to the user
var accentComponent = (Component) Factory.GetComponent(componentType);
AddComp(args.Wearer, accentComponent);
// snowflake case for replacement accent
if (accentComponent is ReplacementAccentComponent rep)
rep.Accent = component.ReplacementPrototype!;
component.IsActive = true;
}
private void OnGotUnequipped(EntityUid uid, AddAccentClothingComponent component, ref ClothingGotUnequippedEvent args)
{
if (!component.IsActive)
return;
// try to remove accent
var componentType = Factory.GetRegistration(component.Accent).Type;
EntityManager.RemoveComponent(args.Wearer, componentType);
component.IsActive = false;
}
}