Add clothing equipped/unequipped events (#27155)

* Added ClothingGotEquipped/ClothingGotUnequipped events

* Better version

* Implemented in a few places

* More implementations

* Add ClothingDidEquipped/ClothingDidUnequipped events
This commit is contained in:
Tayrtahn
2024-04-21 11:00:50 -04:00
committed by GitHub
parent 84c3d225ca
commit 50631f430d
13 changed files with 113 additions and 114 deletions

View File

@@ -1,6 +1,5 @@
using Content.Server.Speech.Components;
using Content.Shared.Clothing.Components;
using Content.Shared.Inventory.Events;
using Content.Shared.Clothing;
namespace Content.Server.Speech.EntitySystems;
@@ -11,29 +10,20 @@ public sealed class AddAccentClothingSystem : EntitySystem
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AddAccentClothingComponent, GotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<AddAccentClothingComponent, GotUnequippedEvent>(OnGotUnequipped);
SubscribeLocalEvent<AddAccentClothingComponent, ClothingGotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<AddAccentClothingComponent, ClothingGotUnequippedEvent>(OnGotUnequipped);
}
private void OnGotEquipped(EntityUid uid, AddAccentClothingComponent component, GotEquippedEvent args)
private void OnGotEquipped(EntityUid uid, AddAccentClothingComponent component, ref ClothingGotEquippedEvent args)
{
if (!TryComp(uid, out ClothingComponent? clothing))
return;
// check if entity was actually used as clothing
// not just taken in pockets or something
var isCorrectSlot = clothing.Slots.HasFlag(args.SlotFlags);
if (!isCorrectSlot)
return;
// does the user already has this accent?
var componentType = _componentFactory.GetRegistration(component.Accent).Type;
if (HasComp(args.Equipee, componentType))
if (HasComp(args.Wearer, componentType))
return;
// add accent to the user
var accentComponent = (Component) _componentFactory.GetComponent(componentType);
AddComp(args.Equipee, accentComponent);
AddComp(args.Wearer, accentComponent);
// snowflake case for replacement accent
if (accentComponent is ReplacementAccentComponent rep)
@@ -42,16 +32,16 @@ public sealed class AddAccentClothingSystem : EntitySystem
component.IsActive = true;
}
private void OnGotUnequipped(EntityUid uid, AddAccentClothingComponent component, GotUnequippedEvent args)
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.Equipee, componentType))
if (EntityManager.HasComponent(args.Wearer, componentType))
{
EntityManager.RemoveComponent(args.Equipee, componentType);
EntityManager.RemoveComponent(args.Wearer, componentType);
}
component.IsActive = false;