using Content.Server.Electrocution;
using Content.Shared._DV.Clothing.Components;
using Content.Shared._DV.Clothing.Systems;
using Content.Shared.Access.Systems;
using Content.Shared.Clothing.Components;
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
namespace Content.Server._DV.Clothing;
///
/// This system implements electrocution for ShockOnUnequipComponent.
///
public sealed class ShockOnUnequipSystem : SharedShockOnUnequipSystem
{
[Dependency] private readonly ElectrocutionSystem _electrocutionSystem = default!;
[Dependency] private readonly AccessReaderSystem _accessReaderSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent(OnUnequipAttempt);
}
private void OnUnequipAttempt(Entity entity, ref BeingUnequippedAttemptEvent args)
{
if (TryComp(entity, out var clothing) && (clothing.Slots & args.SlotFlags) == SlotFlags.NONE)
return;
if (entity.Comp.UseAccess && _accessReaderSystem.IsAllowed(args.Unequipee, args.Equipment))
{
return;
}
var wasStunned = _electrocutionSystem.TryDoElectrocution(args.Unequipee, args.Equipment, entity.Comp.Damage, entity.Comp.Duration, true);
if (wasStunned)
{
args.Cancel();
}
}
}