]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add events for TemperatureProtection and PressureProtection (#25165)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Wed, 14 Feb 2024 07:44:47 +0000 (02:44 -0500)
committerGitHub <noreply@github.com>
Wed, 14 Feb 2024 07:44:47 +0000 (23:44 -0800)
Content.Server/Atmos/Components/PressureProtectionComponent.cs
Content.Server/Atmos/Components/TemperatureProtectionComponent.cs
Content.Server/Atmos/EntitySystems/BarotraumaSystem.cs
Content.Server/Temperature/Systems/TemperatureSystem.cs

index a3a2842159b2c987d9c9525d5455cb738fd9779e..e1f13bca793829de758b55e29043fa0f0e6233b7 100644 (file)
@@ -1,18 +1,33 @@
-namespace Content.Server.Atmos.Components
+using Content.Server.Atmos.EntitySystems;
+
+namespace Content.Server.Atmos.Components;
+
+[RegisterComponent]
+[Access(typeof(BarotraumaSystem))]
+public sealed partial class PressureProtectionComponent : Component
 {
-    [RegisterComponent]
-    public sealed partial class PressureProtectionComponent : Component
-    {
-        [DataField("highPressureMultiplier")]
-        public float HighPressureMultiplier { get; private set; } = 1f;
+    [DataField]
+    public float HighPressureMultiplier = 1f;
+
+    [DataField]
+    public float HighPressureModifier;
 
-        [DataField("highPressureModifier")]
-        public float HighPressureModifier { get; private set; } = 0f;
+    [DataField]
+    public float LowPressureMultiplier = 1f;
 
-        [DataField("lowPressureMultiplier")]
-        public float LowPressureMultiplier { get; private set; } = 1f;
+    [DataField]
+    public float LowPressureModifier;
+}
 
-        [DataField("lowPressureModifier")]
-        public float LowPressureModifier { get; private set; } = 0f;
-    }
+/// <summary>
+/// Event raised on an entity with <see cref="PressureProtectionComponent"/> in order to adjust its default values.
+/// </summary>
+[ByRefEvent]
+public record struct GetPressureProtectionValuesEvent
+{
+    public float HighPressureMultiplier;
+    public float HighPressureModifier;
+    public float LowPressureMultiplier;
+    public float LowPressureModifier;
 }
+
index 3f9d7bc7711f78e136f113d892b0a2575682f376..bdee5ff5140b730bac21fabfda18dc13c3b7f990 100644 (file)
@@ -1,11 +1,20 @@
-namespace Content.Server.Atmos.Components;
+using Content.Server.Temperature.Systems;
+
+namespace Content.Server.Atmos.Components;
 
 [RegisterComponent]
+[Access(typeof(TemperatureSystem))]
 public sealed partial class TemperatureProtectionComponent : Component
 {
     /// <summary>
     ///     How much to multiply temperature deltas by.
     /// </summary>
-    [DataField("coefficient")]
+    [DataField]
     public float Coefficient = 1.0f;
 }
+
+/// <summary>
+/// Event raised on an entity with <see cref="TemperatureProtectionComponent"/> to determine the actual value of the coefficient.
+/// </summary>
+[ByRefEvent]
+public record struct GetTemperatureProtectionEvent(float Coefficient);
index 1b3e1b07a6fcabb6ae4455f1c8a02114574b9de9..023ac287634bcfa8f55c646f77dee85a469c43e3 100644 (file)
@@ -1,3 +1,4 @@
+using System.Diagnostics.CodeAnalysis;
 using Content.Server.Administration.Logs;
 using Content.Server.Atmos.Components;
 using Content.Shared.Alert;
@@ -97,7 +98,11 @@ namespace Content.Server.Atmos.EntitySystems
                 foreach (var slot in barotrauma.ProtectionSlots)
                 {
                     if (!_inventorySystem.TryGetSlotEntity(uid, slot, out var equipment, inv, contMan)
-                        || !TryComp(equipment, out PressureProtectionComponent? protection))
+                        || !TryGetPressureProtectionValues(equipment.Value,
+                            out var itemHighMultiplier,
+                            out var itemHighModifier,
+                            out var itemLowMultiplier,
+                            out var itemLowModifier))
                     {
                         // Missing protection, skin is exposed.
                         hPModifier = 0f;
@@ -108,10 +113,10 @@ namespace Content.Server.Atmos.EntitySystems
                     }
 
                     // The entity is as protected as its weakest part protection
-                    hPModifier = Math.Max(hPModifier, protection.HighPressureModifier);
-                    hPMultiplier = Math.Max(hPMultiplier, protection.HighPressureMultiplier);
-                    lPModifier = Math.Min(lPModifier, protection.LowPressureModifier);
-                    lPMultiplier = Math.Min(lPMultiplier, protection.LowPressureMultiplier);
+                    hPModifier = Math.Max(hPModifier, itemHighModifier.Value);
+                    hPMultiplier = Math.Max(hPMultiplier, itemHighMultiplier.Value);
+                    lPModifier = Math.Min(lPModifier, itemLowModifier.Value);
+                    lPMultiplier = Math.Min(lPMultiplier, itemLowMultiplier.Value);
                 }
 
                 barotrauma.HighPressureModifier = hPModifier;
@@ -121,12 +126,16 @@ namespace Content.Server.Atmos.EntitySystems
             }
 
             // any innate pressure resistance ?
-            if (TryComp<PressureProtectionComponent>(uid, out var innatePressureProtection))
+            if (TryGetPressureProtectionValues(uid,
+                    out var highMultiplier,
+                    out var highModifier,
+                    out var lowMultiplier,
+                    out var lowModifier))
             {
-                barotrauma.HighPressureModifier += innatePressureProtection.HighPressureModifier;
-                barotrauma.HighPressureMultiplier *= innatePressureProtection.HighPressureMultiplier;
-                barotrauma.LowPressureModifier += innatePressureProtection.LowPressureModifier;
-                barotrauma.LowPressureMultiplier *= innatePressureProtection.LowPressureMultiplier;
+                barotrauma.HighPressureModifier += highModifier.Value;
+                barotrauma.HighPressureMultiplier *= highMultiplier.Value;
+                barotrauma.LowPressureModifier += lowModifier.Value;
+                barotrauma.LowPressureMultiplier *= lowMultiplier.Value;
             }
         }
 
@@ -156,6 +165,36 @@ namespace Content.Server.Atmos.EntitySystems
             return (environmentPressure + barotrauma.HighPressureModifier) * (barotrauma.HighPressureMultiplier);
         }
 
+        public bool TryGetPressureProtectionValues(
+            Entity<PressureProtectionComponent?> ent,
+            [NotNullWhen(true)] out float? highMultiplier,
+            [NotNullWhen(true)] out float? highModifier,
+            [NotNullWhen(true)] out float? lowMultiplier,
+            [NotNullWhen(true)] out float? lowModifier)
+        {
+            highMultiplier = null;
+            highModifier = null;
+            lowMultiplier = null;
+            lowModifier = null;
+            if (!Resolve(ent, ref ent.Comp, false))
+                return false;
+
+            var comp = ent.Comp;
+            var ev = new GetPressureProtectionValuesEvent
+            {
+                HighPressureMultiplier = comp.HighPressureMultiplier,
+                HighPressureModifier = comp.HighPressureModifier,
+                LowPressureMultiplier = comp.LowPressureMultiplier,
+                LowPressureModifier = comp.LowPressureModifier
+            };
+            RaiseLocalEvent(ent, ref ev);
+            highMultiplier = ev.HighPressureMultiplier;
+            highModifier = ev.HighPressureModifier;
+            lowMultiplier = ev.LowPressureMultiplier;
+            lowModifier = ev.LowPressureModifier;
+            return true;
+        }
+
         public override void Update(float frameTime)
         {
             _timer += frameTime;
index 9f7057d9b61f5d5f81998504132acc1c3a28b11f..aef4b89d50932ca929d1ff436dd3cb8401f10b03 100644 (file)
@@ -293,7 +293,10 @@ public sealed class TemperatureSystem : EntitySystem
     private void OnTemperatureChangeAttempt(EntityUid uid, TemperatureProtectionComponent component,
         InventoryRelayedEvent<ModifyChangedTemperatureEvent> args)
     {
-        args.Args.TemperatureDelta *= component.Coefficient;
+        var ev = new GetTemperatureProtectionEvent(component.Coefficient);
+        RaiseLocalEvent(uid, ref ev);
+
+        args.Args.TemperatureDelta *= ev.Coefficient;
     }
 
     private void OnParentChange(EntityUid uid, TemperatureComponent component,