This commit is contained in:
Leon Friedrich
2022-01-30 13:49:56 +13:00
committed by GitHub
parent 6fb492aae7
commit c465715273
37 changed files with 1400 additions and 1429 deletions

View File

@@ -1,16 +1,19 @@
using Content.Server.Doors.Components;
using Content.Server.Doors.Components;
using Content.Server.Power.Components;
using Content.Server.WireHacking;
using Content.Shared.Doors;
using Content.Shared.Doors.Components;
using Content.Shared.Doors.Systems;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using System;
namespace Content.Server.Doors.Systems
{
public class AirlockSystem : EntitySystem
public sealed class AirlockSystem : SharedAirlockSystem
{
public override void Initialize()
{
@@ -19,12 +22,8 @@ namespace Content.Server.Doors.Systems
SubscribeLocalEvent<AirlockComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<AirlockComponent, DoorStateChangedEvent>(OnStateChanged);
SubscribeLocalEvent<AirlockComponent, BeforeDoorOpenedEvent>(OnBeforeDoorOpened);
SubscribeLocalEvent<AirlockComponent, BeforeDoorClosedEvent>(OnBeforeDoorClosed);
SubscribeLocalEvent<AirlockComponent, BeforeDoorDeniedEvent>(OnBeforeDoorDenied);
SubscribeLocalEvent<AirlockComponent, DoorSafetyEnabledEvent>(OnDoorSafetyCheck);
SubscribeLocalEvent<AirlockComponent, BeforeDoorAutoCloseEvent>(OnDoorAutoCloseCheck);
SubscribeLocalEvent<AirlockComponent, DoorGetCloseTimeModifierEvent>(OnDoorCloseTimeModifier);
SubscribeLocalEvent<AirlockComponent, DoorClickShouldActivateEvent>(OnDoorClickShouldActivate);
SubscribeLocalEvent<AirlockComponent, ActivateInWorldEvent>(OnActivate, before: new [] {typeof(DoorSystem)});
SubscribeLocalEvent<AirlockComponent, BeforeDoorPryEvent>(OnDoorPry);
}
@@ -35,21 +34,59 @@ namespace Content.Server.Doors.Systems
appearanceComponent.SetData(DoorVisuals.Powered, args.Powered);
}
if (!args.Powered)
{
// stop any scheduled auto-closing
DoorSystem.SetNextStateChange(uid, null);
}
else
{
// door received power. Lets "wake" the door up, in case it is currently open and needs to auto-close.
DoorSystem.SetNextStateChange(uid, TimeSpan.FromSeconds(1));
}
// BoltLights also got out
component.UpdateBoltLightStatus();
}
private void OnStateChanged(EntityUid uid, AirlockComponent component, DoorStateChangedEvent args)
{
// TODO move to shared? having this be server-side, but having client-side door opening/closing & prediction
// means that sometimes the panels & bolt lights may be visible despite a door being completely open.
// Only show the maintenance panel if the airlock is closed
if (TryComp<WiresComponent>(uid, out var wiresComponent))
{
wiresComponent.IsPanelVisible =
component.OpenPanelVisible
|| args.State != SharedDoorComponent.DoorState.Open;
|| args.State != DoorState.Open;
}
// If the door is closed, we should look if the bolt was locked while closing
component.UpdateBoltLightStatus();
UpdateAutoClose(uid, component);
}
/// <summary>
/// Updates the auto close timer.
/// </summary>
public void UpdateAutoClose(EntityUid uid, AirlockComponent? airlock = null, DoorComponent? door = null)
{
if (!Resolve(uid, ref airlock, ref door))
return;
if (door.State != DoorState.Open)
return;
if (!airlock.CanChangeState())
return;
var autoev = new BeforeDoorAutoCloseEvent();
RaiseLocalEvent(uid, autoev, false);
if (autoev.Cancelled)
return;
DoorSystem.SetNextStateChange(uid, airlock.AutoCloseDelay * airlock.AutoCloseDelayModifier);
}
private void OnBeforeDoorOpened(EntityUid uid, AirlockComponent component, BeforeDoorOpenedEvent args)
@@ -58,10 +95,23 @@ namespace Content.Server.Doors.Systems
args.Cancel();
}
private void OnBeforeDoorClosed(EntityUid uid, AirlockComponent component, BeforeDoorClosedEvent args)
protected override void OnBeforeDoorClosed(EntityUid uid, SharedAirlockComponent component, BeforeDoorClosedEvent args)
{
if (!component.CanChangeState())
base.OnBeforeDoorClosed(uid, component, args);
if (args.Cancelled)
return;
// only block based on bolts / power status when initially closing the door, not when its already
// mid-transition. Particularly relevant for when the door was pried-closed with a crowbar, which bypasses
// the initial power-check.
if (TryComp(uid, out DoorComponent? door)
&& !door.Partial
&& !Comp<AirlockComponent>(uid).CanChangeState())
{
args.Cancel();
}
}
private void OnBeforeDoorDenied(EntityUid uid, AirlockComponent component, BeforeDoorDeniedEvent args)
@@ -70,26 +120,10 @@ namespace Content.Server.Doors.Systems
args.Cancel();
}
private void OnDoorSafetyCheck(EntityUid uid, AirlockComponent component, DoorSafetyEnabledEvent args)
{
args.Safety = component.Safety;
}
private void OnDoorAutoCloseCheck(EntityUid uid, AirlockComponent component, BeforeDoorAutoCloseEvent args)
{
if (!component.AutoClose)
args.Cancel();
}
private void OnDoorCloseTimeModifier(EntityUid uid, AirlockComponent component, DoorGetCloseTimeModifierEvent args)
{
args.CloseTimeModifier *= component.AutoCloseDelayModifier;
}
private void OnDoorClickShouldActivate(EntityUid uid, AirlockComponent component, DoorClickShouldActivateEvent args)
private void OnActivate(EntityUid uid, AirlockComponent component, ActivateInWorldEvent args)
{
if (TryComp<WiresComponent>(uid, out var wiresComponent) && wiresComponent.IsPanelOpen &&
EntityManager.TryGetComponent(args.Args.User, out ActorComponent? actor))
EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
{
wiresComponent.OpenInterface(actor.PlayerSession);
args.Handled = true;
@@ -100,12 +134,12 @@ namespace Content.Server.Doors.Systems
{
if (component.IsBolted())
{
component.Owner.PopupMessage(args.Args.User, Loc.GetString("airlock-component-cannot-pry-is-bolted-message"));
component.Owner.PopupMessage(args.User, Loc.GetString("airlock-component-cannot-pry-is-bolted-message"));
args.Cancel();
}
if (component.IsPowered())
{
component.Owner.PopupMessage(args.Args.User, Loc.GetString("airlock-component-cannot-pry-is-powered-message"));
component.Owner.PopupMessage(args.User, Loc.GetString("airlock-component-cannot-pry-is-powered-message"));
args.Cancel();
}
}

View File

@@ -1,69 +1,293 @@
using Content.Server.Doors.Components;
using Content.Server.Access;
using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Construction;
using Content.Server.Construction.Components;
using Content.Server.Tools;
using Content.Server.Tools.Components;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Doors;
using Content.Shared.Doors.Components;
using Content.Shared.Doors.Systems;
using Content.Shared.Interaction;
using Content.Shared.Tag;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Player;
using System.Linq;
namespace Content.Server.Doors
namespace Content.Server.Doors.Systems;
public sealed class DoorSystem : SharedDoorSystem
{
/// <summary>
/// Used on the server side to manage global access level overrides.
/// </summary>
internal sealed class DoorSystem : SharedDoorSystem
[Dependency] private readonly ConstructionSystem _constructionSystem = default!;
[Dependency] private readonly ToolSystem _toolSystem = default!;
[Dependency] private readonly AirtightSystem _airtightSystem = default!;
[Dependency] private readonly AccessReaderSystem _accessReaderSystem = default!;
public override void Initialize()
{
/// <summary>
/// Determines the base access behavior of all doors on the station.
/// </summary>
public AccessTypes AccessType { get; set; }
base.Initialize();
/// <summary>
/// How door access should be handled.
/// </summary>
public enum AccessTypes
SubscribeLocalEvent<DoorComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<DoorComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<DoorComponent, PryFinishedEvent>(OnPryFinished);
SubscribeLocalEvent<DoorComponent, PryCancelledEvent>(OnPryCancelled);
SubscribeLocalEvent<DoorComponent, WeldFinishedEvent>(OnWeldFinished);
SubscribeLocalEvent<DoorComponent, WeldCancelledEvent>(OnWeldCancelled);
}
// TODO AUDIO PREDICT Figure out a better way to handle sound and prediction. For now, this works well enough?
//
// Currently a client will predict when a door is going to close automatically. So any client in PVS range can just
// play their audio locally. Playing it server-side causes an odd delay, while in shared it causes double-audio.
//
// But if we just do that, then if a door is closed prematurely as the result of an interaction (i.e., using "E" on
// an open door), then the audio would only be played for the client performing the interaction.
//
// So we do this:
// - Play audio client-side IF the closing is being predicted (auto-close or predicted interaction)
// - Server assumes automated closing is predicted by clients and does not play audio unless otherwise specified.
// - Major exception is player interactions, which other players cannot predict
// - In that case, send audio to all players, except possibly the interacting player if it was a predicted
// interaction.
/// <summary>
/// Selectively send sound to clients, taking care to not send the double-audio.
/// </summary>
/// <param name="uid">The audio source</param>
/// <param name="sound">The sound</param>
/// <param name="predictingPlayer">The user (if any) that instigated an interaction</param>
/// <param name="predicted">Whether this interaction would have been predicted. If the predicting player is null,
/// this assumes it would have been predicted by all players in PVS range.</param>
protected override void PlaySound(EntityUid uid, string sound, AudioParams audioParams, EntityUid? predictingPlayer, bool predicted)
{
// If this sound would have been predicted by all clients, do not play any audio.
if (predicted && predictingPlayer == null)
return;
var filter = Filter.Pvs(uid);
if (predicted)
{
/// <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
// This interaction is predicted, but only by the instigating user, who will have played their own sounds.
filter.RemoveWhereAttachedEntity(e => e == predictingPlayer);
}
public override void Initialize()
{
base.Initialize();
// send the sound to players.
SoundSystem.Play(filter, sound, uid, AudioParams.Default.WithVolume(-5));
}
AccessType = AccessTypes.Id;
SubscribeLocalEvent<ServerDoorComponent, StartCollideEvent>(HandleCollide);
#region DoAfters
/// <summary>
/// Weld or pry open a door.
/// </summary>
private void OnInteractUsing(EntityUid uid, DoorComponent door, InteractUsingEvent args)
{
if (args.Handled)
return;
if (!TryComp(args.Used, out ToolComponent? tool))
return;
if (tool.Qualities.Contains(door.PryingQuality))
{
TryPryDoor(uid, args.Used, args.User, door);
args.Handled = true;
return;
}
private void HandleCollide(EntityUid uid, ServerDoorComponent component, StartCollideEvent args)
if (door.Weldable && tool.Qualities.Contains(door.WeldingQuality))
{
if (!EntityManager.HasComponent<DoorBumpOpenerComponent>(args.OtherFixture.Body.Owner))
{
return;
}
if (component.State != SharedDoorComponent.DoorState.Closed)
{
return;
}
if (!component.BumpOpen)
{
return;
}
// Disabled because it makes it suck hard to walk through double doors.
component.TryOpen(args.OtherFixture.Body.Owner);
TryWeldDoor(uid, args.Used, args.User, door);
args.Handled = true;
}
}
/// <summary>
/// Attempt to weld a door shut, or unweld it if it is already welded. This does not actually check if the user
/// is holding the correct tool.
/// </summary>
private async void TryWeldDoor(EntityUid target, EntityUid used, EntityUid user, DoorComponent door)
{
if (!door.Weldable || door.BeingWelded || door.CurrentlyCrushing.Count > 0)
return;
// is the door in a weld-able state?
if (door.State != DoorState.Closed && door.State != DoorState.Welded)
return;
// perform a do-after delay
door.BeingWelded = true;
_toolSystem.UseTool(used, user, target, 3f, 3f, door.WeldingQuality,
new WeldFinishedEvent(), new WeldCancelledEvent(), target);
}
/// <summary>
/// Pry open a door. This does not check if the user is holding the required tool.
/// </summary>
private async void TryPryDoor(EntityUid target, EntityUid tool, EntityUid user, DoorComponent door)
{
if (door.State == DoorState.Welded)
return;
var canEv = new BeforeDoorPryEvent(user);
RaiseLocalEvent(target, canEv, false);
if (canEv.Cancelled)
return;
var modEv = new DoorGetPryTimeModifierEvent();
RaiseLocalEvent(target, modEv, false);
_toolSystem.UseTool(tool, user, target, 0f, modEv.PryTimeModifier * door.PryTime, door.PryingQuality,
new PryFinishedEvent(), new PryCancelledEvent(), target);
}
private void OnWeldCancelled(EntityUid uid, DoorComponent door, WeldCancelledEvent args)
{
door.BeingWelded = false;
}
private void OnWeldFinished(EntityUid uid, DoorComponent door, WeldFinishedEvent args)
{
door.BeingWelded = false;
if (!door.Weldable)
return;
if (door.State == DoorState.Closed)
SetState(uid, DoorState.Welded, door);
else if (door.State == DoorState.Welded)
SetState(uid, DoorState.Closed, door);
}
private void OnPryCancelled(EntityUid uid, DoorComponent door, PryCancelledEvent args)
{
door.BeingPried = false;
}
private void OnPryFinished(EntityUid uid, DoorComponent door, PryFinishedEvent args)
{
door.BeingPried = false;
if (door.State == DoorState.Closed)
StartOpening(uid, door);
else if (door.State == DoorState.Open)
StartClosing(uid, door);
}
#endregion
/// <summary>
/// Does the user have the permissions required to open this door?
/// </summary>
public override bool HasAccess(EntityUid uid, EntityUid? user = null, AccessReaderComponent? access = null)
{
// TODO network AccessComponent for predicting doors
// if there is no "user" we skip the access checks. Access is also ignored in some game-modes.
if (user == null || AccessType == AccessTypes.AllowAll)
return true;
if (!Resolve(uid, ref access, false))
return true;
var isExternal = access.AccessLists.Any(list => list.Contains("External"));
return AccessType switch
{
// Some game modes modify access rules.
AccessTypes.AllowAllIdExternal => !isExternal || _accessReaderSystem.IsAllowed(access, user.Value),
AccessTypes.AllowAllNoExternal => !isExternal,
_ => _accessReaderSystem.IsAllowed(access, user.Value)
};
}
/// <summary>
/// Open a door if a player or door-bumper (PDA, ID-card) collide with the door. Sadly, bullets no longer
/// generate "access denied" sounds as you fire at a door.
/// </summary>
protected override 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.
if (!door.BumpOpen)
return;
if (door.State != DoorState.Closed)
return;
if (TryComp(args.OtherFixture.Body.Owner, out TagComponent? tags) && tags.HasTag("DoorBumpOpener"))
TryOpen(uid, door, args.OtherFixture.Body.Owner);
}
public override void OnPartialOpen(EntityUid uid, DoorComponent? door = null, PhysicsComponent? physics = null)
{
if (!Resolve(uid, ref door, ref physics))
return;
base.OnPartialOpen(uid, door, physics);
if (door.ChangeAirtight && TryComp(uid, out AirtightComponent? airtight))
{
_airtightSystem.SetAirblocked(airtight, false);
}
// Path-finding. Has nothing directly to do with access readers.
RaiseLocalEvent(new AccessReaderChangeMessage(uid, false));
}
public override bool OnPartialClose(EntityUid uid, DoorComponent? door = null, PhysicsComponent? physics = null)
{
if (!Resolve(uid, ref door, ref physics))
return false;
if (!base.OnPartialClose(uid, door, physics))
return false;
// update airtight, if we did not crush something.
if (door.ChangeAirtight && door.CurrentlyCrushing.Count == 0 && TryComp(uid, out AirtightComponent? airtight))
_airtightSystem.SetAirblocked(airtight, true);
// Path-finding. Has nothing directly to do with access readers.
RaiseLocalEvent(new AccessReaderChangeMessage(uid, true));
return true;
}
private void OnMapInit(EntityUid uid, DoorComponent door, MapInitEvent args)
{
// Ensure that the construction component is aware of the board container.
if (TryComp(uid, out ConstructionComponent? construction))
_constructionSystem.AddContainer(uid, "board", construction);
// We don't do anything if this is null or empty.
if (string.IsNullOrEmpty(door.BoardPrototype))
return;
var container = uid.EnsureContainer<Container>("board", out var existed);
/* // 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 class PryFinishedEvent : EntityEventArgs { }
public class PryCancelledEvent : EntityEventArgs { }
public class WeldFinishedEvent : EntityEventArgs { }
public class WeldCancelledEvent : EntityEventArgs { }

View File

@@ -1,17 +1,21 @@
using Content.Server.Atmos.Monitor.Components;
using Content.Server.Atmos.Monitor.Components;
using Content.Server.Atmos.Monitor.Systems;
using Content.Server.Doors.Components;
using Content.Shared.Atmos.Monitor;
using Content.Shared.Doors;
using Content.Shared.Doors.Components;
using Content.Shared.Doors.Systems;
using Content.Shared.Popups;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
namespace Content.Server.Doors.Systems
{
public class FirelockSystem : EntitySystem
{
[Dependency] private readonly SharedDoorSystem _doorSystem = default!;
public override void Initialize()
{
base.Initialize();
@@ -19,8 +23,8 @@ namespace Content.Server.Doors.Systems
SubscribeLocalEvent<FirelockComponent, BeforeDoorOpenedEvent>(OnBeforeDoorOpened);
SubscribeLocalEvent<FirelockComponent, BeforeDoorDeniedEvent>(OnBeforeDoorDenied);
SubscribeLocalEvent<FirelockComponent, DoorGetPryTimeModifierEvent>(OnDoorGetPryTimeModifier);
SubscribeLocalEvent<FirelockComponent, DoorClickShouldActivateEvent>(OnDoorClickShouldActivate);
SubscribeLocalEvent<FirelockComponent, BeforeDoorPryEvent>(OnBeforeDoorPry);
SubscribeLocalEvent<FirelockComponent, BeforeDoorAutoCloseEvent>(OnBeforeDoorAutoclose);
SubscribeLocalEvent<FirelockComponent, AtmosMonitorAlarmEvent>(OnAtmosAlarm);
}
@@ -42,26 +46,20 @@ namespace Content.Server.Doors.Systems
args.PryTimeModifier *= component.LockedPryTimeModifier;
}
private void OnDoorClickShouldActivate(EntityUid uid, FirelockComponent component, DoorClickShouldActivateEvent args)
{
// We're a firelock, you can't click to open it
args.Handled = true;
}
private void OnBeforeDoorPry(EntityUid uid, FirelockComponent component, BeforeDoorPryEvent args)
{
if (!TryComp<ServerDoorComponent>(uid, out var doorComponent) || doorComponent.State != SharedDoorComponent.DoorState.Closed)
if (!TryComp<DoorComponent>(uid, out var door) || door.State != DoorState.Closed)
{
return;
}
if (component.IsHoldingPressure())
{
component.Owner.PopupMessage(args.Args.User, Loc.GetString("firelock-component-is-holding-pressure-message"));
component.Owner.PopupMessage(args.User, Loc.GetString("firelock-component-is-holding-pressure-message"));
}
else if (component.IsHoldingFire())
{
component.Owner.PopupMessage(args.Args.User, Loc.GetString("firelock-component-is-holding-fire-message"));
component.Owner.PopupMessage(args.User, Loc.GetString("firelock-component-is-holding-fire-message"));
}
}
@@ -81,12 +79,12 @@ namespace Content.Server.Doors.Systems
private void OnAtmosAlarm(EntityUid uid, FirelockComponent component, AtmosMonitorAlarmEvent args)
{
if (!TryComp<ServerDoorComponent>(uid, out var doorComponent)) return;
if (!TryComp<DoorComponent>(uid, out var doorComponent)) return;
if (args.HighestNetworkType == AtmosMonitorAlarmType.Normal)
{
if (doorComponent.State == SharedDoorComponent.DoorState.Closed)
doorComponent.Open();
if (doorComponent.State == DoorState.Closed)
_doorSystem.TryOpen(uid);
}
else if (args.HighestNetworkType == AtmosMonitorAlarmType.Danger)
{