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:
committed by
GitHub
parent
c5982e0b10
commit
a4685bab4c
@@ -27,6 +27,11 @@ public sealed class StationJobsComponent : Component
|
||||
/// </summary>
|
||||
[DataField("totalJobs")] public int TotalJobs;
|
||||
|
||||
/// <summary>
|
||||
/// Station is running on extended access.
|
||||
/// </summary>
|
||||
[DataField("extendedAccess")] public bool ExtendedAccess;
|
||||
|
||||
/// <summary>
|
||||
/// The percentage of jobs remaining.
|
||||
/// </summary>
|
||||
|
||||
@@ -25,4 +25,14 @@ public sealed partial class StationConfig
|
||||
/// job name: [round-start, mid-round]
|
||||
/// </summary>
|
||||
public IReadOnlyDictionary<string, List<int?>> AvailableJobs => _availableJobs;
|
||||
|
||||
/// <summary>
|
||||
/// If there are less than or equal this amount of players in the game at round start,
|
||||
/// people get extended access levels from job prototypes.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Set to -1 to disable extended access.
|
||||
/// </remarks>
|
||||
[DataField("extendedAccessThreshold")]
|
||||
public int ExtendedAccessThreshold { get; set; } = 15;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Server.Station.Components;
|
||||
using Content.Shared.Preferences;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Shared.Network;
|
||||
@@ -304,6 +305,24 @@ public sealed partial class StationJobsSystem
|
||||
}
|
||||
}
|
||||
|
||||
public void CalcExtendedAccess(Dictionary<EntityUid, int> jobsCount)
|
||||
{
|
||||
// Calculate whether stations need to be on extended access or not.
|
||||
foreach (var (station, count) in jobsCount)
|
||||
{
|
||||
var jobs = Comp<StationJobsComponent>(station);
|
||||
var data = Comp<StationDataComponent>(station);
|
||||
|
||||
var thresh = data.StationConfig?.ExtendedAccessThreshold ?? -1;
|
||||
|
||||
jobs.ExtendedAccess = count <= thresh;
|
||||
|
||||
Logger.DebugS(
|
||||
"station", "Station {Station} on extended access: {ExtendedAccess}",
|
||||
Name(station), jobs.ExtendedAccess);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all jobs that the input players have that match the given weight and priority.
|
||||
/// </summary>
|
||||
|
||||
@@ -7,6 +7,7 @@ using Content.Server.PDA;
|
||||
using Content.Server.Roles;
|
||||
using Content.Server.Station.Components;
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Access.Systems;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.PDA;
|
||||
@@ -35,6 +36,7 @@ public sealed class StationSpawningSystem : EntitySystem
|
||||
[Dependency] private readonly IdCardSystem _cardSystem = default!;
|
||||
[Dependency] private readonly InventorySystem _inventorySystem = default!;
|
||||
[Dependency] private readonly PDASystem _pdaSystem = default!;
|
||||
[Dependency] private readonly AccessSystem _accessSystem = default!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
@@ -82,8 +84,13 @@ public sealed class StationSpawningSystem : EntitySystem
|
||||
/// <param name="coordinates">Coordinates to spawn the character at.</param>
|
||||
/// <param name="job">Job to assign to the character, if any.</param>
|
||||
/// <param name="profile">Appearance profile to use for the character.</param>
|
||||
/// <param name="station">The station this player is being spawned on.</param>
|
||||
/// <returns>The spawned entity</returns>
|
||||
public EntityUid SpawnPlayerMob(EntityCoordinates coordinates, Job? job, HumanoidCharacterProfile? profile)
|
||||
public EntityUid SpawnPlayerMob(
|
||||
EntityCoordinates coordinates,
|
||||
Job? job,
|
||||
HumanoidCharacterProfile? profile,
|
||||
EntityUid? station)
|
||||
{
|
||||
var entity = EntityManager.SpawnEntity(
|
||||
_prototypeManager.Index<SpeciesPrototype>(profile?.Species ?? SpeciesManager.DefaultSpecies).Prototype,
|
||||
@@ -94,7 +101,7 @@ public sealed class StationSpawningSystem : EntitySystem
|
||||
var startingGear = _prototypeManager.Index<StartingGearPrototype>(job.StartingGear);
|
||||
EquipStartingGear(entity, startingGear, profile);
|
||||
if (profile != null)
|
||||
EquipIdCard(entity, profile.Name, job.Prototype);
|
||||
EquipIdCard(entity, profile.Name, job.Prototype, station);
|
||||
}
|
||||
|
||||
if (profile != null)
|
||||
@@ -154,7 +161,8 @@ public sealed class StationSpawningSystem : EntitySystem
|
||||
/// <param name="entity">Entity to load out.</param>
|
||||
/// <param name="characterName">Character name to use for the ID.</param>
|
||||
/// <param name="jobPrototype">Job prototype to use for the PDA and ID.</param>
|
||||
public void EquipIdCard(EntityUid entity, string characterName, JobPrototype jobPrototype)
|
||||
/// <param name="station">The station this player is being spawned on.</param>
|
||||
public void EquipIdCard(EntityUid entity, string characterName, JobPrototype jobPrototype, EntityUid? station)
|
||||
{
|
||||
if (!_inventorySystem.TryGetSlotEntity(entity, "id", out var idUid))
|
||||
return;
|
||||
@@ -163,12 +171,19 @@ public sealed class StationSpawningSystem : EntitySystem
|
||||
return;
|
||||
|
||||
var card = pdaComponent.ContainedID;
|
||||
_cardSystem.TryChangeFullName(card.Owner, characterName, card);
|
||||
_cardSystem.TryChangeJobTitle(card.Owner, jobPrototype.Name, card);
|
||||
var cardId = card.Owner;
|
||||
_cardSystem.TryChangeFullName(cardId, characterName, card);
|
||||
_cardSystem.TryChangeJobTitle(cardId, jobPrototype.Name, card);
|
||||
|
||||
var extendedAccess = false;
|
||||
if (station != null)
|
||||
{
|
||||
var data = Comp<StationJobsComponent>(station.Value);
|
||||
extendedAccess = data.ExtendedAccess;
|
||||
}
|
||||
|
||||
_accessSystem.SetAccessToJob(cardId, jobPrototype, extendedAccess);
|
||||
|
||||
var access = EntityManager.GetComponent<AccessComponent>(card.Owner);
|
||||
var accessTags = access.Tags;
|
||||
accessTags.UnionWith(jobPrototype.Access);
|
||||
_pdaSystem.SetOwner(pdaComponent, characterName);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user