FactionClothingSystem.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using Content.Shared.Clothing.Components;
  2. using Content.Shared.Inventory.Events;
  3. using Content.Shared.NPC.Components;
  4. using Content.Shared.NPC.Systems;
  5. namespace Content.Shared.Clothing.EntitySystems;
  6. /// <summary>
  7. /// Handles <see cref="FactionClothingComponent"/> faction adding and removal.
  8. /// </summary>
  9. public sealed class FactionClothingSystem : EntitySystem
  10. {
  11. [Dependency] private readonly NpcFactionSystem _faction = default!;
  12. public override void Initialize()
  13. {
  14. base.Initialize();
  15. SubscribeLocalEvent<FactionClothingComponent, GotEquippedEvent>(OnEquipped);
  16. SubscribeLocalEvent<FactionClothingComponent, GotUnequippedEvent>(OnUnequipped);
  17. }
  18. private void OnEquipped(Entity<FactionClothingComponent> ent, ref GotEquippedEvent args)
  19. {
  20. TryComp<NpcFactionMemberComponent>(args.Equipee, out var factionComp);
  21. var faction = (args.Equipee, factionComp);
  22. ent.Comp.AlreadyMember = _faction.IsMember(faction, ent.Comp.Faction);
  23. _faction.AddFaction(faction, ent.Comp.Faction);
  24. }
  25. private void OnUnequipped(Entity<FactionClothingComponent> ent, ref GotUnequippedEvent args)
  26. {
  27. if (ent.Comp.AlreadyMember)
  28. {
  29. ent.Comp.AlreadyMember = false;
  30. return;
  31. }
  32. _faction.RemoveFaction(args.Equipee, ent.Comp.Faction);
  33. }
  34. }