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:
@@ -27,6 +27,8 @@ namespace Content.Server.Cabinet
|
|||||||
|
|
||||||
SubscribeLocalEvent<ItemCabinetComponent, EntInsertedIntoContainerMessage>(OnContainerModified);
|
SubscribeLocalEvent<ItemCabinetComponent, EntInsertedIntoContainerMessage>(OnContainerModified);
|
||||||
SubscribeLocalEvent<ItemCabinetComponent, EntRemovedFromContainerMessage>(OnContainerModified);
|
SubscribeLocalEvent<ItemCabinetComponent, EntRemovedFromContainerMessage>(OnContainerModified);
|
||||||
|
|
||||||
|
SubscribeLocalEvent<ItemCabinetComponent, LockToggleAttemptEvent>(OnLockToggleAttempt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnComponentInit(EntityUid uid, ItemCabinetComponent cabinet, ComponentInit args)
|
private void OnComponentInit(EntityUid uid, ItemCabinetComponent cabinet, ComponentInit args)
|
||||||
@@ -63,6 +65,13 @@ namespace Content.Server.Cabinet
|
|||||||
UpdateAppearance(uid, cabinet);
|
UpdateAppearance(uid, cabinet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnLockToggleAttempt(EntityUid uid, ItemCabinetComponent cabinet, ref LockToggleAttemptEvent args)
|
||||||
|
{
|
||||||
|
// Cannot lock or unlock while open.
|
||||||
|
if (cabinet.Opened)
|
||||||
|
args.Cancelled = true;
|
||||||
|
}
|
||||||
|
|
||||||
private void AddToggleOpenVerb(EntityUid uid, ItemCabinetComponent cabinet, GetVerbsEvent<ActivationVerb> args)
|
private void AddToggleOpenVerb(EntityUid uid, ItemCabinetComponent cabinet, GetVerbsEvent<ActivationVerb> args)
|
||||||
{
|
{
|
||||||
if (args.Hands == null || !args.CanAccess || !args.CanInteract)
|
if (args.Hands == null || !args.CanAccess || !args.CanInteract)
|
||||||
|
|||||||
@@ -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");
|
[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>
|
/// <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.
|
/// 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>
|
/// </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))
|
if (!HasComp<SharedHandsComponent>(user))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Cannot lock if the entity is currently opened.
|
var ev = new LockToggleAttemptEvent(user, quiet);
|
||||||
if (storage.Open)
|
RaiseLocalEvent(uid, ref ev, true);
|
||||||
return false;
|
return !ev.Cancelled;
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool HasUserAccess(EntityUid uid, EntityUid user, AccessReaderComponent? reader = null, bool quiet = true)
|
private bool HasUserAccess(EntityUid uid, EntityUid user, AccessReaderComponent? reader = null, bool quiet = true)
|
||||||
|
|||||||
@@ -45,11 +45,13 @@ public sealed class EntityStorageSystem : EntitySystem
|
|||||||
SubscribeLocalEvent<EntityStorageComponent, ActivateInWorldEvent>(OnInteract);
|
SubscribeLocalEvent<EntityStorageComponent, ActivateInWorldEvent>(OnInteract);
|
||||||
SubscribeLocalEvent<EntityStorageComponent, WeldableAttemptEvent>(OnWeldableAttempt);
|
SubscribeLocalEvent<EntityStorageComponent, WeldableAttemptEvent>(OnWeldableAttempt);
|
||||||
SubscribeLocalEvent<EntityStorageComponent, WeldableChangedEvent>(OnWelded);
|
SubscribeLocalEvent<EntityStorageComponent, WeldableChangedEvent>(OnWelded);
|
||||||
|
SubscribeLocalEvent<EntityStorageComponent, LockToggleAttemptEvent>(OnLockToggleAttempt);
|
||||||
SubscribeLocalEvent<EntityStorageComponent, DestructionEventArgs>(OnDestroy);
|
SubscribeLocalEvent<EntityStorageComponent, DestructionEventArgs>(OnDestroy);
|
||||||
|
|
||||||
SubscribeLocalEvent<InsideEntityStorageComponent, InhaleLocationEvent>(OnInsideInhale);
|
SubscribeLocalEvent<InsideEntityStorageComponent, InhaleLocationEvent>(OnInsideInhale);
|
||||||
SubscribeLocalEvent<InsideEntityStorageComponent, ExhaleLocationEvent>(OnInsideExhale);
|
SubscribeLocalEvent<InsideEntityStorageComponent, ExhaleLocationEvent>(OnInsideExhale);
|
||||||
SubscribeLocalEvent<InsideEntityStorageComponent, AtmosExposedGetAirEvent>(OnInsideExposed);
|
SubscribeLocalEvent<InsideEntityStorageComponent, AtmosExposedGetAirEvent>(OnInsideExposed);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnInit(EntityUid uid, EntityStorageComponent component, ComponentInit args)
|
private void OnInit(EntityUid uid, EntityStorageComponent component, ComponentInit args)
|
||||||
@@ -102,6 +104,17 @@ public sealed class EntityStorageSystem : EntitySystem
|
|||||||
component.IsWeldedShut = args.IsWelded;
|
component.IsWeldedShut = args.IsWelded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnLockToggleAttempt(EntityUid uid, EntityStorageComponent target, ref LockToggleAttemptEvent args)
|
||||||
|
{
|
||||||
|
// Cannot (un)lock open lockers.
|
||||||
|
if (target.Open)
|
||||||
|
args.Cancelled = true;
|
||||||
|
|
||||||
|
// Cannot (un)lock from the inside. Maybe a bad idea? Security jocks could trap nerds in lockers?
|
||||||
|
if (target.Contents.Contains(args.User))
|
||||||
|
args.Cancelled = true;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnDestroy(EntityUid uid, EntityStorageComponent component, DestructionEventArgs args)
|
private void OnDestroy(EntityUid uid, EntityStorageComponent component, DestructionEventArgs args)
|
||||||
{
|
{
|
||||||
component.Open = true;
|
component.Open = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user