From 72bddb6bdb6b0b4cefcb3440d34d4ded7fb1fa4c Mon Sep 17 00:00:00 2001 From: keronshb <54602815+keronshb@users.noreply.github.com> Date: Mon, 9 Jan 2023 08:25:46 -0500 Subject: [PATCH] Have crew monitor display entity coordinates instead (#13120) closes https://github.com/space-wizards/space-station-14/issues/13042 --- .../CrewMonitoringWindow.xaml.cs | 7 +++++-- .../CrewMonitoringConsoleSystem.cs | 5 +++-- .../Medical/SuitSensors/SuitSensorSystem.cs | 20 +++++++++---------- .../Medical/SuitSensor/SharedSuitSensor.cs | 2 +- .../Objects/Misc/subdermal_implants.yml | 2 +- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs b/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs index ff9c6529c2..3abf9121dd 100644 --- a/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs +++ b/Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml.cs @@ -18,6 +18,7 @@ namespace Content.Client.Medical.CrewMonitoring private List _rowsContent = new(); private List<(DirectionIcon Icon, Vector2 Position)> _directionIcons = new(); private readonly IEyeManager _eye; + private readonly IEntityManager _entityManager; public static int IconSize = 16; // XAML has a `VSeparationOverride` of 20 for each row. @@ -25,6 +26,7 @@ namespace Content.Client.Medical.CrewMonitoring { RobustXamlLoader.Load(this); _eye = IoCManager.Resolve(); + _entityManager = IoCManager.Resolve(); } public void ShowSensors(List stSensors, Vector2 worldPosition, bool snap, float precision) @@ -72,7 +74,7 @@ namespace Content.Client.Medical.CrewMonitoring } } - private BoxContainer GetPositionBox(MapCoordinates? coordinates, Vector2 sensorPosition, bool snap, float precision) + private BoxContainer GetPositionBox(EntityCoordinates? coordinates, Vector2 sensorPosition, bool snap, float precision) { var box = new BoxContainer() { Orientation = LayoutOrientation.Horizontal }; @@ -90,6 +92,7 @@ namespace Content.Client.Medical.CrewMonitoring { // todo: add locations names (kitchen, bridge, etc) var pos = (Vector2i) coordinates.Value.Position; + var mapCoords = coordinates.Value.ToMap(_entityManager).Position; var dirIcon = new DirectionIcon(snap, precision) { SetSize = (IconSize, IconSize), @@ -97,7 +100,7 @@ namespace Content.Client.Medical.CrewMonitoring }; box.AddChild(dirIcon); box.AddChild(new Label() { Text = pos.ToString() }); - _directionIcons.Add((dirIcon, coordinates.Value.Position - sensorPosition)); + _directionIcons.Add((dirIcon, mapCoords - sensorPosition)); } return box; diff --git a/Content.Server/Medical/CrewMonitoring/CrewMonitoringConsoleSystem.cs b/Content.Server/Medical/CrewMonitoring/CrewMonitoringConsoleSystem.cs index 21beee0fbf..ea77cef6bd 100644 --- a/Content.Server/Medical/CrewMonitoring/CrewMonitoringConsoleSystem.cs +++ b/Content.Server/Medical/CrewMonitoring/CrewMonitoringConsoleSystem.cs @@ -3,6 +3,7 @@ using Content.Server.DeviceNetwork.Systems; using Content.Server.Medical.SuitSensors; using Content.Server.UserInterface; using Content.Shared.Medical.CrewMonitoring; +using Robust.Shared.Map; using Robust.Shared.Timing; namespace Content.Server.Medical.CrewMonitoring @@ -66,9 +67,9 @@ namespace Content.Server.Medical.CrewMonitoring return; // update all sensors info - var worldPos = _xform.GetWorldPosition(uid); + var xform = Transform(uid); var allSensors = component.ConnectedSensors.Values.ToList(); - var uiState = new CrewMonitoringState(allSensors, worldPos, component.Snap, component.Precision); + var uiState = new CrewMonitoringState(allSensors, xform.WorldPosition, component.Snap, component.Precision); ui.SetState(uiState); } diff --git a/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs b/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs index ddb5d2bc2a..e6bb6d0ebf 100644 --- a/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs +++ b/Content.Server/Medical/SuitSensors/SuitSensorSystem.cs @@ -12,7 +12,6 @@ using Content.Shared.MobState.Components; using Content.Shared.Verbs; using Robust.Shared.Containers; using Robust.Shared.Map; -using Robust.Shared.Player; using Robust.Shared.Random; using Robust.Shared.Timing; @@ -26,6 +25,7 @@ namespace Content.Server.Medical.SuitSensors [Dependency] private readonly MobStateSystem _mobStateSystem = default!; [Dependency] private readonly DeviceNetworkSystem _deviceNetworkSystem = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; + [Dependency] private readonly SharedTransformSystem _xform = default!; private const float UpdateRate = 1f; private float _updateDif; @@ -228,7 +228,7 @@ namespace Content.Server.Medical.SuitSensors return null; // check if sensor is enabled and worn by user - if (sensor.Mode == SuitSensorMode.SensorOff || sensor.User == null) + if (sensor.Mode == SuitSensorMode.SensorOff || sensor.User == null || transform.GridUid == null) return null; // try to get mobs id from ID slot @@ -245,18 +245,17 @@ namespace Content.Server.Medical.SuitSensors // get health mob state var isAlive = false; if (EntityManager.TryGetComponent(sensor.User.Value, out MobStateComponent? mobState)) - { isAlive = _mobStateSystem.IsAlive(sensor.User.Value, mobState); - } // get mob total damage var totalDamage = 0; - if (EntityManager.TryGetComponent(sensor.User.Value, out DamageableComponent? damageable)) - { + if (TryComp(sensor.User.Value, out var damageable)) totalDamage = damageable.TotalDamage.Int(); - } // finally, form suit sensor status + var xForm = Transform(sensor.User.Value); + var xFormQuery = GetEntityQuery(); + var coords = _xform.GetMoverCoordinates(xForm, xFormQuery); var status = new SuitSensorStatus(userName, userJob); switch (sensor.Mode) { @@ -270,7 +269,7 @@ namespace Content.Server.Medical.SuitSensors case SuitSensorMode.SensorCords: status.IsAlive = isAlive; status.TotalDamage = totalDamage; - status.Coordinates = transform.MapPosition; + status.Coordinates = coords; break; } @@ -295,6 +294,7 @@ namespace Content.Server.Medical.SuitSensors if (status.Coordinates != null) payload.Add(SuitSensorConstants.NET_CORDINATES, status.Coordinates); + return payload; } @@ -316,13 +316,13 @@ namespace Content.Server.Medical.SuitSensors // try get total damage and cords (optionals) payload.TryGetValue(SuitSensorConstants.NET_TOTAL_DAMAGE, out int? totalDamage); - payload.TryGetValue(SuitSensorConstants.NET_CORDINATES, out MapCoordinates? cords); + payload.TryGetValue(SuitSensorConstants.NET_CORDINATES, out EntityCoordinates? cords); var status = new SuitSensorStatus(name, job) { IsAlive = isAlive.Value, TotalDamage = totalDamage, - Coordinates = cords + Coordinates = cords, }; return status; } diff --git a/Content.Shared/Medical/SuitSensor/SharedSuitSensor.cs b/Content.Shared/Medical/SuitSensor/SharedSuitSensor.cs index 9031f875be..d7aefaedc4 100644 --- a/Content.Shared/Medical/SuitSensor/SharedSuitSensor.cs +++ b/Content.Shared/Medical/SuitSensor/SharedSuitSensor.cs @@ -17,7 +17,7 @@ namespace Content.Shared.Medical.SuitSensor public string Job; public bool IsAlive; public int? TotalDamage; - public MapCoordinates? Coordinates; + public EntityCoordinates? Coordinates; } [Serializable, NetSerializable] diff --git a/Resources/Prototypes/Entities/Objects/Misc/subdermal_implants.yml b/Resources/Prototypes/Entities/Objects/Misc/subdermal_implants.yml index a9b49423e4..fa134da19c 100644 --- a/Resources/Prototypes/Entities/Objects/Misc/subdermal_implants.yml +++ b/Resources/Prototypes/Entities/Objects/Misc/subdermal_implants.yml @@ -71,7 +71,7 @@ randomMode: false controlsLocked: true mode: SensorCords - activationContainer: "ImplantContainer" + activationContainer: "implant" - type: DeviceNetwork deviceNetId: Wireless transmitFrequencyId: SuitSensor