Files
crystall-punk-14/Content.Shared/Armor/SharedArmorSystem.cs
Ed 909dc36158 Spells content (#897)
* modifiers

* counter spell, and 2 new spell scrolls

* Update magical_acceleration.yml

* Update T0_counter_spell.yml
2025-02-14 11:50:57 +03:00

109 lines
3.8 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.AddMarkupOrThrow(Loc.GetString("armor-examine"));
foreach (var coefficientArmor in armorModifiers.Coefficients)
{
msg.PushNewline();
var armorType = Loc.GetString("armor-damage-type-" + coefficientArmor.Key.ToLower());
msg.AddMarkupOrThrow(Loc.GetString("armor-coefficient-value",
("type", armorType),
("value", MathF.Round((1f - coefficientArmor.Value) * 100, 1))
));
}
foreach (var flatArmor in armorModifiers.FlatReduction)
{
msg.PushNewline();
var armorType = Loc.GetString("armor-damage-type-" + flatArmor.Key.ToLower());
msg.AddMarkupOrThrow(Loc.GetString("armor-reduction-value",
("type", armorType),
("value", flatArmor.Value)
));
}
return msg;
}
//CP14 public armor edit API
public void EditArmorCoefficients(EntityUid uid, DamageModifierSet modifiers, ArmorComponent? armor = null)
{
if (!Resolve(uid, ref armor))
return;
//Merge old and new coefficients
foreach (var (armorType, coefficient) in modifiers.Coefficients)
{
if (armor.Modifiers.Coefficients.ContainsKey(armorType))
armor.Modifiers.Coefficients[armorType] += coefficient;
else
armor.Modifiers.Coefficients[armorType] = coefficient;
}
//Merge old and new flat reductions
foreach (var (armorType, reduction) in modifiers.FlatReduction)
{
if (armor.Modifiers.FlatReduction.ContainsKey(armorType))
armor.Modifiers.FlatReduction[armorType] += reduction;
else
armor.Modifiers.FlatReduction[armorType] = reduction;
}
}
//CP14 public armor edit API end
}