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.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,28 +135,53 @@ 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))
{
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();
return;
}
Open();
if (user.TryGetComponent(out HandsComponent? hands) && hands.Count == 0)
{
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Effects/bang.ogg", Owner,
AudioParams.Default.WithVolume(-2));
}
}