class IsAccessPointFilter extends EffectObjectSingleFilter_Scripted
{

	public function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var entity : Entity;
		entity = EffectSingleFilterScriptContext.GetEntity( filterCtx );
		if( ( ( AccessPoint )( entity ) ) )
		{
			return true;
		}
		return false;
	}

}

class IsDeviceTargetValidFilter extends EffectObjectSingleFilter_Scripted
{

	[ profile = "" ]
	public export function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var target : ScriptedPuppet;
		var reactionPresetRecord : weak< ReactionPreset_Record >;
		var reactionPreset : gamedataReactionPresetType;
		var characterRecord : Character_Record;
		var data : PuppetForceVisionAppearanceData;
		var dataVariant : Variant;
		target = ( ( ScriptedPuppet )( EffectSingleFilterScriptContext.GetEntity( filterCtx ) ) );
		if( ( ( target == NULL ) || !( ScriptedPuppet.IsActive( target ) ) ) || !( target.IsOnAutonomousAI() ) )
		{
			return false;
		}
		characterRecord = TweakDBInterface.GetCharacterRecord( target.GetRecordID() );
		if( !( characterRecord ) )
		{
			return false;
		}
		EffectData.GetVariant( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.forceVisionAppearanceData, dataVariant );
		data = ( ( PuppetForceVisionAppearanceData )dataVariant );
		if( data != NULL )
		{
			if( !( CanReactOnStimType( target, data.m_stimRecord ) ) )
			{
				return false;
			}
		}
		reactionPresetRecord = target.GetAIControllerComponent().GetCurrentReactionPreset();
		reactionPreset = reactionPresetRecord.Type();
		if( ( ( ( ( ( ( ( ( reactionPreset == gamedataReactionPresetType.Cerberus_Aggressive || reactionPreset == gamedataReactionPresetType.Corpo_Aggressive ) || reactionPreset == gamedataReactionPresetType.Corpo_Passive ) || reactionPreset == gamedataReactionPresetType.Ganger_Aggressive ) || reactionPreset == gamedataReactionPresetType.Ganger_Passive ) || reactionPreset == gamedataReactionPresetType.Police_Aggressive ) || reactionPreset == gamedataReactionPresetType.Police_Passive ) || reactionPreset == gamedataReactionPresetType.Mechanical_Aggressive ) || reactionPreset == gamedataReactionPresetType.Mechanical_Passive ) || reactionPreset == gamedataReactionPresetType.Mechanical_NonCombat )
		{
			return true;
		}
		return false;
	}

	[ profile = "" ]
	private function CanReactOnStimType( puppet : ScriptedPuppet, stimRecord : Stim_Record ) : Bool
	{
		var propagationType : gamedataStimPropagation;
		var returnValue : Bool;
		returnValue = true;
		if( stimRecord != NULL )
		{
			propagationType = stimRecord.Propagation().Type();
			if( propagationType == gamedataStimPropagation.Audio && ScriptedPuppet.IsDeaf( puppet ) )
			{
				returnValue = false;
			}
		}
		return returnValue;
	}

}

class OnlyNearest_AINavPath_Device extends EffectObjectGroupFilter_Scripted
{

	[ profile = "" ]
	public export function Process( out ctx : EffectScriptContext, out filterCtx : EffectGroupFilterScriptContext ) : Bool
	{
		var numAgents : Int32;
		var i, j : Int32;
		var targets : array< ScriptedPuppet >;
		var target : ScriptedPuppet;
		var sortedTarget : ScriptedPuppet;
		var data : PuppetForceVisionAppearanceData;
		var dataVariant : Variant;
		var source : GameObject;
		var sortedTargets : array< HandleWithValue >;
		var maxCount : Int32;
		EffectData.GetVariant( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.forceVisionAppearanceData, dataVariant );
		data = ( ( PuppetForceVisionAppearanceData )dataVariant );
		if( !( data ) )
		{
			return false;
		}
		numAgents = ( ( Int32 )( EffectGroupFilterScriptContext.GetNumAgents( filterCtx ) ) );
		for( i = 0; i < numAgents; i = i + 1 )
		{
			target = ( ( ScriptedPuppet )( EffectGroupFilterScriptContext.GetEntity( filterCtx, i ) ) );
			if( target )
			{
				targets.PushBack( target );
			}
		}
		maxCount = data.m_investigationSlots;
		source = ( ( GameObject )( EffectScriptContext.GetSource( ctx ) ) );
		sortedTargets = SortTargetsByDistance( source, targets );
		filterCtx.resultIndices.Clear();
		for( i = 0; i < sortedTargets.Size(); i = i + 1 )
		{
			if( filterCtx.resultIndices.Size() >= maxCount )
			{
				break;
			}
			sortedTarget = ( ( ScriptedPuppet )( sortedTargets[ i ].handle ) );
			if( sortedTarget != NULL )
			{
				for( j = 0; j < numAgents; j = j + 1 )
				{
					target = ( ( ScriptedPuppet )( EffectGroupFilterScriptContext.GetEntity( filterCtx, j ) ) );
					if( sortedTarget == target )
					{
						filterCtx.resultIndices.PushBack( j );
						break;
					}
				}
			}
		}
		return true;
	}

	[ profile = "" ]
	private function SortTargetsByDistance( source : GameObject, const targets : ref< array< ScriptedPuppet > > ) : array< HandleWithValue >
	{
		var i : Int32;
		var j : Int32;
		var currentDistance : Float;
		var targetPos : Vector4;
		var path : NavigationPath;
		var closestPath : NavigationPath;
		var posSources : array< Vector4 >;
		var navDistance : Float;
		var closestNavDist : Float;
		var sortedTargets : array< HandleWithValue >;
		var singleSortedTarget : HandleWithValue;
		posSources = ( ( Device )( source ) ).GetNodePosition();
		for( i = 0; i < targets.Size(); i += 1 )
		{
			targetPos = targets[ i ].GetWorldPosition();
			closestPath = NULL;
			for( j = 0; j < posSources.Size(); j += 1 )
			{
				navDistance = Vector4.DistanceSquared( posSources[ j ], targetPos );
				if( ( navDistance < closestNavDist ) || ( closestNavDist == 0.0 ) )
				{
					path = GameInstance.GetAINavigationSystem( source.GetGame() ).CalculatePathForCharacter( targetPos, posSources[ j ], 0.0, source );
					if( path )
					{
						closestNavDist = navDistance;
						closestPath = path;
					}
				}
			}
			if( !( closestPath ) )
			{
				continue;
			}
			currentDistance = closestPath.CalculateLength();
			singleSortedTarget.value = currentDistance;
			singleSortedTarget.handle = targets[ i ];
			sortedTargets.PushBack( singleSortedTarget );
		}
		SortHandleWithValueArray( sortedTargets );
		return sortedTargets;
	}

}

class IsSourceDeviceActveFilter extends EffectObjectGroupFilter_Scripted
{

	[ profile = "" ]
	public export function Process( ctx : EffectScriptContext, out filterCtx : EffectGroupFilterScriptContext ) : Bool
	{
		var device : Device;
		device = ( ( Device )( EffectScriptContext.GetSource( ctx ) ) );
		if( ( !( device ) || device.GetCurrentGameplayRole() == EGameplayRole.None ) || !( device.IsActive() ) )
		{
			filterCtx.resultIndices.Clear();
		}
		return true;
	}

}

class CanAIReactToStimTypeFilter extends EffectObjectSingleFilter_Scripted
{

	[ profile = "" ]
	public function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var puppet : ScriptedPuppet;
		puppet = ( ( ScriptedPuppet )( EffectSingleFilterScriptContext.GetEntity( filterCtx ) ) );
		return puppet && puppet.IsOnAutonomousAI();
	}

}

class IsDeviceFilter extends EffectObjectSingleFilter_Scripted
{

	public function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var entity : Entity;
		entity = EffectSingleFilterScriptContext.GetEntity( filterCtx );
		return ( ( Device )( entity ) );
	}

}

class IsPlayerFilter extends EffectObjectSingleFilter_Scripted
{

	public function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var entity : Entity;
		entity = EffectSingleFilterScriptContext.GetEntity( filterCtx );
		return ( ( PlayerPuppet )( entity ) );
	}

}

class IsCoverDevice extends EffectObjectSingleFilter_Scripted
{

	public function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var entity : Entity;
		entity = EffectSingleFilterScriptContext.GetEntity( filterCtx );
		return ( ( RetractableAd )( entity ) ) || ( ( RoadBlockTrap )( entity ) );
	}

}

class IsNotWeakspotFilter extends EffectObjectSingleFilter_Scripted
{

	public function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var entity : Entity;
		entity = EffectSingleFilterScriptContext.GetEntity( filterCtx );
		if( ( ( WeakspotObject )( entity ) ) )
		{
			return false;
		}
		else
		{
			return true;
		}
	}

}

class IsNotInstigatorWeakspotFilter extends EffectObjectSingleFilter_Scripted
{

	public export function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var entity : Entity;
		var instigator : Entity;
		var weakSpotObject : WeakspotObject;
		var weakSpotObjectOwner : Entity;
		instigator = EffectScriptContext.GetInstigator( ctx );
		entity = EffectSingleFilterScriptContext.GetEntity( filterCtx );
		weakSpotObject = ( ( WeakspotObject )( entity ) );
		if( weakSpotObject )
		{
			weakSpotObjectOwner = weakSpotObject.GetOwner();
		}
		if( ( ( WeakspotObject )( entity ) ) && ( weakSpotObjectOwner == instigator ) )
		{
			return false;
		}
		else
		{
			return true;
		}
	}

}

class IsNotInstigatorProjectileFilter extends EffectObjectSingleFilter_Scripted
{

	public export function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var entity : Entity;
		var instigator : Entity;
		var projectileObject : BaseProjectile;
		var projectileInstigator : weak< GameObject >;
		instigator = EffectScriptContext.GetInstigator( ctx );
		entity = EffectSingleFilterScriptContext.GetEntity( filterCtx );
		projectileObject = ( ( BaseProjectile )( entity ) );
		if( projectileObject )
		{
			projectileInstigator = projectileObject.GetInstigator();
			if( projectileInstigator && ( projectileInstigator == ( ( GameObject )( instigator ) ) ) )
			{
				return false;
			}
		}
		return true;
	}

}

class EffectFilter_DamageOverTime extends EffectObjectSingleFilter_Scripted
{

	public function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var currentTime : Float;
		var lastTimeApplied : Float;
		var cycleDuration : Float;
		currentTime = EngineTime.ToFloat( GameInstance.GetSimTime( EffectScriptContext.GetGameInstance( ctx ) ) );
		EffectData.GetFloat( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.dotLastApplicationTime, lastTimeApplied );
		if( lastTimeApplied == 0.0 )
		{
			EffectData.SetFloat( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.dotLastApplicationTime, currentTime );
			return true;
		}
		EffectData.GetFloat( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.dotCycleDuration, cycleDuration );
		if( ( currentTime - lastTimeApplied ) >= cycleDuration )
		{
			EffectData.SetFloat( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.dotLastApplicationTime, currentTime );
			return true;
		}
		return false;
	}

}

class OnlySingleStatusEffectFromInstigator extends EffectObjectSingleFilter_Scripted
{

	public function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var attack : IAttack;
		var variant : Variant;
		var effects : array< weak< StatusEffectAttackData_Record > >;
		var i : Int32;
		var puppet : NPCPuppet;
		EffectData.GetVariant( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.attack, variant );
		attack = ( ( IAttack )variant );
		puppet = ( ( NPCPuppet )( EffectSingleFilterScriptContext.GetEntity( filterCtx ) ) );
		attack.GetRecord().StatusEffects( effects );
		if( puppet )
		{
			for( i = 0; i < effects.Size(); i += 1 )
			{
				if( StatusEffectHelper.HasStatusEffectFromInstigator( puppet, effects[ i ].StatusEffect().GetID(), EffectScriptContext.GetInstigator( ctx ).GetEntityID() ) )
				{
					return false;
				}
			}
		}
		return true;
	}

}

class NotInDefeated extends EffectObjectSingleFilter_Scripted
{

	public function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var puppet : NPCPuppet;
		puppet = ( ( NPCPuppet )( EffectSingleFilterScriptContext.GetEntity( filterCtx ) ) );
		if( puppet )
		{
			return !( StatusEffectSystem.ObjectHasStatusEffect( puppet, T"BaseStatusEffect.Defeated" ) );
		}
		return true;
	}

}

class IgnoreFriendlyTargets extends EffectObjectSingleFilter_Scripted
{

	public export function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var target : weak< GameObject >;
		var targetAsWeakspot : WeakspotObject;
		target = ( ( GameObject )( EffectSingleFilterScriptContext.GetEntity( filterCtx ) ) );
		targetAsWeakspot = ( ( WeakspotObject )( target ) );
		if( targetAsWeakspot )
		{
			target = targetAsWeakspot.GetOwner();
		}
		if( GameObject.GetAttitudeBetween( target, ( ( GameObject )( EffectScriptContext.GetInstigator( ctx ) ) ) ) == EAIAttitude.AIA_Friendly )
		{
			return false;
		}
		return true;
	}

}

class IgnorePlayerMountedVehicle extends EffectObjectSingleFilter_Scripted
{

	public function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var entity : Entity;
		var vehicle : VehicleObject;
		entity = EffectSingleFilterScriptContext.GetEntity( filterCtx );
		vehicle = ( ( VehicleObject )( entity ) );
		if( vehicle )
		{
			return !( vehicle.IsPlayerMounted() );
		}
		return true;
	}

}

class IgnorePlayerIfMountedToVehicle extends EffectObjectSingleFilter_Scripted
{

	public function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var entity : Entity;
		entity = EffectSingleFilterScriptContext.GetEntity( filterCtx );
		if( ( ( PlayerPuppet )( entity ) ) )
		{
			return !( VehicleComponent.IsMountedToVehicle( EffectScriptContext.GetGameInstance( ctx ), entity.GetEntityID() ) );
		}
		return true;
	}

}

class IgnoreAlreadyAffectedEntities extends EffectObjectSingleFilter_Scripted
{

	public function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var entity : Entity;
		var tempVariant : Variant;
		var affectedEntities : array< EntityID >;
		entity = EffectSingleFilterScriptContext.GetEntity( filterCtx );
		EffectData.GetVariant( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.targets, tempVariant );
		affectedEntities = ( ( array< EntityID > )tempVariant );
		if( entity && !( affectedEntities.Contains( entity.GetEntityID() ) ) )
		{
			affectedEntities.PushBack( entity.GetEntityID() );
			EffectData.SetVariant( EffectScriptContext.GetSharedData( ctx ), GetAllBlackboardDefs().EffectSharedData.targets, affectedEntities );
			return true;
		}
		return false;
	}

}

class IsLootContainer extends EffectObjectSingleFilter_Scripted
{
	editable var m_invert : Bool;

	public function Process( ctx : EffectScriptContext, filterCtx : EffectSingleFilterScriptContext ) : Bool
	{
		var entity : Entity;
		entity = EffectSingleFilterScriptContext.GetEntity( filterCtx );
		if( ( ( gameLootContainerBase )( entity ) ) )
		{
			return ( ( m_invert ) ? ( false ) : ( true ) );
		}
		return ( ( m_invert ) ? ( true ) : ( false ) );
	}

}

