Files
crystall-punk-14/Content.Server/GameObjects/Components/Atmos/FirelockComponent.cs

104 lines
3.3 KiB
C#
Raw Normal View History

2020-08-21 18:29:43 +02:00
using System;
using System.Threading.Tasks;
2020-08-19 12:23:42 +02:00
using Content.Server.GameObjects.Components.Doors;
using Content.Server.GameObjects.Components.Interactable;
using Content.Shared.GameObjects.Components.Doors;
using Content.Shared.GameObjects.Components.Interactable;
2020-09-12 20:10:56 +02:00
using Content.Shared.Interfaces;
2020-08-19 12:23:42 +02:00
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.Interfaces.GameObjects;
namespace Content.Server.GameObjects.Components.Atmos
{
[RegisterComponent]
2020-08-21 18:29:43 +02:00
public class FirelockComponent : ServerDoorComponent, IInteractUsing, ICollideBehavior
2020-08-19 12:23:42 +02:00
{
public override string Name => "Firelock";
2020-08-21 18:29:43 +02:00
protected override TimeSpan CloseTimeOne => TimeSpan.FromSeconds(0.1f);
protected override TimeSpan CloseTimeTwo => TimeSpan.FromSeconds(0.6f);
protected override TimeSpan OpenTimeOne => TimeSpan.FromSeconds(0.1f);
protected override TimeSpan OpenTimeTwo => TimeSpan.FromSeconds(0.6f);
2020-08-19 12:23:42 +02:00
public void CollideWith(IEntity collidedWith)
{
// We do nothing.
}
protected override void Startup()
{
base.Startup();
if (Owner.TryGetComponent(out AirtightComponent airtightComponent))
{
airtightComponent.AirBlocked = false;
}
if (Owner.TryGetComponent(out IPhysicsComponent physics))
{
physics.CanCollide = false;
}
2020-08-19 12:23:42 +02:00
AutoClose = false;
2020-08-19 12:23:42 +02:00
Safety = false;
if (Occludes && Owner.TryGetComponent(out OccluderComponent occluder))
{
occluder.Enabled = false;
}
State = DoorState.Open;
SetAppearance(DoorVisualState.Open);
}
public bool EmergencyPressureStop()
{
var closed = State == DoorState.Open && Close();
if(closed)
Owner.GetComponent<AirtightComponent>().AirBlocked = true;
return closed;
}
2020-08-21 18:29:43 +02:00
public override bool CanOpen()
2020-08-19 12:23:42 +02:00
{
2020-08-21 18:29:43 +02:00
return !IsHoldingFire() && !IsHoldingPressure() && base.CanOpen();
2020-08-19 12:23:42 +02:00
}
public override bool CanClose(IEntity user) => true;
2020-08-21 18:29:43 +02:00
public override bool CanOpen(IEntity user) => CanOpen();
2020-08-19 12:23:42 +02:00
public override async Task<bool> InteractUsing(InteractUsingEventArgs eventArgs)
2020-08-19 12:23:42 +02:00
{
if (!eventArgs.Using.TryGetComponent<ToolComponent>(out var tool))
return false;
2020-08-21 18:29:43 +02:00
if (tool.HasQuality(ToolQuality.Prying))
{
var holdingPressure = IsHoldingPressure();
var holdingFire = IsHoldingFire();
if (State == DoorState.Closed)
{
if(holdingPressure)
2020-09-12 20:10:56 +02:00
Owner.PopupMessage(eventArgs.User, "A gush of air blows in your face... Maybe you should reconsider.");
2020-08-21 18:29:43 +02:00
}
2020-08-19 12:23:42 +02:00
2020-08-21 18:29:43 +02:00
if (!await tool.UseTool(eventArgs.User, Owner, holdingPressure || holdingFire ? 1.5f : 0.25f, ToolQuality.Prying)) return false;
if (State == DoorState.Closed)
Open();
else if (State == DoorState.Open)
Close();
return true;
}
2020-08-19 12:23:42 +02:00
2020-08-21 18:29:43 +02:00
return false;
2020-08-19 12:23:42 +02:00
}
}
}