From 189121935581621b7ce003579b933c1c8504bab3 Mon Sep 17 00:00:00 2001 From: iertis Date: Mon, 6 Jan 2025 17:01:44 +0300 Subject: [PATCH] fixes --- Content.Server/Access/Systems/AccessSystem.cs | 55 +++++++++---------- .../Components/AccessReaderComponent.cs | 9 ++- .../Access/Systems/AccessReaderSystem.cs | 11 +++- .../Access/AccessGroup/access_group.yml | 13 ++++- 4 files changed, 51 insertions(+), 37 deletions(-) diff --git a/Content.Server/Access/Systems/AccessSystem.cs b/Content.Server/Access/Systems/AccessSystem.cs index 81c7dca120a..425bcdf850d 100644 --- a/Content.Server/Access/Systems/AccessSystem.cs +++ b/Content.Server/Access/Systems/AccessSystem.cs @@ -3,13 +3,11 @@ using Content.Server.Station.Systems; using Content.Server.AlertLevel; using Content.Shared.Station.Components; -namespace Content.Server.Access.Systems; + +namespace Content.Server.Access.Systems; //Sunrise-edited public sealed class AccessSystem : SharedAccessSystem { - // - // Запускает обновление уровня аварийных доступов на всех сущностях с AccessReaderComponent - // [Dependency] private readonly StationSystem _station = default!; public override void Initialize() @@ -18,9 +16,12 @@ public override void Initialize() SubscribeLocalEvent(OnAlertLevelChanged); } - + /// + /// Запускает обновление уровня аварийных доступов на всех сущностях с AccessReaderComponent + /// private void OnAlertLevelChanged(AlertLevelChangedEvent ev) { + if (!TryComp(ev.Station, out var alert)) return; @@ -30,6 +31,7 @@ private void OnAlertLevelChanged(AlertLevelChangedEvent ev) var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var reader, out var xform)) { + if (CompOrNull(xform.GridUid)?.Station != ev.Station) continue; @@ -47,9 +49,9 @@ private void OnAlertLevelChanged(AlertLevelChangedEvent ev) } } - // - // Устанавливает значение из прототипа в зависимости от кода - // + /// + /// Устанавливает значение из прототипа в зависимости от кода + /// public void Update(Entity entity) { @@ -62,30 +64,23 @@ public void Update(Entity entity) if (alerts.AlertLevels == null) return; - if (alerts.CurrentLevel.Contains("blue")) - { - entity.Comp.AlertAccesses.TryGetValue(AccessReaderComponent.CurrentAlertLevel.blue, out var value); - entity.Comp.Group = value; - } - else if (alerts.CurrentLevel.Contains("red")) + var alertLevels = new Dictionary { - entity.Comp.AlertAccesses.TryGetValue(AccessReaderComponent.CurrentAlertLevel.red, out var value); - entity.Comp.Group = value; - Dirty(entity); - } - else if (alerts.CurrentLevel.Contains("yellow")) - { - entity.Comp.AlertAccesses.TryGetValue(AccessReaderComponent.CurrentAlertLevel.yellow, out var value); - entity.Comp.Group = value; - } - else if (alerts.CurrentLevel.Contains("gamma")) - { - entity.Comp.AlertAccesses.TryGetValue(AccessReaderComponent.CurrentAlertLevel.gamma, out var value); - entity.Comp.Group = value; - } - else // Все остальные доступы + { "blue", AccessReaderComponent.CurrentAlertLevel.blue }, + { "red", AccessReaderComponent.CurrentAlertLevel.red }, + { "yellow", AccessReaderComponent.CurrentAlertLevel.yellow }, + { "gamma", AccessReaderComponent.CurrentAlertLevel.gamma } + }; + + entity.Comp.Group = string.Empty; // Значение по умолчанию + foreach (var level in alertLevels) { - entity.Comp.Group = string.Empty; + if (alerts.CurrentLevel.Contains(level.Key)) + { + entity.Comp.AlertAccesses.TryGetValue(level.Value, out var value); + entity.Comp.Group = value; + break; + } } } } diff --git a/Content.Shared/Access/Components/AccessReaderComponent.cs b/Content.Shared/Access/Components/AccessReaderComponent.cs index e414146a017..16211305b61 100644 --- a/Content.Shared/Access/Components/AccessReaderComponent.cs +++ b/Content.Shared/Access/Components/AccessReaderComponent.cs @@ -126,7 +126,7 @@ public sealed class AccessReaderComponentState : ComponentState public List>> AccessLists; - public ProtoId Group; // Sunrise-alertAccesses + public ProtoId Group; // Sunrise-alertAccesses, нужно для связывания клиента с сервером public List<(NetEntity, uint)> AccessKeys; @@ -134,7 +134,12 @@ public sealed class AccessReaderComponentState : ComponentState public int AccessLogLimit; - public AccessReaderComponentState(bool enabled, HashSet> denyTags, List>> accessLists, ProtoId group, List<(NetEntity, uint)> accessKeys, Queue accessLog, int accessLogLimit) + public AccessReaderComponentState(bool enabled, HashSet> denyTags, + List>> accessLists, + ProtoId group, + List<(NetEntity, uint)> accessKeys, + Queue accessLog, + int accessLogLimit) //Sunrise-edit { Enabled = enabled; DenyTags = denyTags; diff --git a/Content.Shared/Access/Systems/AccessReaderSystem.cs b/Content.Shared/Access/Systems/AccessReaderSystem.cs index a52d578dc88..390daa73b6b 100644 --- a/Content.Shared/Access/Systems/AccessReaderSystem.cs +++ b/Content.Shared/Access/Systems/AccessReaderSystem.cs @@ -43,7 +43,7 @@ public override void Initialize() private void OnGetState(EntityUid uid, AccessReaderComponent component, ref ComponentGetState args) { args.State = new AccessReaderComponentState(component.Enabled, component.DenyTags, component.AccessLists, component.Group, - _recordsSystem.Convert(component.AccessKeys), component.AccessLog, component.AccessLogLimit); + _recordsSystem.Convert(component.AccessKeys), component.AccessLog, component.AccessLogLimit); // Sunrise-edit } private void OnHandleState(EntityUid uid, AccessReaderComponent component, ref ComponentHandleState args) @@ -64,7 +64,7 @@ private void OnHandleState(EntityUid uid, AccessReaderComponent component, ref C component.AccessLists = new(state.AccessLists); component.DenyTags = new(state.DenyTags); component.AccessLog = new(state.AccessLog); - component.Group = new(state.Group); + component.Group = new(state.Group); // Sunrise-alertAccesses component.AccessLogLimit = state.AccessLogLimit; } @@ -167,8 +167,10 @@ public bool IsAllowed( if (!TryComp(entity, out AccessReaderComponent? containedReader)) continue; + // Sunrise-start if (AreAccessTagsAllowedAlert(access, containedReader)) return true; + // Sunrise-end if (IsAllowed(access, stationKeys, entity, containedReader)) return true; @@ -213,6 +215,10 @@ public bool AreAccessTagsAllowed(ICollection> acce return false; } + // Sunrise-start + /// + /// Сравнивает список аварийных доступов с доступами на карте. + /// public bool AreAccessTagsAllowedAlert(ICollection> access, AccessReaderComponent reader) { if (reader.Group == string.Empty) @@ -234,6 +240,7 @@ public bool AreAccessTagsAllowedAlert(ICollection> return false; } + // Sunrise-end /// /// Compares the given stationrecordkeys with the accessreader to see if it is allowed. diff --git a/Resources/Prototypes/_Sunrise/Access/AccessGroup/access_group.yml b/Resources/Prototypes/_Sunrise/Access/AccessGroup/access_group.yml index 3a2a0763c5d..60c06d8ff85 100644 --- a/Resources/Prototypes/_Sunrise/Access/AccessGroup/access_group.yml +++ b/Resources/Prototypes/_Sunrise/Access/AccessGroup/access_group.yml @@ -1,20 +1,27 @@ - type: accessGroup id: RedAlertAccesses tags: - - Security - HeadOfSecurity + - Security + - Armory + - Detective + - Cryogenics - type: accessGroup id: BlueAlertAccesses tags: - - Security - HeadOfSecurity + - Security + - Armory + - Detective + - Cryogenics - type: accessGroup id: YellowAlertAccesses tags: + - ChiefEngineer - Engineering - - HeadOfSecurity + - Atmospherics - type: accessGroup id: GammaAlertAccesses