Fix emitter lock toggle (#5066)

This commit is contained in:
Leon Friedrich
2021-10-29 00:29:19 +13:00
committed by GitHub
parent 94579d1877
commit 5dd73ff6e0
7 changed files with 11 additions and 51 deletions

View File

@@ -1,5 +1,6 @@
using System;
using Content.Shared.Singularity.Components;
using Content.Shared.Storage;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
@@ -20,7 +21,7 @@ namespace Content.Client.Singularity.Visualizers
return;
}
if (!component.TryGetData(EmitterVisuals.Locked, out bool locked))
if (!component.TryGetData(StorageVisuals.Locked, out bool locked))
locked = false;

View File

@@ -126,9 +126,12 @@ namespace Content.Server.Lock
return true;
}
/// <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, IEntity user, EntityStorageComponent? storage = null, bool quiet = true)
{
if (!Resolve(uid, ref storage))
if (!Resolve(uid, ref storage, logMissing: false))
return true;
// Cannot lock if the entity is currently opened.

View File

@@ -26,7 +26,6 @@ namespace Content.Server.Singularity.Components
[ViewVariables] public bool IsOn;
// Whether the power switch is on AND the machine has enough power (so is actively firing)
[ViewVariables] public bool IsPowered;
[ViewVariables] public bool IsLocked;
// For the "emitter fired" sound
public const float Variation = 0.25f;

View File

@@ -1,10 +1,9 @@
using System;
using System.Threading;
using Content.Server.Access.Components;
using Content.Server.Access.Systems;
using Content.Server.Power.EntitySystems;
using Content.Server.Projectiles.Components;
using Content.Server.Singularity.Components;
using Content.Server.Storage.Components;
using Content.Shared.Audio;
using Content.Shared.Interaction;
using Content.Shared.Popups;
@@ -27,7 +26,6 @@ namespace Content.Server.Singularity.EntitySystems
public class EmitterSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
public override void Initialize()
{
@@ -35,45 +33,12 @@ namespace Content.Server.Singularity.EntitySystems
SubscribeLocalEvent<EmitterComponent, PowerConsumerReceivedChanged>(ReceivedChanged);
SubscribeLocalEvent<EmitterComponent, InteractHandEvent>(OnInteractHand);
SubscribeLocalEvent<EmitterComponent, InteractUsingEvent>(OnInteractUsing);
}
private void OnInteractUsing(EntityUid uid, EmitterComponent component, InteractUsingEvent args)
{
if(args.Handled) return;
if (component.AccessReader == null)
{
return;
}
if (_accessReader.IsAllowed(component.AccessReader, args.Used.Uid))
{
component.IsLocked ^= true;
if (component.IsLocked)
{
component.Owner.PopupMessage(args.User, Loc.GetString("comp-emitter-lock", ("target", component.Owner)));
}
else
{
component.Owner.PopupMessage(args.User, Loc.GetString("comp-emitter-unlock", ("target", component.Owner)));
}
UpdateAppearance(component);
}
else
{
component.Owner.PopupMessage(args.User, Loc.GetString("comp-emitter-access-denied"));
}
args.Handled = true;
}
private void OnInteractHand(EntityUid uid, EmitterComponent component, InteractHandEvent args)
{
args.Handled = true;
if (component.IsLocked)
if (EntityManager.TryGetComponent(uid, out LockComponent? lockComp) && lockComp.Locked)
{
component.Owner.PopupMessage(args.User, Loc.GetString("comp-emitter-access-locked", ("target", component.Owner)));
return;
@@ -252,7 +217,6 @@ namespace Content.Server.Singularity.EntitySystems
}
component.Appearance.SetData(EmitterVisuals.VisualState, state);
component.Appearance.SetData(EmitterVisuals.Locked, component.IsLocked);
}
}
}

View File

@@ -6,8 +6,7 @@ namespace Content.Shared.Singularity.Components
[NetSerializable, Serializable]
public enum EmitterVisuals
{
VisualState,
Locked
VisualState
}
[NetSerializable, Serializable]

View File

@@ -3,14 +3,6 @@
# Shows when attempting to turn the emitter on or off without proper access
comp-emitter-access-locked = The {$target} is access locked!
# Shows when attempting to lock or unlock the emitter without proper access
comp-emitter-access-denied = Access denied.
# Shows when locking/unlocking the emitter
comp-emitter-lock = You lock the {$target}.
comp-emitter-unlock = You unlock the {$target}.
# Shows when turning the emitter on/off
comp-emitter-turned-on = The {$target} turns on.

View File

@@ -69,5 +69,7 @@
- type: Appearance
visuals:
- type: EmitterVisualizer
- type: Lock
locked: false
- type: AccessReader
access: [[ "Engineering" ]]