* #4420 moved sound components to a better spot in the project * MWF-4420 - ported SecureEntityStorageComponent to new ECS system, as a LockComponent * MWF-4420 - removed unused usings * #4420 removed dumb ToggleLockVerb override workaround * #4420 added SoundSpecifier to LockComponent
This commit is contained in:
@@ -24,7 +24,6 @@ using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Broadphase;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -131,7 +130,8 @@ namespace Content.Server.Storage.Components
|
||||
private bool _beingWelded;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool CanWeldShut {
|
||||
public bool CanWeldShut
|
||||
{
|
||||
get => _canWeldShut;
|
||||
set
|
||||
{
|
||||
@@ -160,6 +160,13 @@ namespace Content.Server.Storage.Components
|
||||
|
||||
public virtual void Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
// HACK until EntityStorageComponent gets refactored to the new ECS system
|
||||
if (Owner.TryGetComponent<LockComponent>(out var @lock) && @lock.Locked)
|
||||
{
|
||||
// Do nothing, LockSystem is responsible for handling this case
|
||||
return;
|
||||
}
|
||||
|
||||
ToggleOpen(eventArgs.User);
|
||||
}
|
||||
|
||||
@@ -167,7 +174,7 @@ namespace Content.Server.Storage.Components
|
||||
{
|
||||
if (IsWeldedShut)
|
||||
{
|
||||
if(!silent) Owner.PopupMessage(user, Loc.GetString("entity-storage-component-welded-shut-message"));
|
||||
if (!silent) Owner.PopupMessage(user, Loc.GetString("entity-storage-component-welded-shut-message"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -465,7 +472,8 @@ namespace Content.Server.Storage.Components
|
||||
|
||||
protected virtual void OpenVerbGetData(IEntity user, EntityStorageComponent component, VerbData data)
|
||||
{
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user) ||
|
||||
component.Owner.TryGetComponent(out LockComponent? lockComponent) && lockComponent.Locked) // HACK extra check, until EntityStorage gets refactored
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
@@ -475,7 +483,7 @@ namespace Content.Server.Storage.Components
|
||||
{
|
||||
data.Visibility = VerbVisibility.Disabled;
|
||||
var verb = Loc.GetString(component.Open ? "open-toggle-verb-close" : "open-toggle-verb-open");
|
||||
data.Text = Loc.GetString("open-toggle-verb-welded-shut-message",("verb", verb));
|
||||
data.Text = Loc.GetString("open-toggle-verb-welded-shut-message", ("verb", verb));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,148 +0,0 @@
|
||||
using Content.Server.Access.Components;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Notification.Managers;
|
||||
using Content.Shared.Storage;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Storage.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(EntityStorageComponent))]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IStorageComponent))]
|
||||
public class SecureEntityStorageComponent : EntityStorageComponent
|
||||
{
|
||||
public override string Name => "SecureEntityStorage";
|
||||
[DataField("locked")]
|
||||
private bool _locked = true;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Locked
|
||||
{
|
||||
get => _locked;
|
||||
set
|
||||
{
|
||||
_locked = value;
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(StorageVisuals.Locked, _locked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Startup()
|
||||
{
|
||||
base.Startup();
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(StorageVisuals.CanLock, true);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
if (Locked)
|
||||
{
|
||||
DoToggleLock(eventArgs.User);
|
||||
return;
|
||||
}
|
||||
|
||||
base.Activate(eventArgs);
|
||||
}
|
||||
|
||||
public override bool CanOpen(IEntity user, bool silent = false)
|
||||
{
|
||||
if (Locked)
|
||||
{
|
||||
Owner.PopupMessage(user, "It's locked!");
|
||||
return false;
|
||||
}
|
||||
return base.CanOpen(user, silent);
|
||||
}
|
||||
|
||||
protected override void OpenVerbGetData(IEntity user, EntityStorageComponent component, VerbData data)
|
||||
{
|
||||
if (Locked)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
base.OpenVerbGetData(user, component, data);
|
||||
}
|
||||
|
||||
private void DoToggleLock(IEntity user)
|
||||
{
|
||||
if (Locked)
|
||||
{
|
||||
DoUnlock(user);
|
||||
}
|
||||
else
|
||||
{
|
||||
DoLock(user);
|
||||
}
|
||||
}
|
||||
|
||||
private void DoUnlock(IEntity user)
|
||||
{
|
||||
if (!CheckAccess(user)) return;
|
||||
|
||||
Locked = false;
|
||||
SoundSystem.Play(Filter.Pvs(Owner), "/Audio/Machines/door_lock_off.ogg", Owner, AudioParams.Default.WithVolume(-5));
|
||||
}
|
||||
|
||||
private void DoLock(IEntity user)
|
||||
{
|
||||
if (!CheckAccess(user)) return;
|
||||
|
||||
Locked = true;
|
||||
SoundSystem.Play(Filter.Pvs(Owner), "/Audio/Machines/door_lock_on.ogg", Owner, AudioParams.Default.WithVolume(-5));
|
||||
}
|
||||
|
||||
private bool CheckAccess(IEntity user)
|
||||
{
|
||||
if (Owner.TryGetComponent(out AccessReader? reader))
|
||||
{
|
||||
if (!reader.IsAllowed(user))
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("secure-entity-storage-component-not-allowed-message"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Verb]
|
||||
private sealed class ToggleLockVerb : Verb<SecureEntityStorageComponent>
|
||||
{
|
||||
protected override void GetData(IEntity user, SecureEntityStorageComponent component, VerbData data)
|
||||
{
|
||||
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user) || component.Open)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Invisible;
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString(component.Locked ? "toggle-lock-verb-unlock" : "toggle-lock-verb-lock");
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, SecureEntityStorageComponent component)
|
||||
{
|
||||
component.DoToggleLock(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user