Files
tbd-station-14/Content.Server/Speech/EntitySystems/AddAccentClothingSystem.cs
slarticodefast ceff2bea00 Cloning Refactor and bugfixes (#35555)
* cloning refactor

* cleanup and fixes

* don't pick from 0

* give dwarves the correct species

* fix dna and bloodstream reagent data cloning

* don't copy helmets

* be less redundant
2025-03-02 16:50:12 +01:00

52 lines
1.8 KiB
C#

using Content.Server.Speech.Components;
using Content.Shared.Clothing;
namespace Content.Server.Speech.EntitySystems;
public sealed class AddAccentClothingSystem : EntitySystem
{
[Dependency] private readonly IComponentFactory _componentFactory = default!;
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 = _componentFactory.GetRegistration(component.Accent).Type;
if (HasComp(args.Wearer, componentType))
return;
// add accent to the user
var accentComponent = (Component) _componentFactory.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 = _componentFactory.GetRegistration(component.Accent).Type;
if (EntityManager.HasComponent(args.Wearer, componentType))
{
EntityManager.RemoveComponent(args.Wearer, componentType);
}
component.IsActive = false;
}
}