committed by
Pieter-Jan Briers
parent
0329150109
commit
f3b460c8b4
@@ -0,0 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Access
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class AccessComponent : Component
|
||||
{
|
||||
public override string Name => "Access";
|
||||
private List<string> _tags;
|
||||
[ViewVariables]
|
||||
public List<string> Tags => _tags;
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _tags, "tags", new List<string>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Access
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class AccessReader : Component
|
||||
{
|
||||
public override string Name => "AccessReader";
|
||||
private List<string> _necessaryTags;
|
||||
private List<string> _sufficientTags;
|
||||
|
||||
public bool IsAllowed(IEntity entity)
|
||||
{
|
||||
var accessProvider = FindAccessProvider(entity);
|
||||
return accessProvider != null && IsAllowed(accessProvider);
|
||||
}
|
||||
|
||||
private bool IsAllowed(AccessComponent accessProvider)
|
||||
{
|
||||
foreach (var sufficient in _sufficientTags)
|
||||
{
|
||||
if (accessProvider.Tags.Contains(sufficient))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
foreach (var necessary in _necessaryTags)
|
||||
{
|
||||
if (!accessProvider.Tags.Contains(necessary))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[CanBeNull]
|
||||
private static AccessComponent FindAccessProvider(IEntity entity)
|
||||
{
|
||||
if (entity.TryGetComponent(out AccessComponent accessComponent))
|
||||
{
|
||||
return accessComponent;
|
||||
}
|
||||
|
||||
if (entity.TryGetComponent(out IHandsComponent handsComponent))
|
||||
{
|
||||
var activeHandEntity = handsComponent.GetActiveHand?.Owner;
|
||||
if (activeHandEntity != null &&
|
||||
activeHandEntity.TryGetComponent(out AccessComponent handAccessComponent))
|
||||
{
|
||||
return handAccessComponent;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (entity.TryGetComponent(out InventoryComponent inventoryComponent))
|
||||
{
|
||||
if (inventoryComponent.HasSlot(EquipmentSlotDefines.Slots.IDCARD) &&
|
||||
inventoryComponent.TryGetSlotItem(EquipmentSlotDefines.Slots.IDCARD, out ItemComponent item) &&
|
||||
item.Owner.TryGetComponent(out AccessComponent idAccessComponent)
|
||||
)
|
||||
{
|
||||
return idAccessComponent;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _necessaryTags, "necessary" ,new List<string>());
|
||||
serializer.DataField(ref _sufficientTags, "sufficient", new List<string>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Security.Cryptography;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Access
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class IdCardComponent : Component
|
||||
{
|
||||
public override string Name => "IdCard";
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private string _fullName;
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private string _jobTitle;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _fullName, "fullName", string.Empty);
|
||||
serializer.DataField(ref _jobTitle, "jobTitle", string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Access;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Components.Doors;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -26,6 +27,7 @@ namespace Content.Server.GameObjects
|
||||
private static readonly TimeSpan CloseTime = TimeSpan.FromSeconds(1.2f);
|
||||
private static readonly TimeSpan OpenTimeOne = TimeSpan.FromSeconds(0.3f);
|
||||
private static readonly TimeSpan OpenTimeTwo = TimeSpan.FromSeconds(0.9f);
|
||||
private static readonly TimeSpan DenyTime = TimeSpan.FromSeconds(0.45f);
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -51,7 +53,7 @@ namespace Content.Server.GameObjects
|
||||
}
|
||||
else if (_state == DoorState.Closed)
|
||||
{
|
||||
Open();
|
||||
TryOpen(eventArgs.User);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,11 +75,24 @@ namespace Content.Server.GameObjects
|
||||
return;
|
||||
}
|
||||
|
||||
Open();
|
||||
TryOpen(msg.Entity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void TryOpen(IEntity user)
|
||||
{
|
||||
if (Owner.TryGetComponent(out AccessReader accessReader))
|
||||
{
|
||||
if (!accessReader.IsAllowed(user))
|
||||
{
|
||||
Deny();
|
||||
return;
|
||||
}
|
||||
}
|
||||
Open();
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
if (_state != DoorState.Closed)
|
||||
@@ -120,6 +135,15 @@ namespace Content.Server.GameObjects
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Deny()
|
||||
{
|
||||
_appearance.SetData(DoorVisuals.VisualState, DoorVisualState.Deny);
|
||||
Timer.Spawn(DenyTime, () =>
|
||||
{
|
||||
_appearance.SetData(DoorVisuals.VisualState, DoorVisualState.Closed);
|
||||
});
|
||||
}
|
||||
|
||||
private const float AUTO_CLOSE_DELAY = 5;
|
||||
public void OnUpdate(float frameTime)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user