Skip to content
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion Content.Server/CrewManifest/CrewManifestSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Linq;
using Content.Server.Administration;
using Content.Server.EUI;
using Content.Server.Silicons.StationAi;
using Content.Server.Station.Systems;
using Content.Server.StationRecords;
using Content.Server.StationRecords.Systems;
Expand All @@ -24,6 +25,8 @@
using Content.Shared.CrewManifest;
using Content.Shared.GameTicking;
using Content.Shared.Roles;
using Content.Shared.Silicons.Borgs.Components;
using Content.Shared.Silicons.StationAi;
using Content.Shared.Station.Components;
using Content.Shared.StationRecords;
using Robust.Shared.Configuration;
Expand All @@ -37,6 +40,7 @@ public sealed class CrewManifestSystem : EntitySystem
{
[Dependency] private readonly StationSystem _stationSystem = default!;
[Dependency] private readonly StationRecordsSystem _recordsSystem = default!;
[Dependency] private readonly StationAiSystem _stationAiSystem = default!;
[Dependency] private readonly EuiManager _euiManager = default!;
[Dependency] private readonly IConfigurationManager _configManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
Expand Down Expand Up @@ -129,6 +133,8 @@ private void OnBoundUiClose(EntityUid uid, CrewManifestViewerComponent component
/// <returns>The name and crew manifest entries (unordered) of the station.</returns>
public (string name, CrewManifestEntries? entries) GetCrewManifest(EntityUid station)
{
BuildCrewManifest(station);

var valid = _cachedEntries.TryGetValue(station, out var manifest);
return (valid ? MetaData(station).EntityName : string.Empty, valid ? manifest : null);
}
Expand Down Expand Up @@ -239,6 +245,8 @@ private void BuildCrewManifest(EntityUid station)
var iter = _recordsSystem.GetRecordsOfType<GeneralStationRecord>(station);

var entries = new CrewManifestEntries();
var borgJob = _prototypeManager.Index<JobPrototype>("Borg");
var stationAiJob = _prototypeManager.Index<JobPrototype>("StationAi");

var entriesSort = new List<(JobPrototype? job, CrewManifestEntry entry)>();
foreach (var recordObject in iter)
Expand All @@ -250,6 +258,30 @@ private void BuildCrewManifest(EntityUid station)
entriesSort.Add((job, entry));
}

var borgQuery = EntityQueryEnumerator<BorgChassisComponent>();
while (borgQuery.MoveNext(out var uid, out var chassis))
{
if (_stationSystem.GetOwningStation(uid) != station)
continue;

if (chassis.BrainEntity == null)
continue;

entriesSort.Add((borgJob, BuildSiliconEntry(uid, borgJob)));
}

var aiQuery = EntityQueryEnumerator<StationAiCoreComponent>();
while (aiQuery.MoveNext(out var uid, out var core))
{
if (_stationSystem.GetOwningStation(uid) != station)
continue;

if (!_stationAiSystem.TryGetHeld((uid, core), out var held))
continue;

entriesSort.Add((stationAiJob, BuildSiliconEntry(held, stationAiJob)));
}

entriesSort.Sort((a, b) =>
{
var cmp = JobUIComparer.Instance.Compare(a.job, b.job);
Expand All @@ -262,6 +294,15 @@ private void BuildCrewManifest(EntityUid station)
entries.Entries = entriesSort.Select(x => x.entry).ToArray();
_cachedEntries[station] = entries;
}

private CrewManifestEntry BuildSiliconEntry(EntityUid uid, JobPrototype job)
{
return new CrewManifestEntry(
MetaData(uid).EntityName,
job.LocalizedName,
job.Icon.ToString(),
job.ID);
}
}

[AdminCommand(AdminFlags.Admin)]
Expand Down Expand Up @@ -309,4 +350,4 @@ public override CompletionResult GetCompletion(IConsoleShell shell, string[] arg

return CompletionResult.FromHintOptions(stations, null);
}
}
}
Loading