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 partial class SharedJobStatusSystem : EntitySystem { [Dependency] private AccessReaderSystem _accessReader = 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 = ProtoMan.Index(iconId).IsCrewJob; Dirty(ent); } /// /// Updates the job status of the entity wearing/holding the given ID card. /// public void UpdateIdHolderStatus(EntityUid idCard) { var holder = Transform(idCard).ParentUid; // ID is inside a PDA, ascend to whoever is wearing/holding the PDA. if (HasComp(holder)) holder = Transform(holder).ParentUid; UpdateStatus(holder); } }