Extended access system (#8469)

* Extended access system

Allows jobs to specify "extended" access levels, which will be granted if the round-start crew count is below a certain threshold.

* Extended accesses for jobs

* Spook
This commit is contained in:
Pieter-Jan Briers
2022-05-27 06:01:07 +02:00
committed by GitHub
parent c5982e0b10
commit a4685bab4c
15 changed files with 182 additions and 18 deletions

View File

@@ -1,4 +1,7 @@
using Content.Server.Access.Components;
using Content.Server.GameTicking;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Shared.Access.Systems;
using Content.Shared.Roles;
using Robust.Shared.Prototypes;
@@ -10,16 +13,50 @@ namespace Content.Server.Access.Systems
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IdCardSystem _cardSystem = default!;
[Dependency] private readonly AccessSystem _accessSystem = default!;
[Dependency] private readonly StationSystem _stationSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PresetIdCardComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<RulePlayerJobsAssignedEvent>(PlayerJobsAssigned);
}
private void PlayerJobsAssigned(RulePlayerJobsAssignedEvent ev)
{
// Go over all ID cards and make sure they're correctly configured for extended access.
foreach (var card in EntityQuery<PresetIdCardComponent>())
{
var station = _stationSystem.GetOwningStation(card.Owner);
// If we're not on an extended access station, the ID is already configured correctly from MapInit.
if (station == null || !Comp<StationJobsComponent>(station.Value).ExtendedAccess)
return;
SetupIdAccess(card.Owner, card, true);
}
}
private void OnMapInit(EntityUid uid, PresetIdCardComponent id, MapInitEvent args)
{
if (id.JobName == null) return;
// If a preset ID card is spawned on a station at setup time,
// the station may not exist,
// or may not yet know whether it is on extended access (players not spawned yet).
// PlayerJobsAssigned makes sure extended access is configured correctly in that case.
var station = _stationSystem.GetOwningStation(id.Owner);
var extended = false;
if (station != null)
extended = Comp<StationJobsComponent>(station.Value).ExtendedAccess;
SetupIdAccess(uid, id, extended);
}
private void SetupIdAccess(EntityUid uid, PresetIdCardComponent id, bool extended)
{
if (id.JobName == null)
return;
if (!_prototypeManager.TryIndex(id.JobName, out JobPrototype? job))
{
@@ -27,9 +64,7 @@ namespace Content.Server.Access.Systems
return;
}
// set access for access component
_accessSystem.TrySetTags(uid, job.Access);
_accessSystem.TryAddGroups(uid, job.AccessGroups);
_accessSystem.SetAccessToJob(uid, job, extended);
// and also change job title on a card id
_cardSystem.TryChangeJobTitle(uid, job.Name);