47 lines
1.6 KiB
C#
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;
|
|
}
|
|
}
|