Move id and health examinable to shared (#27867)
* Move id and health examinable to shared * Make GetInfo public
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
using Content.Server.Access.Systems;
|
||||
|
||||
namespace Content.Server.Access.Components;
|
||||
|
||||
[RegisterComponent, Access(typeof(IdExaminableSystem))]
|
||||
public sealed partial class IdExaminableComponent : Component
|
||||
{
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
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<IdExaminableComponent, GetVerbsEvent<ExamineVerb>>(OnGetExamineVerbs);
|
||||
}
|
||||
|
||||
private void OnGetExamineVerbs(EntityUid uid, IdExaminableComponent component, GetVerbsEvent<ExamineVerb> args)
|
||||
{
|
||||
var detailsRange = _examineSystem.IsInDetailsRange(args.User, uid);
|
||||
var info = GetInfo(uid) ?? 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 = detailsRange ? null : Loc.GetString("id-examinable-component-verb-disabled"),
|
||||
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/character.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) &&
|
||||
TryComp<IdCardComponent>(pda.ContainedId, out var id))
|
||||
{
|
||||
return GetNameAndJob(id);
|
||||
}
|
||||
// ID Card
|
||||
if (EntityManager.TryGetComponent(idUid, out 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",
|
||||
("jobSuffix", jobSuffix))
|
||||
: Loc.GetString("access-id-card-component-owner-full-name-job-title-text",
|
||||
("fullName", id.FullName),
|
||||
("jobSuffix", jobSuffix));
|
||||
|
||||
return val;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ using Content.Server.Chemistry.Containers.EntitySystems;
|
||||
using Content.Server.Chemistry.ReactionEffects;
|
||||
using Content.Server.Fluids.EntitySystems;
|
||||
using Content.Server.Forensics;
|
||||
using Content.Server.HealthExaminable;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Chemistry.Components;
|
||||
@@ -13,6 +12,7 @@ using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.Drunk;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.HealthExaminable;
|
||||
using Content.Shared.Mobs.Systems;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Rejuvenate;
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
|
||||
namespace Content.Server.HealthExaminable;
|
||||
|
||||
[RegisterComponent, Access(typeof(HealthExaminableSystem))]
|
||||
public sealed partial class HealthExaminableComponent : Component
|
||||
{
|
||||
public List<FixedPoint2> Thresholds = new()
|
||||
{ FixedPoint2.New(10), FixedPoint2.New(25), FixedPoint2.New(50), FixedPoint2.New(75) };
|
||||
|
||||
[DataField("examinableTypes", required: true, customTypeSerializer:typeof(PrototypeIdHashSetSerializer<DamageTypePrototype>))]
|
||||
public HashSet<string> ExaminableTypes = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Health examine text is automatically generated through creating loc string IDs, in the form:
|
||||
/// `health-examine-[prefix]-[type]-[threshold]`
|
||||
/// This part determines the prefix.
|
||||
/// </summary>
|
||||
[DataField("locPrefix")]
|
||||
public string LocPrefix = "carbon";
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.HealthExaminable;
|
||||
|
||||
public sealed class HealthExaminableSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ExamineSystemShared _examineSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<HealthExaminableComponent, GetVerbsEvent<ExamineVerb>>(OnGetExamineVerbs);
|
||||
}
|
||||
|
||||
private void OnGetExamineVerbs(EntityUid uid, HealthExaminableComponent component, GetVerbsEvent<ExamineVerb> args)
|
||||
{
|
||||
if (!TryComp<DamageableComponent>(uid, out var damage))
|
||||
return;
|
||||
|
||||
var detailsRange = _examineSystem.IsInDetailsRange(args.User, uid);
|
||||
|
||||
var verb = new ExamineVerb()
|
||||
{
|
||||
Act = () =>
|
||||
{
|
||||
var markup = CreateMarkup(uid, component, damage);
|
||||
_examineSystem.SendExamineTooltip(args.User, uid, markup, false, false);
|
||||
},
|
||||
Text = Loc.GetString("health-examinable-verb-text"),
|
||||
Category = VerbCategory.Examine,
|
||||
Disabled = !detailsRange,
|
||||
Message = detailsRange ? null : Loc.GetString("health-examinable-verb-disabled"),
|
||||
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/rejuvenate.svg.192dpi.png"))
|
||||
};
|
||||
|
||||
args.Verbs.Add(verb);
|
||||
}
|
||||
|
||||
private FormattedMessage CreateMarkup(EntityUid uid, HealthExaminableComponent component, DamageableComponent damage)
|
||||
{
|
||||
var msg = new FormattedMessage();
|
||||
|
||||
var first = true;
|
||||
foreach (var type in component.ExaminableTypes)
|
||||
{
|
||||
if (!damage.Damage.DamageDict.TryGetValue(type, out var dmg))
|
||||
continue;
|
||||
|
||||
if (dmg == FixedPoint2.Zero)
|
||||
continue;
|
||||
|
||||
FixedPoint2 closest = FixedPoint2.Zero;
|
||||
|
||||
string chosenLocStr = string.Empty;
|
||||
foreach (var threshold in component.Thresholds)
|
||||
{
|
||||
var str = $"health-examinable-{component.LocPrefix}-{type}-{threshold}";
|
||||
var tempLocStr = Loc.GetString($"health-examinable-{component.LocPrefix}-{type}-{threshold}", ("target", Identity.Entity(uid, EntityManager)));
|
||||
|
||||
// i.e., this string doesn't exist, because theres nothing for that threshold
|
||||
if (tempLocStr == str)
|
||||
continue;
|
||||
|
||||
if (dmg > threshold && threshold > closest)
|
||||
{
|
||||
chosenLocStr = tempLocStr;
|
||||
closest = threshold;
|
||||
}
|
||||
}
|
||||
|
||||
if (closest == FixedPoint2.Zero)
|
||||
continue;
|
||||
|
||||
if (!first)
|
||||
{
|
||||
msg.PushNewline();
|
||||
}
|
||||
else
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
msg.AddMarkup(chosenLocStr);
|
||||
}
|
||||
|
||||
if (msg.IsEmpty)
|
||||
{
|
||||
msg.AddMarkup(Loc.GetString($"health-examinable-{component.LocPrefix}-none"));
|
||||
}
|
||||
|
||||
// Anything else want to add on to this?
|
||||
RaiseLocalEvent(uid, new HealthBeingExaminedEvent(msg), true);
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A class raised on an entity whose health is being examined
|
||||
/// in order to add special text that is not handled by the
|
||||
/// damage thresholds.
|
||||
/// </summary>
|
||||
public sealed class HealthBeingExaminedEvent
|
||||
{
|
||||
public FormattedMessage Message;
|
||||
|
||||
public HealthBeingExaminedEvent(FormattedMessage message)
|
||||
{
|
||||
Message = message;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user