Security barriers take 5 seconds to (un)lock (#24637)
People are using these as unhackable and hard-to-tailgate airlocks into sec. They should not be trivial for security officers to move through. Made LockComponent have configurable lock times to implement this.
This commit is contained in:
committed by
GitHub
parent
3e3cb10a96
commit
8ca7cb59a3
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Access.Systems;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.Emag.Systems;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Hands.Components;
|
||||
@@ -26,6 +27,7 @@ public sealed class LockSystem : EntitySystem
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _sharedPopupSystem = default!;
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Initialize()
|
||||
@@ -38,6 +40,8 @@ public sealed class LockSystem : EntitySystem
|
||||
SubscribeLocalEvent<LockComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<LockComponent, GetVerbsEvent<AlternativeVerb>>(AddToggleLockVerb);
|
||||
SubscribeLocalEvent<LockComponent, GotEmaggedEvent>(OnEmagged);
|
||||
SubscribeLocalEvent<LockComponent, LockDoAfter>(OnDoAfterLock);
|
||||
SubscribeLocalEvent<LockComponent, UnlockDoAfter>(OnDoAfterUnlock);
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, LockComponent lockComp, ComponentStartup args)
|
||||
@@ -86,11 +90,15 @@ public sealed class LockSystem : EntitySystem
|
||||
/// <summary>
|
||||
/// Attmempts to lock a given entity
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If the lock is set to require a do-after, a true return value only indicates that the do-after started.
|
||||
/// </remarks>
|
||||
/// <param name="uid">The entity with the lock</param>
|
||||
/// <param name="user">The person trying to lock it</param>
|
||||
/// <param name="lockComp"></param>
|
||||
/// <param name="skipDoAfter">If true, skip the required do-after if one is configured.</param>
|
||||
/// <returns>If locking was successful</returns>
|
||||
public bool TryLock(EntityUid uid, EntityUid user, LockComponent? lockComp = null)
|
||||
public bool TryLock(EntityUid uid, EntityUid user, LockComponent? lockComp = null, bool skipDoAfter = false)
|
||||
{
|
||||
if (!Resolve(uid, ref lockComp))
|
||||
return false;
|
||||
@@ -101,6 +109,16 @@ public sealed class LockSystem : EntitySystem
|
||||
if (!HasUserAccess(uid, user, quiet: false))
|
||||
return false;
|
||||
|
||||
if (!skipDoAfter && lockComp.LockTime != TimeSpan.Zero)
|
||||
{
|
||||
return _doAfter.TryStartDoAfter(
|
||||
new DoAfterArgs(EntityManager, user, lockComp.LockTime, new LockDoAfter(), uid, uid)
|
||||
{
|
||||
BreakOnDamage = true, BreakOnTargetMove = true, BreakOnUserMove = true, RequireCanInteract = true,
|
||||
NeedHand = true
|
||||
});
|
||||
}
|
||||
|
||||
_sharedPopupSystem.PopupClient(Loc.GetString("lock-comp-do-lock-success",
|
||||
("entityName", Identity.Name(uid, EntityManager))), uid, user);
|
||||
_audio.PlayPredicted(lockComp.LockSound, uid, user);
|
||||
@@ -117,6 +135,9 @@ public sealed class LockSystem : EntitySystem
|
||||
/// <summary>
|
||||
/// Forces a given entity to be unlocked
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This does not process do-after times.
|
||||
/// </remarks>
|
||||
/// <param name="uid">The entity with the lock</param>
|
||||
/// <param name="user">The person unlocking it. Can be null</param>
|
||||
/// <param name="lockComp"></param>
|
||||
@@ -145,11 +166,15 @@ public sealed class LockSystem : EntitySystem
|
||||
/// <summary>
|
||||
/// Attmempts to unlock a given entity
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If the lock is set to require a do-after, a true return value only indicates that the do-after started.
|
||||
/// </remarks>
|
||||
/// <param name="uid">The entity with the lock</param>
|
||||
/// <param name="user">The person trying to unlock it</param>
|
||||
/// <param name="lockComp"></param>
|
||||
/// <param name="skipDoAfter">If true, skip the required do-after if one is configured.</param>
|
||||
/// <returns>If locking was successful</returns>
|
||||
public bool TryUnlock(EntityUid uid, EntityUid user, LockComponent? lockComp = null)
|
||||
public bool TryUnlock(EntityUid uid, EntityUid user, LockComponent? lockComp = null, bool skipDoAfter = false)
|
||||
{
|
||||
if (!Resolve(uid, ref lockComp))
|
||||
return false;
|
||||
@@ -160,6 +185,16 @@ public sealed class LockSystem : EntitySystem
|
||||
if (!HasUserAccess(uid, user, quiet: false))
|
||||
return false;
|
||||
|
||||
if (!skipDoAfter && lockComp.UnlockTime != TimeSpan.Zero)
|
||||
{
|
||||
return _doAfter.TryStartDoAfter(
|
||||
new DoAfterArgs(EntityManager, user, lockComp.LockTime, new UnlockDoAfter(), uid, uid)
|
||||
{
|
||||
BreakOnDamage = true, BreakOnTargetMove = true, BreakOnUserMove = true, RequireCanInteract = true,
|
||||
NeedHand = true
|
||||
});
|
||||
}
|
||||
|
||||
Unlock(uid, user, lockComp);
|
||||
return true;
|
||||
}
|
||||
@@ -219,5 +254,21 @@ public sealed class LockSystem : EntitySystem
|
||||
RemComp<LockComponent>(uid); //Literally destroys the lock as a tell it was emagged
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnDoAfterLock(EntityUid uid, LockComponent component, LockDoAfter args)
|
||||
{
|
||||
if (args.Cancelled)
|
||||
return;
|
||||
|
||||
TryLock(uid, args.User, skipDoAfter: true);
|
||||
}
|
||||
|
||||
private void OnDoAfterUnlock(EntityUid uid, LockComponent component, UnlockDoAfter args)
|
||||
{
|
||||
if (args.Cancelled)
|
||||
return;
|
||||
|
||||
TryUnlock(uid, args.User, skipDoAfter: true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user