Airlock construction (#3609)
* Add construction and deconstsruction of airlocks * Change name to door electronics * Rearrange things * Fix errors * Fix physics error from bumping * Prevent editing the map for now * Address reviews * Change switch to if * Fix newlines
This commit is contained in:
43
Content.Server/Construction/Conditions/AirlockBolted.cs
Normal file
43
Content.Server/Construction/Conditions/AirlockBolted.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.Doors;
|
||||
using Content.Shared.Construction;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Content.Server.Construction.Conditions
|
||||
{
|
||||
[UsedImplicitly]
|
||||
[DataDefinition]
|
||||
public class AirlockBolted : IEdgeCondition
|
||||
{
|
||||
[DataField("value")]
|
||||
public bool Value { get; private set; } = true;
|
||||
|
||||
public async Task<bool> Condition(IEntity entity)
|
||||
{
|
||||
if (!entity.TryGetComponent(out AirlockComponent? airlock)) return true;
|
||||
|
||||
return airlock.BoltsDown == Value;
|
||||
}
|
||||
|
||||
public bool DoExamine(IEntity entity, FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if (!entity.TryGetComponent(out AirlockComponent? airlock)) return false;
|
||||
|
||||
if (airlock.BoltsDown != Value)
|
||||
{
|
||||
if (Value == true)
|
||||
message.AddMarkup(Loc.GetString("construction-condition-airlock-bolt", ("entityName", entity.Name)) + "\n");
|
||||
else
|
||||
message.AddMarkup(Loc.GetString("construction-condition-airlock-unbolt", ("entityName", entity.Name)) + "\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
#nullable enable
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.GameObjects.Components.Doors;
|
||||
using Content.Shared.Construction;
|
||||
using JetBrains.Annotations;
|
||||
@@ -14,29 +15,30 @@ namespace Content.Server.Construction.Conditions
|
||||
[DataDefinition]
|
||||
public class DoorWelded : IEdgeCondition
|
||||
{
|
||||
[DataField("welded")] public bool Welded { get; private set; } = true;
|
||||
[DataField("welded")]
|
||||
public bool Welded { get; private set; } = true;
|
||||
|
||||
public async Task<bool> Condition(IEntity entity)
|
||||
{
|
||||
if (!entity.TryGetComponent(out ServerDoorComponent? doorComponent)) return false;
|
||||
|
||||
return doorComponent.IsWeldedShut == Welded;
|
||||
}
|
||||
|
||||
public bool DoExamine(IEntity entity, FormattedMessage message, bool inDetailsRange)
|
||||
{
|
||||
if (!entity.TryGetComponent(out ServerDoorComponent? doorComponent)) return false;
|
||||
if (!entity.TryGetComponent(out ServerDoorComponent? door)) return false;
|
||||
|
||||
if (doorComponent.State == DoorState.Closed && Welded)
|
||||
if (door.IsWeldedShut != Welded)
|
||||
{
|
||||
message.AddMarkup(Loc.GetString("First, weld the door.\n"));
|
||||
if (Welded == true)
|
||||
message.AddMarkup(Loc.GetString("construction-condition-door-weld", ("entityName", entity.Name)) + "\n");
|
||||
else
|
||||
message.AddMarkup(Loc.GetString("construction-condition-door-unweld", ("entityName", entity.Name)) + "\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!doorComponent.IsWeldedShut || Welded) return false;
|
||||
|
||||
message.AddMarkup(Loc.GetString("First, unweld the door.\n"));
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@@ -31,6 +31,8 @@ using Robust.Shared.Physics.Collision;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Timer = Robust.Shared.Timing.Timer;
|
||||
using Content.Server.GameObjects.Components.Construction;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Doors
|
||||
{
|
||||
@@ -42,6 +44,10 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
[ComponentDependency]
|
||||
private readonly IDoorCheck? _doorCheck = null;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("board")]
|
||||
private string? _boardPrototype;
|
||||
|
||||
public override DoorState State
|
||||
{
|
||||
get => base.State;
|
||||
@@ -164,6 +170,8 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
}
|
||||
SetAppearance(DoorVisualState.Welded);
|
||||
}
|
||||
|
||||
CreateDoorElectronicsBoard();
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
@@ -185,6 +193,8 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
}
|
||||
QuickOpen();
|
||||
}
|
||||
|
||||
CreateDoorElectronicsBoard();
|
||||
}
|
||||
|
||||
void IActivate.Activate(ActivateEventArgs eventArgs)
|
||||
@@ -638,6 +648,39 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the corresponding door electronics board on the door.
|
||||
/// This exists so when you deconstruct doors that were serialized with the map,
|
||||
/// you can retrieve the door electronics board.
|
||||
/// </summary>
|
||||
private void CreateDoorElectronicsBoard()
|
||||
{
|
||||
// Ensure that the construction component is aware of the board container.
|
||||
if (Owner.TryGetComponent(out ConstructionComponent? construction))
|
||||
construction.AddContainer("board");
|
||||
|
||||
// We don't do anything if this is null or empty.
|
||||
if (string.IsNullOrEmpty(_boardPrototype))
|
||||
return;
|
||||
|
||||
var container = Owner.EnsureContainer<Container>("board", out var existed);
|
||||
|
||||
return;
|
||||
/* // TODO ShadowCommander: Re-enable when access is added to boards. Requires map update.
|
||||
if (existed)
|
||||
{
|
||||
// We already contain a board. Note: We don't check if it's the right one!
|
||||
if (container.ContainedEntities.Count != 0)
|
||||
return;
|
||||
}
|
||||
|
||||
var board = Owner.EntityManager.SpawnEntity(_boardPrototype, Owner.Transform.Coordinates);
|
||||
|
||||
if(!container.Insert(board))
|
||||
Logger.Warning($"Couldn't insert board {board} into door {Owner}!");
|
||||
*/
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
return new DoorComponentState(State, StateChangeStartTime, CurrentlyCrushing, GameTiming.CurTime);
|
||||
|
||||
Reference in New Issue
Block a user