
#ScriptVersion[3]
#Title["SeiranN4"]
#Text["SeiranN4"]
#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);
	PatternCross;
	DamageRateAtFrame(120,20,0);
	wait( 135 );
	PatternMove;
}

	task PatternMove{
	while( !Obj_IsDeleted( objBoss )){
              	TMovement( 30, 6, 6 );
	wait( 90 );
	}
	}

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

              			let speed = 3;
	                                	let way = 40;
                                                	let shote = 309;
              			let angle1 = 200;
              			let angle2 = 20;
			let delay = 30;
			let x1 = ObjMove_GetX( objBoss );
			let x2 = ObjMove_GetX( objBoss );
			let y1 = ObjMove_GetY( objBoss ) + 400;
			let y2 = ObjMove_GetY( objBoss ) - 400;

			loop( way ){
			let r = 480;
                      	                	let sx1 = x1 + r*cos( angle1 );
                      	                	let sx2 = x2 + r*cos( angle2 );
                        		let sy1 = y1 + r*sin( angle1 );
                        		let sy2 = y2 + r*sin( angle2 );
				
				let sht1 = TShotA2( sx1, sy1, speed, angle1, 0, speed, shote, delay );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				let sht2= TShotA2( sx2, sy2, speed, angle2, 0, speed, shote, delay );
				NotifyEventAll( EV_USER + 40, [ sht2, delay ] );

				/*let sht3= TShotA2( sx1, sy + 800, speed, angle, 0, speed, shote, delay );
				NotifyEventAll( EV_USER + 40, [ sht3, delay ] );

				let sht4= TShotA2( sx2, sy + 800, speed, angle, 0, speed, shote, delay );
				NotifyEventAll( EV_USER + 40, [ sht4, delay ] );*/

				CheckBounceManyTimesUpDownOnly( sht1, 2, -0.005, 0 );
				CheckBounceManyTimesUpDownOnly( sht2, 2, -0.005, 0 );

				ReAngle( sht1, 0.5 );
				ReAngle( sht2, 0.5 );

				angle1 += 120 / way;
				angle2 += 120 / way;

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

	}

   }

task ReAngle( obj, speed ){
while( ObjMove_GetSpeed( obj ) > 0 ){ yield; }
ObjMove_AddPatternA3( obj, 0, speed, rand( 0, 360 ), 0, 0, speed, 310 );
}

  task CheckBounceManyTimesUpDownOnly(obj,time, acc, speed)
{
   while(!Obj_IsDeleted(obj) &&  ObjMove_GetY(obj) > 0 && ObjMove_GetY(obj)<GetStgFrameHeight){yield;}

   if(ObjMove_GetY(obj)<0 || ObjMove_GetY(obj)>GetStgFrameHeight)
   {ObjMove_AddPatternA2( obj, 0, NO_CHANGE, -ObjMove_GetAngle( obj ), acc, 0, speed );
   PlaySound( "LenenBulletWave", 92, 0 );}
 
   time--;
   yield;
   if(time>0){CheckBounceManyTimesUpDownOnly(obj,time, acc, speed);}
}
	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());
	}