79 lines
2.7 KiB
C#
79 lines
2.7 KiB
C#
using Content.Shared.Damage;
|
|
using Content.Shared.Examine;
|
|
using Content.Shared.Inventory;
|
|
using Content.Shared.Silicons.Borgs;
|
|
using Content.Shared.Verbs;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Shared.Armor;
|
|
|
|
/// <summary>
|
|
/// This handles logic relating to <see cref="ArmorComponent"/>
|
|
/// </summary>
|
|
public abstract class SharedArmorSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly ExamineSystemShared _examine = default!;
|
|
|
|
/// <inheritdoc/>
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<ArmorComponent, InventoryRelayedEvent<DamageModifyEvent>>(OnDamageModify);
|
|
SubscribeLocalEvent<ArmorComponent, BorgModuleRelayedEvent<DamageModifyEvent>>(OnBorgDamageModify);
|
|
SubscribeLocalEvent<ArmorComponent, GetVerbsEvent<ExamineVerb>>(OnArmorVerbExamine);
|
|
}
|
|
|
|
private void OnDamageModify(EntityUid uid, ArmorComponent component, InventoryRelayedEvent<DamageModifyEvent> args)
|
|
{
|
|
args.Args.Damage = DamageSpecifier.ApplyModifierSet(args.Args.Damage, component.Modifiers);
|
|
}
|
|
|
|
private void OnBorgDamageModify(EntityUid uid, ArmorComponent component, ref BorgModuleRelayedEvent<DamageModifyEvent> args)
|
|
{
|
|
args.Args.Damage = DamageSpecifier.ApplyModifierSet(args.Args.Damage, component.Modifiers);
|
|
}
|
|
|
|
private void OnArmorVerbExamine(EntityUid uid, ArmorComponent component, GetVerbsEvent<ExamineVerb> args)
|
|
{
|
|
if (!args.CanInteract || !args.CanAccess)
|
|
return;
|
|
|
|
var examineMarkup = GetArmorExamine(component.Modifiers);
|
|
|
|
var ev = new ArmorExamineEvent(examineMarkup);
|
|
RaiseLocalEvent(uid, ref ev);
|
|
|
|
_examine.AddDetailedExamineVerb(args, component, examineMarkup,
|
|
Loc.GetString("armor-examinable-verb-text"), "/Textures/Interface/VerbIcons/dot.svg.192dpi.png",
|
|
Loc.GetString("armor-examinable-verb-message"));
|
|
}
|
|
|
|
private 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;
|
|
}
|
|
}
|