From 42b053159cd227edb2fe66b8c5b2b74535fe1fa4 Mon Sep 17 00:00:00 2001 From: ike709 Date: Mon, 4 Jul 2022 19:20:44 -0500 Subject: [PATCH] Humans can now have their ID cards examined (#9415) Co-authored-by: ike709 --- .../Components/IdExaminableComponent.cs | 8 ++ .../Access/Systems/IdExaminableSystem.cs | 77 +++++++++++++++++++ .../components/id-examinable-component.ftl | 3 + .../Entities/Mobs/Species/human.yml | 1 + 4 files changed, 89 insertions(+) create mode 100644 Content.Server/Access/Components/IdExaminableComponent.cs create mode 100644 Content.Server/Access/Systems/IdExaminableSystem.cs create mode 100644 Resources/Locale/en-US/access/components/id-examinable-component.ftl diff --git a/Content.Server/Access/Components/IdExaminableComponent.cs b/Content.Server/Access/Components/IdExaminableComponent.cs new file mode 100644 index 0000000000..f1b641b6dd --- /dev/null +++ b/Content.Server/Access/Components/IdExaminableComponent.cs @@ -0,0 +1,8 @@ +using Content.Server.Access.Systems; + +namespace Content.Server.Access.Components; + +[RegisterComponent, Access(typeof(IdExaminableSystem))] +public sealed class IdExaminableComponent : Component +{ +} diff --git a/Content.Server/Access/Systems/IdExaminableSystem.cs b/Content.Server/Access/Systems/IdExaminableSystem.cs new file mode 100644 index 0000000000..d1edc3f199 --- /dev/null +++ b/Content.Server/Access/Systems/IdExaminableSystem.cs @@ -0,0 +1,77 @@ +using Content.Server.Access.Components; +using Content.Shared.Access.Components; +using Content.Shared.Examine; +using Content.Shared.Inventory; +using Content.Shared.PDA; +using Content.Shared.Verbs; +using Robust.Shared.Utility; + +namespace Content.Server.Access.Systems; + +public sealed class IdExaminableSystem : EntitySystem +{ + [Dependency] private readonly ExamineSystemShared _examineSystem = default!; + [Dependency] private readonly InventorySystem _inventorySystem = default!; + + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent>(OnGetExamineVerbs); + } + + private void OnGetExamineVerbs(EntityUid uid, IdExaminableComponent component, GetVerbsEvent args) + { + + var detailsRange = _examineSystem.IsInDetailsRange(args.User, uid); + var info = GetInfo(component.Owner) ?? Loc.GetString("id-examinable-component-verb-no-id"); + + var verb = new ExamineVerb() + { + Act = () => + { + var markup = FormattedMessage.FromMarkup(info); + _examineSystem.SendExamineTooltip(args.User, uid, markup, false, false); + }, + Text = Loc.GetString("id-examinable-component-verb-text"), + Category = VerbCategory.Examine, + Disabled = !detailsRange, + Message = Loc.GetString("id-examinable-component-verb-disabled"), + IconTexture = "/Textures/Interface/VerbIcons/information.svg.192dpi.png" + }; + + args.Verbs.Add(verb); + } + + private string? GetInfo(EntityUid uid) + { + if (_inventorySystem.TryGetSlotEntity(uid, "id", out var idUid)) + { + // PDA + if (EntityManager.TryGetComponent(idUid, out PDAComponent? pda) && pda.ContainedID is not null) + { + return GetNameAndJob(pda.ContainedID); + } + // ID Card + if (EntityManager.TryGetComponent(idUid, out IdCardComponent? id)) + { + return GetNameAndJob(id); + } + } + return null; + } + + private string GetNameAndJob(IdCardComponent id) + { + var jobSuffix = string.IsNullOrWhiteSpace(id.JobTitle) ? string.Empty : $" ({id.JobTitle})"; + + var val = string.IsNullOrWhiteSpace(id.FullName) + ? Loc.GetString("access-id-card-component-owner-name-job-title-text", + ("originalOwnerName", id.OriginalOwnerName), + ("jobSuffix", jobSuffix)) + : Loc.GetString("access-id-card-component-owner-full-name-job-title-text", + ("fullName", id.FullName), + ("jobSuffix", jobSuffix)); + + return val; + } +} diff --git a/Resources/Locale/en-US/access/components/id-examinable-component.ftl b/Resources/Locale/en-US/access/components/id-examinable-component.ftl new file mode 100644 index 0000000000..e9ad65e357 --- /dev/null +++ b/Resources/Locale/en-US/access/components/id-examinable-component.ftl @@ -0,0 +1,3 @@ +id-examinable-component-verb-text = ID Card +id-examinable-component-verb-disabled = Read an ID card in close range. +id-examinable-component-verb-no-id = No ID card visible. diff --git a/Resources/Prototypes/Entities/Mobs/Species/human.yml b/Resources/Prototypes/Entities/Mobs/Species/human.yml index b6b3a136ac..0c5672d4f4 100644 --- a/Resources/Prototypes/Entities/Mobs/Species/human.yml +++ b/Resources/Prototypes/Entities/Mobs/Species/human.yml @@ -52,6 +52,7 @@ solution: chemicals - type: DrawableSolution solution: bloodstream + - type: IdExaminable - type: HealthExaminable examinableTypes: - Blunt