class PsychoSquadAvHelperClass extends ScriptableSystem
{

	public static function TurnOffPsychoSquadAvCammoEventDelayed( instance : GameInstance, go : GameObject, delay : Float )
	{
		var evt : TurnOffPsychoSquadAvCammoEvent;
		evt = new TurnOffPsychoSquadAvCammoEvent;
		evt.go = go;
		GameInstance.GetDelaySystem( instance ).DelayScriptableSystemRequest( 'PsychoSquadAvHelperClass', evt, delay );
	}

	public static function TurnOnPsychoSquadAvCammoEventDelayed( instance : GameInstance, go : GameObject, delay : Float )
	{
		var evt : TurnOnPsychoSquadAvCammoEvent;
		evt = new TurnOnPsychoSquadAvCammoEvent;
		evt.go = go;
		GameInstance.GetDelaySystem( instance ).DelayScriptableSystemRequest( 'PsychoSquadAvHelperClass', evt, delay );
	}

	public export static function GetOffAV( go : GameObject )
	{
		var i : Int32;
		var gi : GameInstance;
		var id : EntityID;
		var jumpDelay : Float;
		var passengers : array< weak< GameObject > >;
		var passenger : weak< ScriptedPuppet >;
		var numberOfSnipers : Int32;
		var numberOfMantisBlades : Int32;
		var numberOfLMGs : Int32;
		var biggestDelay : Float;
		var evt : PushAnimEventDelayed;
		gi = go.GetGame();
		id = go.GetEntityID();
		VehicleComponent.GetAllPassengers( gi, id, false, passengers );
		for( i = 0; i < passengers.Size(); i += 1 )
		{
			jumpDelay = 0.0;
			passenger = ( ( ScriptedPuppet )( passengers[ i ] ) );
			switch( passenger.GetRecordID() )
			{
				case T"Character.maxtac_av_mantis_wa":
				case T"Character.maxtac_av_mantis_wa_2nd_wave":
					jumpDelay = 2.0 + ( ( ( Float )( numberOfMantisBlades ) ) / 4.0 );
				numberOfMantisBlades += 1;
				break;
				case T"Character.maxtac_av_LMG_mb":
				case T"Character.maxtac_av_LMG_mb_2nd_wave":
				case T"Character.maxtac_av_riffle_ma":
				case T"Character.maxtac_av_riffle_ma_2nd_wave":
					jumpDelay = 0.5 + ( ( ( Float )( numberOfLMGs ) ) / 4.0 );
				numberOfLMGs += 1;
				break;
				case T"Character.maxtac_av_netrunner_ma":
				case T"Character.maxtac_av_netrunner_ma_2nd_wave":
				case T"Character.maxtac_av_sniper_wa_elite":
				case T"Character.maxtac_av_sniper_wa_elite_2nd_wave":
					jumpDelay = 1.20000005 + ( ( ( Float )( numberOfSnipers ) ) / 4.0 );
				numberOfSnipers += 1;
				break;
				default:
					jumpDelay = ( ( Float )( i ) );
				break;
			}
			if( jumpDelay > biggestDelay )
			{
				biggestDelay = jumpDelay;
			}
			StatusEffectHelper.ApplyStatusEffect( passenger, T"BaseStatusEffect.MaxtacFightStartHelperStatus", jumpDelay );
			GameInstance.GetDelaySystem( gi ).DelayEvent( passenger, AIEvents.ExitVehicleEvent(), jumpDelay );
			if( i == 0 )
			{
				StatusEffectHelper.ApplyStatusEffect( GetPlayer( gi ), T"StatusEffect.HackReveal", passenger.GetEntityID() );
			}
		}
		if( passengers.Size() > 0 )
		{
			biggestDelay += 2.0;
			evt = new PushAnimEventDelayed;
			evt.go = go;
			evt.eventName = 'close_door_event';
			GameInstance.GetDelaySystem( gi ).DelayScriptableSystemRequest( 'PsychoSquadAvHelperClass', evt, biggestDelay );
		}
	}

	private function OnTurnOffPsychoSquadAvCammoEventDelayed( evt : TurnOffPsychoSquadAvCammoEvent )
	{
		var gi : GameInstance;
		var id : EntityID;
		var i : Int32;
		var mountInfos : array< MountingInfo >;
		gi = evt.go.GetGame();
		id = evt.go.GetEntityID();
		mountInfos = GameInstance.GetMountingFacility( gi ).GetMountingInfoMultipleWithIds( , id );
		for( i = 0; i < mountInfos.Size(); i += 1 )
		{
			StatusEffectHelper.RemoveAllStatusEffectsByType( gi, mountInfos[ i ].childId, gamedataStatusEffectType.Cloaked );
		}
	}

	private function OnTurnOnPsychoSquadAvCammoEventDelayed( evt : TurnOnPsychoSquadAvCammoEvent )
	{
		GameObjectEffectHelper.StartEffectEvent( evt.go, 'cloak_on' );
		GameObjectEffectHelper.BreakEffectLoopEvent( evt.go, 'flare_light_maxtac_prevention_system' );
		( ( AVObject )( evt.go ) ).TurnOffThrusters();
	}

	private function OnMaxTacFearEventDelayed( evt : MaxTacFearEvent )
	{
		StimBroadcasterComponent.BroadcastStim( evt.player, gamedataStimType.VehicleHit, 100.0 );
		StimBroadcasterComponent.BroadcastStim( evt.player, gamedataStimType.Terror, 100.0 );
		GameObject.PlaySound( evt.av, 'av_maxtac_descent_horn', 'vehicle_general_emitter' );
	}

	private function OnPushAnimEventDelayed( evt : PushAnimEventDelayed )
	{
		if( evt.go )
		{
			AnimationControllerComponent.PushEvent( evt.go, evt.eventName );
		}
	}

}

class PushAnimEventDelayed extends ScriptableSystemRequest
{
	var eventName : CName;
	var go : weak< GameObject >;
}

class MaxTacFearEvent extends ScriptableSystemRequest
{
	var player : weak< GameObject >;
	var av : weak< GameObject >;
}

class TurnOffPsychoSquadAvCammoEvent extends ScriptableSystemRequest
{
	var go : weak< GameObject >;
}

class TurnOnPsychoSquadAvCammoEvent extends ScriptableSystemRequest
{
	var go : weak< GameObject >;
}

class GetOffAVDelayedEvent extends ScriptableSystemRequest
{
	var go : weak< GameObject >;
	var checkForHazards : Bool;
}

class IsPsychoSquadAvWithoutPassangers extends PreventionConditionAbstract
{

	protected override function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		var vehicle : weak< VehicleObject >;
		var gi : GameInstance;
		var go : GameObject;
		var id : EntityID;
		go = ScriptExecutionContext.GetOwner( context );
		gi = go.GetGame();
		id = go.GetEntityID();
		VehicleComponent.GetVehicleFromID( gi, id, vehicle );
		return ( vehicle && !( vehicle.IsDestroyed() ) ) && !( VehicleComponent.HasAnyPreventionPassengers( vehicle ) );
	}

}

class TurnOnPsychoSquadAvCammo extends AIbehaviortaskScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		var go : weak< GameObject >;
		go = ScriptExecutionContext.GetOwner( context );
		PsychoSquadAvHelperClass.TurnOnPsychoSquadAvCammoEventDelayed( go.GetGame(), go, 3.0 );
	}

}

class TurnOnPsychoSquadAvCammoImmediatly extends AIbehaviortaskScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		var go : weak< GameObject >;
		var gi : GameInstance;
		var id : EntityID;
		var i : Int32;
		var mountInfos : array< MountingInfo >;
		go = ScriptExecutionContext.GetOwner( context );
		gi = go.GetGame();
		id = go.GetEntityID();
		mountInfos = GameInstance.GetMountingFacility( gi ).GetMountingInfoMultipleWithIds( , id );
		for( i = 0; i < mountInfos.Size(); i += 1 )
		{
			StatusEffectHelper.ApplyStatusEffectOnSelf( gi, T"BaseStatusEffect.MaxtacCloaked", mountInfos[ i ].childId );
		}
		GameObjectEffectHelper.StopEffectEvent( go, 'thrusters' );
		GameObjectEffectHelper.StopEffectEvent( go, 'flare_light_maxtac_prevention_system' );
		GameObjectEffectHelper.StartEffectEvent( go, 'cloak_on_instant' );
	}

}

class TurnOffPsychoSquadAvCammo extends AIbehaviortaskScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		var go : weak< GameObject >;
		go = ScriptExecutionContext.GetOwner( context );
		( ( AVObject )( go ) ).TurnOnThrusters();
		GameObjectEffectHelper.StartEffectEvent( go, 'cloak_off' );
		GameObjectEffectHelper.StartEffectEvent( go, 'flare_light_maxtac_prevention_system' );
		PsychoSquadAvHelperClass.TurnOffPsychoSquadAvCammoEventDelayed( go.GetGame(), go, 3.0 );
	}

}

class TurnOffPsychoSquadAvCammoImmediatly extends AIbehaviortaskScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		var go : weak< GameObject >;
		go = ScriptExecutionContext.GetOwner( context );
		( ( AVObject )( go ) ).TurnOnThrusters();
		GameObjectEffectHelper.StartEffectEvent( go, 'cloak_off_instant' );
	}

}

class RegisterPsychoSquadPassengers extends AIbehaviortaskScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		var evt : MaxTacFearEvent;
		var i : Int32;
		var gi : GameInstance;
		var go : GameObject;
		var id : EntityID;
		var passengers : array< weak< GameObject > >;
		var passenger : weak< ScriptedPuppet >;
		evt = new MaxTacFearEvent;
		go = ScriptExecutionContext.GetOwner( context );
		gi = go.GetGame();
		id = go.GetEntityID();
		VehicleComponent.GetAllPassengers( gi, id, false, passengers );
		for( i = 0; i < passengers.Size(); i += 1 )
		{
			passenger = ( ( ScriptedPuppet )( passengers[ i ] ) );
			passenger.TryRegisterToPrevention();
		}
		evt.player = GetPlayer( gi );
		evt.av = go;
		GameInstance.GetDelaySystem( gi ).DelayScriptableSystemRequest( 'PsychoSquadAvHelperClass', evt, 2.5 );
	}

}

class GetOffThePsychoSquadAV extends AIbehaviortaskScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		var go : GameObject;
		go = ScriptExecutionContext.GetOwner( context );
		PsychoSquadAvHelperClass.GetOffAV( go );
	}

}

class DetectPlayerFromAV extends AIbehaviortaskScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		var i : Int32;
		var gi : GameInstance;
		var go : GameObject;
		var id : EntityID;
		var passengers : array< weak< GameObject > >;
		var puppet : ScriptedPuppet;
		go = ScriptExecutionContext.GetOwner( context );
		gi = go.GetGame();
		id = go.GetEntityID();
		VehicleComponent.GetAllPassengers( gi, id, false, passengers );
		for( i = 0; i < passengers.Size(); i += 1 )
		{
			puppet = ( ( ScriptedPuppet )( passengers[ i ] ) );
			if( AIActionHelper.TryChangingAttitudeToHostile( puppet, GetPlayer( gi ) ) )
			{
				TargetTrackingExtension.InjectThreat( puppet, GetPlayer( gi ), 1.0, -1.0 );
				NPCPuppet.ChangeHighLevelState( puppet, gamedataNPCHighLevelState.Combat );
			}
		}
	}

}

class AvStartDescentSFXBehaviour extends AIbehaviortaskScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		var go : GameObject;
		go = ScriptExecutionContext.GetOwner( context );
		GameObject.PlaySound( go, 'av_maxtac_start_descent', 'vehicle_general_emitter' );
	}

}

class AvHoverIdleSFXBehaviour extends AIbehaviortaskScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		var go : GameObject;
		go = ScriptExecutionContext.GetOwner( context );
		GameObject.PlaySound( go, 'av_maxtac_hover_idle', 'vehicle_general_emitter' );
	}

}

class AvStartAscentSFXBehaviour extends AIbehaviortaskScript
{

	protected override function Activate( context : ScriptExecutionContext )
	{
		var go : GameObject;
		go = ScriptExecutionContext.GetOwner( context );
		GameObject.PlaySound( go, 'av_maxtac_start_ascent', 'vehicle_general_emitter' );
	}

}

class IsPreventionMaxtacCondition extends PreventionConditionAbstract
{

	protected override function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		var owner : gamePuppet;
		var gameInstance : GameInstance;
		owner = ScriptExecutionContext.GetOwner( context );
		gameInstance = owner.GetGame();
		return PreventionSystem.IsPreventionMaxTac( gameInstance, owner );
	}

}

