class FilterNPCDodgeOpportunity extends EffectObjectGroupFilter_Scripted
{
	private editable var m_applyToTechWeapons : Bool;
	default m_applyToTechWeapons = false;
	private editable var m_doDodgingTargetsGetFilteredOut : Bool;
	default m_doDodgingTargetsGetFilteredOut = true;

	public export function Process( ctx : EffectScriptContext, out filterCtx : EffectGroupFilterScriptContext ) : Bool
	{
		var instigator : GameObject;
		var targetNPC : NPCPuppet;
		var weapon : WeaponObject;
		var aiHumanComponent : AIHumanComponent;
		var gameInstance : GameInstance;
		var enemyVisible : Bool;
		var numAgents : Int32;
		var i : Int32;
		var dodgingIndices : array< Int32 >;
		var newResults : array< Int32 >;
		var instigatorID : EntityID;
		instigator = ( ( GameObject )( EffectScriptContext.GetInstigator( ctx ) ) );
		if( !( instigator ) )
		{
			return true;
		}
		instigatorID = instigator.GetEntityID();
		if( GameInstance.GetStatsSystem( EffectScriptContext.GetGameInstance( ctx ) ).GetStatBoolValue( instigatorID, gamedataStatType.HasKerenzikovOmen ) )
		{
			return false;
		}
		weapon = ( ( WeaponObject )( EffectScriptContext.GetWeapon( ctx ) ) );
		if( !( weapon ) )
		{
			return true;
		}
		numAgents = ( ( Int32 )( EffectGroupFilterScriptContext.GetNumAgents( filterCtx ) ) );
		gameInstance = EffectScriptContext.GetGameInstance( ctx );
		for( i = 0; i < numAgents; i = i + 1 )
		{
			targetNPC = ( ( NPCPuppet )( EffectGroupFilterScriptContext.GetEntity( filterCtx, i ) ) );
			if( !( targetNPC ) )
			{
				continue;
			}
			if( ScriptedPuppet.IsDefeated( targetNPC ) || !( ScriptedPuppet.IsAlive( targetNPC ) ) )
			{
				continue;
			}
			if( !( m_applyToTechWeapons ) && weapon.GetWeaponRecord().Evolution().Type() == gamedataWeaponEvolution.Tech )
			{
				if( !( StatusEffectSystem.ObjectHasStatusEffect( targetNPC, T"BaseStatusEffect.ForceAllowTechWeaponDodge" ) ) )
				{
					continue;
				}
			}
			aiHumanComponent = targetNPC.GetAIControllerComponent();
			if( !( aiHumanComponent ) )
			{
				continue;
			}
			if( GameObject.GetAttitudeBetween( instigator, targetNPC ) == EAIAttitude.AIA_Friendly )
			{
				continue;
			}
			enemyVisible = false;
			if( ( ( PlayerPuppet )( instigator ) ) )
			{
				enemyVisible = GameInstance.GetTargetingSystem( gameInstance ).IsVisibleTarget( instigator, targetNPC );
			}
			else
			{
				enemyVisible = GameInstance.GetSenseManager( gameInstance ).IsObjectVisible( instigator.GetEntityID(), targetNPC.GetEntityID() );
			}
			if( ( enemyVisible && aiHumanComponent.TryBulletDodgeOpportunity() ) && m_doDodgingTargetsGetFilteredOut )
			{
				dodgingIndices.PushBack( i );
			}
		}
		if( dodgingIndices.Size() > 0 )
		{
			for( i = 0; i < numAgents; i = i + 1 )
			{
				if( !( dodgingIndices.Contains( i ) ) )
				{
					newResults.PushBack( i );
				}
			}
			filterCtx.resultIndices = newResults;
		}
		return true;
	}

}

