using Content.Shared.CrewManifest; using Content.Shared.Roles; using Robust.Shared.Prototypes; namespace Content.Client.CrewManifest; public sealed class CrewManifestSystem : EntitySystem { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; private Dictionary> _jobDepartmentLookup = new(); private HashSet _departments = new(); public IReadOnlySet Departments => _departments; public override void Initialize() { base.Initialize(); BuildDepartmentLookup(); SubscribeLocalEvent(OnPrototypesReload); } /// /// Requests a crew manifest from the server. /// /// EntityUid of the entity we're requesting the crew manifest from. public void RequestCrewManifest(NetEntity netEntity) { RaiseNetworkEvent(new RequestCrewManifestMessage(netEntity)); } private void OnPrototypesReload(PrototypesReloadedEventArgs args) { if (args.WasModified()) BuildDepartmentLookup(); } private void BuildDepartmentLookup() { _jobDepartmentLookup.Clear(); _departments.Clear(); foreach (var department in _prototypeManager.EnumeratePrototypes()) { _departments.Add(department.ID); for (var i = 1; i <= department.Roles.Count; i++) { if (!_jobDepartmentLookup.TryGetValue(department.Roles[i - 1], out var departments)) { departments = new(); _jobDepartmentLookup.Add(department.Roles[i - 1], departments); } departments.Add(department.ID, i); } } } public int GetDepartmentOrder(string department, string jobPrototype) { if (!Departments.Contains(department)) { return -1; } if (!_jobDepartmentLookup.TryGetValue(jobPrototype, out var departments)) { return -1; } return departments.TryGetValue(department, out var order) ? order : -1; } }