2023-12-29 04:47:43 -08:00
|
|
|
using Content.Server.Body.Components;
|
|
|
|
|
using Content.Server.Chemistry.Containers.EntitySystems;
|
2023-04-11 17:11:02 -07:00
|
|
|
using Content.Server.Medical.Components;
|
2023-04-23 12:25:12 +10:00
|
|
|
using Content.Server.PowerCell;
|
2023-12-29 04:47:43 -08:00
|
|
|
using Content.Server.Temperature.Components;
|
2022-03-07 21:45:52 -06:00
|
|
|
using Content.Shared.Damage;
|
2023-02-24 19:01:25 -05:00
|
|
|
using Content.Shared.DoAfter;
|
2022-03-07 21:45:52 -06:00
|
|
|
using Content.Shared.Interaction;
|
2023-04-03 13:13:48 +12:00
|
|
|
using Content.Shared.MedicalScanner;
|
2023-01-13 16:57:10 -08:00
|
|
|
using Content.Shared.Mobs.Components;
|
2022-03-07 21:45:52 -06:00
|
|
|
using Robust.Server.GameObjects;
|
2023-11-27 22:12:34 +11:00
|
|
|
using Robust.Shared.Audio.Systems;
|
2023-10-29 04:21:02 +11:00
|
|
|
using Robust.Shared.Player;
|
2022-03-07 21:45:52 -06:00
|
|
|
|
|
|
|
|
namespace Content.Server.Medical
|
|
|
|
|
{
|
|
|
|
|
public sealed class HealthAnalyzerSystem : EntitySystem
|
|
|
|
|
{
|
2023-04-23 12:25:12 +10:00
|
|
|
[Dependency] private readonly PowerCellSystem _cell = default!;
|
|
|
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
|
|
|
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
2023-12-29 04:47:43 -08:00
|
|
|
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
2023-02-24 19:01:25 -05:00
|
|
|
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
2022-03-07 21:45:52 -06:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<HealthAnalyzerComponent, AfterInteractEvent>(OnAfterInteract);
|
2023-04-03 13:13:48 +12:00
|
|
|
SubscribeLocalEvent<HealthAnalyzerComponent, HealthAnalyzerDoAfterEvent>(OnDoAfter);
|
2022-03-07 21:45:52 -06:00
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
private void OnAfterInteract(Entity<HealthAnalyzerComponent> entity, ref AfterInteractEvent args)
|
2022-03-07 21:45:52 -06:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
if (args.Target == null || !args.CanReach || !HasComp<MobStateComponent>(args.Target) || !_cell.HasActivatableCharge(entity.Owner, user: args.User))
|
2022-03-07 21:45:52 -06:00
|
|
|
return;
|
2023-01-12 01:38:39 -05:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
_audio.PlayPvs(entity.Comp.ScanningBeginSound, entity);
|
2023-01-12 01:38:39 -05:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, args.User, TimeSpan.FromSeconds(entity.Comp.ScanDelay), new HealthAnalyzerDoAfterEvent(), entity.Owner, target: args.Target, used: entity.Owner)
|
2022-03-07 21:45:52 -06:00
|
|
|
{
|
|
|
|
|
BreakOnTargetMove = true,
|
|
|
|
|
BreakOnUserMove = true,
|
|
|
|
|
NeedHand = true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
private void OnDoAfter(Entity<HealthAnalyzerComponent> entity, ref HealthAnalyzerDoAfterEvent args)
|
2022-03-07 21:45:52 -06:00
|
|
|
{
|
2023-12-29 04:47:43 -08:00
|
|
|
if (args.Handled || args.Cancelled || args.Target == null || !_cell.TryUseActivatableCharge(entity.Owner, user: args.User))
|
2023-02-24 19:01:25 -05:00
|
|
|
return;
|
2023-01-12 01:38:39 -05:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
_audio.PlayPvs(entity.Comp.ScanningEndSound, args.User);
|
2023-01-12 01:38:39 -05:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
UpdateScannedUser(entity, args.User, args.Target.Value, entity.Comp);
|
2023-02-24 19:01:25 -05:00
|
|
|
args.Handled = true;
|
2022-03-07 21:45:52 -06:00
|
|
|
}
|
|
|
|
|
|
2023-10-11 02:17:59 -07:00
|
|
|
private void OpenUserInterface(EntityUid user, EntityUid analyzer)
|
2022-03-07 21:45:52 -06:00
|
|
|
{
|
2023-10-11 02:17:59 -07:00
|
|
|
if (!TryComp<ActorComponent>(user, out var actor) || !_uiSystem.TryGetUi(analyzer, HealthAnalyzerUiKey.Key, out var ui))
|
2022-03-07 21:45:52 -06:00
|
|
|
return;
|
|
|
|
|
|
2023-10-11 02:17:59 -07:00
|
|
|
_uiSystem.OpenUi(ui ,actor.PlayerSession);
|
2022-03-07 21:45:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateScannedUser(EntityUid uid, EntityUid user, EntityUid? target, HealthAnalyzerComponent? healthAnalyzer)
|
|
|
|
|
{
|
|
|
|
|
if (!Resolve(uid, ref healthAnalyzer))
|
|
|
|
|
return;
|
|
|
|
|
|
2023-10-11 02:17:59 -07:00
|
|
|
if (target == null || !_uiSystem.TryGetUi(uid, HealthAnalyzerUiKey.Key, out var ui))
|
2022-03-07 21:45:52 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!HasComp<DamageableComponent>(target))
|
|
|
|
|
return;
|
|
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
float bodyTemperature;
|
|
|
|
|
if (TryComp<TemperatureComponent>(target, out var temp))
|
|
|
|
|
bodyTemperature = temp.CurrentTemperature;
|
|
|
|
|
else
|
|
|
|
|
bodyTemperature = float.NaN;
|
|
|
|
|
|
|
|
|
|
float bloodAmount;
|
|
|
|
|
if (TryComp<BloodstreamComponent>(target, out var bloodstream) &&
|
|
|
|
|
_solutionContainerSystem.ResolveSolution(target.Value, bloodstream.BloodSolutionName, ref bloodstream.BloodSolution, out var bloodSolution))
|
|
|
|
|
bloodAmount = bloodSolution.FillFraction;
|
|
|
|
|
else
|
|
|
|
|
bloodAmount = float.NaN;
|
2023-07-18 17:13:26 -04:00
|
|
|
|
2023-10-11 02:17:59 -07:00
|
|
|
OpenUserInterface(user, uid);
|
2023-07-18 17:13:26 -04:00
|
|
|
|
2023-12-29 04:47:43 -08:00
|
|
|
_uiSystem.SendUiMessage(ui, new HealthAnalyzerScannedUserMessage(
|
|
|
|
|
GetNetEntity(target),
|
|
|
|
|
bodyTemperature,
|
|
|
|
|
bloodAmount
|
|
|
|
|
));
|
2022-03-07 21:45:52 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|