mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* IoC source gen compatibility Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter. * Missed a spot
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using Content.Shared.Clothing.Components;
|
|
using Content.Shared.Inventory.Events;
|
|
using Content.Shared.NPC.Components;
|
|
using Content.Shared.NPC.Systems;
|
|
|
|
namespace Content.Shared.Clothing.EntitySystems;
|
|
|
|
/// <summary>
|
|
/// Handles <see cref="FactionClothingComponent"/> faction adding and removal.
|
|
/// </summary>
|
|
public sealed partial class FactionClothingSystem : EntitySystem
|
|
{
|
|
[Dependency] private NpcFactionSystem _faction = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<FactionClothingComponent, GotEquippedEvent>(OnEquipped);
|
|
SubscribeLocalEvent<FactionClothingComponent, GotUnequippedEvent>(OnUnequipped);
|
|
}
|
|
|
|
private void OnEquipped(Entity<FactionClothingComponent> ent, ref GotEquippedEvent args)
|
|
{
|
|
TryComp<NpcFactionMemberComponent>(args.EquipTarget, out var factionComp);
|
|
var faction = (args.EquipTarget, factionComp);
|
|
ent.Comp.AlreadyMember = _faction.IsMember(faction, ent.Comp.Faction);
|
|
|
|
_faction.AddFaction(faction, ent.Comp.Faction);
|
|
}
|
|
|
|
private void OnUnequipped(Entity<FactionClothingComponent> ent, ref GotUnequippedEvent args)
|
|
{
|
|
if (ent.Comp.AlreadyMember)
|
|
{
|
|
ent.Comp.AlreadyMember = false;
|
|
return;
|
|
}
|
|
|
|
_faction.RemoveFaction(args.EquipTarget, ent.Comp.Faction);
|
|
}
|
|
}
|