Predicted armor (#20560)
This commit is contained in:
78
Content.Shared/Armor/SharedArmorSystem.cs
Normal file
78
Content.Shared/Armor/SharedArmorSystem.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user