* Creates Content.Shared.Chemistry.Solutions Copies Solution class to new namespace Obsoletes old Solution class * Switches over to the Solutions.Solution Solution * Creates Content.Shared.Chemistry.Containers Copies relevant components/systems to the new namespace Obsoletes old versions * Switches over to the Containers.XYZ namespace * Creates SolutionSystem and obsoletes old SolutionContainerSystem methods * Start using SolutionSystem for Solution manipulation * EnumerateSolutions * Move TryGetMixableSolution * Move EnsureSolution to Server * Create Solution Entities * Stop using obsolete solution system methods * Fix prototype component tests * Add using ..Audio.Systems; back * Wrap solution container slots in ContainerSlots * Actually add the slot to the solution container map * Dirty SolutionContainerComponent when ensuring solutions * Revert namespace changes * Remerge SolutionSystem and SolutionContainerSystem * SolutionContainerManagerComponent refactor * Avoid wrapping necessary code in DebugTools.Assert as it is removed when compiling for release * Readd examine reagent sorting * Fix errors * Poke tests * Fix solution names not being applied * Fix WoolyComponent including statement * Fix merge skew * Fix compile errors * Make reactions use solntities * Reindent solution class namespace * Field attribute changes * AutoGenerateComponentState for SolutionContainerComponent * SolutionContainerComponent -> ContainedSolutionComponent * ref ReactionAttemptEvent * Denetwork preinit solutions * Misc 1 * Nullable TryGetSolution out vars * Cache associated solutions * Fix merge skew * Use explicit regions in SharedSolutionContainerSystem.Capabilities * Add debug assert * Use explicit regions in SharedSolutionContainerSystem.Relay + ref SolutionContainerChangedEvent * ContainedSolutionComponent.Name -> ContainedSolutionComponent.ContainerName * SolutionComponent doc comments * Implicit DataField names and property purge * ReagentEffect DataField names * Local variables for readability * Sort using statements + Entity<T> event handlers * Fix compile erros * Fix compile errors --------- Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
100 lines
4.0 KiB
C#
100 lines
4.0 KiB
C#
using Content.Server.Body.Components;
|
|
using Content.Server.Chemistry.Containers.EntitySystems;
|
|
using Content.Server.Medical.Components;
|
|
using Content.Server.PowerCell;
|
|
using Content.Server.Temperature.Components;
|
|
using Content.Shared.Damage;
|
|
using Content.Shared.DoAfter;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.MedicalScanner;
|
|
using Content.Shared.Mobs.Components;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Content.Server.Medical
|
|
{
|
|
public sealed class HealthAnalyzerSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly PowerCellSystem _cell = default!;
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
|
|
[Dependency] private readonly SolutionContainerSystem _solutionContainerSystem = default!;
|
|
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<HealthAnalyzerComponent, AfterInteractEvent>(OnAfterInteract);
|
|
SubscribeLocalEvent<HealthAnalyzerComponent, HealthAnalyzerDoAfterEvent>(OnDoAfter);
|
|
}
|
|
|
|
private void OnAfterInteract(Entity<HealthAnalyzerComponent> entity, ref AfterInteractEvent args)
|
|
{
|
|
if (args.Target == null || !args.CanReach || !HasComp<MobStateComponent>(args.Target) || !_cell.HasActivatableCharge(entity.Owner, user: args.User))
|
|
return;
|
|
|
|
_audio.PlayPvs(entity.Comp.ScanningBeginSound, entity);
|
|
|
|
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, args.User, TimeSpan.FromSeconds(entity.Comp.ScanDelay), new HealthAnalyzerDoAfterEvent(), entity.Owner, target: args.Target, used: entity.Owner)
|
|
{
|
|
BreakOnTargetMove = true,
|
|
BreakOnUserMove = true,
|
|
NeedHand = true
|
|
});
|
|
}
|
|
|
|
private void OnDoAfter(Entity<HealthAnalyzerComponent> entity, ref HealthAnalyzerDoAfterEvent args)
|
|
{
|
|
if (args.Handled || args.Cancelled || args.Target == null || !_cell.TryUseActivatableCharge(entity.Owner, user: args.User))
|
|
return;
|
|
|
|
_audio.PlayPvs(entity.Comp.ScanningEndSound, args.User);
|
|
|
|
UpdateScannedUser(entity, args.User, args.Target.Value, entity.Comp);
|
|
args.Handled = true;
|
|
}
|
|
|
|
private void OpenUserInterface(EntityUid user, EntityUid analyzer)
|
|
{
|
|
if (!TryComp<ActorComponent>(user, out var actor) || !_uiSystem.TryGetUi(analyzer, HealthAnalyzerUiKey.Key, out var ui))
|
|
return;
|
|
|
|
_uiSystem.OpenUi(ui ,actor.PlayerSession);
|
|
}
|
|
|
|
public void UpdateScannedUser(EntityUid uid, EntityUid user, EntityUid? target, HealthAnalyzerComponent? healthAnalyzer)
|
|
{
|
|
if (!Resolve(uid, ref healthAnalyzer))
|
|
return;
|
|
|
|
if (target == null || !_uiSystem.TryGetUi(uid, HealthAnalyzerUiKey.Key, out var ui))
|
|
return;
|
|
|
|
if (!HasComp<DamageableComponent>(target))
|
|
return;
|
|
|
|
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;
|
|
|
|
OpenUserInterface(user, uid);
|
|
|
|
_uiSystem.SendUiMessage(ui, new HealthAnalyzerScannedUserMessage(
|
|
GetNetEntity(target),
|
|
bodyTemperature,
|
|
bloodAmount
|
|
));
|
|
}
|
|
}
|
|
}
|