Allow all door access in Suspicion mode (#1817)
* Add AccessTypes, let RuleSuspicion change it * Fix enum description Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> * Move check to CanOpen() Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
@@ -6,6 +6,7 @@ using Content.Server.GameObjects.Components.Access;
|
||||
using Content.Server.GameObjects.Components.Atmos;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.GameObjects.Components.Body;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
@@ -134,22 +135,42 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
public 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))
|
||||
{
|
||||
Deny();
|
||||
return;
|
||||
}
|
||||
|
||||
Open();
|
||||
|
||||
if (user.TryGetComponent(out HandsComponent? hands) && hands.Count == 0)
|
||||
@@ -158,6 +179,11 @@ namespace Content.Server.GameObjects.Components.Doors
|
||||
AudioParams.Default.WithVolume(-2));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Deny();
|
||||
}
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
|
||||
@@ -1,10 +1,44 @@
|
||||
using Content.Server.GameObjects.Components.Doors;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
|
||||
namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
class DoorSystem : EntitySystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines the base access behavior of all doors on the station.
|
||||
/// </summary>
|
||||
public AccessTypes AccessType { get; set; }
|
||||
|
||||
/// <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
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
AccessType = AccessTypes.Id;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Content.Server.GameObjects.Components.Suspicion;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces.Chat;
|
||||
using Content.Server.Interfaces.GameTicking;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Server.Mobs.Roles;
|
||||
using Content.Server.Players;
|
||||
using Content.Shared.GameObjects.Components.Damage;
|
||||
@@ -38,6 +38,8 @@ namespace Content.Server.GameTicking.GameRules
|
||||
EntitySystem.Get<AudioSystem>().PlayGlobal("/Audio/Misc/tatoralert.ogg", AudioParams.Default,
|
||||
(session) => session.ContentData().Mind?.HasRole<SuspicionTraitorRole>() ?? false);
|
||||
|
||||
EntitySystem.Get<DoorSystem>().AccessType = DoorSystem.AccessTypes.AllowAllNoExternal;
|
||||
|
||||
Timer.SpawnRepeating(DeadCheckDelay, _checkWinConditions, _checkTimerCancel.Token);
|
||||
}
|
||||
|
||||
@@ -45,6 +47,8 @@ namespace Content.Server.GameTicking.GameRules
|
||||
{
|
||||
base.Removed();
|
||||
|
||||
EntitySystem.Get<DoorSystem>().AccessType = DoorSystem.AccessTypes.Id;
|
||||
|
||||
_checkTimerCancel.Cancel();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user