#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SeiranS1"]
#Text["Real Battle 'Evil Portal'. A regular trick. Nothing special. Well, at least it's better than Junk o."]
#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 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("BGShow",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(30000000);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
                //ObjPlayer_ClearIntersection(GetPlayerObjectID);
	magiccircle(objBoss,1,-1);
	DamageRateAtFrame( 27,20,180 );
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy-110,5,7);
	Cutin("Real Battle 'Evil Portal'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "Butterfly.mp3");
	wait(150);
	TShot1;
	wait(1200);
	}
//----------------------------------------------------

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

              task PatternPortal{ 
              let c = 0;
              while( !Obj_IsDeleted( objBoss )){

			let man = [ 120, -120 ];
              			let speed = 2.2;
	                                	let way = 20;
                                                	let shote = 330;
              			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.02, speed, shote, delay );
				ObjRender_SetColor( sht1, 0, 0, 0 );
				ObjShot_SetSpellResist( sht1, true );
				//ObjShot_SetAutoDelete( sht1, false );

				//ObjectRotation( sht1, objBoss, 0, 1000, angle, 1, 3, 0, 0 );

				FlashyOrb(sht1, shote);

				PatternSub1( sht1, man[c%length(man)] );

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

				angle += 360 / way;

			}
			c++;
			speed += 0.25;
			PlaySound("Boon1",92,0);
			wait( 300 );
	}

   }

              task PatternSub1( core, man ){ 
              let speed = 0.2;
              while( !Obj_IsDeleted( core )){

	                                	let way = 1;
                                                	let shote = 118;
              			let angle = ObjMove_GetAngle( core ) + man;
			let delay = 20;

			loop( way ){

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

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

				angle += 360 / way;

			}
			//speed -= 0.05;
			PlaySound("LenenShot1",92,0);
			wait( 11 );
	}

   }
	task Add( obj ){
	wait( 150 );
	ObjMove_AddPatternA3( obj, 0, NO_CHANGE, NO_CHANGE, 0.02, 0, 1.5, 114 );
	 PlaySound("BulletWave",92,0);
	}

	task FlashyOrb( core, shot ){
	while( !Obj_IsDeleted( core )){
	FlashyOrb1( core, shot );
	wait( 10 );
	}
	}

	task FlashyOrb1(core, shot)
	{
		let obj = CreateShotOA1(core,0,0,shot,0);
		ObjShot_SetSpellResist(obj,true);
		ObjShot_SetIntersectionEnable(obj,false);
		ascent(i in 0..50)
		{
			ObjRender_SetScaleXYZ(obj,1-i/50,1-i/50,1-i/50);
			ObjRender_SetColor(obj,0,0,0);
			wait( 1 );
		}
		Obj_Delete(obj);
	}

task ObjectRotation( 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; }

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

      angle += av;
      av += aav;

      yield;

      
 
   }
}

              task PatternForbid{ 
              while( !Obj_IsDeleted( objBoss )){
              while( ObjMove_GetY( objPlayer ) < ObjMove_GetY( objBoss )){

              			let speed = 8;
	                                	let way = 4;
                                                	let shote = 613;
              			let angle1 = GetAngleToPlayer( objBoss );
              			let angle2 = GetAngleToPlayer( objBoss );
			let delay = 10;

			loop( way ){
                      	                	let sx = ObjMove_GetX( objBoss ) + rand( -20, 20 );
                        		let sy = ObjMove_GetY( objBoss ) + rand( -20, 20 );
				
				let sht1 = TShotA2( sx, sy, speed, angle1, 0, speed, shote, delay );
				let sht2 = TShotA2( sx, sy, speed, angle2, 0, speed, shote, delay );

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

				angle1 += 80 / way;
				angle2 -= 80 / way;

			}
			PlaySound("LenenShot3",92,0);
                        		wait( 1 );
	
}
	yield;
   }
}

	function GetGapAngle( pos1, pos2 ){
		return atan2( pos2[1]-pos1[1], pos2[0]-pos1[0] );
	}

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