#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["YukariS2"]
#Text["Magic Eye 'Laplace's Demon', Yukari's UoNL 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(1250);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(90);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
	//ObjPlayer_ClearIntersection(GetPlayerObjectID);
	YukariCircle(objBoss,1,-1);
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy-50,10,7);
	Cutin("Magic Eye 'Laplace's Demon'",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( 120 );
	maple;
	wait( 90 );
	PatternDemonEye;
	DamageRateAtFrame(26,10,0);
	wait( 990 );
	PatternSub;

}

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

              			let angle = rand( 0, 360 );
			let speed = 2;
	                                	let way = 16;
                                                	let shote = 293;
			let delay = 20;

			loop( way ){
			let r = 50;
                      	                	let sx = ObjMove_GetX( objBoss ) + r*cos( angle );
                        		let sy = ObjMove_GetY( objBoss ) + r*sin( angle );
				
				let sht1 = TShotA2( sx, sy, 0, angle, 0.01, speed, shote, delay );

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

				angle += 360 / way;

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

	}

   }

              task PatternDemonEye{ 
              while( !Obj_IsDeleted( objBoss )){
              loop( 1 ){

              			let angle1 = rand( 0, 360 );
			let speed = 0.25;
	                                	let way = 5;
                                                	let shote = 328;
			let shote2 = 277;
			let delay = 0;

			loop( way ){

			let r = rand( 60, 120 );
                      	                	let sx = ObjMove_GetX( objBoss ) + r*cos( angle1 );
                        		let sy = ObjMove_GetY( objBoss ) + r*sin( angle1 );
				
				let sht1 = TShotA2( sx, sy, speed, 0, 0, speed, shote, delay );
				ObjRender_SetAlpha( sht1, 255/2 + 30 );
              				ObjShot_SetIntersectionEnable( sht1, false );
				ObjShot_SetSpellResist( sht1, true );

				DarkAngle( sht1 , speed );

				let sht2 = TShotA2( sx, sy, speed, 0, 0, speed, shote2, delay );
				ObjRender_SetAlpha( sht2, 255/2 + 30 );
              				ObjShot_SetIntersectionEnable( sht2, false );
				ObjShot_SetSpellResist( sht2, true );

				DarkAngle( sht2 , speed );

				PatternShoot1( sht1, sht2 );

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

				angle1 += 360 / way;

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

	}
			wait( 810 );
              			TMovement(30,8,2);
                        		wait( 90 );
			attack( 90 );
			maple;
			wait( 90 );

	}
			

   }

task DarkAngle(obj,speed){
while(!Obj_IsDeleted(obj)){
	ObjMove_SetDestAtSpeed( obj, GetPlayerX, GetPlayerY, speed );
       	yield;
   	}
}

              task PatternShoot1( sht1, sht2 ){ 
              wait( 90 );
              loop( 40 ){

              			let angle = GetAngleToPlayer( sht1 );
			let speed = 4.8;
	                                	let way = 8;
                                                	let shote = 309;
			let delay = 20;

			loop( way ){

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

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

				angle += 360 / way;

			}
			PlaySound("BulletWave",92,0);
                        		wait( 5 );

	}
              loop( 8 ){
              let angle = GetAngleToPlayer( sht1 );
              loop( 5 ){

			let speed = 4.8;
	                                	let way = 8;
                                                	let shote = 309;
			let delay = 20;

			loop( way ){

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

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

				angle += 360 / way;

			}
			PlaySound("BulletWave",92,0);
                        		wait( 5 );

	}
	}

              let speed = 0.5;
              loop( 3 ){
              			let c = 0;
	                                	let way = 14;
                                                	let shote = [ 20, 212, 285 ];
			let delay = 20;
			let angle = rand( 0, 360 );

			loop( way ){

                      	                	let sx = ObjMove_GetX( sht1 );
                        		let sy = ObjMove_GetY( sht1 );
				
				let sht2 = TShotA2( sx, sy, 0, angle, 0.01, speed, shote[c%length(shote)], delay );

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

				angle += 360 / way;
				c += 1;
			}
			speed += 0.38;
			PlaySound("LenenShot1",92,0);

	}
			Obj_Delete( sht1 );
			Obj_Delete( sht2 );

   }

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