#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SeiranS6"]
#Text["'Eagle Ravi of Lunatic Kingdom'. So, Was 'Eagle Ravi' a 'Legacy' ??"]
#Player["./Reisen/Reisen.txt","./MoF_Reimu/Reimu.txt","./sanae/sane.txt","./Marisa/Marisa.txt"]
#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("Yukari",true);
SetCommonData("BGShow",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(4000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(120);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(40000000);
	}
}

//----------------------------------------------------
task mainTask{
	ascent( i in 0..60 ){
	ObjRender_SetAlpha( objBoss, 255 - 60 + i );
	wait( 1 );
	}
	maple;
	wait(80);
	SetCommonData("ForceLifebar",0);
	StartCountDown;
                //ObjPlayer_ClearIntersection(GetPlayerObjectID);
	magiccircle(objBoss,1,-1);
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy-100,5,6);
	Cutin("'Eagle Ravi of Lunatic Kingdom'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "Butterfly.mp3");
	wait(105);
	TShot1;
	wait(1200);
	}
//----------------------------------------------------

task TShot1
{
	if( ObjEnemy_GetInfo( objBoss, INFO_LIFE ) == 1 ){ DeleteShotAll( TYPE_ALL, TYPE_IMMEDIATE ); }
	attack(70,1);
	let r = 70;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;
	Pattern;
	DamageRateAtFrame(50,10,60);
}

	task Pattern{
                	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 4000){ yield; }
	WayEagle;

                	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 3000){ yield; }
	maple2;
	WayEagle2;

                	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 2000){ yield; }
	maple2;
	PatternBullet4;

                	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 1000){ yield; }
	maple2;
	PatternBullet5;

	}

              task WayEagle{
              let angle2 = 90;
              let angle1 = 90;
              while(!Obj_IsDeleted( objBoss )){
              let way = 6;
              loop( way ){
	PatternEagle( angle2 );
	PatternEagle( angle1 );
	angle2 += 360 / way;
	angle1 += 360 / way;
	}
	angle2 += 5.5;
	angle1 -= 5.5;
	wait( 30 );
	}
               }

              task PatternEagle( ang ){
              let e = ang + 2/2;
              let sx = ObjMove_GetX( objBoss );
              let sy = ObjMove_GetY( objBoss );
              let speed = 1.8;
              ascent(i in 0..(4)){

                        let t = 2;
                        let way = i;
                        let shote = 115;
                        let delay = 10;
                        ascent(j in 0..way){
 
                                let angle = e+j*t-i*t/2;
                                let sht = TShotA2( sx, sy, speed+5, angle, -0.5, speed, shote, delay );
                                NotifyEventAll( EV_USER + 40, [ sht, delay ] );
                        }
	    //speed -= 0.1;
                        PlaySound("LenenShot1",92,0);
                        wait( 5 );

                }
}

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

                                              let speed = 0;
	                          let way = 1;
                                              let shote = 1;
              		      let angle = 0;
	                          let delay = 0;

			loop( way ){

                      	                    let sx1 = ObjMove_GetX( objBoss ) + rand( 100, 140 );
                      	                    let sx2 = ObjMove_GetX( objBoss ) - rand( 100, 140 );
                        		let sy = ObjMove_GetY( objBoss ) + rand( -30, 50 );
				
				let sht1 = TShotA2( sx1, sy, speed, angle, 0, speed, shote, delay );
				ObjRender_SetAlpha( sht1, 0 );
				DelayDelete( sht1, 1 );
                                			ObjShot_SetSpellResist( sht1, true );

				let sht2 = TShotA2( sx2, sy, speed, angle, 0, speed, shote, delay );
				ObjRender_SetAlpha( sht2, 0 );
				DelayDelete( sht2, 1 );
                                			ObjShot_SetSpellResist( sht2, true );

				PatternEagle3( GetAngleToPlayer( sht1 ), sx1, sy );
				PatternEagle3( GetAngleToPlayer( sht2 ), sx2, sy );

				angle += 360 / way;

			}
                        		if( wait( 70 ) ){ return; }

	}

   }

              task PatternEagle3( ang, sx, sy ){
              loop( 1 ){
              let way = 5;
              loop( way ){
	PatternEagle2( ang, sx, sy );
	ang += 360 / way;
	}
	wait( 1 );
	}
               }

              task PatternEagle2( ang, sx, sy ){
              let e = ang + 2/2;
              let speed = 1.7;
              ascent(i in 0..(6)){

                        let t = 2;
                        let way = i;
                        let shote = 117;
                        let delay = 10;
                        ascent(j in 0..way){
 
                                let angle = e+j*t-i*t/2;
                                let sht = TShotA2( sx, sy, speed+5, angle, -0.5, speed, shote, delay );
                                NotifyEventAll( EV_USER + 40, [ sht, delay ] );
                        }
                        PlaySound("LenenShot1",92,0);
                        wait( 8 );

                }
}

	task FlashyOrb( core, shot ){
	while( !Obj_IsDeleted( core )){
	FlashyOrb1( core, shot );
	wait( 10 );
	}
	}

	task FlashyOrb1(core, shot)
	{
		let obj = CreateShotOA1(core,0,0,shot,0);
		ObjShot_SetSpellResist(obj,true);
		ObjShot_SetIntersectionEnable(obj,false);
		ascent(i in 0..50)
		{
			ObjRender_SetScaleXYZ(obj,1+i/50,1+i/50,1+i/50);
			//ObjRender_SetAlpha( obj, 255 -i*5 );
			ObjRender_SetBlendType( obj, BLEND_ALPHA );
			ObjRender_SetColor(obj,0,0,0);
			wait( 1 );
		}
		Obj_Delete(obj);
	}

              task PatternBullet4{ 
              let speed = 2.2;
              while( !Obj_IsDeleted( objBoss )){

              			let angle = rand( 0, 360 );
	                                	let way = 30;
                                                	let shote = 278;
			let delay = 30;
                      	                	let sx1 = ObjMove_GetX( objBoss ) + rand( 140, 160 );
                      	                	let sx2 = ObjMove_GetX( objBoss ) - rand( 140, 160 );
                        		let sy = ObjMove_GetY( objBoss ) + rand( 40, 80 );

			loop( way ){
				
				let sht1 = TShotA2( sx1, sy, speed, angle, 0, speed, shote, delay );
				let sht2 = TShotA2( sx2, sy, speed, angle, 0, speed, shote, delay );
	
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );
				NotifyEventAll( EV_USER + 40, [ sht2, delay ] );

				angle += 360/way;
			}
			PlaySound("LenenShot1",92,0);
                       		wait( 90 );

	}

   }

              task PatternBullet5{ 
              let speed = 3;
              while( !Obj_IsDeleted( objBoss )){

              			let angle = 0;
	                                	let way = 20;
			let delay = 30;
			let shote = rand( 807, 814 );
			loop( way ){

				let r = 60;
                      	                		let sx = ObjMove_GetX( objBoss ) + r*cos( angle );
                        			let sy = ObjMove_GetY( objBoss ) + r*sin( angle );

				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
	
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360/way;
			}
			PlaySound("LenenShot1",92,0);
                       		wait( 20 );

	}

   }

	task StartCountDown
	{
		wait((60*60 + 60 + 80) - (10*60));
		loop(5)
		{
			PlaySound("time1",100,0);
			wait(60);
		}
		loop(5)
		{
			PlaySound("time2",100,0);
			wait(60);
		}
	}


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

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