Fix item cabinet locking while open and locker favoritism (#12508)
Co-authored-by: Moony <moony@hellomouse.net> Fixes https://github.com/space-wizards/space-station-14/issues/12426
This commit is contained in:
@@ -14,3 +14,17 @@ namespace Content.Server.Storage.Components
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("lockingSound")] public SoundSpecifier LockSound { get; set; } = new SoundPathSpecifier("/Audio/Machines/door_lock_on.ogg");
|
||||
}
|
||||
}
|
||||
[ByRefEvent]
|
||||
public struct LockToggleAttemptEvent
|
||||
{
|
||||
public bool Silent = false;
|
||||
public bool Cancelled = false;
|
||||
public EntityUid User;
|
||||
|
||||
public LockToggleAttemptEvent(EntityUid user, bool silent = false)
|
||||
{
|
||||
User = user;
|
||||
Silent = silent;
|
||||
}
|
||||
}
|
||||
public sealed class LockToggleAttemptArgs : EventArgs { }
|
||||
|
||||
@@ -148,23 +148,14 @@ namespace Content.Server.Lock
|
||||
/// <summary>
|
||||
/// Before locking the entity, check whether it's a locker. If is, prevent it from being locked from the inside or while it is open.
|
||||
/// </summary>
|
||||
public bool CanToggleLock(EntityUid uid, EntityUid user, EntityStorageComponent? storage = null, bool quiet = true)
|
||||
public bool CanToggleLock(EntityUid uid, EntityUid user, bool quiet = true)
|
||||
{
|
||||
if (!Resolve(uid, ref storage, logMissing: false))
|
||||
return true;
|
||||
|
||||
if (!HasComp<SharedHandsComponent>(user))
|
||||
return false;
|
||||
|
||||
// Cannot lock if the entity is currently opened.
|
||||
if (storage.Open)
|
||||
return false;
|
||||
|
||||
// Cannot (un)lock from the inside. Maybe a bad idea? Security jocks could trap nerds in lockers?
|
||||
if (storage.Contents.Contains(user))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
var ev = new LockToggleAttemptEvent(user, quiet);
|
||||
RaiseLocalEvent(uid, ref ev, true);
|
||||
return !ev.Cancelled;
|
||||
}
|
||||
|
||||
private bool HasUserAccess(EntityUid uid, EntityUid user, AccessReaderComponent? reader = null, bool quiet = true)
|
||||
|
||||
Reference in New Issue
Block a user