Create a Armor CoeffientQuery (#35024)

* Create a Armor CoeffientQuery

- add Armor Coefficent Query Event for InventoryRelay system

* CR - cleanup, comments and fix typos

* CR - Remove Whitespace

* typos

* on't

---------

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
This commit is contained in:
Zachary Higgs
2025-02-10 10:51:44 -04:00
committed by GitHub
parent 96cb951555
commit 9d48f66a61
3 changed files with 38 additions and 0 deletions

View File

@@ -19,11 +19,25 @@ public abstract class SharedArmorSystem : EntitySystem
{
base.Initialize();
SubscribeLocalEvent<ArmorComponent, InventoryRelayedEvent<CoefficientQueryEvent>>(OnCoefficientQuery);
SubscribeLocalEvent<ArmorComponent, InventoryRelayedEvent<DamageModifyEvent>>(OnDamageModify);
SubscribeLocalEvent<ArmorComponent, BorgModuleRelayedEvent<DamageModifyEvent>>(OnBorgDamageModify);
SubscribeLocalEvent<ArmorComponent, GetVerbsEvent<ExamineVerb>>(OnArmorVerbExamine);
}
/// <summary>
/// Get the total Damage reduction value of all equipment caught by the relay.
/// </summary>
/// <param name="ent">The item that's being relayed to</param>
/// <param name="args">The event, contains the running count of armor percentage as a coefficient</param>
private void OnCoefficientQuery(Entity<ArmorComponent> ent, ref InventoryRelayedEvent<CoefficientQueryEvent> args)
{
foreach (var armorCoefficient in ent.Comp.Modifiers.Coefficients)
{
args.Args.DamageModifiers.Coefficients[armorCoefficient.Key] = args.Args.DamageModifiers.Coefficients.TryGetValue(armorCoefficient.Key, out var coefficient) ? coefficient * armorCoefficient.Value : armorCoefficient.Value;
}
}
private void OnDamageModify(EntityUid uid, ArmorComponent component, InventoryRelayedEvent<DamageModifyEvent> args)
{
args.Args.Damage = DamageSpecifier.ApplyModifierSet(args.Args.Damage, component.Modifiers);