class CerberusComponent extends ScriptableComponent
{
	protected var m_laserGameEffectUp : EffectInstance;
	protected editable var m_laserGameEffectRefUp : EffectRef;
	protected var m_laserGameEffectUp2 : EffectInstance;
	protected editable var m_laserGameEffectRefUp2 : EffectRef;
	protected var m_laserGameEffectBeam : EffectInstance;
	protected editable var m_laserGameEffectRefBeam : EffectRef;
	protected var m_laserGameEffectBottom : EffectInstance;
	protected editable var m_laserGameEffectRefBottom : EffectRef;
	protected var m_laserGameEffectBottom2 : EffectInstance;
	protected editable var m_laserGameEffectRefBottom2 : EffectRef;
	private var m_gameObject : weak< GameObject >;

	private function OnGameAttach()
	{
		m_gameObject = ( ( NPCPuppet )( GetOwner() ) );
	}

	protected function RunGameEffect( out effectInstance : EffectInstance, effectRef : EffectRef, slotName : CName, range : Float )
	{
		TerminateGameEffect( effectInstance );
		effectInstance = GameInstance.GetGameEffectSystem( m_gameObject.GetGame() ).CreateEffect( effectRef, m_gameObject );
		EffectData.SetVector( effectInstance.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.position, m_gameObject.GetWorldPosition() );
		EffectData.SetVector( effectInstance.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.forward, m_gameObject.GetWorldForward() );
		EffectData.SetFloat( effectInstance.GetSharedData(), GetAllBlackboardDefs().EffectSharedData.range, range );
		effectInstance.AttachToSlot( m_gameObject, slotName, GetAllBlackboardDefs().EffectSharedData.position, GetAllBlackboardDefs().EffectSharedData.forward );
		effectInstance.Run();
	}

	protected function TerminateGameEffect( out effectInstance : EffectInstance )
	{
		if( effectInstance )
		{
			effectInstance.Terminate();
			effectInstance = NULL;
		}
	}

	protected event OnAIEvent( aiEvent : AIEvent )
	{
		switch( aiEvent.name )
		{
			case 'CerberusScan':
				RunGameEffect( m_laserGameEffectUp, m_laserGameEffectRefUp, 'ScannerRoot_Up', 10.0 );
			RunGameEffect( m_laserGameEffectUp2, m_laserGameEffectRefUp2, 'ScannerRoot_Up2', 10.0 );
			RunGameEffect( m_laserGameEffectBeam, m_laserGameEffectRefBeam, 'ScannerRoot_beam', 10.0 );
			RunGameEffect( m_laserGameEffectBottom, m_laserGameEffectRefBottom, 'ScannerRoot_Bottom', 10.0 );
			RunGameEffect( m_laserGameEffectBottom2, m_laserGameEffectRefBottom2, 'ScannerRoot_Bottom2', 10.0 );
			break;
			case 'CerberusStopScan':
				TerminateGameEffect( m_laserGameEffectUp );
			TerminateGameEffect( m_laserGameEffectUp2 );
			TerminateGameEffect( m_laserGameEffectBeam );
			TerminateGameEffect( m_laserGameEffectBottom );
			TerminateGameEffect( m_laserGameEffectBottom2 );
			break;
			case 'eye_flare_red':
				GameObject.StartReplicatedEffectEvent( GetOwner(), 'big_eye_flare' );
			GameObject.StartReplicatedEffectEvent( GetOwner(), 'eyes_flare' );
			break;
			case 'stop_eye_flare_red':
				GameObject.BreakReplicatedEffectLoopEvent( GetOwner(), 'big_eye_flare' );
			GameObject.BreakReplicatedEffectLoopEvent( GetOwner(), 'eyes_flare' );
			break;
			case 'eye_flare_yellow':
				GameObject.StartReplicatedEffectEvent( GetOwner(), 'big_eye_flare_yellow' );
			GameObject.StartReplicatedEffectEvent( GetOwner(), 'eyes_flare_yellow' );
			break;
			case 'stop_eye_flare_yellow':
				GameObject.BreakReplicatedEffectLoopEvent( GetOwner(), 'big_eye_flare_yellow' );
			GameObject.BreakReplicatedEffectLoopEvent( GetOwner(), 'eyes_flare_yellow' );
			break;
		}
	}

	private export function OnGameDetach()
	{
		TerminateGameEffect( m_laserGameEffectUp );
		TerminateGameEffect( m_laserGameEffectUp2 );
		TerminateGameEffect( m_laserGameEffectBeam );
		TerminateGameEffect( m_laserGameEffectBottom );
		TerminateGameEffect( m_laserGameEffectBottom2 );
		StatusEffectHelper.RemoveStatusEffect( GetOwner(), T"WorkspotStatus.Braindance" );
	}

	protected event OnPreUninitialize( evt : entPreUninitializeEvent )
	{
		TerminateGameEffect( m_laserGameEffectUp );
		TerminateGameEffect( m_laserGameEffectUp2 );
		TerminateGameEffect( m_laserGameEffectBeam );
		TerminateGameEffect( m_laserGameEffectBottom );
		TerminateGameEffect( m_laserGameEffectBottom2 );
	}

	protected event OnHit( evt : gameHitEvent )
	{
		if( !( StatusEffectSystem.ObjectHasStatusEffect( GetOwner(), T"BaseStatusEffect.CerberusSkipPreAlerted" ) ) )
		{
			StatusEffectHelper.ApplyStatusEffect( GetOwner(), T"BaseStatusEffect.CerberusSkipPreAlerted" );
		}
	}

}

class CerberusDetectionCombat extends AIbehaviorconditionScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		SetUpdateInterval( context, RandomizeOffsetForUpdateInterval( 0.2 ) );
	}

	protected export override function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		var senseComponent : SenseComponent;
		var target : weak< GameObject >;
		senseComponent = GetPuppet( context ).GetSensesComponent();
		target = GameInstance.GetPlayerSystem( ScriptExecutionContext.GetOwner( context ).GetGame() ).GetLocalPlayerControlledGameObject();
		if( GetPuppet( context ).IsCerberus() )
		{
			if( target && target.IsPlayer() )
			{
				if( senseComponent.GetDetection( target.GetEntityID() ) <= 99.90000153 )
				{
					return true;
				}
			}
		}
		return false;
	}

}

class CerberusDetectionOpticalCamo extends AIbehaviorconditionScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		SetUpdateInterval( context, RandomizeOffsetForUpdateInterval( 0.2 ) );
	}

	protected export override function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		var senseComponent : SenseComponent;
		var target : weak< GameObject >;
		var hasOpticalCamo : Bool;
		senseComponent = GetPuppet( context ).GetSensesComponent();
		target = GameInstance.GetPlayerSystem( ScriptExecutionContext.GetOwner( context ).GetGame() ).GetLocalPlayerControlledGameObject();
		hasOpticalCamo = StatusEffectSystem.ObjectHasStatusEffectWithTag( target, 'Cloak' );
		if( GetPuppet( context ).IsCerberus() )
		{
			if( target && target.IsPlayer() )
			{
				if( ( senseComponent.GetDetection( target.GetEntityID() ) >= 1.0 ) && hasOpticalCamo )
				{
					return true;
				}
			}
		}
		return false;
	}

}

class CerberusSensePresetChange extends AIbehaviortaskScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		SenseComponent.RequestPresetChange( ( ( GameObject )( ScriptExecutionContext.GetOwner( context ) ) ), T"Senses.Alerted", true );
	}

}

class CerberusAbsoluteSensePresetChange extends AIbehaviortaskScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		SenseComponent.RequestPresetChange( ( ( GameObject )( ScriptExecutionContext.GetOwner( context ) ) ), T"Senses.AbsoluteInstant", true );
	}

}

class CerberusOpticalCamoVisibilityChange extends AIbehaviortaskScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		var senseComponent : SenseComponent;
		senseComponent = GetPuppet( context ).GetSensesComponent();
		RPGManager.RemoveAbility( ( ( GameObject )( ScriptExecutionContext.GetOwner( context ) ) ), TweakDBInterface.GetGameplayAbilityRecord( T"Ability.CanSeeThroughOpticalCamos" ) );
		senseComponent.UpdateVisionBlockersIgnoredBySensor();
	}

}

class IsCerberus extends AIbehaviorconditionScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		SetUpdateInterval( context, RandomizeOffsetForUpdateInterval( 0.2 ) );
	}

	protected export override function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		if( GetPuppet( context ).IsCerberus() )
		{
			return true;
		}
		return false;
	}

}

