#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["YukariS3"]
#Text["Barrier 'Yakumo Nest', Yukari's SWR 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(1200);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(90);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(40000000);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
                //ObjPlayer_ClearIntersection(GetPlayerObjectID);
	YukariCircle(objBoss,1,-1);
	ObjMove_SetDestAtWeight(objBoss,stgx,140,10,7);
	Cutin("Barrier 'Yakumo Nest'",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(80);
	let r = 70;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;
	maple;
	wait(80);
	PatternNest1;
	wait( 200 );
	DamageRateAtFrame(30,10,60);
}
               task PatternNest1{ 
               let sx = ObjMove_GetX( objBoss );
               let sy = ObjMove_GetY( objBoss );
               while( !Obj_IsDeleted( objBoss )){

	                                	let way = 6;
                                                	let shote = 1007;
              			let angle = rand( 0, 360 );
			let delay = 180;
			let length = 500;
			let width = 20;
			let duration = 500;

			loop( way ){
				
				let sht1 = CreateStraightLaserA1( sx, sy, angle, length, width, duration, shote, delay );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );
				PatternNest2( sht1, way );

				ObjectRotationStopType( sht1, objBoss, 0, 0, angle, 0, 10, 0, -0.07 );
				ObjLaser_SetIntersectionWidth( sht1, 16 );

				ClosingCurtain( sht1, 660, width, -0.01 );

				angle += 360 / way;

			}
			PlaySound("Laser2",92,0);
                       		wait( 720 );

	}

   }

              task PatternNest2( sht1, way ){ 
              wait( 220 );
              loop( 2 ){
              			let speed = 2.2;
                                                	let shote = 1;
              			let angle = ObjStLaser_GetAngle( sht1 );
			let delay = 0;
			let sht2;

			loop( way ){

                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				sht2 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjShot_SetSpellResist( sht2, true );
				ObjRender_SetAlpha( sht2, 0 );

				angle += 360 / way;

			}

			PatternNest3( sht2 );
			PatternNest4( sht2 );
                       		wait( 100 );

	}

   }

              task PatternNest3( sht2 ){ 
              let angle1 = ObjMove_GetAngle( sht2 ) + 120;
              let angle2 = ObjMove_GetAngle( sht2 ) - 120;
              while( !Obj_IsDeleted( sht2 )){
              loop( 2 ){

              			let speed = 2.4;
	                                	let way = 1;
                                                	let shote = 55;
			let delay = 0;
			let length = 140;
			let width = 14;

			loop( way ){
                      	                	let sx = ObjMove_GetX( sht2 );
                        		let sy = ObjMove_GetY( sht2 );
				
				let sht3 = CreateLooseLaserA1( sx, sy, speed, angle1, length, width, shote, delay );
				let sht4 = CreateLooseLaserA1( sx, sy, speed, angle2, length, width, shote, delay );

				angle1 += 360 / way;
				angle2 += 360 / way;

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

	}

   }

              task PatternNest4( sht2 ){ 
              wait( 60 );
              loop( 2 ){

              			let angle = rand( 0, 360 );
	                               	let way = 6;
                                                	let shote = 294;
			let delay = 20;

			loop( way ){
              			let speed = rand( 0.4, 1.2 );
                      	                	let sx = ObjMove_GetX( sht2 );
                        		let sy = ObjMove_GetY( sht2 );
				
				let sht8 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				NotifyEventAll( EV_USER + 40, [ sht8, delay ] );

				angle += 360 / way;

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


	}

   }

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

   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; }

      angle += av;
      av += aav;

      if( av < 0 ){ aav = 0; av = 0; }

      yield;
   }
}

task ClosingCurtain( obj, t, width, speed ){
wait( t );
descent(i in 0..width){
ObjLaser_SetRenderWidth( obj, i );
ObjLaser_SetIntersectionWidth( obj, i );
width -= speed;
yield;
}
}

	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());
	}