Files
space-station-14/Content.Shared/Access/Systems/SharedJobStatusSystem.cs
SlamBamActionman 407664a536 Add Cyborg crew indicator (#37038)
* Initial commit

* Include uncertain crew and make it work for AI

* Add new definition to Silicon Rules 8

* Update based on review

* Remove Cluwne from job list

* ProtoIdify

* Update and also make monkey/corgi show IDs

* Remove unnecessary property

* Remove redundant code

* Carrrrd

* cleanup

* Nicer code

* Update to fix the spawn bug + agent ID

* Fix new icons

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
2026-01-29 06:59:06 +00:00

66 lines
2.3 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 class SharedJobStatusSystem : EntitySystem
{
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
[Dependency] private readonly IPrototypeManager _prototype = 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 = _prototype.Index(iconId).IsCrewJob;
Dirty(ent);
}
}