]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Create a Armor CoeffientQuery (#35024)
authorZachary Higgs <compgeek223@gmail.com>
Mon, 10 Feb 2025 14:51:44 +0000 (10:51 -0400)
committerGitHub <noreply@github.com>
Mon, 10 Feb 2025 14:51:44 +0000 (15:51 +0100)
* 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
Content.Shared/Armor/SharedArmorSystem.cs
Content.Shared/Inventory/InventorySystem.Relay.cs

index fd04c5d29c862dd3ed4a95887d50fb2f19161b4a..8ffbb5a4f83d0280ad52fc8298b88ac8e012c451 100644 (file)
@@ -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
 /// <param name="Msg"></param>
 [ByRefEvent]
 public record struct ArmorExamineEvent(FormattedMessage Msg);
+
+/// <summary>
+/// A Relayed inventory event, gets the total Armor for all Inventory slots defined by the Slotflags in TargetSlots
+/// </summary>
+public sealed class CoefficientQueryEvent : EntityEventArgs, IInventoryRelayEvent
+{
+    /// <summary>
+    /// All slots to relay to
+    /// </summary>
+    public SlotFlags TargetSlots { get; set; }
+
+    /// <summary>
+    /// The Total of all Coefficients.
+    /// </summary>
+    public DamageModifierSet DamageModifiers { get; set; } = new DamageModifierSet();
+
+    public CoefficientQueryEvent(SlotFlags slots)
+    {
+        TargetSlots = slots;
+    }
+}
index 010ee5e65b0e0657715abf735a5ba19fe6e2bf58..bea875256f86f7777fa474e8a11715361f1b783a 100644 (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);
index bb5dd02ab3d82b7d337f77a9cd16b14c30b87663..94a32f5ef3b46d3f91b264585d32697b87825012 100644 (file)
@@ -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<InventoryComponent, TargetBeforeHyposprayInjectsEvent>(RelayInventoryEvent);
         SubscribeLocalEvent<InventoryComponent, SelfBeforeGunShotEvent>(RelayInventoryEvent);
         SubscribeLocalEvent<InventoryComponent, SelfBeforeClimbEvent>(RelayInventoryEvent);
+        SubscribeLocalEvent<InventoryComponent, CoefficientQueryEvent>(RelayInventoryEvent);
 
         // by-ref events
         SubscribeLocalEvent<InventoryComponent, GetExplosionResistanceEvent>(RefRelayInventoryEvent);