#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["YukariS6"]
#Text["Evil Spirits 'Manji-Parasol of Yakumo', Yukari's IaMP Spell Card."]
#Player["./Hecatia/Hecatia.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);
}

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

//----------------------------------------------------
task mainTask{
	StartCountDown;
	//ObjPlayer_ClearIntersection(GetPlayerObjectID);
	YukariCircle(objBoss,1,-1);
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy-80,10,7);
	Cutin("Evil Spirits 'Manji-Parasol of Yakumo'",14,"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(120);
	let r = 70;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;
	maple;
	wait( 80 );
	PatternParasol;
	DamageRateAtFrame(28,10,200);
}

	task PatternParasol{
	while( !Obj_IsDeleted( objBoss )){
	PatternParasolF;
	wait( 690 );
	maple;
	wait( 90 );
	}
	}

               task PatternParasolF{ 
               let sx = ObjMove_GetX( objBoss );
               let sy = ObjMove_GetY( objBoss );
               let sht3 = TShotA2( sx, sy, 0, 0, 0, 0, 786, 0 );
               loop( 1 ){

	                                	let way = 4;
                                                	let shote = 55;
              			let angle = rand( 0, 360 );
			let delay = 180;
			let length = 122;
			let width = 50;
			let duration = 50000000;

			loop( way ){

				let sht0 = TShotA2( sx, sy, 0, angle, 0, 0, 786, 0 );
				let sht1 = CreateStraightLaserA1( sx, sy, angle, length, width, duration, shote, delay );
				let sht2 = CreateStraightLaserA1( sx, sy, angle, length, width, duration, shote, delay );

				ObjectRotation( sht0, sht3, length, length, angle, 0, 0, 0, 0.02, 10 );

				ObjectRotation( sht1, sht3, 0, 0, angle, 0, 0, 0, 0.02, 10 );
				ObjLaser_SetIntersectionWidth( sht1, 1 );

				ObjectRotation2( sht2, sht3, length, length, angle, 0, 0, 0, 0.02, 10 );
				ObjLaser_SetIntersectionWidth( sht2, 1 );

               				ObjShot_SetSpellResist( sht0, true );
               				ObjShot_SetSpellResist( sht3, true );

               				ObjShot_SetAutoDelete( sht0, false );
               				ObjShot_SetAutoDelete( sht1, false );
               				ObjShot_SetAutoDelete( sht2, false );
               				ObjShot_SetAutoDelete( sht3, false );

				DelayDeletes( 900, sht0 );
				DelayDeletes( 900, sht1 );
				DelayDeletes( 900, sht2 );
				DelayDeletes( 900, sht3 );

				angle += 360 / way;
			}
			
			WaitForAddA2( sht3, 500 );
			PatternParasolSub1( sht3 );
			PatternParasolSub2( sht3 );
			PlaySound("Laser2",92,0);

	}

   }

task DelayDeletes( time, obj ){
wait( time );
Obj_Delete( obj );
}


	task WaitForAddA2( obj, t ){
	wait( t );
	ObjMove_AddPatternA2( obj, 0, 0, GetAngleToPlayer( objBoss ), 0.01, 0, 2.2 );
	PlaySound("Boon1",92,0);
	}

	function GetDotAngle(x1,y1,x2,y2){
	let angle=atan2(y1-y2,x1-x2);
	return angle;
	}


              task PatternParasolSub1( sht3 ){ 
              wait( 250 );
              while( !Obj_IsDeleted( sht3 )){

              			let speed = rand( 0.8, 2.6 );
	                                	let way = 1;
                                                	let shote = 294;
              			let angle = rand( 0, 360 );
			let delay = 30;

			loop( way ){
			let r = rand( 15, 130 );
                      	                	let sx = ObjMove_GetX( sht3 ) + r*cos( angle );
                        		let sy = ObjMove_GetY( sht3 ) + r*sin( angle );
				
				let sht1 = TShotA2( sx, sy, 6, angle, -1.5, speed, shote, delay );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

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

	}

   }


              task PatternParasolSub2( sht3 ){ 
              while( ObjMove_GetX( sht3 ) > 60 && ObjMove_GetX( sht3 ) < GetStgFrameWidth - 60 && ObjMove_GetY( sht3 ) > 60 && ObjMove_GetY( sht3 ) < GetStgFrameHeight - 60 ){ yield; }
	
              let speed = 1;
              let angle = rand( 0, 360 );
              loop( 3 ){

	                                	let way = 35;
                                                	let shote = 292;
			let delay = 20;

			loop( way ){
			let r = 125;
                      	                	let sx = ObjMove_GetX( sht3 ) + r*cos( angle );
                        		let sy = ObjMove_GetY( sht3 ) + r*sin( angle );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
			speed -= 0.08;
			PlaySound("LenenShot1",92,0);

	}
	


   }


task ObjectRotation( obj, target, rstart, rmax, angle, ad, av, aad, aav, avmax ){

   let ox;
   let oy;
   let r = rstart;
   while(!Obj_IsDeleted(obj)){

      ox = ObjMove_GetX( target ) + r*cos( angle );
      oy = ObjMove_GetY( target ) + r*sin( angle );

      ObjMove_SetPosition(obj,ox,oy);
      ObjStLaser_SetAngle(obj,angle);

      if(r < rmax){
      r += ad;
      ad += aad; }

      if(r > rmax){
      r -= ad;
      ad += aad; }

      if( av < avmax ){
      angle += av;
      av += aav; }

      if( av > avmax ){
      angle += avmax; }

      yield;
   }
}

task ObjectRotation2( obj, target, rstart, rmax, angle, ad, av, aad, aav, avmax ){

   let ox;
   let oy;
   let r = rstart;
   while(!Obj_IsDeleted(obj)){

      ox = ObjMove_GetX( target ) + r*cos( angle );
      oy = ObjMove_GetY( target ) + r*sin( angle );

      ObjMove_SetPosition(obj,ox,oy);
      ObjStLaser_SetAngle(obj,angle - 90);

      if(r < rmax){
      r += ad;
      ad += aad; }

      if(r > rmax){
      r -= ad;
      ad += aad; }

      if( av < avmax ){
      angle += av;
      av += aav; }

      if( av > avmax ){
      angle += avmax; }

      yield;
   }
}

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