
#ScriptVersion[3]
#Title["SeiranN3"]
#Text["SeiranN3"]
#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 objScene=GetEnemyBossSceneObjectID();
let color = [0,0];
@Initialize
{
SetCommonData("Scroll",0);
SetBoss("Yukari",false);
}

@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(4400);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(85);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
                //ObjPlayer_ClearIntersection(GetPlayerObjectID);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,5,6);
	magiccircle(objBoss,1,-1);
	SetCommonData("Scroll",1);
	NotifyEventAll(EV_SET_SONG,1);
	wait(60);
	wait(90);
	TShot1;
	yield;

	}

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

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;
	maple;
	wait(80);
	WayWave2;
	wait( 240 );
	PatternMovingBeat;
	TTrail;
	DamageRateAtFrame(160,20,0);
	PatternMovingBeat;
}


              task PatternMovingBeat{
              while( !Obj_IsDeleted( objBoss )){
              	TMovement(30,30,2);
              	wait( 350 );
		}
	}

              task WayWave{
              let way = 4;
              let angle2 = GetAngleToPlayer( objBoss );
              loop( way ){
	PatternEagle( angle2 );
	angle2 += 360 / way;
	}
               }

              task PatternEagle( angle2 ){
              let e = angle2 + 6/2;
              let sx = ObjMove_GetX( objBoss );
              let sy = ObjMove_GetY( objBoss );
               let speed = 1;
              ascent(i in 0..(25)){

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

                }
}

              task WayWave2{
              let way = 4;
              let shote = [ 117, 119, 121, 123, 125, 127, 115 ];
              let c = 0;
              while(!Obj_IsDeleted( objBoss )){
	let angle2 = GetAngleToPlayer( objBoss );
              loop( way ){
	PatternEagle2( angle2, shote[c%length( shote )] );
	angle2 += 360 / way;
	}
	c++;
	wait( 350 );
	}
               }

              task PatternEagle2( angle2, shote ){
              let e = angle2 + 3/2;
              let sx = ObjMove_GetX( objBoss );
              let sy = ObjMove_GetY( objBoss );
               let speed = 2;
               let x = 0;
              ascent(i in 0..(20)){

                        let way = i;
                        let delay = 20;
                        let t = x;
                        ascent(j in 0..way){
 
                                let angle = e+j*t-i*t/2;
                                let sht = TShotA2( sx, sy, speed+7, angle, -0.8, speed, shote, delay );
	            //ObjMove_AddPatternA2( sht, 20, NO_CHANGE, NO_CHANGE, 0.02, 0, 2.5 );
	            //angular( sht, 0.3, 0, 150 );
                                NotifyEventAll( EV_USER + 40, [ sht, delay ] );
                        }
	    x += rand( 0.8, 0.9 );
	    speed -= 0.02;
                        PlaySound("LenenShot1",92,0);
                        wait( 10 );

                }
}

              task TTrail{             
              let time = 10;
              while(!Obj_IsDeleted( objBoss )){
              loop( time ){
	PatternTrail;
	wait( 10 );
	}
	wait( 250 );
	}
               }

              task PatternTrail{ 
              let speed = 6;
              let angle = GetAngleToPlayer( objBoss );
              let sx = ObjMove_GetX( objBoss ) + rand( -120, 120 );
              let sy = ObjMove_GetY( objBoss ) + rand( -30, 30 );
              loop( 12 ){
	                                	let way = 1;
                                                	let shote = 310;
			let delay = 20;

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

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

	}

   } 

task angular( obj, ang, t, time ){
wait( t );
ObjMove_SetAngularVelocity( obj, ang );
wait( time );
ObjMove_SetAngularVelocity( obj, 0 );
}

	task ReflectAndChange( obj, acceleration, angular, v, shot ){
	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_AddPatternA3( obj, 0, NO_CHANGE, 180-ObjMove_GetAngle( obj ), acceleration, angular, v, shot ); }

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

	PlaySound("LenenBulletWave",70,0);

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



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

task SizeCircle
{
	ascent(i in 0..60)
	{
		SetCommonData("CircleSize",sin(i*1.5));
		yield;
	}
}	

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

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