using Content.Shared.Containers.ItemSlots;
using Content.Shared.Ghost;
using Content.Shared.Lock;
using Content.Shared.Popups;
using Content.Shared._EE.Silicon.Components;
using Content.Shared.IdentityManagement;
namespace Content.Server._EE.Silicons.BatteryLocking;
public sealed class BatterySlotRequiresLockSystem : EntitySystem
{
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
///
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent(LockToggled);
SubscribeLocalEvent(LockToggleAttempted);
}
private void LockToggled(EntityUid uid, BatterySlotRequiresLockComponent component, LockToggledEvent args)
{
if (!TryComp(uid, out var lockComp)
|| !TryComp(uid, out var itemslots)
|| !_itemSlotsSystem.TryGetSlot(uid, component.ItemSlot, out var slot, itemslots))
return;
_itemSlotsSystem.SetLock(uid, slot, lockComp.Locked, itemslots);
}
private void LockToggleAttempted(EntityUid uid, BatterySlotRequiresLockComponent component, LockToggleAttemptEvent args)
{
if (args.Cancelled)
return;
if (args.User == uid || !HasComp(uid))
return;
if (HasComp(args.User)) // Prevent admin ghosts from triggering popup
return;
_popupSystem.PopupEntity(Loc.GetString("batteryslotrequireslock-component-alert-owner", ("user", Identity.Entity(args.User, EntityManager))), uid, uid, PopupType.Large);
}
}