ECS Doors (#5887)
This commit is contained in:
229
Content.Shared/Doors/Components/DoorComponent.cs
Normal file
229
Content.Shared/Doors/Components/DoorComponent.cs
Normal file
@@ -0,0 +1,229 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Tools;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using DrawDepthTag = Robust.Shared.GameObjects.DrawDepth;
|
||||
|
||||
namespace Content.Shared.Doors.Components;
|
||||
|
||||
[NetworkedComponent]
|
||||
[RegisterComponent]
|
||||
public sealed class DoorComponent : Component
|
||||
{
|
||||
public override string Name => "Door";
|
||||
|
||||
/// <summary>
|
||||
/// The current state of the door -- whether it is open, closed, opening, or closing.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This should never be set directly.
|
||||
/// </remarks>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public DoorState State = DoorState.Closed;
|
||||
|
||||
[DataField("startOpen")]
|
||||
public readonly bool StartOpen = false;
|
||||
|
||||
#region Timing
|
||||
// if you want do dynamically adjust these times, you need to add networking for them. So for now, they are all
|
||||
// read-only.
|
||||
|
||||
/// <summary>
|
||||
/// Closing time until impassable. Total time is this plus <see cref="CloseTimeTwo"/>.
|
||||
/// </summary>
|
||||
[DataField("closeTimeOne")]
|
||||
public readonly TimeSpan CloseTimeOne = TimeSpan.FromSeconds(0.4f);
|
||||
|
||||
/// <summary>
|
||||
/// Closing time until fully closed. Total time is this plus <see cref="CloseTimeOne"/>.
|
||||
/// </summary>
|
||||
[DataField("closeTimeTwo")]
|
||||
public readonly TimeSpan CloseTimeTwo = TimeSpan.FromSeconds(0.2f);
|
||||
|
||||
/// <summary>
|
||||
/// Opening time until passable. Total time is this plus <see cref="OpenTimeTwo"/>.
|
||||
/// </summary>
|
||||
[DataField("openTimeOne")]
|
||||
public readonly TimeSpan OpenTimeOne = TimeSpan.FromSeconds(0.4f);
|
||||
|
||||
/// <summary>
|
||||
/// Opening time until fully open. Total time is this plus <see cref="OpenTimeOne"/>.
|
||||
/// </summary>
|
||||
[DataField("openTimeTwo")]
|
||||
public readonly TimeSpan OpenTimeTwo = TimeSpan.FromSeconds(0.2f);
|
||||
|
||||
/// <summary>
|
||||
/// Interval between deny sounds & visuals;
|
||||
/// </summary>
|
||||
[DataField("denyDuration")]
|
||||
public readonly TimeSpan DenyDuration = TimeSpan.FromSeconds(0.45f);
|
||||
|
||||
/// <summary>
|
||||
/// When the door is active, this is the time when the state will next update.
|
||||
/// </summary>
|
||||
public TimeSpan? NextStateChange;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the door is currently partially closed or open. I.e., when the door is "closing" and is already opaque,
|
||||
/// but not yet actually closed.
|
||||
/// </summary>
|
||||
public bool Partial;
|
||||
#endregion
|
||||
|
||||
#region Welding
|
||||
// TODO WELDING. Consider creating a WeldableComponent for use with doors, crates and lockers? Currently they all
|
||||
// have their own welding logic.
|
||||
[DataField("weldingQuality", customTypeSerializer: typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
|
||||
public string WeldingQuality = "Welding";
|
||||
|
||||
/// <summary>
|
||||
/// Whether the door can ever be welded shut.
|
||||
/// </summary>
|
||||
[DataField("weldable")]
|
||||
public bool Weldable = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether something is currently using a welder on this so DoAfter isn't spammed.
|
||||
/// </summary>
|
||||
public bool BeingWelded;
|
||||
#endregion
|
||||
|
||||
public bool BeingPried;
|
||||
|
||||
#region Sounds
|
||||
/// <summary>
|
||||
/// Sound to play when the door opens.
|
||||
/// </summary>
|
||||
[DataField("openSound")]
|
||||
public SoundSpecifier? OpenSound;
|
||||
|
||||
/// <summary>
|
||||
/// Sound to play when the door closes.
|
||||
/// </summary>
|
||||
[DataField("closeSound")]
|
||||
public SoundSpecifier? CloseSound;
|
||||
|
||||
/// <summary>
|
||||
/// Sound to play if the door is denied.
|
||||
/// </summary>
|
||||
[DataField("denySound")]
|
||||
public SoundSpecifier? DenySound;
|
||||
|
||||
/// <summary>
|
||||
/// Sound to play when a disarmed (hands comp with 0 hands) entity opens the door. What?
|
||||
/// </summary>
|
||||
[DataField("tryOpenDoorSound")]
|
||||
public SoundSpecifier TryOpenDoorSound = new SoundPathSpecifier("/Audio/Effects/bang.ogg");
|
||||
#endregion
|
||||
|
||||
#region Crushing
|
||||
/// <summary>
|
||||
/// This is how long a door-crush will stun you. This also determines how long it takes the door to open up
|
||||
/// again. Total stun time is actually given by this plus <see cref="OpenTimeOne"/>.
|
||||
/// </summary>
|
||||
[DataField("doorStunTime")]
|
||||
public readonly TimeSpan DoorStunTime = TimeSpan.FromSeconds(2f);
|
||||
|
||||
[DataField("crushDamage")]
|
||||
public DamageSpecifier? CrushDamage;
|
||||
|
||||
/// <summary>
|
||||
/// If false, this door is incapable of crushing entities. Note that this differs from the airlock's "safety"
|
||||
/// feature that checks for colliding entities.
|
||||
/// </summary>
|
||||
[DataField("canCrush")]
|
||||
public readonly bool CanCrush = true;
|
||||
|
||||
/// <summary>
|
||||
/// List of EntityUids of entities we're currently crushing. Cleared in OnPartialOpen().
|
||||
/// </summary>
|
||||
public List<EntityUid> CurrentlyCrushing = new();
|
||||
#endregion
|
||||
|
||||
[DataField("board", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string? BoardPrototype;
|
||||
|
||||
[DataField("pryingQuality", customTypeSerializer: typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
|
||||
public string PryingQuality = "Prying";
|
||||
|
||||
/// <summary>
|
||||
/// Default time that the door should take to pry open.
|
||||
/// </summary>
|
||||
[DataField("pryTime")]
|
||||
public float PryTime = 1.5f;
|
||||
|
||||
[DataField("changeAirtight")]
|
||||
public bool ChangeAirtight = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the door blocks light.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("occludes")]
|
||||
public bool Occludes = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the door will open when it is bumped into.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("bumpOpen")]
|
||||
public bool BumpOpen = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether the door will open when it is activated or clicked.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("clickOpen")]
|
||||
public bool ClickOpen = true;
|
||||
|
||||
[DataField("openDrawDepth", customTypeSerializer: typeof(ConstantSerializer<DrawDepthTag>))]
|
||||
public int OpenDrawDepth = (int) DrawDepth.DrawDepth.Doors;
|
||||
|
||||
[DataField("closedDrawDepth", customTypeSerializer: typeof(ConstantSerializer<DrawDepthTag>))]
|
||||
public int ClosedDrawDepth = (int) DrawDepth.DrawDepth.Doors;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum DoorState
|
||||
{
|
||||
Closed,
|
||||
Closing,
|
||||
Open,
|
||||
Opening,
|
||||
Welded,
|
||||
Denying,
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum DoorVisuals
|
||||
{
|
||||
State,
|
||||
Powered,
|
||||
BoltLights
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class DoorComponentState : ComponentState
|
||||
{
|
||||
public readonly DoorState DoorState;
|
||||
public readonly List<EntityUid> CurrentlyCrushing;
|
||||
public readonly TimeSpan? NextStateChange;
|
||||
public readonly bool Partial;
|
||||
|
||||
public DoorComponentState(DoorComponent door)
|
||||
{
|
||||
DoorState = door.State;
|
||||
CurrentlyCrushing = door.CurrentlyCrushing;
|
||||
NextStateChange = door.NextStateChange;
|
||||
Partial = door.Partial;
|
||||
}
|
||||
}
|
||||
29
Content.Shared/Doors/Components/SharedAirlockComponent.cs
Normal file
29
Content.Shared/Doors/Components/SharedAirlockComponent.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System;
|
||||
|
||||
namespace Content.Shared.Doors.Components;
|
||||
|
||||
[NetworkedComponent]
|
||||
public abstract class SharedAirlockComponent : Component
|
||||
{
|
||||
public override string Name => "Airlock";
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("safety")]
|
||||
public bool Safety = true;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class AirlockComponentState : ComponentState
|
||||
{
|
||||
public readonly bool Safety;
|
||||
|
||||
public AirlockComponentState(bool safety)
|
||||
{
|
||||
Safety = safety;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Doors.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Doors
|
||||
@@ -8,9 +8,9 @@ namespace Content.Shared.Doors
|
||||
/// </summary>
|
||||
public class DoorStateChangedEvent : EntityEventArgs
|
||||
{
|
||||
public SharedDoorComponent.DoorState State;
|
||||
public readonly DoorState State;
|
||||
|
||||
public DoorStateChangedEvent(SharedDoorComponent.DoorState state)
|
||||
public DoorStateChangedEvent(DoorState state)
|
||||
{
|
||||
State = state;
|
||||
}
|
||||
@@ -28,6 +28,11 @@ namespace Content.Shared.Doors
|
||||
/// Raised when the door is determining whether it is able to close.
|
||||
/// Cancel to stop the door from being closed.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This event is raised both when the door is initially closed, and when it is just about to become "partially"
|
||||
/// closed (opaque & collidable). If canceled while partially closing, it will start opening again. Useful for
|
||||
/// things like airlock anti-crush safety features.
|
||||
/// </remarks>
|
||||
public class BeforeDoorClosedEvent : CancellableEntityEventArgs
|
||||
{
|
||||
}
|
||||
@@ -40,19 +45,13 @@ namespace Content.Shared.Doors
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised to determine whether the door's safety is on.
|
||||
/// Modify Safety to set the door's safety.
|
||||
/// </summary>
|
||||
public class DoorSafetyEnabledEvent : HandledEntityEventArgs
|
||||
{
|
||||
public bool Safety = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised to determine whether the door should automatically close.
|
||||
/// Cancel to stop it from automatically closing.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is called when a door decides whether it SHOULD auto close, not when it actually closes.
|
||||
/// </remarks>
|
||||
public class BeforeDoorAutoCloseEvent : CancellableEntityEventArgs
|
||||
{
|
||||
}
|
||||
@@ -66,52 +65,17 @@ namespace Content.Shared.Doors
|
||||
public float PryTimeModifier = 1.0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised to determine how long the door's close time should be modified by.
|
||||
/// Multiply CloseTimeModifier by the desired amount.
|
||||
/// </summary>
|
||||
public class DoorGetCloseTimeModifierEvent : EntityEventArgs
|
||||
{
|
||||
public float CloseTimeModifier = 1.0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised to determine whether clicking the door should open/close it.
|
||||
/// </summary>
|
||||
public class DoorClickShouldActivateEvent : HandledEntityEventArgs
|
||||
{
|
||||
public ActivateEventArgs Args;
|
||||
|
||||
public DoorClickShouldActivateEvent(ActivateEventArgs args)
|
||||
{
|
||||
Args = args;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when an attempt to pry open the door is made.
|
||||
/// Cancel to stop the door from being pried open.
|
||||
/// </summary>
|
||||
public class BeforeDoorPryEvent : CancellableEntityEventArgs
|
||||
{
|
||||
public InteractUsingEventArgs Args;
|
||||
public readonly EntityUid User;
|
||||
|
||||
public BeforeDoorPryEvent(InteractUsingEventArgs args)
|
||||
public BeforeDoorPryEvent(EntityUid user)
|
||||
{
|
||||
Args = args;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when a door is successfully pried open.
|
||||
/// </summary>
|
||||
public class OnDoorPryEvent : EntityEventArgs
|
||||
{
|
||||
public InteractUsingEventArgs Args;
|
||||
|
||||
public OnDoorPryEvent(InteractUsingEventArgs args)
|
||||
{
|
||||
Args = args;
|
||||
User = user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,189 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.Doors
|
||||
{
|
||||
[NetworkedComponent]
|
||||
public abstract class SharedDoorComponent : Component
|
||||
{
|
||||
public override string Name => "Door";
|
||||
|
||||
[Dependency]
|
||||
protected readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
[ViewVariables]
|
||||
private DoorState _state = DoorState.Closed;
|
||||
/// <summary>
|
||||
/// The current state of the door -- whether it is open, closed, opening, or closing.
|
||||
/// </summary>
|
||||
public virtual DoorState State
|
||||
{
|
||||
get => _state;
|
||||
protected set
|
||||
{
|
||||
if (_state == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_state = value;
|
||||
|
||||
SetAppearance(State switch
|
||||
{
|
||||
DoorState.Open => DoorVisualState.Open,
|
||||
DoorState.Closed => DoorVisualState.Closed,
|
||||
DoorState.Opening => DoorVisualState.Opening,
|
||||
DoorState.Closing => DoorVisualState.Closing,
|
||||
_ => throw new ArgumentOutOfRangeException(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Closing time until impassable.
|
||||
/// </summary>
|
||||
[DataField("closeTimeOne")]
|
||||
protected TimeSpan CloseTimeOne = TimeSpan.FromSeconds(0.4f);
|
||||
|
||||
/// <summary>
|
||||
/// Closing time until fully closed.
|
||||
/// </summary>
|
||||
[DataField("closeTimeTwo")]
|
||||
protected TimeSpan CloseTimeTwo = TimeSpan.FromSeconds(0.2f);
|
||||
|
||||
/// <summary>
|
||||
/// Opening time until passable.
|
||||
/// </summary>
|
||||
[DataField("openTimeOne")]
|
||||
protected TimeSpan OpenTimeOne = TimeSpan.FromSeconds(0.4f);
|
||||
|
||||
/// <summary>
|
||||
/// Opening time until fully open.
|
||||
/// </summary>
|
||||
[DataField("openTimeTwo")]
|
||||
protected TimeSpan OpenTimeTwo = TimeSpan.FromSeconds(0.2f);
|
||||
|
||||
/// <summary>
|
||||
/// Time to finish denying.
|
||||
/// </summary>
|
||||
protected static TimeSpan DenyTime => TimeSpan.FromSeconds(0.45f);
|
||||
|
||||
/// <summary>
|
||||
/// Used by ServerDoorComponent to get the CurTime for the client to use to know when to open, and by ClientDoorComponent to know the CurTime to correctly open.
|
||||
/// </summary>
|
||||
[Dependency] protected IGameTiming GameTiming = default!;
|
||||
|
||||
/// <summary>
|
||||
/// The time the door began to open or close, if the door is opening or closing, or null if it is neither.
|
||||
/// </summary>
|
||||
protected TimeSpan? StateChangeStartTime = null;
|
||||
|
||||
/// <summary>
|
||||
/// List of EntityUids of entities we're currently crushing. Cleared in OnPartialOpen().
|
||||
/// </summary>
|
||||
protected List<EntityUid> CurrentlyCrushing = new();
|
||||
|
||||
public bool IsCrushing(EntityUid entity)
|
||||
{
|
||||
return CurrentlyCrushing.Contains(entity);
|
||||
}
|
||||
|
||||
protected void SetAppearance(DoorVisualState state)
|
||||
{
|
||||
if (_entMan.TryGetComponent<AppearanceComponent>(Owner, out var appearanceComponent))
|
||||
{
|
||||
appearanceComponent.SetData(DoorVisuals.VisualState, state);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the door is partially opened.
|
||||
/// </summary>
|
||||
protected virtual void OnPartialOpen()
|
||||
{
|
||||
if (_entMan.TryGetComponent<PhysicsComponent>(Owner, out var physicsComponent))
|
||||
{
|
||||
physicsComponent.CanCollide = false;
|
||||
}
|
||||
// we can't be crushing anyone anymore, since we're opening
|
||||
CurrentlyCrushing.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the door is partially closed.
|
||||
/// </summary>
|
||||
protected virtual void OnPartialClose()
|
||||
{
|
||||
if (_entMan.TryGetComponent<PhysicsComponent>(Owner, out var physicsComponent))
|
||||
{
|
||||
physicsComponent.CanCollide = true;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum DoorState
|
||||
{
|
||||
Open,
|
||||
Closed,
|
||||
Opening,
|
||||
Closing,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum DoorVisualState
|
||||
{
|
||||
Open,
|
||||
Closed,
|
||||
Opening,
|
||||
Closing,
|
||||
Deny,
|
||||
Welded
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum DoorVisuals
|
||||
{
|
||||
VisualState,
|
||||
Powered,
|
||||
BoltLights
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class DoorComponentState : ComponentState
|
||||
{
|
||||
public readonly SharedDoorComponent.DoorState DoorState;
|
||||
public readonly TimeSpan? StartTime;
|
||||
public readonly List<EntityUid> CurrentlyCrushing;
|
||||
public readonly TimeSpan CurTime;
|
||||
|
||||
public DoorComponentState(SharedDoorComponent.DoorState doorState, TimeSpan? startTime, List<EntityUid> currentlyCrushing, TimeSpan curTime)
|
||||
{
|
||||
DoorState = doorState;
|
||||
StartTime = startTime;
|
||||
CurrentlyCrushing = currentlyCrushing;
|
||||
CurTime = curTime;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class DoorOpenAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public sealed class DoorCloseAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
|
||||
namespace Content.Shared.Doors
|
||||
{
|
||||
public abstract class SharedDoorSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<SharedDoorComponent, PreventCollideEvent>(PreventCollision);
|
||||
}
|
||||
|
||||
private void PreventCollision(EntityUid uid, SharedDoorComponent component, PreventCollideEvent args)
|
||||
{
|
||||
if (component.IsCrushing(args.BodyB.Owner))
|
||||
{
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
41
Content.Shared/Doors/Systems/SharedAirlockSystem.cs
Normal file
41
Content.Shared/Doors/Systems/SharedAirlockSystem.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Content.Shared.Doors.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Shared.Doors.Systems;
|
||||
|
||||
public abstract class SharedAirlockSystem : EntitySystem
|
||||
{
|
||||
[Dependency] protected readonly SharedDoorSystem DoorSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SharedAirlockComponent, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<SharedAirlockComponent, ComponentHandleState>(OnHandleState);
|
||||
SubscribeLocalEvent<SharedAirlockComponent, BeforeDoorClosedEvent>(OnBeforeDoorClosed);
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, SharedAirlockComponent airlock, ref ComponentGetState args)
|
||||
{
|
||||
// Need to network airlock safety state to avoid mis-predicts when a door auto-closes as the client walks through the door.
|
||||
args.State = new AirlockComponentState(airlock.Safety);
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, SharedAirlockComponent airlock, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not AirlockComponentState state)
|
||||
return;
|
||||
|
||||
airlock.Safety = state.Safety;
|
||||
}
|
||||
|
||||
protected virtual void OnBeforeDoorClosed(EntityUid uid, SharedAirlockComponent airlock, BeforeDoorClosedEvent args)
|
||||
{
|
||||
if (airlock.Safety && DoorSystem.GetColliding(uid).Any())
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
579
Content.Shared/Doors/Systems/SharedDoorSystem.cs
Normal file
579
Content.Shared/Doors/Systems/SharedDoorSystem.cs
Normal file
@@ -0,0 +1,579 @@
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Doors.Components;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Stunnable;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Timing;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Shared.Doors.Systems;
|
||||
|
||||
public abstract class SharedDoorSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedPhysicsSystem _physicsSystem = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
||||
[Dependency] private readonly SharedStunSystem _stunSystem = default!;
|
||||
[Dependency] protected readonly IGameTiming GameTiming = default!;
|
||||
|
||||
/// <summary>
|
||||
/// A body must have an intersection percentage larger than this in order to be considered as colliding with a
|
||||
/// door. Used for safety close-blocking and crushing.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The intersection percentage relies on WORLD AABBs. So if this is too small, and the grid is rotated 45
|
||||
/// degrees, then an entity outside of the airlock may be crushed.
|
||||
/// </remarks>
|
||||
public const float IntersectPercentage = 0.2f;
|
||||
|
||||
/// <summary>
|
||||
/// A set of doors that are currently opening, closing, or just queued to open/close after some delay.
|
||||
/// </summary>
|
||||
private readonly HashSet<DoorComponent> _activeDoors = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<DoorComponent, ComponentStartup>(OnStartup);
|
||||
SubscribeLocalEvent<DoorComponent, ComponentShutdown>(OnShutdown);
|
||||
|
||||
SubscribeLocalEvent<DoorComponent, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<DoorComponent, ComponentHandleState>(OnHandleState);
|
||||
|
||||
SubscribeLocalEvent<DoorComponent, ActivateInWorldEvent>(OnActivate);
|
||||
SubscribeLocalEvent<DoorComponent, ExaminedEvent>(OnExamine);
|
||||
|
||||
SubscribeLocalEvent<DoorComponent, StartCollideEvent>(HandleCollide);
|
||||
SubscribeLocalEvent<DoorComponent, PreventCollideEvent>(PreventCollision);
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, DoorComponent door, ComponentStartup args)
|
||||
{
|
||||
// if the door state is not standard (i.e., door starts open), make sure collision & occlusion are properly set.
|
||||
if (door.StartOpen)
|
||||
{
|
||||
// disable occluder & physics
|
||||
OnPartialOpen(uid, door);
|
||||
|
||||
// THEN set the correct state, inc disabling partial = true
|
||||
SetState(uid, DoorState.Open, door);
|
||||
|
||||
// The airlock component may schedule an auto-close for this door during the SetState.
|
||||
// Give the door is supposed to start open, let's prevent any auto-closing that might occur.
|
||||
door.NextStateChange = null;
|
||||
}
|
||||
|
||||
UpdateAppearance(uid, door);
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, DoorComponent door, ComponentShutdown args)
|
||||
{
|
||||
_activeDoors.Remove(door);
|
||||
}
|
||||
|
||||
#region StateManagement
|
||||
private void OnGetState(EntityUid uid, DoorComponent door, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new DoorComponentState(door);
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, DoorComponent door, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not DoorComponentState state)
|
||||
return;
|
||||
|
||||
door.CurrentlyCrushing = state.CurrentlyCrushing;
|
||||
door.State = state.DoorState;
|
||||
door.NextStateChange = state.NextStateChange;
|
||||
door.Partial = state.Partial;
|
||||
|
||||
if (state.NextStateChange == null)
|
||||
_activeDoors.Remove(door);
|
||||
else
|
||||
_activeDoors.Add(door);
|
||||
|
||||
RaiseLocalEvent(uid, new DoorStateChangedEvent(door.State), false);
|
||||
UpdateAppearance(uid, door);
|
||||
}
|
||||
|
||||
protected void SetState(EntityUid uid, DoorState state, DoorComponent? door = null)
|
||||
{
|
||||
if (!Resolve(uid, ref door))
|
||||
return;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case DoorState.Opening:
|
||||
_activeDoors.Add(door);
|
||||
door.NextStateChange = GameTiming.CurTime + door.OpenTimeOne;
|
||||
break;
|
||||
|
||||
case DoorState.Closing:
|
||||
_activeDoors.Add(door);
|
||||
door.NextStateChange = GameTiming.CurTime + door.CloseTimeOne;
|
||||
break;
|
||||
|
||||
case DoorState.Denying:
|
||||
_activeDoors.Add(door);
|
||||
door.NextStateChange = GameTiming.CurTime + door.DenyDuration;
|
||||
break;
|
||||
|
||||
case DoorState.Open:
|
||||
case DoorState.Closed:
|
||||
door.Partial = false;
|
||||
if (door.NextStateChange == null)
|
||||
_activeDoors.Remove(door);
|
||||
break;
|
||||
}
|
||||
|
||||
door.State = state;
|
||||
door.Dirty();
|
||||
RaiseLocalEvent(uid, new DoorStateChangedEvent(state), false);
|
||||
UpdateAppearance(uid, door);
|
||||
}
|
||||
|
||||
protected virtual void UpdateAppearance(EntityUid uid, DoorComponent? door = null)
|
||||
{
|
||||
if (!Resolve(uid, ref door))
|
||||
return;
|
||||
|
||||
if (!TryComp(uid, out AppearanceComponent? appearance))
|
||||
return;
|
||||
|
||||
appearance.SetData(DoorVisuals.State, door.State);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Interactions
|
||||
private void OnActivate(EntityUid uid, DoorComponent door, ActivateInWorldEvent args)
|
||||
{
|
||||
if (args.Handled || !door.ClickOpen)
|
||||
return;
|
||||
|
||||
TryToggleDoor(uid, door, args.User);
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnExamine(EntityUid uid, DoorComponent door, ExaminedEvent args)
|
||||
{
|
||||
if (door.State == DoorState.Welded)
|
||||
args.PushText(Loc.GetString("door-component-examine-is-welded"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the door state/visuals and play an access denied sound when a user without access interacts with the
|
||||
/// door.
|
||||
/// </summary>
|
||||
public void Deny(EntityUid uid, DoorComponent? door = null, EntityUid? user = null, bool predicted = false)
|
||||
{
|
||||
if (!Resolve(uid, ref door))
|
||||
return;
|
||||
|
||||
if (door.State != DoorState.Closed)
|
||||
return;
|
||||
|
||||
// might not be able to deny without power or some other blocker.
|
||||
var ev = new BeforeDoorDeniedEvent();
|
||||
RaiseLocalEvent(uid, ev, false);
|
||||
if (ev.Cancelled)
|
||||
return;
|
||||
|
||||
SetState(uid, DoorState.Denying, door);
|
||||
|
||||
if (door.DenySound != null)
|
||||
PlaySound(uid, door.DenySound.GetSound(), AudioParams.Default.WithVolume(-3), user, predicted);
|
||||
}
|
||||
|
||||
public bool TryToggleDoor(EntityUid uid, DoorComponent? door = null, EntityUid? user = null, bool predicted = false)
|
||||
{
|
||||
if (!Resolve(uid, ref door))
|
||||
return false;
|
||||
|
||||
if (door.State == DoorState.Closed)
|
||||
{
|
||||
return TryOpen(uid, door, user, predicted);
|
||||
}
|
||||
else if (door.State == DoorState.Open)
|
||||
{
|
||||
return TryClose(uid, door, user, predicted);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Opening
|
||||
public bool TryOpen(EntityUid uid, DoorComponent? door = null, EntityUid? user = null, bool predicted = false)
|
||||
{
|
||||
if (!Resolve(uid, ref door))
|
||||
return false;
|
||||
|
||||
if (!CanOpen(uid, door, user, false))
|
||||
return false;
|
||||
|
||||
StartOpening(uid, door, user, predicted);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanOpen(EntityUid uid, DoorComponent? door = null, EntityUid? user = null, bool quiet = true)
|
||||
{
|
||||
if (!Resolve(uid, ref door))
|
||||
return false;
|
||||
|
||||
if (door.State == DoorState.Welded)
|
||||
return false;
|
||||
|
||||
var ev = new BeforeDoorOpenedEvent();
|
||||
RaiseLocalEvent(uid, ev, false);
|
||||
if (ev.Cancelled)
|
||||
return false;
|
||||
|
||||
if (!HasAccess(uid, user))
|
||||
{
|
||||
if (!quiet)
|
||||
Deny(uid, door);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual void StartOpening(EntityUid uid, DoorComponent? door = null, EntityUid? user = null, bool predicted = false)
|
||||
{
|
||||
if (!Resolve(uid, ref door))
|
||||
return;
|
||||
|
||||
SetState(uid, DoorState.Opening, door);
|
||||
|
||||
if (door.OpenSound != null)
|
||||
PlaySound(uid, door.OpenSound.GetSound(), AudioParams.Default.WithVolume(-5), user, predicted);
|
||||
|
||||
// I'm not sure what the intent here is/was? It plays a sound if the user is opening a door with a hands
|
||||
// component, but no actual hands!? What!? Is this the sound of them head-butting the door to get it to open??
|
||||
// I'm 99% sure something is wrong here, but I kind of want to keep it this way.
|
||||
|
||||
if (user != null && TryComp(user.Value, out SharedHandsComponent? hands) && hands.Hands.Count == 0)
|
||||
PlaySound(uid, door.TryOpenDoorSound.GetSound(), AudioParams.Default.WithVolume(-2), user, predicted);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the door is partially opened. The door becomes transparent and stops colliding with entities.
|
||||
/// </summary>
|
||||
public virtual void OnPartialOpen(EntityUid uid, DoorComponent? door = null, PhysicsComponent? physics = null)
|
||||
{
|
||||
if (!Resolve(uid, ref door, ref physics))
|
||||
return;
|
||||
|
||||
// we can't be crushing anyone anymore, since we're opening
|
||||
door.CurrentlyCrushing.Clear();
|
||||
physics.CanCollide = false;
|
||||
door.Partial = true;
|
||||
door.NextStateChange = GameTiming.CurTime + door.CloseTimeTwo;
|
||||
_activeDoors.Add(door);
|
||||
door.Dirty();
|
||||
|
||||
if (door.Occludes && TryComp(uid, out OccluderComponent? occluder))
|
||||
occluder.Enabled = false;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Closing
|
||||
public bool TryClose(EntityUid uid, DoorComponent? door = null, EntityUid? user = null, bool predicted = false)
|
||||
{
|
||||
if (!Resolve(uid, ref door))
|
||||
return false;
|
||||
|
||||
if (!CanClose(uid, door, user, false))
|
||||
return false;
|
||||
|
||||
StartClosing(uid, door, user, predicted);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CanClose(EntityUid uid, DoorComponent? door = null, EntityUid? user = null, bool quiet = true)
|
||||
{
|
||||
if (!Resolve(uid, ref door))
|
||||
return false;
|
||||
|
||||
var ev = new BeforeDoorClosedEvent();
|
||||
RaiseLocalEvent(uid, ev, false);
|
||||
if (ev.Cancelled)
|
||||
return false;
|
||||
|
||||
return HasAccess(uid, user);
|
||||
}
|
||||
|
||||
public virtual void StartClosing(EntityUid uid, DoorComponent? door = null, EntityUid? user = null, bool predicted = false)
|
||||
{
|
||||
if (!Resolve(uid, ref door))
|
||||
return;
|
||||
|
||||
SetState(uid, DoorState.Closing, door);
|
||||
|
||||
if (door.CloseSound != null)
|
||||
PlaySound(uid, door.CloseSound.GetSound(), AudioParams.Default.WithVolume(-5), user, predicted);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the door is partially closed. This is when the door becomes "solid". If this process fails (e.g., a
|
||||
/// mob entered the door as it was closing), then this returns false. Otherwise, returns true;
|
||||
/// </summary>
|
||||
public virtual bool OnPartialClose(EntityUid uid, DoorComponent? door = null, PhysicsComponent? physics = null)
|
||||
{
|
||||
if (!Resolve(uid, ref door, ref physics))
|
||||
return false;
|
||||
|
||||
door.Partial = true;
|
||||
door.Dirty();
|
||||
|
||||
// Make sure no entity waled into the airlock when it started closing.
|
||||
if (!CanClose(uid, door))
|
||||
{
|
||||
door.NextStateChange = GameTiming.CurTime + door.OpenTimeTwo;
|
||||
door.State = DoorState.Opening;
|
||||
UpdateAppearance(uid, door);
|
||||
return false;
|
||||
}
|
||||
|
||||
physics.CanCollide = true;
|
||||
door.NextStateChange = GameTiming.CurTime + door.CloseTimeTwo;
|
||||
_activeDoors.Add(door);
|
||||
|
||||
if (door.Occludes && TryComp(uid, out OccluderComponent? occluder))
|
||||
occluder.Enabled = true;
|
||||
|
||||
// Crush any entities. Note that we don't check airlock safety here. This should have been checked before
|
||||
// the door closed.
|
||||
Crush(uid, door, physics);
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Collisions
|
||||
/// <summary>
|
||||
/// Crushes everyone colliding with us by more than <see cref="IntersectPercentage"/>%.
|
||||
/// </summary>
|
||||
public void Crush(EntityUid uid, DoorComponent? door = null, PhysicsComponent? physics = null)
|
||||
{
|
||||
if (!Resolve(uid, ref door))
|
||||
return;
|
||||
|
||||
// is this door capable of crushing? NOT the same as an airlock safety check. The door will still close.
|
||||
if (!door.CanCrush)
|
||||
return;
|
||||
|
||||
// Crush
|
||||
var stunTime = door.DoorStunTime + door.OpenTimeOne;
|
||||
foreach (var entity in GetColliding(uid, physics))
|
||||
{
|
||||
door.CurrentlyCrushing.Add(entity);
|
||||
if (door.CrushDamage != null)
|
||||
_damageableSystem.TryChangeDamage(entity, door.CrushDamage);
|
||||
|
||||
_stunSystem.TryParalyze(entity, stunTime, true);
|
||||
}
|
||||
|
||||
if (door.CurrentlyCrushing.Count == 0)
|
||||
return;
|
||||
|
||||
// queue the door to open so that the player is no longer stunned once it has FINISHED opening.
|
||||
door.NextStateChange = GameTiming.CurTime + door.DoorStunTime;
|
||||
door.Partial = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all entities that collide with this door by more than <see cref="IntersectPercentage"/> percent.\
|
||||
/// </summary>
|
||||
public IEnumerable<EntityUid> GetColliding(EntityUid uid, PhysicsComponent? physics = null)
|
||||
{
|
||||
if (!Resolve(uid, ref physics))
|
||||
yield break;
|
||||
|
||||
// TODO SLOTH fix electro's code.
|
||||
var doorAABB = physics.GetWorldAABB();
|
||||
|
||||
foreach (var body in _physicsSystem.GetCollidingEntities(Transform(uid).MapID, doorAABB))
|
||||
{
|
||||
// static bodies (e.g., furniture) shouldn't stop airlocks/windoors from closing.
|
||||
if (body.BodyType == BodyType.Static)
|
||||
continue;
|
||||
|
||||
if (body.GetWorldAABB().IntersectPercentage(doorAABB) < IntersectPercentage)
|
||||
continue;
|
||||
|
||||
yield return body.Owner;
|
||||
}
|
||||
}
|
||||
|
||||
private void PreventCollision(EntityUid uid, DoorComponent component, PreventCollideEvent args)
|
||||
{
|
||||
if (component.CurrentlyCrushing.Contains(args.BodyB.Owner))
|
||||
{
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void HandleCollide(EntityUid uid, DoorComponent door, StartCollideEvent args)
|
||||
{
|
||||
// TODO ACCESS READER move access reader to shared and predict door opening/closing
|
||||
// Then this can be moved to the shared system without mispredicting.
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Access
|
||||
public virtual bool HasAccess(EntityUid uid, EntityUid? user = null, AccessReaderComponent? access = null)
|
||||
{
|
||||
// TODO network AccessComponent for predicting doors
|
||||
|
||||
// Currently all door open/close & door-bumper collision stuff is done server side.
|
||||
// so this return value means nothing.
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines the base access behavior of all doors on the station.
|
||||
/// </summary>
|
||||
public AccessTypes AccessType = AccessTypes.Id;
|
||||
|
||||
/// <summary>
|
||||
/// How door access should be handled.
|
||||
/// </summary>
|
||||
public enum AccessTypes
|
||||
{
|
||||
/// <summary> ID based door access. </summary>
|
||||
Id,
|
||||
/// <summary>
|
||||
/// Allows everyone to open doors, except external which airlocks are still handled with ID's
|
||||
/// </summary>
|
||||
AllowAllIdExternal,
|
||||
/// <summary>
|
||||
/// Allows everyone to open doors, except external airlocks which are never allowed, even if the user has
|
||||
/// ID access.
|
||||
/// </summary>
|
||||
AllowAllNoExternal,
|
||||
/// <summary> Allows everyone to open all doors. </summary>
|
||||
AllowAll
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Updating
|
||||
/// <summary>
|
||||
/// Schedule an open or closed door to progress to the next state after some time.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If the requested delay is null or non-positive, this will make the door stay open or closed indefinitely.
|
||||
/// </remarks>
|
||||
public void SetNextStateChange(EntityUid uid, TimeSpan? delay, DoorComponent? door = null)
|
||||
{
|
||||
if (!Resolve(uid, ref door, false))
|
||||
return;
|
||||
|
||||
// If the door is not currently just open or closed, it is busy doing something else (or welded shut). So in
|
||||
// that case we do nothing.
|
||||
if (door.State != DoorState.Open && door.State != DoorState.Closed)
|
||||
return;
|
||||
|
||||
// Is this trying to prevent an update? (e.g., cancel an auto-close)
|
||||
if (delay == null || delay.Value <= TimeSpan.Zero)
|
||||
{
|
||||
door.NextStateChange = null;
|
||||
_activeDoors.Remove(door);
|
||||
return;
|
||||
}
|
||||
|
||||
door.NextStateChange = GameTiming.CurTime + delay.Value;
|
||||
_activeDoors.Add(door);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Iterate over active doors and progress them to the next state if they need to be updated.
|
||||
/// </summary>
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
var time = GameTiming.CurTime;
|
||||
|
||||
foreach (var door in _activeDoors.ToList())
|
||||
{
|
||||
if (door.Deleted || door.NextStateChange == null)
|
||||
{
|
||||
_activeDoors.Remove(door);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Paused(door.Owner))
|
||||
continue;
|
||||
|
||||
if (door.NextStateChange.Value < time)
|
||||
NextState(door, time);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes a door proceed to the next state (if applicable).
|
||||
/// </summary>
|
||||
private void NextState(DoorComponent door, TimeSpan time)
|
||||
{
|
||||
door.NextStateChange = null;
|
||||
|
||||
if (door.CurrentlyCrushing.Count > 0)
|
||||
// This is a closed door that is crushing people and needs to auto-open. Note that we don't check "can open"
|
||||
// here. The door never actually finished closing and we don't want people to get stuck inside of doors.
|
||||
StartOpening(door.Owner, door, predicted: true);
|
||||
|
||||
switch (door.State)
|
||||
{
|
||||
case DoorState.Opening:
|
||||
// Either fully or partially open this door.
|
||||
if (door.Partial)
|
||||
SetState(door.Owner, DoorState.Open, door);
|
||||
else
|
||||
OnPartialOpen(door.Owner, door);
|
||||
|
||||
break;
|
||||
|
||||
case DoorState.Closing:
|
||||
// Either fully or partially close this door.
|
||||
if (door.Partial)
|
||||
SetState(door.Owner, DoorState.Closed, door);
|
||||
else
|
||||
OnPartialClose(door.Owner, door);
|
||||
|
||||
break;
|
||||
|
||||
case DoorState.Denying:
|
||||
// Finish denying entry and return to the closed state.
|
||||
SetState(door.Owner, DoorState.Closed, door);
|
||||
break;
|
||||
|
||||
case DoorState.Open:
|
||||
// This door is open, and queued for an auto-close.
|
||||
if (!TryClose(door.Owner, door, predicted: true))
|
||||
{
|
||||
// The door failed to close (blocked?). Try again in one second.
|
||||
door.NextStateChange = time + TimeSpan.FromSeconds(1);
|
||||
}
|
||||
break;
|
||||
|
||||
case DoorState.Welded:
|
||||
// A welded door? This should never have been active in the first place.
|
||||
Logger.Error($"Welded door was in the list of active doors. Door: {ToPrettyString(door.Owner)}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected abstract void PlaySound(EntityUid uid, string sound, AudioParams audioParams, EntityUid? predictingPlayer, bool predicted);
|
||||
}
|
||||
@@ -1,18 +1,18 @@
|
||||
using System;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Rotation;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Shared.Standing
|
||||
{
|
||||
public sealed class StandingStateSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly SharedHandsSystem _sharedHandsSystem = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
public bool IsDown(EntityUid uid, StandingStateComponent? standingState = null)
|
||||
{
|
||||
@@ -56,10 +56,14 @@ namespace Content.Shared.Standing
|
||||
standingState.Dirty();
|
||||
RaiseLocalEvent(uid, new DownedEvent(), false);
|
||||
|
||||
if (!_gameTiming.IsFirstTimePredicted)
|
||||
return true;
|
||||
|
||||
// Seemed like the best place to put it
|
||||
appearance?.SetData(RotationVisuals.RotationState, RotationState.Horizontal);
|
||||
|
||||
// Currently shit is only downed by server but when it's predicted we can probably only play this on server / client
|
||||
// > no longer true with door crushing. There just needs to be a better way to handle audio prediction.
|
||||
if (playSound)
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(uid), standingState.DownSoundCollection.GetSound(), uid, AudioHelpers.WithVariation(0.25f));
|
||||
|
||||
Reference in New Issue
Block a user