2023-01-12 16:41:40 +13:00
using Content.Server.Body.Components ;
2021-11-30 16:47:21 -07:00
using Content.Server.Body.Systems ;
2021-10-29 13:40:15 +01:00
using Content.Server.Chemistry.EntitySystems ;
2022-12-15 12:33:27 -06:00
using Content.Shared.Administration.Logs ;
2021-02-03 11:26:46 -03:00
using Content.Shared.Chemistry ;
2021-06-09 22:19:39 +02:00
using Content.Shared.Chemistry.Reagent ;
2022-12-15 12:33:27 -06:00
using Content.Shared.Database ;
2021-11-03 16:48:03 -07:00
using Content.Shared.FixedPoint ;
2021-06-09 22:19:39 +02:00
using Content.Shared.Smoking ;
2023-01-12 16:41:40 +13:00
using Robust.Shared.Prototypes ;
2021-02-03 11:26:46 -03:00
2021-06-09 22:19:39 +02:00
namespace Content.Server.Chemistry.Components
2021-02-03 11:26:46 -03:00
{
[RegisterComponent]
[ComponentReference(typeof(SolutionAreaEffectComponent))]
2022-02-16 00:23:23 -07:00
public sealed class SmokeSolutionAreaEffectComponent : SolutionAreaEffectComponent
2021-02-03 11:26:46 -03:00
{
2021-12-08 17:04:21 +01:00
[Dependency] private readonly IEntityManager _entMan = default ! ;
2023-01-12 16:41:40 +13:00
[Dependency] private readonly IPrototypeManager _proto = default ! ;
2022-12-15 12:33:27 -06:00
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default ! ;
2021-12-08 17:04:21 +01:00
2021-11-22 01:40:14 -07:00
public new const string SolutionName = "solutionArea" ;
2021-02-03 11:26:46 -03:00
protected override void UpdateVisuals ( )
{
2021-12-08 17:04:21 +01:00
if ( _entMan . TryGetComponent ( Owner , out AppearanceComponent ? appearance ) & &
2021-12-03 15:53:09 +01:00
EntitySystem . Get < SolutionContainerSystem > ( ) . TryGetSolution ( Owner , SolutionName , out var solution ) )
2021-02-03 11:26:46 -03:00
{
2023-01-12 16:41:40 +13:00
appearance . SetData ( SmokeVisuals . Color , solution . GetColor ( _proto ) ) ;
2021-02-03 11:26:46 -03:00
}
}
2021-12-05 18:09:01 +01:00
protected override void ReactWithEntity ( EntityUid entity , double solutionFraction )
2021-02-03 11:26:46 -03:00
{
2021-12-03 15:53:09 +01:00
if ( ! EntitySystem . Get < SolutionContainerSystem > ( ) . TryGetSolution ( Owner , SolutionName , out var solution ) )
2021-02-03 11:26:46 -03:00
return ;
2021-12-08 17:04:21 +01:00
if ( ! _entMan . TryGetComponent ( entity , out BloodstreamComponent ? bloodstream ) )
2021-02-03 11:26:46 -03:00
return ;
2021-12-08 17:04:21 +01:00
if ( _entMan . TryGetComponent ( entity , out InternalsComponent ? internals ) & &
2022-07-25 14:42:25 +10:00
IoCManager . Resolve < IEntitySystemManager > ( ) . GetEntitySystem < InternalsSystem > ( ) . AreInternalsWorking ( internals ) )
2021-02-03 11:26:46 -03:00
return ;
2021-11-22 02:17:35 -07:00
var chemistry = EntitySystem . Get < ReactiveSystem > ( ) ;
2021-09-06 15:49:44 +02:00
var cloneSolution = solution . Clone ( ) ;
2023-01-12 16:41:40 +13:00
var transferAmount = FixedPoint2 . Min ( cloneSolution . Volume * solutionFraction , bloodstream . ChemicalSolution . AvailableVolume ) ;
2021-02-03 11:26:46 -03:00
var transferSolution = cloneSolution . SplitSolution ( transferAmount ) ;
foreach ( var reagentQuantity in transferSolution . Contents . ToArray ( ) )
{
2021-11-03 16:48:03 -07:00
if ( reagentQuantity . Quantity = = FixedPoint2 . Zero ) continue ;
2021-12-03 15:53:09 +01:00
chemistry . ReactionEntity ( entity , ReactionMethod . Ingestion , reagentQuantity . ReagentId , reagentQuantity . Quantity , transferSolution ) ;
2021-02-03 11:26:46 -03:00
}
2021-11-30 16:47:21 -07:00
var bloodstreamSys = EntitySystem . Get < BloodstreamSystem > ( ) ;
2022-12-15 12:33:27 -06:00
if ( bloodstreamSys . TryAddToChemicals ( entity , transferSolution , bloodstream ) )
{
// Log solution addition by smoke
_adminLogger . Add ( LogType . ForceFeed , LogImpact . Medium , $"{_entMan.ToPrettyString(entity):target} was affected by smoke {SolutionContainerSystem.ToPrettyString(transferSolution)}" ) ;
}
2021-02-03 11:26:46 -03:00
}
protected override void OnKill ( )
{
2021-12-09 12:29:27 +01:00
if ( _entMan . Deleted ( Owner ) )
2021-02-03 11:26:46 -03:00
return ;
2021-12-08 17:04:21 +01:00
_entMan . DeleteEntity ( Owner ) ;
2021-02-03 11:26:46 -03:00
}
}
}