Secure lockers & locker welding.
This commit is contained in:
@@ -1,18 +1,22 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.Interactable;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Server.GameObjects.Components.Sound;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Interactable;
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
@@ -22,18 +26,26 @@ namespace Content.Server.GameObjects.Components
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IActivate))]
|
||||
[ComponentReference(typeof(IStorageComponent))]
|
||||
public class EntityStorageComponent : Component, IActivate, IStorageComponent
|
||||
public class EntityStorageComponent : Component, IActivate, IStorageComponent, IInteractUsing
|
||||
{
|
||||
public override string Name => "EntityStorage";
|
||||
|
||||
private const float MaxSize = 1.0f; // maximum width or height of an entity allowed inside the storage.
|
||||
|
||||
private static readonly TimeSpan InternalOpenAttemptDelay = TimeSpan.FromSeconds(0.5);
|
||||
private TimeSpan _lastInternalOpenAttempt;
|
||||
|
||||
[ViewVariables]
|
||||
private int StorageCapacityMax;
|
||||
[ViewVariables]
|
||||
private bool IsCollidableWhenOpen;
|
||||
[ViewVariables]
|
||||
private Container Contents;
|
||||
[ViewVariables]
|
||||
private IEntityQuery entityQuery;
|
||||
private bool _showContents;
|
||||
private bool _open;
|
||||
private bool _isWeldedShut;
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the container contents should be drawn when the container is closed.
|
||||
@@ -49,6 +61,31 @@ namespace Content.Server.GameObjects.Components
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Open
|
||||
{
|
||||
get => _open;
|
||||
private set => _open = value;
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool IsWeldedShut
|
||||
{
|
||||
get => _isWeldedShut;
|
||||
set
|
||||
{
|
||||
_isWeldedShut = value;
|
||||
|
||||
if (Owner.TryGetComponent(out AppearanceComponent appearance))
|
||||
{
|
||||
appearance.SetData(StorageVisuals.Welded, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool CanWeldShut { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -73,29 +110,30 @@ namespace Content.Server.GameObjects.Components
|
||||
serializer.DataField(ref IsCollidableWhenOpen, "IsCollidableWhenOpen", false);
|
||||
serializer.DataField(ref _showContents, "showContents", false);
|
||||
serializer.DataField(ref _open, "open", false);
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Open
|
||||
{
|
||||
get => _open;
|
||||
private set => _open = value;
|
||||
serializer.DataField(this, a => a.IsWeldedShut, "IsWeldedShut", false);
|
||||
serializer.DataField(this, a => a.CanWeldShut, "CanWeldShut", true);
|
||||
}
|
||||
|
||||
public virtual void Activate(ActivateEventArgs eventArgs)
|
||||
{
|
||||
ToggleOpen();
|
||||
ToggleOpen(eventArgs.User);
|
||||
}
|
||||
|
||||
private void ToggleOpen()
|
||||
protected virtual void ToggleOpen(IEntity user)
|
||||
{
|
||||
if (IsWeldedShut)
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("It's welded completely shut!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (Open)
|
||||
{
|
||||
CloseStorage();
|
||||
}
|
||||
else
|
||||
{
|
||||
OpenStorage();
|
||||
TryOpenStorage(user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +168,7 @@ namespace Content.Server.GameObjects.Components
|
||||
{
|
||||
soundComponent.Play("/Audio/machines/closetclose.ogg");
|
||||
}
|
||||
_lastInternalOpenAttempt = default;
|
||||
}
|
||||
|
||||
private void OpenStorage()
|
||||
@@ -238,12 +277,30 @@ namespace Content.Server.GameObjects.Components
|
||||
case RelayMovementEntityMessage msg:
|
||||
if (msg.Entity.HasComponent<HandsComponent>())
|
||||
{
|
||||
OpenStorage();
|
||||
var timing = IoCManager.Resolve<IGameTiming>();
|
||||
if (timing.CurTime <
|
||||
_lastInternalOpenAttempt + InternalOpenAttemptDelay)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
_lastInternalOpenAttempt = timing.CurTime;
|
||||
TryOpenStorage(msg.Entity);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void TryOpenStorage(IEntity user)
|
||||
{
|
||||
if (IsWeldedShut)
|
||||
{
|
||||
Owner.PopupMessage(user, Loc.GetString("It's welded completely shut!"));
|
||||
return;
|
||||
}
|
||||
OpenStorage();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Remove(IEntity entity)
|
||||
{
|
||||
@@ -284,14 +341,43 @@ namespace Content.Server.GameObjects.Components
|
||||
{
|
||||
protected override void GetData(IEntity user, EntityStorageComponent component, VerbData data)
|
||||
{
|
||||
data.Text = component.Open ? "Close" : "Open";
|
||||
component.OpenVerbGetData(user, component, data);
|
||||
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Activate(IEntity user, EntityStorageComponent component)
|
||||
{
|
||||
component.ToggleOpen();
|
||||
component.ToggleOpen(user);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OpenVerbGetData(IEntity user, EntityStorageComponent component, VerbData data)
|
||||
{
|
||||
if (IsWeldedShut)
|
||||
{
|
||||
data.Visibility = VerbVisibility.Disabled;
|
||||
var verb = Loc.GetString(component.Open ? "Close" : "Open");
|
||||
data.Text = Loc.GetString("{0} (welded shut)", verb);
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = component.Open ? "Close" : "Open";
|
||||
}
|
||||
|
||||
public bool InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (!CanWeldShut)
|
||||
return false;
|
||||
|
||||
if (!eventArgs.Using.TryGetComponent(out WelderComponent tool))
|
||||
return false;
|
||||
|
||||
if (!tool.UseTool(eventArgs.User, Owner, ToolQuality.Welding, 1f))
|
||||
return false;
|
||||
|
||||
IsWeldedShut ^= true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user