diff --git a/Content.Shared/Armor/ArmorComponent.cs b/Content.Shared/Armor/ArmorComponent.cs index fd04c5d29c..8ffbb5a4f8 100644 --- a/Content.Shared/Armor/ArmorComponent.cs +++ b/Content.Shared/Armor/ArmorComponent.cs @@ -1,4 +1,5 @@ using Content.Shared.Damage; +using Content.Shared.Inventory; using Robust.Shared.GameStates; using Robust.Shared.Utility; @@ -30,3 +31,24 @@ public sealed partial class ArmorComponent : Component /// [ByRefEvent] public record struct ArmorExamineEvent(FormattedMessage Msg); + +/// +/// A Relayed inventory event, gets the total Armor for all Inventory slots defined by the Slotflags in TargetSlots +/// +public sealed class CoefficientQueryEvent : EntityEventArgs, IInventoryRelayEvent +{ + /// + /// All slots to relay to + /// + public SlotFlags TargetSlots { get; set; } + + /// + /// The Total of all Coefficients. + /// + public DamageModifierSet DamageModifiers { get; set; } = new DamageModifierSet(); + + public CoefficientQueryEvent(SlotFlags slots) + { + TargetSlots = slots; + } +} diff --git a/Content.Shared/Armor/SharedArmorSystem.cs b/Content.Shared/Armor/SharedArmorSystem.cs index 010ee5e65b..bea875256f 100644 --- a/Content.Shared/Armor/SharedArmorSystem.cs +++ b/Content.Shared/Armor/SharedArmorSystem.cs @@ -19,11 +19,25 @@ public abstract class SharedArmorSystem : EntitySystem { base.Initialize(); + SubscribeLocalEvent>(OnCoefficientQuery); SubscribeLocalEvent>(OnDamageModify); SubscribeLocalEvent>(OnBorgDamageModify); SubscribeLocalEvent>(OnArmorVerbExamine); } + /// + /// Get the total Damage reduction value of all equipment caught by the relay. + /// + /// The item that's being relayed to + /// The event, contains the running count of armor percentage as a coefficient + private void OnCoefficientQuery(Entity ent, ref InventoryRelayedEvent 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 args) { args.Args.Damage = DamageSpecifier.ApplyModifierSet(args.Args.Damage, component.Modifiers); diff --git a/Content.Shared/Inventory/InventorySystem.Relay.cs b/Content.Shared/Inventory/InventorySystem.Relay.cs index bb5dd02ab3..94a32f5ef3 100644 --- a/Content.Shared/Inventory/InventorySystem.Relay.cs +++ b/Content.Shared/Inventory/InventorySystem.Relay.cs @@ -1,3 +1,4 @@ +using Content.Shared.Armor; using Content.Shared.Chat; using Content.Shared.Chemistry; using Content.Shared.Chemistry.Hypospray.Events; @@ -40,6 +41,7 @@ public partial class InventorySystem SubscribeLocalEvent(RelayInventoryEvent); SubscribeLocalEvent(RelayInventoryEvent); SubscribeLocalEvent(RelayInventoryEvent); + SubscribeLocalEvent(RelayInventoryEvent); // by-ref events SubscribeLocalEvent(RefRelayInventoryEvent);