From e4e878b76b8004de8feee296c49dd28ad924276a Mon Sep 17 00:00:00 2001 From: rolfero <45628623+rolfero@users.noreply.github.com> Date: Thu, 8 Sep 2022 06:11:22 +0200 Subject: [PATCH] Adds examine values to armor (#11104) Co-authored-by: CommieFlowers --- Content.Server/Armor/ArmorSystem.cs | 60 +++++++++++++++++++ .../Locale/en-US/armor/armor-examine.ftl | 6 ++ 2 files changed, 66 insertions(+) create mode 100644 Resources/Locale/en-US/armor/armor-examine.ftl diff --git a/Content.Server/Armor/ArmorSystem.cs b/Content.Server/Armor/ArmorSystem.cs index 2e5fbce53b..2fd6ce532e 100644 --- a/Content.Server/Armor/ArmorSystem.cs +++ b/Content.Server/Armor/ArmorSystem.cs @@ -1,19 +1,79 @@ using Content.Shared.Damage; +using Content.Server.Examine; +using Content.Shared.Verbs; +using Robust.Shared.Utility; namespace Content.Server.Armor { public sealed class ArmorSystem : EntitySystem { + + [Dependency] private readonly ExamineSystem _examine = default!; + public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnDamageModify); + SubscribeLocalEvent>(OnArmorVerbExamine); } private void OnDamageModify(EntityUid uid, ArmorComponent component, DamageModifyEvent args) { args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, component.Modifiers); } + + private void OnArmorVerbExamine(EntityUid uid, ArmorComponent component, GetVerbsEvent args) + { + if (!args.CanInteract || !args.CanAccess) + return; + + var armorModifiers = component.Modifiers; + + if (armorModifiers == null) + return; + + var verb = new ExamineVerb() + { + Act = () => + { + var markup = GetArmorExamine(armorModifiers); + _examine.SendExamineTooltip(args.User, uid, markup, false, false); + }, + Text = Loc.GetString("armor-examinable-verb-text"), + Message = Loc.GetString("armor-examinable-verb-message"), + Category = VerbCategory.Examine, + IconTexture = "/Textures/Interface/VerbIcons/dot.svg.192dpi.png" + }; + + args.Verbs.Add(verb); + } + + private static FormattedMessage GetArmorExamine(DamageModifierSet armorModifiers) + { + var msg = new FormattedMessage(); + + msg.AddMarkup(Loc.GetString("armor-examine")); + + foreach (var coefficientArmor in armorModifiers.Coefficients) + { + msg.PushNewline(); + msg.AddMarkup(Loc.GetString("armor-coefficient-value", + ("type", coefficientArmor.Key), + ("value", MathF.Round((1f - coefficientArmor.Value) * 100,1)) + )); + } + + foreach (var flatArmor in armorModifiers.FlatReduction) + { + msg.PushNewline(); + msg.AddMarkup(Loc.GetString("armor-reduction-value", + ("type", flatArmor.Key), + ("value", flatArmor.Value) + )); + } + + return msg; + } } } diff --git a/Resources/Locale/en-US/armor/armor-examine.ftl b/Resources/Locale/en-US/armor/armor-examine.ftl new file mode 100644 index 0000000000..376871fd81 --- /dev/null +++ b/Resources/Locale/en-US/armor/armor-examine.ftl @@ -0,0 +1,6 @@ +# Armor examines +armor-examinable-verb-text = Armor +armor-examinable-verb-message = Examine the armor values. +armor-examine = It provides the following protection: +armor-coefficient-value = - [color=yellow]{$type}[/color] damage reduced by [color=lightblue]{$value}%[/color]. +armor-reduction-value = - [color=yellow]{$type}[/color] damage reduced by [color=lightblue]{$value}[/color].