//====================================================================
// Fujiwara no Mokou's Spell #2
//====================================================================
//--------------------------------------------------------------------
// Load Danmakufu
//--------------------------------------------------------------------


#ScriptVersion[2]
#Title[Fujiwara no Mokou - Spell 02]
#Text[Imperishable-ness right?]
#BackGround[User]

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

script_enemy_main{

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

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

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

/** Moo string! */
let TString = "";
let TString2 = "";
let TString3 = "";

/** Position */
let PosX = GetClipMinX() + 7;
let PosY = 59;
let _PosY = 73;

//--------------------------------------------------------------------
// 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( 2800 );
		SetTimer( 72 );
		SetDamageRate( 60, 90 );
		SetInvincibility( 240 );
		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();

		/** Create a drop item! */
		CreateItem( ITEM_1UP, GetX(), GetY() );
	}

	/**
	*	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 );

		TexTextColor( 240, 128, 128, 240, 128, 128 );
		DrawTexText( TString, PosX, PosY, 0.411, 5, 255 );
		TexTextColor( 255, 255, 255, 255, 255, 255 );
		DrawTexText( TString2, PosX + 26, _PosY, 0.4, 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 ){

		/** Draw the spell BG */
		DrawSpellBG;

	}

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

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

		/** The spellcard stuff */
		PlaySE( seSpellCall );
		SetAction( ACT_SPELL5, 0 );	
		SetScore( SpellScore );
		SetText( "" );
		
		/** CutIn and the text */
		PushCLCutIn( ImageCutIn, 0, 0, 192, 320 );
		Wait( 40 );
		SpellText;	
		SpellExtraAnim;	

		/** spell line */
		SetSpellLine( CL_TT_TYPE_EIYA );
		Wait( 120 );
			
		loop{
			/** Curvy bullets */
			SetAction( ACT_SHOT_A3, 150 );
			Wait( 20 );
			CurveShot( 1 );
			CurveShot( - 1 );
			CurveShot( 0 );
			Wait( 240 );

			/** Movement! */
			Move();
			Wait( 140 );

			/** More shots */
			SetAction( ACT_SHOT_B2, 180 );
			Wait( 20 );
			loop( 4 ){
				CurveShot( 0 );
				Wait( 40 );
			}
			Wait( 20 );

			/** Slow movement! */
			ExMoveSlow();
			Wait( 180 );
		}
	}

	/**
	*	Curvy shots...
	*	@param Assign	( Bullet assignment )
	*/
	task CurveShot( let Assign ){
		let X = GetX();
		let Y = GetY();
		let Way = 4;
		let Frame = 120;
		let Speed = 2;
		let Angle = GetAngleToPlayer();
		let WayAngle = 360 / Way;
		let AddAngle = 2.6 * Assign;
		let Graphic = [ US_BALL_L_BLUE, US_FIRE_BLUE ];
		let Delay = 10;

		PlaySE( seSpawnFamEx );
		loop( Way ){
			CreateShotA( 0, X, Y, Delay );
			SetShotDataA( 0, 0, Speed, Angle, AddAngle, 0, 0, Graphic[ 0 ] );
			SetShotDataA( 0, Frame, NULL, NULL, 0, 0, 0, Graphic[ 0 ] );
			ascent( let i in 1 .. 120 ){
				CreateShotA( 1, 0, 0, Delay + 40 );
				SetShotDataA( 1, 0, rand( 1, 2 ), rand( 0, 360 ), AddAngle, 0, 0, Graphic[ 1 ] );
				SetShotDataA( 1, 70, NULL, NULL, 0, 0, 0, Graphic[ 1 ] );
				AddShot( i * 5, 0, 1, 0 );
			}
			FireShot( 0 );
			Angle += WayAngle;
		}
	}	

	/**
	*	Animation of the spell text
	*/
	task SpellText{
		TString = "Strange Flame \Hitodama, into the Night\";
		loop( 1 ){
			ascent( let i in 0 .. 60 ){ PosY += i / 8; }
			ascent( i in 0 .. 30 ){ PosX += i / 5; }
			descent( i in 0 .. 30 ){
				PosX -= i / 5;
				yield;
			}
			loop( 30 ){ yield; }
			descent( i in 0 .. 60 ){ PosY -= i / 8; yield; }
		yield;
		}
	}

	/**
	*	Hurr
	*/
	task SpellExtraAnim{
		_SpellExtraAnim;
		loop( 1 ){
			ascent( let i in 0 .. 60 ){ _PosY += i / 8; }
			ascent( i in 0 .. 30 ){ PosX += i / 5; }
			descent( i in 0 .. 30 ){
				PosX -= i / 5;
				yield;
			}
			loop( 30 ){ yield; }
			descent( i in 0 .. 60 ){ _PosY -= i / 8; yield; }
		yield;
		}
	}

	/**
	*	Extra stuff ;_;
	*/
	task _SpellExtraAnim{
		loop{
			if( GetSpellCardBonusScore > 0 ){
				let score = IntString( GetSpellCardBonusScore ); 		
				ascent( let i in 0 .. length( score ) ){ TString2 = "SCORE " ~ score; }
			} else { TString2 = "SCORE FAILED"; }
		yield;
		}
	}
}					