using Content.Shared.Access.Components; using Content.Shared.Hands; using Content.Shared.Inventory.Events; using Content.Shared.PDA; using Content.Shared.StatusIcon; using Content.Shared.StatusIcon.Components; using Robust.Shared.Prototypes; namespace Content.Shared.Access.Systems; public abstract class SharedJobStatusSystem : EntitySystem { [Dependency] private readonly AccessReaderSystem _accessReader = default!; [Dependency] private readonly IPrototypeManager _prototype = default!; private static readonly ProtoId JobIconForNoId = "JobIconNoId"; public override void Initialize() { base.Initialize(); // if the mob picks up, drops or (un)equips a pda or Id card then update their crew status SubscribeLocalEvent((uid, comp, _) => UpdateStatus((uid, comp))); SubscribeLocalEvent((uid, comp, _) => UpdateStatus((uid, comp))); SubscribeLocalEvent((uid, comp, _) => UpdateStatus((uid, comp))); SubscribeLocalEvent((uid, comp, _) => UpdateStatus((uid, comp))); } /// /// Updates this mob's job and crew status depending on their currently equipped or held pda or Id card. /// public void UpdateStatus(Entity ent) { if (!Resolve(ent, ref ent.Comp, false)) return; var iconId = JobIconForNoId; if (_accessReader.FindAccessItemsInventory(ent.Owner, out var items)) { foreach (var item in items) { // ID Card if (TryComp(item, out var id)) { iconId = id.JobIcon; break; } // PDA if (TryComp(item, out var pda) && pda.ContainedId != null && TryComp(pda.ContainedId, out id)) { iconId = id.JobIcon; break; } } } ent.Comp.JobStatusIcon = iconId; ent.Comp.IsCrew = _prototype.Index(iconId).IsCrewJob; Dirty(ent); } }