Adds examine values to armor (#11104)

Co-authored-by: CommieFlowers <rasmus.cedergren@hotmail.com>
This commit is contained in:
rolfero
2022-09-08 06:11:22 +02:00
committed by GitHub
parent f5e98d60ea
commit e4e878b76b
2 changed files with 66 additions and 0 deletions

View File

@@ -1,19 +1,79 @@
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Server.Examine;
using Content.Shared.Verbs;
using Robust.Shared.Utility;
namespace Content.Server.Armor namespace Content.Server.Armor
{ {
public sealed class ArmorSystem : EntitySystem public sealed class ArmorSystem : EntitySystem
{ {
[Dependency] private readonly ExamineSystem _examine = default!;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<ArmorComponent, DamageModifyEvent>(OnDamageModify); SubscribeLocalEvent<ArmorComponent, DamageModifyEvent>(OnDamageModify);
SubscribeLocalEvent<ArmorComponent, GetVerbsEvent<ExamineVerb>>(OnArmorVerbExamine);
} }
private void OnDamageModify(EntityUid uid, ArmorComponent component, DamageModifyEvent args) private void OnDamageModify(EntityUid uid, ArmorComponent component, DamageModifyEvent args)
{ {
args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, component.Modifiers); args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, component.Modifiers);
} }
private void OnArmorVerbExamine(EntityUid uid, ArmorComponent component, GetVerbsEvent<ExamineVerb> 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;
}
} }
} }

View File

@@ -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].