* Update DamageableSystem to modern standards * DamageContainerId -> DamageContainerID with lint flag * Replace strings with protoids * Make CVar subscription declarations all consistently whitespaced * ChangeDamage -> TryChangeDamage, cope with C# jank * Revert event signature changes * Restore a comment * Re-add two queries * Init the queries * Use appearanceQuery in DamageChanged * Use damageableQuery in TryChangeDamage * Use damageableQuery in SetDamageModifierSetId * Final cleanup, fix sandboxing * Rectify ExplosionSystem:::ProcessEntity's call to TryChangeDamage * Re-organize DamageableSystem * first big fuck you breaking change. * THATS A LOT OF DAMAGE!!! * Fix test fails * test fixes 2 * push it --------- Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
117 lines
3.6 KiB
C#
117 lines
3.6 KiB
C#
using Content.Shared.Damage.Components;
|
|
using Content.Shared.Examine;
|
|
using Content.Shared.FixedPoint;
|
|
using Content.Shared.IdentityManagement;
|
|
using Content.Shared.Verbs;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Shared.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);
|
|
}
|
|
|
|
public 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.AddMarkupOrThrow(chosenLocStr);
|
|
}
|
|
|
|
if (msg.IsEmpty)
|
|
{
|
|
msg.AddMarkupOrThrow(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;
|
|
}
|
|
}
|