using Content.Shared.Trigger.Components.Triggers;
using Robust.Shared.Timing;
using Content.Shared.Inventory.Events;
namespace Content.Shared.Trigger.Systems;
///
/// System for creating triggers when entities are equipped or unequipped from inventory slots.
///
public sealed class TriggerOnEquipmentSystem : TriggerOnXSystem
{
[Dependency] private readonly IGameTiming _timing = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent(OnDidEquip);
SubscribeLocalEvent(OnDidUnequip);
SubscribeLocalEvent(OnGotEquipped);
SubscribeLocalEvent(OnGotUnequipped);
}
// Used by entities when equipping or unequipping other entities
private void OnDidEquip(Entity ent, ref DidEquipEvent args)
{
if (_timing.ApplyingState)
return;
if ((ent.Comp.SlotFlags & args.SlotFlags) == 0)
return;
Trigger.Trigger(ent.Owner, args.Equipment, ent.Comp.KeyOut);
}
private void OnDidUnequip(Entity ent, ref DidUnequipEvent args)
{
if (_timing.ApplyingState)
return;
if ((ent.Comp.SlotFlags & args.SlotFlags) == 0)
return;
Trigger.Trigger(ent.Owner, args.Equipment, ent.Comp.KeyOut);
}
// Used by entities when they get equipped or unequipped
private void OnGotEquipped(Entity ent, ref GotEquippedEvent args)
{
if (_timing.ApplyingState)
return;
if ((ent.Comp.SlotFlags & args.SlotFlags) == 0)
return;
Trigger.Trigger(ent.Owner, args.Equipee, ent.Comp.KeyOut);
}
private void OnGotUnequipped(Entity ent, ref GotUnequippedEvent args)
{
if (_timing.ApplyingState)
return;
if ((ent.Comp.SlotFlags & args.SlotFlags) == 0)
return;
Trigger.Trigger(ent.Owner, args.Equipee, ent.Comp.KeyOut);
}
}