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


#ScriptVersion[2]
#Title[Fujiwara no Mokou - Spell 01]
#Text[Oh god more mokou curses! D:]
#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_BOMB, 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{
			/** Limit the curses! */
			SetAction( ACT_SHOT_B2, 640 );
			Wait( 20 );
			MineShot();
			Wait( 680 );

			/** Movement just cuz */
			ExMove();
			Wait( 160 );
		}
	}

	/**
	*	GOOD JOB!
	*/
	task MineShot{
		let Way = 7;
		let Angle = 90;
		let WayAngle = 360 / Way;
		let Frame = [ 10, 8 ];
		let Assign = 1;

		PlaySELoop( seShot4, Frame[ 0 ] * 60, 5 );
		loop( Way ){
			_MineShot( Angle, Frame[ 1 ], 0 );
			_MineShot( Angle, Frame[ 0 ], 1 );
			Angle += WayAngle;
		}
	}
		
	/**
	*	Shoot simple spirals again~!
	*	@param Angle	( lol angle )
	*	@param __Frame		( Frame for the spiral )
	*	@param Assign	( Bullet assignment )
	*/
	task _MineShot( let Angle, let __Frame, let Assign ){
		let X = GetX();
		let Y = GetY() - 28;
		let Way = 60;
		let GapLength = 30;
		let Frame = 218;
		let Speed = [ 1.3, 3.7 ];
		let WayAngle = 360 / Way;
		let AccelSpeed = - 0.02;
		let MaxSpeed = 0;
		let Graphic = [ US_RICE_S_GREEN, US_KNIFE_YOUMU_BLUE ];
		let Delay = 10;
		if( Assign == 1 ){ Angle = - Angle; }

		loop( Way ){
			CreateShotA( 0, X, Y, Delay );
			if( Assign == 0 ){
				SetShotDataA( 0, 0, Speed[ 0 ], Angle, 0, 0, 0, Graphic[ 0 ] );
			}
			else{
				SetShotDataA( 0, 0, Speed[ 1 ], - Angle, 0, AccelSpeed, MaxSpeed, Graphic[ 1 ] );
				SetShotDirectionType( PLAYER );
				SetShotDataA( 0, Frame, 1.2, 0, 0, 0, 0, US_KNIFE_YOUMU_RED );
				SetShotDirectionType( ABSOLUTE );
			}
			FireShot( 0 );
			Angle += WayAngle;
			Wait( __Frame );
		}
	}				

	/**
	*	Animation of the spell text
	*/
	task SpellText{
		TString = "Limiting Edict \Tsuki no Iwakasa/s Curse ~ Lunatic\";
		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;
		}
	}
}					