
#ScriptVersion[3]
#Title["TsubakuraS10"]
#Text["TsubakuraS10"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Background["./BG.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/AllStarShot_Const.dnh"
#include"./system/Default_Effect.Txt"


let objBoss;
let GCSD=GetCurrentScriptDirectory~"";
let enemy;
let bSpell=false;
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
let idle = true;
let atk = false;
let fog = 0;
let action = false;
let objScene=GetEnemyBossSceneObjectID();
let color = [276,277,278];
let color2 = [51,53,55];
let dcolor = [308,309,310];
@Initialize
{
SetBoss("Doremy",true);
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),18);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(3000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(130);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(99999999);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
	ObjMove_SetPosition( objBoss, stgx, 120 );
	PlaySound("SpellStart",100,0);
	SetCommonData("Scroll",1);
	SetCommonData("ForceLifebar",1);
	wait( 30 );
	BlindBackground;
	wait( 120 );
	SetCommonData("ForceLifebar",0);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,7);
	Cutin("'Evanescent Existence'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	wait( 175 );
	TShot1;
	}
//----------------------------------------------------

task TShot1
{
	if( ObjEnemy_GetInfo( objBoss, INFO_LIFE ) == 1 ){ DeleteShotAll( TYPE_ALL, TYPE_IMMEDIATE ); }
	let r = 70;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;
	PatternWing;
	PlaySound("LenenLaserDelayLong",92,0);
	wait( 100 );

	Pattern1;
	wait( 100 );
              	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 2000){
	if((ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 2000)){ 
             	ObjMove_SetDestAtWeight( objBoss, 20, rand( 110, 150 ), 6, 6 );
	}
	Pattern11;
	loop( 180 ){
	yield;
	if((ObjEnemy_GetInfo(objBoss, INFO_LIFE) < 2000)){ break; }
	}
	if((ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 2000)){ 
	ObjMove_SetDestAtWeight( objBoss, GetStgFrameWidth - 20, rand( 110, 150 ), 6, 6 );
	}
	Pattern11;
	loop( 180 ){
	yield;
	if((ObjEnemy_GetInfo(objBoss, INFO_LIFE) < 2000)){ break; }
	}
	DamageRateAtFrame(90,0,0);
	}

	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 2000){ yield; }
	PlaySound("Pause",92,0);
	DeleteShotAll( TYPE_ALL, TYPE_ITEM );
	DamageRateAtFrame(0,0,0);
	wait( 30 );
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,7);
	wait( 120 );

	DamageRateAtFrame(14,0,0);
	Pattern2;
	SheliaCheck;
	wait( 100 );
	Pattern21;

	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 1000){ yield; }
	PlaySound("Pause",92,0);
	DeleteShotAll( TYPE_ALL, TYPE_ITEM );
	DamageRateAtFrame(0,0,0);
	wait( 50 );

	DamageRateAtFrame(30,0,0);
	Pattern3;
	Move;
}

let blind = GCSD~"img/Blind.png";

task BlindBackground(){ 
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,25);
	ObjPrim_SetTexture(obj,blind);
	ObjSprite2D_SetSourceRect(obj,0,0,384,448);
	ObjSprite2D_SetDestRect(obj,-384,-448,384,448);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,384/2,448/2,0);
	dDelete( obj );
	Appearing( obj );
	while( !Obj_IsDeleted(objBoss) && bSpell == false){
	/*descent( x in 0..255 ){
	ObjRender_SetColor(obj,x,x,x);
	yield;
	}
	wait( 30 );
	ascent( x in 0..255 ){
	ObjRender_SetColor(obj,x,x,x);*/
	yield;
	//}
	//wait( 30 );
	}
	Obj_Delete(obj);
}

	task Appearing( obj ){
	ascent( i in 0..255/2 ){
	ObjRender_SetAlpha( obj, i*2 );
	yield;
	}
	ObjRender_SetAlpha( obj, 255 );
	}	

	task dDelete( obj ){
	while( !Obj_IsDeleted( objBoss )){ yield; }
	Obj_Delete( obj );
	}

             task PatternWing{
             while( !Obj_IsDeleted( objBoss )){ 
             let angle1 = 0;
             let angle2 = 180;
             let speed1 = 10;
             loop( 20 ){

	                                let way = 1;
                                                    let shote = 129;
		            let delay = 0;

			loop( way ){

				let sx = ObjMove_GetX( objBoss );
				let sy = ObjMove_GetY( objBoss );
				
				let sht1 = CreateLooseLaserA1( sx, sy, speed1, angle1, 150, 18, shote, delay );
				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				ObjRender_SetColor( sht1, 0, 0, 0 );
				let sht2 = CreateLooseLaserA1( sx, sy, speed1, angle2, 150, 18, shote, delay );
				ObjRender_SetBlendType( sht2, BLEND_ALPHA );
				ObjRender_SetColor( sht2, 0, 0, 0 );

				angle1 += 360 / way;
				angle2 += 360 / way;

			}
			//PlaySound("LenenShot1",92,0);
			angle1 += 2.5;
			angle2 -= 2.5;
			wait( 1 );
	}
             let speed2 = 10;
             loop( 20 ){

	                                let way = 1;
                                                    let shote = 129;
		            let delay = 0;

			loop( way ){

				let sx = ObjMove_GetX( objBoss );
				let sy = ObjMove_GetY( objBoss );
				
				let sht1 = CreateLooseLaserA1( sx, sy, speed2, angle1, 150, 18, shote, delay );
				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				ObjRender_SetColor( sht1, 0, 0, 0 );
				let sht2 = CreateLooseLaserA1( sx, sy, speed2, angle2, 150, 18, shote, delay );
				ObjRender_SetBlendType( sht2, BLEND_ALPHA );
				ObjRender_SetColor( sht2, 0, 0, 0 );

				angle1 += 360 / way;
				angle2 += 360 / way;

			}
			//PlaySound("LenenShot1",92,0);
			angle1 -= 2.5;
			angle2 += 2.5;
			wait( 1 );
	}
             loop( 20 ){

	                                let way = 1;
                                                    let shote = 129;
		            let delay = 0;

			loop( way ){

				let sx = ObjMove_GetX( objBoss );
				let sy = ObjMove_GetY( objBoss );
				
				let sht1 = CreateLooseLaserA1( sx, sy, speed1, angle1, 150, 18, shote, delay );
				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				ObjRender_SetColor( sht1, 0, 0, 0 );
				let sht2 = CreateLooseLaserA1( sx, sy, speed1, angle2, 150, 18, shote, delay );
				ObjRender_SetBlendType( sht2, BLEND_ALPHA );
				ObjRender_SetColor( sht2, 0, 0, 0 );

				angle1 += 360 / way;
				angle2 += 360 / way;

			}
			//PlaySound("LenenShot1",92,0);
			angle1 -= 2.5;
			angle2 += 2.5;
			wait( 1 );
	}
             loop( 20 ){

	                                let way = 1;
                                                    let shote = 129;
		            let delay = 0;

			loop( way ){

				let sx = ObjMove_GetX( objBoss );
				let sy = ObjMove_GetY( objBoss );
				
				let sht1 = CreateLooseLaserA1( sx, sy, speed2, angle1, 150, 18, shote, delay );
				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				ObjRender_SetColor( sht1, 0, 0, 0 );
				let sht2 = CreateLooseLaserA1( sx, sy, speed2, angle2, 150, 18, shote, delay );
				ObjRender_SetBlendType( sht2, BLEND_ALPHA );
				ObjRender_SetColor( sht2, 0, 0, 0 );

				angle1 += 360 / way;
				angle2 += 360 / way;

			}
			//PlaySound("LenenShot1",92,0);
			angle1 += 2.5;
			angle2 -= 2.5;
			wait( 1 );
	}
	}
	}


              task Pattern1{ 
              while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 2000){

	                                let way = 40;
                                                    let shote = 49;
		            let delay = 0;
		            let angle = rand( 0, 360 );

			loop( way ){

			if((ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 2000)){
			
                                                    	let speed = 2.5;
                      	                    let sx = GetStgFrameWidth / 2;
                        		let sy = 0;
				
				let sht1 = TShotA2( sx, sy, speed+10, angle, -0.6, speed, shote, delay );
				//ObjMove_AddPatternA2( sht1, 0, NO_CHANGE, NO_CHANGE, 0, tt, NO_CHANGE );
				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				ObjRender_SetColor( sht1, 0, 0, 0 );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle -= rand( 300, 500 ) / way;
			}
			}
			if((ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 2000)){
			PlaySound("LenenShot1",92,0);
                        		wait( 20 );
			}

	}

   }

              task Pattern11{ 
	if((ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 2000)){
              PlaySound("Eff2",92,0);
              loop( 27 ){
              	let speed = 2.5;
	loop( 1 ){

              		            let angle = rand( 0, 360 );
	                                let way = 1;
                                                    let shote = 283;
		            let delay = 0;

			loop( way ){

			if((ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 2000)){
			
                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed + 8, angle, -0.6, speed, shote, delay );
				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				ObjRender_SetColor( sht1, 0, 0, 0 );
				Reflect( sht1, -2, 0, 2.5 );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle -= 360 / way;

			}
			}
			//speed -= 0.75;
			}
			if((ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 2000)){
			PlaySound("LenenShot1",92,0);
                        		wait( 2 );
			}

	}
	}

   }

              task Pattern2{ 
              while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 1000){
              let angle1 = rand( 0, 360 );
              let angle2 = angle1;
              loop( 3 ){

	                                let way = 30;
                                                    let shote = 299;
		            let delay = 0;

			loop( way ){

			if((ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 1000)){
			
                                                    	let speed = 3.5;
                      	                    let sx = GetStgFrameWidth / 2;
                        		let sy = 0;
				
				let sht1 = TShotA2( sx, sy, speed+10, angle1, -2, speed, shote, delay );
				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				ObjRender_SetColor( sht1, 0, 0, 0 );

				let sht2 = TShotA2( sx, sy, speed+10, angle2, -2, speed, shote, delay );
				ObjRender_SetBlendType( sht2, BLEND_ALPHA );
				ObjRender_SetColor( sht2, 0, 0, 0 );

				angle1 += 360 / way;
				angle2 += 360 / way;
			}
			}
			angle1 += 0.8;
			angle2 -= 0.8;
			PlaySound("LenenShot1",92,0);
			wait( 2 );
			}
                        		if( wait( 18 ) ){ return; }

	}

   }

             task Pattern21{
             while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 1000){
             let angle1 = 0;
             let angle2 = 180;
             let speed1 = 27.5;
             loop( 40 ){

	                                let way = 14;
                                                    let shote = 144;
		            let delay = 0;

			loop( way ){

			if((ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 1000)){

				let sx = GetStgFrameWidth / 2;
				let sy = 0;
				
				let sht1 = CreateLooseLaserA1( sx, sy, speed1, angle1, 300, 18, shote, delay );
				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				ObjRender_SetColor( sht1, 0, 0, 0 );
				let sht2 = CreateLooseLaserA1( sx, sy, speed1, angle2, 300, 18, shote, delay );
				ObjRender_SetBlendType( sht2, BLEND_ALPHA );
				ObjRender_SetColor( sht2, 0, 0, 0 );

				angle1 += 360 / way;
				angle2 += 360 / way;
			}
			}
			PlaySound("LenenShot1",92,0);
			angle1 += 2.8;
			angle2 -= 2.8;
			wait( 3 );
	}
	wait( 180 );
	}
	}

              task Pattern22( obj ){ 

              			let speed = 4;
                                                	let shote = 33;
			let angle = GetAngleToPlayer( obj );//ObjMove_GetAngle( obj );

                      	                	let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				
			let sht1 = TShotA2( sx, sy, 0, angle, 0.02, speed, shote, 0 );
			ObjRender_SetBlendType( sht1, BLEND_ALPHA );
			ObjRender_SetColor( sht1, 0, 0, 0 );

			Obj_Delete( obj );
   }

              task Pattern3{ 
	while( !Obj_IsDeleted( objBoss )){

			loop( round( rand( 1, 2 )) ){

              			let speed = 4.8;
                                                	let shote = [ 33, 307, 275, 299 ];
			let angle = rand( 0, 360 );

                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
			let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote[ round( rand( 0, 3 ))], 0 );
			ObjRender_SetBlendType( sht1, BLEND_ALPHA );
			ObjRender_SetColor( sht1, 0, 0, 0 );
			}

			wait( 1 );
			PlaySound("LenenShot1",92,0);
			}
   }

	task Move{
	while( !Obj_IsDeleted( objBoss )){
	TMovement( 120, 10, 6 );
	wait( 50 );
	}
	}

             task SheliaCheck{
	while((ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 1000)){	
            	let shotarray = GetShotIdInCircleA2( GetPlayerX, GetPlayerY, rand( 120, 100 ), TARGET_ALL );
             	ascent( i in 0..length( shotarray )){
             	if( ObjShot_GetImageID( shotarray[ i ] ) == 144 ){ Pattern22( shotarray[ i ] ); }
                                                                   }
		yield;
	              }
	}

	task Reflect( obj, acceleration, angular, v ){
	while( !Obj_IsDeleted( obj ) && ObjMove_GetX( obj ) > 0 && ObjMove_GetX( obj ) < GetStgFrameWidth && ObjMove_GetY( obj ) > 0 ){ yield; }

   	if(ObjMove_GetX(obj)<0 || ObjMove_GetX(obj)>GetStgFrameWidth)
   	{ ObjMove_AddPatternA2( obj, 0, NO_CHANGE, 180-ObjMove_GetAngle( obj ), acceleration, angular, v ); }

   	if( ObjMove_GetY( obj ) < 0 )
   	{ ObjMove_AddPatternA2( obj, 0, NO_CHANGE, -ObjMove_GetAngle( obj ), acceleration, angular, v ); }

	PlaySound("LenenBulletWave",70,0);

}

	task StartCountDown
	{
		wait((130*60) - (10*60));
		loop(10)
		{
			PlaySound("time",100,0);
			wait(60);
		}

	}


//----------------------------------------------------

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		EndBoss(1);
		yield;
		CloseScript(GetOwnScriptID());
	}