class GameEffectExecutor_StimOnHit extends EffectExecutor_Scripted
{
	editable var stimType : gamedataStimType;
	editable var silentStimType : gamedataStimType;
	const editable var suppressedByStimTypes : array< gamedataStimType >;

	private function CreateStim( ctx : EffectScriptContext, stimuliType : gamedataStimType, position : Vector4, optional radius : Float ) : Bool
	{
		var stimInfo : StimuliMergeInfo;
		var stimRecord : Stim_Record;
		var stimSystem : StimuliSystem;
		stimSystem = GameInstance.GetStimuliSystem( EffectScriptContext.GetGameInstance( ctx ) );
		stimRecord = stimSystem.GetStimRecord( stimuliType );
		if( radius <= 0.0 )
		{
			radius = stimRecord.Radius();
		}
		stimInfo.position = position;
		stimInfo.instigator = ( ( GameObject )( EffectScriptContext.GetInstigator( ctx ) ) );
		stimInfo.radius = radius;
		stimInfo.type = stimuliType;
		stimInfo.propagationType = gamedataStimPropagation.Audio;
		stimInfo.targets = stimRecord.Targets().Type();
		stimSystem.BroadcastMergeableStimuli( stimInfo, suppressedByStimTypes );
		return true;
	}

	public export function Process( ctx : EffectScriptContext, applierCtx : EffectExecutionScriptContext ) : Bool
	{
		var position : Vector4;
		var weapon : WeaponObject;
		var sniperNestOverride : Bool;
		var silentStimRadius : Float;
		silentStimRadius = 0.0;
		position = EffectExecutionScriptContext.GetHitPosition( applierCtx );
		if( Vector4.IsZero( position ) )
		{
			return false;
		}
		if( GameInstance.GetStatusEffectSystem( EffectScriptContext.GetGameInstance( ctx ) ).HasStatusEffect( EffectScriptContext.GetSource( ctx ).GetEntityID(), T"BaseStatusEffect.PersonalSoundSilencerPlayerBuff" ) )
		{
			return false;
		}
		if( GameInstance.GetStatsSystem( EffectScriptContext.GetGameInstance( ctx ) ).GetStatValue( EffectScriptContext.GetWeapon( ctx ).GetEntityID(), gamedataStatType.CanSilentKill ) > 0.0 )
		{
			if( ( ( ScriptedPuppet )( EffectExecutionScriptContext.GetTarget( applierCtx ) ) ) && RPGManager.HasStatFlag( ( ( GameObject )( EffectScriptContext.GetInstigator( ctx ) ) ), gamedataStatType.CanPlayerGagOnDetection ) )
			{
				silentStimRadius = 3.0;
			}
			weapon = ( ( WeaponObject )( EffectScriptContext.GetWeapon( ctx ) ) );
			if( weapon && WeaponObject.GetWeaponType( weapon.GetItemID() ) == gamedataItemType.Wea_SniperRifle )
			{
				sniperNestOverride = GameInstance.GetBlackboardSystem( EffectScriptContext.GetGameInstance( ctx ) ).Get( GetAllBlackboardDefs().SniperNestDeviceBlackboard ).GetBool( GetAllBlackboardDefs().SniperNestDeviceBlackboard.IsInTheSniperNest );
				if( !( sniperNestOverride ) && !( CreateStim( ctx, stimType, position, 5.0 ) ) )
				{
					return false;
				}
			}
		}
		else
		{
			if( !( CreateStim( ctx, stimType, position ) ) )
			{
				return false;
			}
			silentStimRadius = 20.0;
		}
		return CreateStim( ctx, silentStimType, position, silentStimRadius );
	}

}

