#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SeiranS2"]
#Text["Flight 'Eagle Kamikaze'. Explosive trick. Looks like Junko's lilies. Except that it's not pure."]
#Player["./Reisen/Reisen.txt","./MoF_Reimu/Reimu.txt","./sanae/sane.txt","./Marisa/Marisa.txt"]
#Player["./MoF_Reimu/Reimu.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("Seiran",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(1250);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(90);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
	//ObjPlayer_ClearIntersection(GetPlayerObjectID);
	magiccircle(objBoss,1,-1);
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy-100,5,6);
	Cutin("Flight 'Eagle Kamikaze'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "Butterfly.mp3");
	wait( 120 );
	TShot1;
	}
//----------------------------------------------------

task TShot1
{
	if( ObjEnemy_GetInfo( objBoss, INFO_LIFE ) == 1 ){ DeleteShotAll( TYPE_ALL, TYPE_IMMEDIATE ); }
	attack( 80, 1 );
	maple;
	wait( 90 );
	DamageRateAtFrame(26,10,0);
	PatternPure;
}

	task PatternPure{
	while(!Obj_IsDeleted( objBoss )){
	PatternPureA;
	wait( 80 );
              	TMovement( 30, 4, 2 );
	wait( 80 );
	PatternPureA;
	wait( 80 );
              	TMovement( 30, 4, 2 );
	wait( 80 );
	PatternPureA;
	wait( 80 );
              	TMovement( 30, 4, 2 );
	wait( 80 );
	maple;
	wait( 80 );
	PatternPureB;
	wait( 240 );
              	TMovement( 30, 4, 2 );
	wait( 80 );
	}
	}
	

              task PatternPureB{ 
			let speed = 3.8;
	                                	let way = 5;
                                                	let shote = 855;
              			let angle = GetAngleToPlayer( objBoss );
			let delay = 20;

			loop( way ){

                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht2 = TShotA2( sx, sy, speed-0, angle - 48, 0, speed-0, shote, delay );

				ObjRender_SetBlendType( sht2, BLEND_ALPHA );
				ObjRender_SetColor( sht2, 0, 0, 0 );

				FlashyOrb( sht2, shote );

				Impure( sht2 );				

				NotifyEventAll( EV_USER + 40, [ sht2, delay ] );

				angle += 360 / way;

				wait( 2 );

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

   }

              task PatternPureA{ 

              			let angle2 = rand( 0, 360 );
			let speed = 3.8;
	                                	let way = 1;
                                                	let shote = 855;
              			let angle = GetAngleToPlayer( objBoss );
			let delay = 20;

			loop( way ){

                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				//ObjMove_AddPatternA2( sht1, 0, NO_CHANGE, NO_CHANGE, 0, 1.3, NO_CHANGE );
				//let sht2 = TShotA2( sx, sy, speed, angle + 4, 0, speed, shote, delay );

				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				ObjRender_SetColor( sht1, 0, 0, 0 );

				FlashyOrb( sht1, shote );

				Impure( sht1 );
				//Impure( sht2, angle2 );				


				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );
				//NotifyEventAll( EV_USER + 40, [ sht2, delay ] );


				angle += 360 / way;

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

   }

              /*task PatternImpure( obj, angle, angle2 ){
              loop( 1 ){
			let speed = -0.5;
	                                	let way = 1;
                                                	let shote = 855;
			let delay = 20;

			loop( way ){

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

				FlashyOrb( sht1, shote );

				PatternBulletPillar( sht1, angle2 );
	
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

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

	}

   }*/

              task PatternBulletPillar( obj, angle ){ 
              //wait( 20 );
              loop( 1 ){

	                                	let way = 20;
                                                	let shote = 276;
			let delay = 0;
			let speed = 2.2;

			loop( way ){

                      	                	let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				
				let sht1 = TShotA2( sx, sy, speed+6, angle, -0.5, speed, shote, delay );
				ObjMove_AddPatternA2( sht1, 180, NO_CHANGE, NO_CHANGE, 0.01, 0, 3 );

				//Impure( sht1 );
	
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

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

	}

   }

              task WayWave( obj, angle1 ){
              let way = 8;
              loop( way ){
	PatternBulletPillar2( obj, angle1 );
	angle1 += 360 / way;
	}
               }


              task PatternBulletPillar2( obj, angle1 ){ 
              let e = angle1 + 4/2;
              let sx = ObjMove_GetX( obj );
              let sy = ObjMove_GetY( obj );
              let speed = 1.8;
              ascent(i in 0..7){

                        let way = i;
                        let shote = 119;
                        let delay = 10;
                        let t = 4;
                        ascent(j in 0..way){
 
                                let angle = e+j*t-i*t/2;
                                let sht = TShotA2( sx, sy, speed+5, angle, -0.4, speed, shote, delay );
	            ObjMove_AddPatternA2( sht, 180, NO_CHANGE, NO_CHANGE, 0.01, 0, 3 );
                                NotifyEventAll( EV_USER + 40, [ sht, delay ] );
                        }
	    speed -= 0.115;
                        PlaySound("Eff2",92,0);
                        wait( 0 );

                }
}

              task PatternBulletPillar3( obj ){ 
              let speed = 1;
              loop( 30 ){
              			let angle = rand( 0, 360 );
	                                	let way = 1;
                                                	let shote = 19;
			let delay = 0;

			loop( way ){

                      	                	let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjMove_AddPatternA2( sht1, 180, NO_CHANGE, NO_CHANGE, 0.01, 0, 3 );
	
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

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

	}

   }

	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_SetBlendType( obj, BLEND_ALPHA );
			ObjRender_SetColor(obj,0,0,0);
			wait( 1 );
		}
		Obj_Delete(obj);
	}

	task Impure(obj)
{
	while( !Obj_IsDeleted( obj ) && ObjMove_GetX( obj ) > 0 && ObjMove_GetX( obj ) < GetStgFrameWidth && ObjMove_GetY( obj ) > 0 && ObjMove_GetY( obj ) <  GetStgFrameHeight ){ yield; }

   	if(ObjMove_GetX( obj ) < 0 )
   	{ ObjMove_AddPatternA2( obj, 0, 0, NO_CHANGE, 0.01, 0, 1 ); PatternBulletPillar( obj, 0 ); WayWave( obj, GetAngleToPlayer( obj ) ); PatternBulletPillar3( obj ); }

   	if(ObjMove_GetX( obj ) > GetStgFrameWidth )
   	{ ObjMove_AddPatternA2( obj, 0, 0, NO_CHANGE, 0.01, 0, 1 ); PatternBulletPillar( obj, 180 ); WayWave( obj, GetAngleToPlayer( obj ) );  PatternBulletPillar3( obj );}

   	if( ObjMove_GetY( obj ) < 0 )
   	{ ObjMove_AddPatternA2( obj, 0, 0, NO_CHANGE, 0.01, 0, 1 ); PatternBulletPillar( obj, 90 ); WayWave( obj, GetAngleToPlayer( obj ) );  PatternBulletPillar3( obj );}

   	if(ObjMove_GetY( obj ) > GetStgFrameHeight )
   	{ ObjMove_AddPatternA2( obj, 0, 0, NO_CHANGE, 0.01, 0, 1 ); PatternBulletPillar( obj, 270 ); WayWave( obj, GetAngleToPlayer( obj ) );  PatternBulletPillar3( obj );}

	PlaySound("LenenBulletWave",70,0);

}


	task StartCountDown
	{
		wait((90*60) - (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());
	}