//====================================================================
// Fujiwara no Mokou's Nonspell #1
//====================================================================
//--------------------------------------------------------------------
// Load Danmakufu
//--------------------------------------------------------------------

//TouhouDanmakufu
#ScriptVersion[2]
#Title[Fujiwara no Mokou - Nonspell 01]
#Text[I think this is too generic... ;w;]
#BackGround[User]

//--------------------------------------------------------------------
// Start the script
//--------------------------------------------------------------------

script_enemy_main{

//--------------------------------------------------------------------
// Include 
//--------------------------------------------------------------------

#include_function ".\Data\Boss.dnh"
#include_function ".\System\Boss\Mokou.dnh"

//--------------------------------------------------------------------
// Variables
//--------------------------------------------------------------------

//--------------------------------------------------------------------
// Extra Variables
//--------------------------------------------------------------------

//--------------------------------------------------------------------
// The Script 
//--------------------------------------------------------------------

	/**
	*	Set the Boss Initialize
	*
	*	@param nArgv	( Any Value )
	*	@param nLevel	( Level of Boss )
	*/
	function onInitialize( let nArgv, let nLevel ){
		
		/** Initialize the Boss */
		InitializeBoss();
	
		/** Boss Initialize Stuff */
		SetLife( 3500 );
		SetTimer( 66 );
		SetDamageRate( 90, 120 );
		SetInvincibility( 120 );
		BehaviorBoss( ACT_STAND3 );

	}

	/**
	*	Boss MainLoop, if bullets spawned here
	*
	*	@param nArgv	( Any Value )
	*	@param nLevel	( Level )
	*	@param nCount	( Count Num )
	*	@param nPhase	( if Phase active )
	*	@param nPhaseCount	( If the Phase is increasing )
	*	@param bIsAppear	( Does not work )
	*/
	function onMainLoop( let nArgv, let nLevel, let nCount, let nPhase, let nPhaseCount, let bIsAppear ){

	}

	/**
	*	Finalize the Boss
	*
	*	@param nArgv	( Any Value )
	*	@param nLevel	( Level )
	*	@param nCount	( Count Num )
	*	@param nPhase	( if Phase active )
	*	@param nPhaseCount	( If the Phase is increasing )
	*	@param bIsAppear	( Does not work )
	*/
	function onFinalize( let nArgv, let nLevel, let nCount, let nPhase, let nPhaseCount, let bIsAppear ){

		/** Delete Boss Graphics */
		FinalizeBoss();
	}

	/**
	*	Draw the Boss Effects, sprite, movement, etc
	*
	*	@param nArgv	( Any Value )
	*	@param nLevel	( Level )
	*	@param nCount	( Count Num )
	*	@param nPhase	( if Phase active )
	*	@param nPhaseCount	( If the Phase is increasing )
	*	@param bIsAppear	( Does not work )
	*/
	function onDrawLoop( let nArgv, let nLevel, let nCount, let nPhase, let nPhaseCount, let bIsAppear ){

		/** Draw the Boss */
		DrawBoss( ImageBoss );

		/** TEXT! */
		DrawTexText( "Fujiwara no Mokou", GetCenterX() - 120, GetCenterY() - 202, 0.38, 5, 255 );		
	}

	/**
	*	If Spell active, use this for Spell BG
	*
	*	@param nArgv	( Any Value )
	*	@param nLevel	( Level )
	*	@param nCount	( Count Num )
	*	@param nPhase	( if Phase active )
	*	@param nPhaseCount	( If the Phase is increasing )
	*	@param bIsAppear	( Does not work )
	*/
	function onBackGround( let nArgv, let nLevel, let nCount, let nPhase, let nPhaseCount, let bIsAppear ){

	}

//--------------------------------------------------------------------
// The MainTask 
//--------------------------------------------------------------------

	/**
	*	The Main Task of the Boss
	*
	*	@param nArgv	( Any Value )
	*	@param nLevel	( Level )
	*/
	task MainTask( nArgv, nLevel ){
	
		SetAction( ACT_MOVE, 90 );
		SetMovePosition02( GetCenterX(), GetCenterY() - 80, 90 );
		Wait( 120 );

		/** Charge */
		PlaySE( seChargeEx );
		Concentration01( 120 );
		Wait( 120 );

		/** Bullet assignment */
		let Assign = 1;

		loop{
			/** Mokou shots */
			SetAction( ACT_SHOT_A3, 130 );
			Wait( 10 );
			RoundSpinShot( Assign );
			Wait( 170 );

			/** Movement plus more shots */
			WideShot();
			ExMove03Slow();
			Wait( 140 );

			Assign = - Assign;
		}
	}

	/**
	*	Spirals!
	*	@param Assign	 ( Bullet assignment )
	*/
	task RoundSpinShot( let Assign ){
		let Way = 3;
		let Angle = 90;
		let WayAngle = 360 / Way;
		if( Assign == - 1 ){ Angle = - Angle; }

		loop( Way ){
			_RoundSpinShot( Angle, Assign );
			Angle += WayAngle;
		}
	}

	/**
	*	Shoot mokou spirals!
	*	@param Angle	( Obvious )
	*	@param Assign	( Bullet assignment )
	*/
	task _RoundSpinShot( let Angle, let Assign ){
		let Way = 53;
		let Speed = 3;
		let WayAngle = 360 / Way;
		let Graphic = [ US_BILL_RED, US_BILL_BLUE, US_BILL_PURPLE ];
		let Frame = 2;
		let Delay = 10;

		if( Assign == - 1 ){ Angle = - Angle; }
		PlaySELoop( seShot4, Delay + Way * Frame, 6 );
		loop( Way ){
			ascent( i in 0 .. 3 ){
				ascent( j in 0 .. 5 ){
					CreateShot01( GetGapX( GetX(), 34, Angle ), GetGapY( GetY(), 34, Angle ), Speed - j * 1 / 4, Angle + i * 360 - j, Graphic[ j % 3 ], Delay );
				}
			}
		Angle += WayAngle;
		Wait( Frame );
		}
	}

	/**
	*	Shoot a wide barrage of bullets.
	*/
	task WideShot{
		let Num = 21;
		let Speed = 2;
		let AccelSpeed = 0.09;
		let MaxSpeed = 5;
		let Graphic = US_BALL_M_A_RED;	
		let Frame = 4;
		let Delay = 10;

		PlaySELoop( seShot5, Delay + Frame * Num, 6 );
		loop( Num ){
			let X = GetX();
			let Y = GetY();
			let Angle = GetAngleToPlayer();
			ascent( let i in - 7 .. 6 ){
				CreateShot02( X, Y, Speed, Angle + i * 7, AccelSpeed, MaxSpeed, Graphic, Delay );
			}
		Wait( Frame );
		}
	}
}						