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:
Visne
2020-08-25 13:37:21 +02:00
committed by GitHub
parent b5a68748ea
commit 318f051fb9
3 changed files with 77 additions and 13 deletions

View File

@@ -6,6 +6,7 @@ using Content.Server.GameObjects.Components.Access;
using Content.Server.GameObjects.Components.Atmos; using Content.Server.GameObjects.Components.Atmos;
using Content.Server.GameObjects.Components.GUI; using Content.Server.GameObjects.Components.GUI;
using Content.Server.GameObjects.Components.Mobs; using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.GameObjects.Components.Body; using Content.Shared.GameObjects.Components.Body;
using Content.Shared.GameObjects.Components.Damage; using Content.Shared.GameObjects.Components.Damage;
@@ -134,28 +135,53 @@ namespace Content.Server.GameObjects.Components.Doors
public bool CanOpen(IEntity user) public bool CanOpen(IEntity user)
{ {
if (!CanOpen()) return false; if (!CanOpen()) return false;
if (!Owner.TryGetComponent(out AccessReader? accessReader))
if (!Owner.TryGetComponent<AccessReader>(out var accessReader))
{ {
return true; 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) 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(); 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));
} }
} }

View File

@@ -1,10 +1,44 @@
using Content.Server.GameObjects.Components.Doors; using Content.Server.GameObjects.Components.Doors;
using JetBrains.Annotations;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
namespace Content.Server.GameObjects.EntitySystems namespace Content.Server.GameObjects.EntitySystems
{ {
[UsedImplicitly]
class DoorSystem : EntitySystem 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 /> /// <inheritdoc />
public override void Update(float frameTime) public override void Update(float frameTime)
{ {

View File

@@ -1,9 +1,9 @@
using System; using System;
using System.Threading; using System.Threading;
using Content.Server.GameObjects.Components.Suspicion; using Content.Server.GameObjects.Components.Suspicion;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces.Chat; using Content.Server.Interfaces.Chat;
using Content.Server.Interfaces.GameTicking; using Content.Server.Interfaces.GameTicking;
using Content.Server.Mobs;
using Content.Server.Mobs.Roles; using Content.Server.Mobs.Roles;
using Content.Server.Players; using Content.Server.Players;
using Content.Shared.GameObjects.Components.Damage; 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, EntitySystem.Get<AudioSystem>().PlayGlobal("/Audio/Misc/tatoralert.ogg", AudioParams.Default,
(session) => session.ContentData().Mind?.HasRole<SuspicionTraitorRole>() ?? false); (session) => session.ContentData().Mind?.HasRole<SuspicionTraitorRole>() ?? false);
EntitySystem.Get<DoorSystem>().AccessType = DoorSystem.AccessTypes.AllowAllNoExternal;
Timer.SpawnRepeating(DeadCheckDelay, _checkWinConditions, _checkTimerCancel.Token); Timer.SpawnRepeating(DeadCheckDelay, _checkWinConditions, _checkTimerCancel.Token);
} }
@@ -45,6 +47,8 @@ namespace Content.Server.GameTicking.GameRules
{ {
base.Removed(); base.Removed();
EntitySystem.Get<DoorSystem>().AccessType = DoorSystem.AccessTypes.Id;
_checkTimerCancel.Cancel(); _checkTimerCancel.Cancel();
} }