From f5d9d3c4586252b6741f1c7473eef2b63b8fe586 Mon Sep 17 00:00:00 2001 From: Pspritechologist <81725545+Pspritechologist@users.noreply.github.com> Date: Thu, 4 Apr 2024 04:38:27 -0400 Subject: [PATCH] Suit Sensors No Longer Use a Hardcoded 'Total Health' (#26658) * Suit sensors now know the 'total health' of an entity * Missed the constructor :pensive: --- .../CrewMonitoring/CrewMonitoringWindow.xaml.cs | 4 ++-- .../Medical/SuitSensors/SuitSensorSystem.cs | 12 ++++++++++++ .../Medical/SuitSensor/SharedSuitSensor.cs | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs b/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs index 39326c8a99..863412e553 100644 --- a/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs +++ b/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs @@ -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"); diff --git a/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs b/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs index 29e4ceebbe..9864badc62 100644 --- a/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs +++ b/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs @@ -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(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(); @@ -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; diff --git a/Content.Shared/Medical/SuitSensor/SharedSuitSensor.cs b/Content.Shared/Medical/SuitSensor/SharedSuitSensor.cs index 07e0eca33b..e3ca466b08 100644 --- a/Content.Shared/Medical/SuitSensor/SharedSuitSensor.cs +++ b/Content.Shared/Medical/SuitSensor/SharedSuitSensor.cs @@ -23,6 +23,8 @@ public sealed class SuitSensorStatus public List 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";