From 9d48f66a61e32dd1d59f21db8a7dd5ac5d35898e Mon Sep 17 00:00:00 2001 From: Zachary Higgs Date: Mon, 10 Feb 2025 10:51:44 -0400 Subject: [PATCH] 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> --- Content.Shared/Armor/ArmorComponent.cs | 22 +++++++++++++++++++ Content.Shared/Armor/SharedArmorSystem.cs | 14 ++++++++++++ .../Inventory/InventorySystem.Relay.cs | 2 ++ 3 files changed, 38 insertions(+) diff --git a/Content.Shared/Armor/ArmorComponent.cs b/Content.Shared/Armor/ArmorComponent.cs index fd04c5d29c86..8ffbb5a4f83d 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 010ee5e65b0e..bea875256f86 100644 --- a/Content.Shared/Armor/SharedArmorSystem.cs +++ b/Content.Shared/Armor/SharedArmorSystem.cs @@ -19,11 +19,25 @@ public override void Initialize() { 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 bb5dd02ab3d8..94a32f5ef3b4 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 void InitializeRelay() SubscribeLocalEvent(RelayInventoryEvent); SubscribeLocalEvent(RelayInventoryEvent); SubscribeLocalEvent(RelayInventoryEvent); + SubscribeLocalEvent(RelayInventoryEvent); // by-ref events SubscribeLocalEvent(RefRelayInventoryEvent);