#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["YukariS7"]
#Text["Photon 'Doppler Effect', 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);
SetCommonData("Bomb",1);
}

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

//----------------------------------------------------
task mainTask{
	StartCountDown;
	YukariCircle(objBoss,1,-1);
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy - 80,10,7);
	Cutin("Photon 'Doppler Effect'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "Butterfly.mp3");
	wait(120);
	TShot1;
	wait(400);
	DamageRateAtFrame(26,10,200);
	}
//----------------------------------------------------

task TShot1
{
	//ObjPlayer_ClearIntersection(GetPlayerObjectID);
	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);
                	let sht = TShotA2( stgx, stgy - 80, 0, 0, 0, 0, 1, 0 );
	ObjShot_SetSpellResist( sht, true );
	ObjRender_SetAlpha( sht, 0 );
	PatternLoop( sht );

	task PatternLoop( sht ){ 
	while( !Obj_IsDeleted( objBoss )){
		PatternLoop1( sht );
		wait( 860 + 150 + 210 );
		PatternLoop2( sht );
		wait( 860 + 150 + 210 );
		}
	}

	task PatternLoop1( sht ){
	loop( 1 ){
		PatternPhoton( sht );
		PatternPhoton2( sht );
		wait( 860 );
			PatternPhoton3;
			EdgeWarpingA(objBoss,1);
			ObjMove_AddPatternA2( objBoss, 0, 0, 0, 0.02, 0, 3 );
		wait( 148 );
            			PlaySound("WarpRight",92,0);
			ObjMove_SetDestAtWeight( objBoss, stgx,stgy - 80, 20, 2.5 );
		wait( 212 );
		}	
	}

	task PatternLoop2( sht ){
	loop( 1 ){
		PatternPhoton( sht );
		PatternPhoton2( sht );
		wait( 860 );
			PatternPhoton3;
			EdgeWarpingB(objBoss,1);
			ObjMove_AddPatternA2( objBoss, 0, 0, 180, 0.02, 0, 3 );
		wait( 148 );
            			PlaySound("WarpLeft",92,0);
			ObjMove_SetDestAtWeight( objBoss, stgx,stgy - 80, 20, 2.5 );
		wait( 212 );
		}	
	}
}


              task PatternPhoton( sht ){ 
              loop( 15 ){

	                                	let way = 22;
                                                	let shote = 858;
              			let angle = rand( 0, 360 );
			let delay = 0;

			loop( way ){
                      	                	let sx = ObjMove_GetX( sht );
                        		let sy = ObjMove_GetY( sht );
				
				let sht1 = TShotA2( sx, sy, 2, angle, 0, 2, shote, delay );

				ObjectRotation2( sht1, sht, 0, 600, angle, 2.1, 0.5, 0, 0, 0.5 );

				EdgeWarpingA(sht1,1);

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

				angle += 360 / way;

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

	}

   }

              task PatternPhoton2( sht ){ 
              loop( 7 ){

	                                	let way = 22;
                                                	let shote = 856;
              			let angle = rand( 0, 360 );
			let delay = 0;

			loop( way ){

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

				ObjectRotation2( sht1, sht, 0, 600, angle, 1, -0.5, 0, 0, -0.5 );

 				EdgeWarpingA(sht1,1);

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

				angle += 360 / way;

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

	}

   }

              task PatternPhoton3{ 
              let way = 21;
              loop( 22 ){

			let speed = 3.75;
                                                	let shote = 860;
              			let angle = rand( 0, 360 );
			let delay = 0;

			loop( way ){
                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, 0, angle, 0.1, speed, shote, delay );

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

				angle += 360 / way;

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

	}

   }

task EdgeWarpingA(obj,time)
{
        let count = 0;
        while(!Obj_IsDeleted(obj) )
        {
            if(count==time){break;}
            
            if(ObjMove_GetX(obj)>GetStgFrameWidth+20){ObjMove_SetX(obj,-20);yield;count++;}
            yield;
        }
}

task EdgeWarpingB(obj,time)
{
        let count = 0;
        while(!Obj_IsDeleted(obj) )
        {
            if(count==time){break;}
            
            if(ObjMove_GetX(obj)<-20){ObjMove_SetX(obj,GetStgFrameWidth+20);yield;count++;}
            yield;
        }
}

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

	PlaySound("LenenBulletWave",70,0);

}

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


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

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

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

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