]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Suit Sensors No Longer Use a Hardcoded 'Total Health' (#26658)
authorPspritechologist <81725545+Pspritechologist@users.noreply.github.com>
Thu, 4 Apr 2024 08:38:27 +0000 (04:38 -0400)
committerGitHub <noreply@github.com>
Thu, 4 Apr 2024 08:38:27 +0000 (02:38 -0600)
* Suit sensors now know the 'total health' of an entity

* Missed the constructor :pensive:

Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs
Content.Server/Medical/SuitSensors/SuitSensorSystem.cs
Content.Shared/Medical/SuitSensor/SharedSuitSensor.cs

index 39326c8a99c49626a602388697fe10d78d026658..863412e5532b996e95725d09343e6b81eb9e4750 100644 (file)
@@ -210,9 +210,9 @@ public sealed partial class CrewMonitoringWindow : FancyWindow
                 specifier = new SpriteSpecifier.Rsi(new ResPath("Interface/Alerts/human_crew_monitoring.rsi"), "dead");
             }
 
-            else if (sensor.TotalDamage != null)
+            else if (sensor.DamagePercentage != null)
             {
-                var index = MathF.Round(4f * (sensor.TotalDamage.Value / 100f));
+                var index = MathF.Round(4f * sensor.DamagePercentage.Value);
 
                 if (index >= 5)
                     specifier = new SpriteSpecifier.Rsi(new ResPath("Interface/Alerts/human_crew_monitoring.rsi"), "critical");
index 29e4ceebbecda3f117128daef452fa65ef61f6ee..9864badc620bf1dab7eafc189ab0fd1ea33ce151 100644 (file)
@@ -33,6 +33,7 @@ public sealed class SuitSensorSystem : EntitySystem
     [Dependency] private readonly SharedTransformSystem _transform = default!;
     [Dependency] private readonly StationSystem _stationSystem = default!;
     [Dependency] private readonly SingletonDeviceNetServerSystem _singletonServerSystem = default!;
+    [Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
 
     public override void Initialize()
     {
@@ -344,6 +345,11 @@ public sealed class SuitSensorSystem : EntitySystem
         if (TryComp<DamageableComponent>(sensor.User.Value, out var damageable))
             totalDamage = damageable.TotalDamage.Int();
 
+        // Get mob total damage crit threshold
+        int? totalDamageThreshold = null;
+        if (_mobThresholdSystem.TryGetThresholdForState(sensor.User.Value, Shared.Mobs.MobState.Critical, out var critThreshold))
+            totalDamageThreshold = critThreshold.Value.Int();
+
         // finally, form suit sensor status
         var status = new SuitSensorStatus(GetNetEntity(uid), userName, userJob, userJobIcon, userJobDepartments);
         switch (sensor.Mode)
@@ -354,10 +360,12 @@ public sealed class SuitSensorSystem : EntitySystem
             case SuitSensorMode.SensorVitals:
                 status.IsAlive = isAlive;
                 status.TotalDamage = totalDamage;
+                status.TotalDamageThreshold = totalDamageThreshold;
                 break;
             case SuitSensorMode.SensorCords:
                 status.IsAlive = isAlive;
                 status.TotalDamage = totalDamage;
+                status.TotalDamageThreshold = totalDamageThreshold;
                 EntityCoordinates coordinates;
                 var xformQuery = GetEntityQuery<TransformComponent>();
 
@@ -402,6 +410,8 @@ public sealed class SuitSensorSystem : EntitySystem
 
         if (status.TotalDamage != null)
             payload.Add(SuitSensorConstants.NET_TOTAL_DAMAGE, status.TotalDamage);
+        if (status.TotalDamageThreshold != null)
+            payload.Add(SuitSensorConstants.NET_TOTAL_DAMAGE_THRESHOLD, status.TotalDamageThreshold);
         if (status.Coordinates != null)
             payload.Add(SuitSensorConstants.NET_COORDINATES, status.Coordinates);
 
@@ -429,12 +439,14 @@ public sealed class SuitSensorSystem : EntitySystem
 
         // try get total damage and cords (optionals)
         payload.TryGetValue(SuitSensorConstants.NET_TOTAL_DAMAGE, out int? totalDamage);
+        payload.TryGetValue(SuitSensorConstants.NET_TOTAL_DAMAGE_THRESHOLD, out int? totalDamageThreshold);
         payload.TryGetValue(SuitSensorConstants.NET_COORDINATES, out NetCoordinates? coords);
 
         var status = new SuitSensorStatus(suitSensorUid, name, job, jobIcon, jobDepartments)
         {
             IsAlive = isAlive.Value,
             TotalDamage = totalDamage,
+            TotalDamageThreshold = totalDamageThreshold,
             Coordinates = coords,
         };
         return status;
index 07e0eca33bdff254f2c515c3a2e39c83fb9983a5..e3ca466b085d20e53924caac7c9d0fa9a61f984f 100644 (file)
@@ -23,6 +23,8 @@ public sealed class SuitSensorStatus
     public List<string> JobDepartments;
     public bool IsAlive;
     public int? TotalDamage;
+    public int? TotalDamageThreshold;
+    public float? DamagePercentage => TotalDamageThreshold == null || TotalDamage == null ? null : TotalDamage / TotalDamageThreshold;
     public NetCoordinates? Coordinates;
 }
 
@@ -58,6 +60,7 @@ public static class SuitSensorConstants
     public const string NET_JOB_DEPARTMENTS = "jobDepartments";
     public const string NET_IS_ALIVE = "alive";
     public const string NET_TOTAL_DAMAGE = "vitals";
+    public const string NET_TOTAL_DAMAGE_THRESHOLD = "vitalsThreshold";
     public const string NET_COORDINATES = "coords";
     public const string NET_SUIT_SENSOR_UID = "uid";