Add voice locks to various hidden syndicate items (#39310)
This commit is contained in:
@@ -28,12 +28,12 @@ public sealed class LockSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
|
||||
[Dependency] private readonly ActivatableUISystem _activatableUI = default!;
|
||||
[Dependency] private readonly EmagSystem _emag = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _sharedPopupSystem = default!;
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
|
||||
[Dependency] private readonly SharedUserInterfaceSystem _ui = default!;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Initialize()
|
||||
@@ -54,8 +54,8 @@ public sealed class LockSystem : EntitySystem
|
||||
SubscribeLocalEvent<LockedWiresPanelComponent, AttemptChangePanelEvent>(OnAttemptChangePanel);
|
||||
SubscribeLocalEvent<LockedAnchorableComponent, UnanchorAttemptEvent>(OnUnanchorAttempt);
|
||||
|
||||
SubscribeLocalEvent<ActivatableUIRequiresLockComponent, ActivatableUIOpenAttemptEvent>(OnUIOpenAttempt);
|
||||
SubscribeLocalEvent<ActivatableUIRequiresLockComponent, LockToggledEvent>(LockToggled);
|
||||
SubscribeLocalEvent<UIRequiresLockComponent, ActivatableUIOpenAttemptEvent>(OnUIOpenAttempt);
|
||||
SubscribeLocalEvent<UIRequiresLockComponent, LockToggledEvent>(LockToggled);
|
||||
|
||||
SubscribeLocalEvent<ItemToggleRequiresLockComponent, ItemToggleActivateAttemptEvent>(OnActivateAttempt);
|
||||
}
|
||||
@@ -96,6 +96,9 @@ public sealed class LockSystem : EntitySystem
|
||||
|
||||
private void OnExamined(EntityUid uid, LockComponent lockComp, ExaminedEvent args)
|
||||
{
|
||||
if (!lockComp.ShowExamine)
|
||||
return;
|
||||
|
||||
args.PushText(Loc.GetString(lockComp.Locked
|
||||
? "lock-comp-on-examined-is-locked"
|
||||
: "lock-comp-on-examined-is-unlocked",
|
||||
@@ -239,6 +242,20 @@ public sealed class LockSystem : EntitySystem
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggle the lock to locked if unlocked, and unlocked if locked.
|
||||
/// </summary>
|
||||
/// <param name="uid">Entity to toggle the lock state of.</param>
|
||||
/// <param name="user">The person trying to toggle the lock</param>
|
||||
/// <param name="lockComp">Entities lock comp (will be resolved)</param>
|
||||
public void ToggleLock(EntityUid uid, EntityUid? user, LockComponent? lockComp = null)
|
||||
{
|
||||
if (IsLocked((uid, lockComp)))
|
||||
Unlock(uid, user, lockComp);
|
||||
else
|
||||
Lock(uid, user, lockComp);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the entity is locked.
|
||||
/// Entities with no lock component are considered unlocked.
|
||||
@@ -287,7 +304,7 @@ public sealed class LockSystem : EntitySystem
|
||||
|
||||
private void AddToggleLockVerb(EntityUid uid, LockComponent component, GetVerbsEvent<AlternativeVerb> args)
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract || !args.CanComplexInteract)
|
||||
if (!args.CanAccess || !args.CanInteract || !args.CanComplexInteract || !component.ShowLockVerbs)
|
||||
return;
|
||||
|
||||
AlternativeVerb verb = new()
|
||||
@@ -394,41 +411,54 @@ public sealed class LockSystem : EntitySystem
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
private void OnUIOpenAttempt(EntityUid uid, ActivatableUIRequiresLockComponent component, ActivatableUIOpenAttemptEvent args)
|
||||
private void OnUIOpenAttempt(EntityUid uid, UIRequiresLockComponent component, ActivatableUIOpenAttemptEvent args)
|
||||
{
|
||||
if (args.Cancelled)
|
||||
return;
|
||||
|
||||
if (TryComp<LockComponent>(uid, out var lockComp) && lockComp.Locked != component.RequireLocked)
|
||||
{
|
||||
args.Cancel();
|
||||
if (lockComp.Locked)
|
||||
{
|
||||
_sharedPopupSystem.PopupClient(Loc.GetString("entity-storage-component-locked-message"), uid, args.User);
|
||||
}
|
||||
if (!TryComp<LockComponent>(uid, out var lockComp) || lockComp.Locked == component.RequireLocked)
|
||||
return;
|
||||
|
||||
_audio.PlayPredicted(component.AccessDeniedSound, uid, args.User);
|
||||
args.Cancel();
|
||||
if (lockComp.Locked && component.Popup != null)
|
||||
{
|
||||
_sharedPopupSystem.PopupClient(Loc.GetString(component.Popup), uid, args.User);
|
||||
}
|
||||
|
||||
_audio.PlayPredicted(component.AccessDeniedSound, uid, args.User);
|
||||
}
|
||||
|
||||
private void LockToggled(EntityUid uid, ActivatableUIRequiresLockComponent component, LockToggledEvent args)
|
||||
private void LockToggled(EntityUid uid, UIRequiresLockComponent component, LockToggledEvent args)
|
||||
{
|
||||
if (!TryComp<LockComponent>(uid, out var lockComp) || lockComp.Locked == component.RequireLocked)
|
||||
return;
|
||||
|
||||
_activatableUI.CloseAll(uid);
|
||||
if (component.UserInterfaceKeys == null)
|
||||
{
|
||||
_ui.CloseUis(uid);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var key in component.UserInterfaceKeys)
|
||||
{
|
||||
_ui.CloseUi(uid, key);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnActivateAttempt(EntityUid uid, ItemToggleRequiresLockComponent component, ref ItemToggleActivateAttemptEvent args)
|
||||
{
|
||||
if (args.Cancelled)
|
||||
return;
|
||||
|
||||
if (TryComp<LockComponent>(uid, out var lockComp) && lockComp.Locked != component.RequireLocked)
|
||||
if (!TryComp<LockComponent>(uid, out var lockComp) || lockComp.Locked == component.RequireLocked)
|
||||
return;
|
||||
|
||||
args.Cancelled = true;
|
||||
|
||||
if (lockComp.Locked && component.LockedPopup != null)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
if (lockComp.Locked)
|
||||
_sharedPopupSystem.PopupClient(Loc.GetString("lock-comp-generic-fail",
|
||||
("target", Identity.Entity(uid, EntityManager))),
|
||||
_sharedPopupSystem.PopupClient(Loc.GetString(component.LockedPopup,
|
||||
("target", Identity.Entity(uid, EntityManager))),
|
||||
uid,
|
||||
args.User);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user