-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Автоматические доступы, что выдаются в зависимости от кода станции #1004
Changes from all commits
21692cd
df217e1
828341c
76a93ba
1caab60
1891219
b6ca0d4
469a3da
d59814d
652b2a8
2f02f93
40747a1
f7b9741
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,84 @@ | ||
using Content.Shared.Access.Systems; | ||
using Content.Shared.Access.Components; | ||
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 | ||
{ | ||
[Dependency] private readonly StationSystem _station = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<AlertLevelChangedEvent>(OnAlertLevelChanged); | ||
} | ||
/// <summary> | ||
/// Запускает обновление уровня аварийных доступов на всех сущностях с AccessReaderComponent | ||
/// </summary> | ||
private void OnAlertLevelChanged(AlertLevelChangedEvent ev) | ||
{ | ||
|
||
if (!TryComp<AlertLevelComponent>(ev.Station, out var alert)) | ||
return; | ||
|
||
if (alert.AlertLevels == null) | ||
return; | ||
|
||
var query = EntityQueryEnumerator<AccessReaderComponent, TransformComponent>(); | ||
while (query.MoveNext(out var uid, out var reader, out var xform)) | ||
{ | ||
|
||
if (CompOrNull<StationMemberComponent>(xform.GridUid)?.Station != ev.Station) | ||
continue; | ||
|
||
if (alert.AlertLevels == null) | ||
return; | ||
|
||
if (!TryComp<AccessReaderComponent>(uid, out var comp)) | ||
return; | ||
|
||
if (comp.AlertAccesses.Count == 0) | ||
continue; | ||
|
||
Update((uid, reader)); | ||
Dirty(uid, reader); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Устанавливает значение из прототипа в зависимости от кода | ||
/// </summary> | ||
public void Update(Entity<AccessReaderComponent> entity) | ||
{ | ||
|
||
if (!TryComp<AlertLevelComponent>(_station.GetOwningStation(entity.Owner), out var alerts)) | ||
return; | ||
|
||
if (alerts.AlertLevels == null) | ||
return; | ||
|
||
var alertLevels = new Dictionary<string, AccessReaderComponent.CurrentAlertLevel> | ||
{ | ||
{ "blue", AccessReaderComponent.CurrentAlertLevel.blue }, | ||
{ "red", AccessReaderComponent.CurrentAlertLevel.red }, | ||
{ "yellow", AccessReaderComponent.CurrentAlertLevel.yellow }, | ||
{ "gamma", AccessReaderComponent.CurrentAlertLevel.gamma }, | ||
{ "delta", AccessReaderComponent.CurrentAlertLevel.delta } | ||
}; | ||
|
||
entity.Comp.Group = string.Empty; // Значение по умолчанию | ||
foreach (var level in alertLevels) | ||
{ | ||
if (alerts.CurrentLevel.Contains(level.Key)) | ||
{ | ||
entity.Comp.AlertAccesses.TryGetValue(level.Value, out var value); | ||
entity.Comp.Group = value; | ||
break; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
using System.Text.RegularExpressions; | ||
using Content.Shared.StationRecords; | ||
using Content.Shared.Weapons.Melee; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Serialization; | ||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set; | ||
using Robust.Shared.Toolshed.Syntax; | ||
|
||
namespace Content.Shared.Access.Components; | ||
|
||
|
@@ -20,6 +23,29 @@ public sealed partial class AccessReaderComponent : Component | |
[DataField] | ||
public bool Enabled = true; | ||
|
||
// Sunrise-start | ||
|
||
/// <summary> | ||
/// Именно от Group происходит проверка аварийных доступов | ||
/// </summary> | ||
[ViewVariables(VVAccess.ReadWrite)] | ||
public ProtoId<AccessGroupPrototype> Group = string.Empty; | ||
|
||
[ViewVariables(VVAccess.ReadWrite)] | ||
[DataField] | ||
public Dictionary<CurrentAlertLevel, ProtoId<AccessGroupPrototype>> AlertAccesses = new(); | ||
|
||
[Flags] | ||
public enum CurrentAlertLevel : byte | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Зачем данный enum? Эти доступы уже существуют в игре прототипами. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. я не могу их добавить в дикт потому что станционные коды на сервере написаны There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
перенеси их в шейред... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а конфликты с оффами? К тому же придется еще редактировать их системы подвязанные на кодах There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. вроде енум не сильно бьет по оптимизации There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
не выйдет, я проверял. Тогда ловишь фантомную ошибку о том что нет прототипа с таким Типом и айди. Да и в целом плохая затея There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ну это бред, если оффы новый код добавлять в прототипы надо сразу пиздовать и тут его добавлять. В чем проблема заюзать enumeratePrototypes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. а зачем новый код, если все из 13 уже перенесены There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
оффы могут новые коды добавить There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. та забей и замерджи уже, даже если добавят там всего 2 строки добавлять |
||
{ | ||
blue, | ||
red, | ||
yellow, | ||
gamma, | ||
delta | ||
} | ||
// Sunrise-end | ||
|
||
/// <summary> | ||
/// The set of tags that will automatically deny an allowed check, if any of them are present. | ||
/// </summary> | ||
|
@@ -100,20 +126,28 @@ public sealed class AccessReaderComponentState : ComponentState | |
|
||
public List<HashSet<ProtoId<AccessLevelPrototype>>> AccessLists; | ||
|
||
public ProtoId<AccessGroupPrototype> Group; // Sunrise-alertAccesses, нужно для связывания клиента с сервером | ||
|
||
public List<(NetEntity, uint)> AccessKeys; | ||
|
||
public Queue<AccessRecord> AccessLog; | ||
|
||
public int AccessLogLimit; | ||
|
||
public AccessReaderComponentState(bool enabled, HashSet<ProtoId<AccessLevelPrototype>> denyTags, List<HashSet<ProtoId<AccessLevelPrototype>>> accessLists, List<(NetEntity, uint)> accessKeys, Queue<AccessRecord> accessLog, int accessLogLimit) | ||
public AccessReaderComponentState(bool enabled, HashSet<ProtoId<AccessLevelPrototype>> denyTags, | ||
List<HashSet<ProtoId<AccessLevelPrototype>>> accessLists, | ||
ProtoId<AccessGroupPrototype> group, | ||
List<(NetEntity, uint)> accessKeys, | ||
Queue<AccessRecord> accessLog, | ||
int accessLogLimit) //Sunrise-edit | ||
{ | ||
Enabled = enabled; | ||
DenyTags = denyTags; | ||
AccessLists = accessLists; | ||
AccessKeys = accessKeys; | ||
AccessLog = accessLog; | ||
AccessLogLimit = accessLogLimit; | ||
Group = group; // Sunrise-alertAccesses | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Просто передай сюда текущий уровень и запиши его в компоненте двери.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
данная система уникальная и может не только на двери работать. Залог на будущие возможные приколы
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
По проверкам я сделал так что оно проверяет только те AccessReader`ы, в которых есть значения AlertAccesses. То есть пока в прототипе не пропишешь апдейт проводиться не будет