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

@@ -107,6 +107,7 @@ namespace Content.Client.GameObjects.Components.Doors
var unlitVisible = true; var unlitVisible = true;
var boltedVisible = false; var boltedVisible = false;
var weldedVisible = false;
switch (state) switch (state)
{ {
case DoorVisualState.Closed: case DoorVisualState.Closed:
@@ -137,6 +138,9 @@ namespace Content.Client.GameObjects.Components.Doors
animPlayer.Play(DenyAnimation, AnimationKey); animPlayer.Play(DenyAnimation, AnimationKey);
} }
break; break;
case DoorVisualState.Welded:
weldedVisible = true;
break;
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }
@@ -151,6 +155,7 @@ namespace Content.Client.GameObjects.Components.Doors
} }
sprite.LayerSetVisible(DoorVisualLayers.BaseUnlit, unlitVisible); sprite.LayerSetVisible(DoorVisualLayers.BaseUnlit, unlitVisible);
sprite.LayerSetVisible(DoorVisualLayers.BaseWelded, weldedVisible);
sprite.LayerSetVisible(DoorVisualLayers.BaseBolted, unlitVisible && boltedVisible); sprite.LayerSetVisible(DoorVisualLayers.BaseBolted, unlitVisible && boltedVisible);
} }
} }
@@ -159,6 +164,7 @@ namespace Content.Client.GameObjects.Components.Doors
{ {
Base, Base,
BaseUnlit, BaseUnlit,
BaseBolted BaseWelded,
BaseBolted,
} }
} }

View File

@@ -26,7 +26,7 @@ namespace Content.Server.GameObjects.Components.Doors
[RegisterComponent] [RegisterComponent]
[ComponentReference(typeof(IActivate))] [ComponentReference(typeof(IActivate))]
[ComponentReference(typeof(ServerDoorComponent))] [ComponentReference(typeof(ServerDoorComponent))]
public class AirlockComponent : ServerDoorComponent, IWires, IInteractUsing public class AirlockComponent : ServerDoorComponent, IWires
{ {
public override string Name => "Airlock"; public override string Name => "Airlock";
@@ -383,7 +383,7 @@ namespace Content.Server.GameObjects.Components.Doors
public override bool CanOpen() public override bool CanOpen()
{ {
return IsPowered() && !IsBolted(); return base.CanOpen() && IsPowered() && !IsBolted();
} }
public override bool CanClose() public override bool CanClose()
@@ -412,8 +412,11 @@ namespace Content.Server.GameObjects.Components.Doors
|| receiver.Powered; || receiver.Powered;
} }
public async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs) public override async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
{ {
if (await base.InteractUsing(eventArgs))
return true;
if (!eventArgs.Using.TryGetComponent<ToolComponent>(out var tool)) if (!eventArgs.Using.TryGetComponent<ToolComponent>(out var tool))
return false; return false;

View File

@@ -2,15 +2,18 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Access; using Content.Server.GameObjects.Components.Access;
using Content.Server.GameObjects.Components.Atmos; using Content.Server.GameObjects.Components.Atmos;
using Content.Server.GameObjects.Components.GUI; using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Interactable;
using Content.Server.GameObjects.Components.Mobs; using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.GameObjects.Components.Body; using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Damage; using Content.Shared.GameObjects.Components.Damage;
using Content.Shared.GameObjects.Components.Doors; using Content.Shared.GameObjects.Components.Doors;
using Content.Shared.GameObjects.Components.Interactable;
using Content.Shared.GameObjects.Components.Movement; using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
@@ -29,7 +32,7 @@ namespace Content.Server.GameObjects.Components.Doors
{ {
[RegisterComponent] [RegisterComponent]
[ComponentReference(typeof(IActivate))] [ComponentReference(typeof(IActivate))]
public class ServerDoorComponent : Component, IActivate, ICollideBehavior public class ServerDoorComponent : Component, IActivate, ICollideBehavior, IInteractUsing
{ {
public override string Name => "Door"; public override string Name => "Door";
@@ -60,11 +63,31 @@ namespace Content.Server.GameObjects.Components.Doors
[ViewVariables] private bool _occludes; [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) public override void ExposeData(ObjectSerializer serializer)
{ {
base.ExposeData(serializer); base.ExposeData(serializer);
serializer.DataField(ref _occludes, "occludes", true); serializer.DataField(ref _occludes, "occludes", true);
serializer.DataField(ref _isWeldedShut, "welded", false);
} }
public override void OnRemove() public override void OnRemove()
@@ -129,7 +152,7 @@ namespace Content.Server.GameObjects.Components.Doors
public virtual bool CanOpen() public virtual bool CanOpen()
{ {
return true; return !_isWeldedShut;
} }
public bool CanOpen(IEntity user) public bool CanOpen(IEntity user)
@@ -192,6 +215,7 @@ namespace Content.Server.GameObjects.Components.Doors
return; return;
} }
_canWeldShut = false;
State = DoorState.Opening; State = DoorState.Opening;
SetAppearance(DoorVisualState.Opening); SetAppearance(DoorVisualState.Opening);
if (_occludes && Owner.TryGetComponent(out OccluderComponent? occluder)) if (_occludes && Owner.TryGetComponent(out OccluderComponent? occluder))
@@ -325,6 +349,7 @@ namespace Content.Server.GameObjects.Components.Doors
await Timer.Delay(CloseTimeTwo, _cancellationTokenSource.Token); await Timer.Delay(CloseTimeTwo, _cancellationTokenSource.Token);
_canWeldShut = true;
State = DoorState.Closed; State = DoorState.Closed;
SetAppearance(DoorVisualState.Closed); SetAppearance(DoorVisualState.Closed);
}, _cancellationTokenSource.Token); }, _cancellationTokenSource.Token);
@@ -334,7 +359,7 @@ namespace Content.Server.GameObjects.Components.Doors
public virtual void Deny() public virtual void Deny()
{ {
if (State == DoorState.Open) if (State == DoorState.Open || _isWeldedShut)
{ {
return; return;
} }
@@ -375,5 +400,20 @@ namespace Content.Server.GameObjects.Components.Doors
Closing, Closing,
Opening, 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;
}
} }
} }

View File

@@ -21,5 +21,6 @@ namespace Content.Shared.GameObjects.Components.Doors
Open, Open,
Closing, Closing,
Deny, Deny,
Welded,
} }
} }

View File

@@ -16,6 +16,8 @@
- state: closed_unlit - state: closed_unlit
shader: unshaded shader: unshaded
map: ["enum.DoorVisualLayers.BaseUnlit"] map: ["enum.DoorVisualLayers.BaseUnlit"]
- state: welded
map: ["enum.DoorVisualLayers.BaseWelded"]
- state: bolted - state: bolted
shader: unshaded shader: unshaded
map: ["enum.DoorVisualLayers.BaseBolted"] map: ["enum.DoorVisualLayers.BaseBolted"]