CatStation/Content.Shared/Access/Systems/SharedJobStatusSystem.cs
Whatstone a8453723d8
Cleanup: ProtoMan Part 1 - remove Shared EntitySystem IPrototypeManager instances (#44386)
* Remove Shared System IPrototypeManager instances

* Remove RecipeManager IPrototypeManager instance

* Fix ItemSystem IPrototypeManager refs, use TryComp

* SharedItemSystem changes, EntWhitelist CompName

* HasComponent->HasComp
2026-06-29 10:18:44 +00:00

64 lines
2.2 KiB
C#

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<JobIconPrototype> 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<JobStatusComponent, DidEquipEvent>((uid, comp, _) => UpdateStatus((uid, comp)));
SubscribeLocalEvent<JobStatusComponent, DidEquipHandEvent>((uid, comp, _) => UpdateStatus((uid, comp)));
SubscribeLocalEvent<JobStatusComponent, DidUnequipEvent>((uid, comp, _) => UpdateStatus((uid, comp)));
SubscribeLocalEvent<JobStatusComponent, DidUnequipHandEvent>((uid, comp, _) => UpdateStatus((uid, comp)));
}
/// <summary>
/// Updates this mob's job and crew status depending on their currently equipped or held pda or Id card.
/// </summary>
public void UpdateStatus(Entity<JobStatusComponent?> 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<IdCardComponent>(item, out var id))
{
iconId = id.JobIcon;
break;
}
// PDA
if (TryComp<PdaComponent>(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);
}
}