2021-11-11 16:10:57 -07:00
using Content.Server.Body.Components ;
2021-11-30 16:47:21 -07:00
using Content.Server.Body.Systems ;
2021-07-21 01:41:22 +10:00
using Content.Server.Chemistry.Components ;
2021-10-29 13:40:15 +01:00
using Content.Server.Chemistry.Components.SolutionManager ;
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-11-30 16:47:21 -07:00
[Dependency] private readonly BloodstreamSystem _bloodstreamSystem = 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 )
{
2021-12-08 13:00:43 +01:00
if ( ! EntityManager . TryGetComponent < BloodstreamComponent ? > ( args . OtherFixture . Body . Owner , out var bloodstream ) | |
2021-12-03 15:53:09 +01:00
! _solutionsSystem . TryGetInjectableSolution ( component . Owner , 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 ) ;
2022-02-17 15:00:41 -07:00
_bloodstreamSystem . TryAddToChemicals ( ( args . OtherFixture . Body ) . Owner , solToInject , bloodstream ) ;
2021-07-21 01:41:22 +10:00
}
}
}