2021-07-21 01:41:22 +10:00
using Content.Server.Body.Circulatory ;
using Content.Server.Chemistry.Components ;
2021-09-06 15:49:44 +02:00
using Content.Shared.Chemistry.Components.SolutionManager ;
using Content.Shared.Chemistry.EntitySystems ;
2021-07-21 01:41:22 +10:00
using JetBrains.Annotations ;
using Robust.Shared.GameObjects ;
2021-09-06 15:49:44 +02:00
using Robust.Shared.IoC ;
2021-07-21 01:41:22 +10:00
using Robust.Shared.Physics.Dynamics ;
namespace Content.Server.Chemistry.EntitySystems
{
[UsedImplicitly]
internal sealed class SolutionInjectOnCollideSystem : EntitySystem
{
2021-09-06 15:49:44 +02:00
[Dependency] private readonly SolutionContainerSystem _solutionsSystem = default ! ;
2021-07-21 01:41:22 +10:00
public override void Initialize ( )
{
base . Initialize ( ) ;
SubscribeLocalEvent < SolutionInjectOnCollideComponent , ComponentInit > ( HandleInit ) ;
SubscribeLocalEvent < SolutionInjectOnCollideComponent , StartCollideEvent > ( HandleInjection ) ;
}
private void HandleInit ( EntityUid uid , SolutionInjectOnCollideComponent component , ComponentInit args )
{
2021-09-06 15:49:44 +02:00
component . Owner
. EnsureComponentWarn < SolutionContainerManagerComponent > ( $"{nameof(SolutionInjectOnCollideComponent)} requires a SolutionContainerManager on {component.Owner}!" ) ;
2021-07-21 01:41:22 +10:00
}
private void HandleInjection ( EntityUid uid , SolutionInjectOnCollideComponent component , StartCollideEvent args )
{
if ( ! args . OtherFixture . Body . Owner . TryGetComponent < BloodstreamComponent > ( out var bloodstream ) | |
2021-09-06 15:49:44 +02:00
! _solutionsSystem . TryGetInjectableSolution ( component . Owner . Uid , out var solution ) ) return ;
2021-07-21 01:41:22 +10:00
var solRemoved = solution . SplitSolution ( component . TransferAmount ) ;
var solRemovedVol = solRemoved . TotalVolume ;
var solToInject = solRemoved . SplitSolution ( solRemovedVol * component . TransferEfficiency ) ;
bloodstream . TryTransferSolution ( solToInject ) ;
}
}
}