Files
tbd-station-14/Content.Server/HealthExaminable/HealthExaminableSystem.cs
Kara 2d5ec7f85c Id[entity] 2.0 (real) (#9612)
* starter API

* network ID cards

* Port more stuff from old identity

* Re-implement identity representation + name updating

* move

* proper name returning for `IdentityName`

* move everything important to server, give in to  temptation

* shared / server / client split sadly. move ensure to shared and spawn to server

* identity update queueing + identityblocker

* fixes

* and just like that it's usable for admins

* huge identity pass

* pass dos

* jesus christ

* figs :D

* fuck u

* fix bad merge.

Co-authored-by: Moony <moonheart08@users.noreply.github.com>
2022-07-10 20:36:53 -05:00

117 lines
3.5 KiB
C#

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 = Loc.GetString("health-examinable-verb-disabled"),
IconTexture = "/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;
}
}