Merge branch 'master' into 2020-08-19-firelocks
# Conflicts: # Content.Server/GameObjects/Components/Atmos/AirtightComponent.cs # Content.Server/GameObjects/Components/Atmos/GridAtmosphereComponent.cs # SpaceStation14.sln.DotSettings
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Content.Server.Atmos;
|
||||
@@ -35,10 +36,10 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
|
||||
private DoorState _state = DoorState.Closed;
|
||||
|
||||
protected virtual DoorState State
|
||||
public virtual DoorState State
|
||||
{
|
||||
get => _state;
|
||||
set => _state = value;
|
||||
protected set => _state = value;
|
||||
}
|
||||
|
||||
protected float OpenTimeCounter;
|
||||
@@ -46,10 +47,7 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
protected const float AutoCloseDelay = 5;
|
||||
protected float CloseSpeed = AutoCloseDelay;
|
||||
|
||||
private AirtightComponent airtightComponent;
|
||||
private ICollidableComponent _collidableComponent;
|
||||
private AppearanceComponent _appearance;
|
||||
private CancellationTokenSource _cancellationTokenSource;
|
||||
private CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
protected virtual TimeSpan CloseTimeOne => TimeSpan.FromSeconds(0.3f);
|
||||
protected virtual TimeSpan CloseTimeTwo => TimeSpan.FromSeconds(0.9f);
|
||||
@@ -72,21 +70,9 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
serializer.DataField(ref _occludes, "occludes", true);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
airtightComponent = Owner.GetComponent<AirtightComponent>();
|
||||
_collidableComponent = Owner.GetComponent<ICollidableComponent>();
|
||||
_appearance = Owner.GetComponent<AppearanceComponent>();
|
||||
_cancellationTokenSource = new CancellationTokenSource();
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
{
|
||||
_cancellationTokenSource.Cancel();
|
||||
_collidableComponent = null;
|
||||
_appearance = null;
|
||||
_cancellationTokenSource?.Cancel();
|
||||
|
||||
base.OnRemove();
|
||||
}
|
||||
@@ -108,7 +94,6 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
ActivateImpl(eventArgs);
|
||||
}
|
||||
|
||||
|
||||
void ICollideBehavior.CollideWith(IEntity entity)
|
||||
{
|
||||
if (State != DoorState.Closed)
|
||||
@@ -139,8 +124,10 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
|
||||
protected void SetAppearance(DoorVisualState state)
|
||||
{
|
||||
if (_appearance != null || Owner.TryGetComponent(out _appearance))
|
||||
_appearance.SetData(DoorVisuals.VisualState, state);
|
||||
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
||||
{
|
||||
appearance.SetData(DoorVisuals.VisualState, state);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool CanOpen()
|
||||
@@ -151,28 +138,53 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
public virtual bool CanOpen(IEntity user)
|
||||
{
|
||||
if (!CanOpen()) return false;
|
||||
if (!Owner.TryGetComponent(out AccessReader accessReader))
|
||||
|
||||
if (!Owner.TryGetComponent<AccessReader>(out var accessReader))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return accessReader.IsAllowed(user);
|
||||
var doorSystem = EntitySystem.Get<DoorSystem>();
|
||||
var isAirlockExternal = HasAccessType("External");
|
||||
|
||||
return doorSystem.AccessType switch
|
||||
{
|
||||
DoorSystem.AccessTypes.AllowAll => true,
|
||||
DoorSystem.AccessTypes.AllowAllIdExternal => isAirlockExternal ? accessReader.IsAllowed(user) : true,
|
||||
DoorSystem.AccessTypes.AllowAllNoExternal => !isAirlockExternal,
|
||||
_ => accessReader.IsAllowed(user)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether a door has a certain access type. For example, maintenance doors will have access type
|
||||
/// "Maintenance" in their AccessReader.
|
||||
/// </summary>
|
||||
private bool HasAccessType(string accesType)
|
||||
{
|
||||
if(Owner.TryGetComponent<AccessReader>(out var accessReader))
|
||||
{
|
||||
return accessReader.AccessLists.Any(list => list.Contains(accesType));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void TryOpen(IEntity user)
|
||||
{
|
||||
if (!CanOpen(user))
|
||||
if (CanOpen(user))
|
||||
{
|
||||
Open();
|
||||
|
||||
if (user.TryGetComponent(out HandsComponent? hands) && hands.Count == 0)
|
||||
{
|
||||
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Effects/bang.ogg", Owner,
|
||||
AudioParams.Default.WithVolume(-2));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Deny();
|
||||
return;
|
||||
}
|
||||
|
||||
Open();
|
||||
|
||||
if (user.TryGetComponent(out HandsComponent hands) && hands.Count == 0)
|
||||
{
|
||||
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Effects/bang.ogg", Owner,
|
||||
AudioParams.Default.WithVolume(-2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,15 +197,22 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
|
||||
State = DoorState.Opening;
|
||||
SetAppearance(DoorVisualState.Opening);
|
||||
if (_occludes && Owner.TryGetComponent(out OccluderComponent occluder))
|
||||
if (_occludes && Owner.TryGetComponent(out OccluderComponent? occluder))
|
||||
{
|
||||
occluder.Enabled = false;
|
||||
}
|
||||
|
||||
Timer.Spawn(OpenTimeOne, async () =>
|
||||
{
|
||||
airtightComponent.AirBlocked = false;
|
||||
_collidableComponent.Hard = false;
|
||||
if (Owner.TryGetComponent(out AirtightComponent? airtight))
|
||||
{
|
||||
airtight.AirBlocked = false;
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out ICollidableComponent? collidable))
|
||||
{
|
||||
collidable.Hard = false;
|
||||
}
|
||||
|
||||
await Timer.Delay(OpenTimeTwo, _cancellationTokenSource.Token);
|
||||
|
||||
@@ -212,7 +231,7 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
public virtual bool CanClose(IEntity user)
|
||||
{
|
||||
if (!CanClose()) return false;
|
||||
if (!Owner.TryGetComponent(out AccessReader accessReader))
|
||||
if (!Owner.TryGetComponent(out AccessReader? accessReader))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -233,18 +252,22 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
|
||||
private void CheckCrush()
|
||||
{
|
||||
if (!Owner.TryGetComponent(out ICollidableComponent? body))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if collides with something
|
||||
var collidesWith = _collidableComponent.GetCollidingEntities(Vector2.Zero, false);
|
||||
var collidesWith = body.GetCollidingEntities(Vector2.Zero, false);
|
||||
if (collidesWith.Count() != 0)
|
||||
{
|
||||
// Crush
|
||||
bool hitSomeone = false;
|
||||
foreach (var e in collidesWith)
|
||||
{
|
||||
if (!e.TryGetComponent(out StunnableComponent stun)
|
||||
|| !e.TryGetComponent(out IDamageableComponent damage)
|
||||
|| !e.TryGetComponent(out ICollidableComponent otherBody)
|
||||
|| !Owner.TryGetComponent(out ICollidableComponent body))
|
||||
if (!e.TryGetComponent(out StunnableComponent? stun)
|
||||
|| !e.TryGetComponent(out IDamageableComponent? damage)
|
||||
|| !e.TryGetComponent(out ICollidableComponent? otherBody))
|
||||
continue;
|
||||
|
||||
var percentage = otherBody.WorldAABB.IntersectPercentage(body.WorldAABB);
|
||||
@@ -319,7 +342,8 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
public bool Close()
|
||||
{
|
||||
bool shouldCheckCrush = false;
|
||||
if (_collidableComponent.IsColliding(Vector2.Zero, false))
|
||||
|
||||
if (Owner.TryGetComponent(out ICollidableComponent? collidable) && collidable.IsColliding(Vector2.Zero, false))
|
||||
{
|
||||
if (Safety)
|
||||
return false;
|
||||
@@ -331,7 +355,7 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
State = DoorState.Closing;
|
||||
OpenTimeCounter = 0;
|
||||
SetAppearance(DoorVisualState.Closing);
|
||||
if (_occludes && Owner.TryGetComponent(out OccluderComponent occluder))
|
||||
if (_occludes && Owner.TryGetComponent(out OccluderComponent? occluder))
|
||||
{
|
||||
occluder.Enabled = true;
|
||||
}
|
||||
@@ -343,8 +367,15 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
CheckCrush();
|
||||
}
|
||||
|
||||
airtightComponent.AirBlocked = true;
|
||||
_collidableComponent.Hard = true;
|
||||
if (Owner.TryGetComponent(out AirtightComponent? airtight))
|
||||
{
|
||||
airtight.AirBlocked = true;
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out ICollidableComponent? body))
|
||||
{
|
||||
body.Hard = true;
|
||||
}
|
||||
|
||||
await Timer.Delay(CloseTimeTwo, _cancellationTokenSource.Token);
|
||||
|
||||
@@ -391,7 +422,7 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
}
|
||||
}
|
||||
|
||||
protected enum DoorState
|
||||
public enum DoorState
|
||||
{
|
||||
Closed,
|
||||
Open,
|
||||
|
||||
Reference in New Issue
Block a user