using Content.Shared.Damage; using Content.Shared.Doors.Systems; using Content.Shared.Tools; using JetBrains.Annotations; using Robust.Shared.Audio; using Robust.Shared.GameStates; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; using Robust.Shared.Timing; using DrawDepthTag = Robust.Shared.GameObjects.DrawDepth; namespace Content.Shared.Doors.Components; [RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)] public sealed partial class DoorComponent : Component { /// /// The current state of the door -- whether it is open, closed, opening, or closing. /// /// /// This should never be set directly, use instead. /// [ViewVariables(VVAccess.ReadWrite)] [DataField, AutoNetworkedField] [Access(typeof(SharedDoorSystem))] public DoorState State = DoorState.Closed; #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. /// /// Closing time until impassable. Total time is this plus . /// [DataField] public TimeSpan CloseTimeOne = TimeSpan.FromSeconds(0.4f); /// /// Closing time until fully closed. Total time is this plus . /// [DataField] public TimeSpan CloseTimeTwo = TimeSpan.FromSeconds(0.2f); /// /// Opening time until passable. Total time is this plus . /// [DataField] public TimeSpan OpenTimeOne = TimeSpan.FromSeconds(0.4f); /// /// Opening time until fully open. Total time is this plus . /// [DataField] public TimeSpan OpenTimeTwo = TimeSpan.FromSeconds(0.2f); /// /// Interval between deny sounds & visuals; /// [DataField] public TimeSpan DenyDuration = TimeSpan.FromSeconds(0.45f); [DataField] public TimeSpan EmagDuration = TimeSpan.FromSeconds(0.8f); /// /// When the door is active, this is the time when the state will next update. /// [AutoNetworkedField, ViewVariables] public TimeSpan? NextStateChange; /// /// 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. /// [DataField, AutoNetworkedField] public bool Partial; #endregion #region Sounds /// /// Sound to play when the door opens. /// [DataField("openSound")] public SoundSpecifier? OpenSound; /// /// Sound to play when the door closes. /// [DataField("closeSound")] public SoundSpecifier? CloseSound; /// /// Sound to play if the door is denied. /// [DataField("denySound")] public SoundSpecifier? DenySound; /// /// Sound to play when door has been emagged or possibly electrically tampered /// [DataField("sparkSound")] public SoundSpecifier SparkSound = new SoundCollectionSpecifier("sparks"); #endregion #region Crushing /// /// 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 . /// [DataField] public TimeSpan DoorStunTime = TimeSpan.FromSeconds(2f); [DataField] public DamageSpecifier? CrushDamage; /// /// If false, this door is incapable of crushing entities. This just determines whether it will apply damage and /// stun, not whether it can close despite entities being in the way. /// [DataField, AutoNetworkedField] public bool CanCrush = true; /// /// Whether to check for colliding entities before closing. This may be overridden by other system by subscribing to /// . For example, hacked airlocks will set this to false. /// [DataField, AutoNetworkedField] public bool PerformCollisionCheck = true; /// /// List of EntityUids of entities we're currently crushing. Cleared in OnPartialOpen(). /// [DataField, AutoNetworkedField] public HashSet CurrentlyCrushing = new(); #endregion #region Graphics /// /// The key used when playing door opening/closing/emagging/deny animations. /// public const string AnimationKey = "door_animation"; /// /// The sprite state used for the door when it's open. /// [DataField] [ViewVariables(VVAccess.ReadWrite)] public string OpenSpriteState = "open"; /// /// The sprite states used for the door while it's open. /// [ViewVariables(VVAccess.ReadOnly)] public List<(DoorVisualLayers, string)> OpenSpriteStates = default!; /// /// The sprite state used for the door when it's closed. /// [DataField] [ViewVariables(VVAccess.ReadWrite)] public string ClosedSpriteState = "closed"; /// /// The sprite states used for the door while it's closed. /// [ViewVariables(VVAccess.ReadOnly)] public List<(DoorVisualLayers, string)> ClosedSpriteStates = default!; /// /// The sprite state used for the door when it's opening. /// [DataField] public string OpeningSpriteState = "opening"; /// /// The sprite state used for the door when it's closing. /// [DataField] public string ClosingSpriteState = "closing"; /// /// The sprite state used for the door when it's being emagged. /// [DataField] public string EmaggingSpriteState = "sparks"; /// /// The length of the door's opening animation. /// [DataField] public TimeSpan OpeningAnimationTime = TimeSpan.FromSeconds(0.8); /// /// The length of the door's closing animation. /// [DataField] public TimeSpan ClosingAnimationTime = TimeSpan.FromSeconds(0.8); /// /// The length of the door's emagging animation. /// [DataField] public TimeSpan EmaggingAnimationTime = TimeSpan.FromSeconds(1.5); /// /// The animation used when the door opens. /// public object OpeningAnimation = default!; /// /// The animation used when the door closes. /// public object ClosingAnimation = default!; /// /// The animation used when the door denies access. /// public object DenyingAnimation = default!; /// /// The animation used when the door is emagged. /// public object EmaggingAnimation = default!; #endregion Graphics #region Serialization /// /// Time until next state change. Because apparently might not get saved/restored. /// [DataField] private float? SecondsUntilStateChange { [UsedImplicitly] get { if (NextStateChange == null) { return null; } var curTime = IoCManager.Resolve().CurTime; return (float)(NextStateChange.Value - curTime).TotalSeconds; } set { if (value == null || value.Value > 0) return; NextStateChange = IoCManager.Resolve().CurTime + TimeSpan.FromSeconds(value.Value); } } #endregion [DataField, ViewVariables(VVAccess.ReadWrite)] public bool CanPry = true; [DataField] public ProtoId PryingQuality = "Prying"; /// /// Default time that the door should take to pry open. /// [DataField] public TimeSpan PryTime = TimeSpan.FromSeconds(1.5f); [DataField] public bool ChangeAirtight = true; /// /// Whether the door blocks light. /// [ViewVariables(VVAccess.ReadWrite)] [DataField] public bool Occludes = true; /// /// Whether the door will open when it is bumped into. /// [ViewVariables(VVAccess.ReadWrite)] [DataField] public bool BumpOpen = true; /// /// Whether the door will open when it is activated or clicked. /// [ViewVariables(VVAccess.ReadWrite)] [DataField] public bool ClickOpen = true; [DataField(customTypeSerializer: typeof(ConstantSerializer))] public int OpenDrawDepth = (int) DrawDepth.DrawDepth.Doors; [DataField(customTypeSerializer: typeof(ConstantSerializer))] public int ClosedDrawDepth = (int) DrawDepth.DrawDepth.Doors; } [Serializable, NetSerializable] public enum DoorState : byte { Closed, Closing, Open, Opening, Welded, Denying, Emagging } [Serializable, NetSerializable] public enum DoorVisuals : byte { State, BoltLights, EmergencyLights, ClosedLights, } public enum DoorVisualLayers : byte { Base, BaseUnlit, BaseBolted, BaseEmergencyAccess, }