Add door welding (#1951)

* Add door welding

Surprised this wasn't in already.

* smug's feedback

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2020-08-30 19:16:29 +10:00
committed by GitHub
parent 38b9a5a901
commit 72eb1fdc1c
5 changed files with 60 additions and 8 deletions

View File

@@ -2,15 +2,18 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Access;
using Content.Server.GameObjects.Components.Atmos;
using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Interactable;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Damage;
using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.GameObjects.Components.Doors;
using Content.Shared.GameObjects.Components.Interactable;
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects;
@@ -29,7 +32,7 @@ namespace Content.Server.GameObjects.Components.Doors
{
[RegisterComponent]
[ComponentReference(typeof(IActivate))]
public class ServerDoorComponent : Component, IActivate, ICollideBehavior
public class ServerDoorComponent : Component, IActivate, ICollideBehavior, IInteractUsing
{
public override string Name => "Door";
@@ -45,7 +48,7 @@ namespace Content.Server.GameObjects.Components.Doors
protected bool AutoClose = true;
protected const float AutoCloseDelay = 5;
protected float CloseSpeed = AutoCloseDelay;
private CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
private static readonly TimeSpan CloseTimeOne = TimeSpan.FromSeconds(0.3f);
@@ -60,11 +63,31 @@ namespace Content.Server.GameObjects.Components.Doors
[ViewVariables] private bool _occludes;
[ViewVariables]
public bool IsWeldedShut
{
get => _isWeldedShut;
set
{
if (_isWeldedShut == value)
{
return;
}
_isWeldedShut = value;
SetAppearance(_isWeldedShut ? DoorVisualState.Welded : DoorVisualState.Closed);
}
}
private bool _isWeldedShut;
private bool _canWeldShut = true;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _occludes, "occludes", true);
serializer.DataField(ref _isWeldedShut, "welded", false);
}
public override void OnRemove()
@@ -129,7 +152,7 @@ namespace Content.Server.GameObjects.Components.Doors
public virtual bool CanOpen()
{
return true;
return !_isWeldedShut;
}
public bool CanOpen(IEntity user)
@@ -192,6 +215,7 @@ namespace Content.Server.GameObjects.Components.Doors
return;
}
_canWeldShut = false;
State = DoorState.Opening;
SetAppearance(DoorVisualState.Opening);
if (_occludes && Owner.TryGetComponent(out OccluderComponent? occluder))
@@ -325,6 +349,7 @@ namespace Content.Server.GameObjects.Components.Doors
await Timer.Delay(CloseTimeTwo, _cancellationTokenSource.Token);
_canWeldShut = true;
State = DoorState.Closed;
SetAppearance(DoorVisualState.Closed);
}, _cancellationTokenSource.Token);
@@ -334,7 +359,7 @@ namespace Content.Server.GameObjects.Components.Doors
public virtual void Deny()
{
if (State == DoorState.Open)
if (State == DoorState.Open || _isWeldedShut)
{
return;
}
@@ -375,5 +400,20 @@ namespace Content.Server.GameObjects.Components.Doors
Closing,
Opening,
}
public virtual async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!_canWeldShut)
return false;
if (!eventArgs.Using.TryGetComponent(out WelderComponent? tool))
return false;
if (!await tool.UseTool(eventArgs.User, Owner, 3f, ToolQuality.Welding, 3f, () => _canWeldShut))
return false;
IsWeldedShut ^= true;
return true;
}
}
}