using Content.Shared.Lock; namespace Content.Shared.Containers.ItemSlots; public sealed partial class ItemSlotsSystem { [SubscribeLocalEvent] private void OnLockMapInit(Entity ent, ref MapInitEvent args) { if (!TryComp(ent.Owner, out LockComponent? lockComp)) return; UpdateLocks(ent, lockComp.Locked); } [SubscribeLocalEvent] private void OnLockToggled(Entity ent, ref LockToggledEvent args) { UpdateLocks(ent, args.Locked); } private void UpdateLocks(Entity ent, bool locked) { foreach (var slot in ent.Comp.Slots) { if (!TryGetSlot(ent.Owner, slot, out var itemSlot)) continue; SetLock(ent.Owner, itemSlot, locked); } } /// /// Sets whether an item slot is locked, preventing checked insertion and ejection while locked. /// public void SetLock(Entity ent, string id, bool locked) { if (!Resolve(ent, ref ent.Comp)) return; if (!ent.Comp.Slots.TryGetValue(id, out var slot)) return; SetLock(ent, slot, locked); } /// /// Sets whether an item slot is locked, preventing checked insertion and ejection while locked. /// public void SetLock(Entity ent, ItemSlot slot, bool locked) { if (!Resolve(ent, ref ent.Comp)) return; slot.Locked = locked; Dirty(ent); } }