-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76a93ba
commit 1caab60
Showing
5 changed files
with
140 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,91 @@ | ||
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; | ||
|
||
public sealed class AccessSystem : SharedAccessSystem | ||
{ | ||
// <summary> | ||
// Запускает обновление уровня аварийных доступов на всех сущностях с AccessReaderComponent | ||
// </summary> | ||
[Dependency] private readonly StationSystem _station = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<AlertLevelChangedEvent>(OnAlertLevelChanged); | ||
} | ||
|
||
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 (entity.Comp.AlertAccesses.Count == 0) | ||
return; | ||
|
||
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")) | ||
{ | ||
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 // Все остальные доступы | ||
{ | ||
entity.Comp.Group = string.Empty; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters