#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["DoremyN4"]
#Text["DoremyN4"]
#Player[DEFAULT]
#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 objScene=GetEnemyBossSceneObjectID();
let color = [0,0];
@Initialize
{
SetCommonData("Scroll",0);
SetBoss("Doremy",false);
}

@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(5000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(65);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,10);
	SetCommonData("CircleSize",0);
	magiccircle(objBoss,1,-1);
	SetCommonData("Scroll",1);
	NotifyEventAll(EV_SET_SONG,1);
	wait(60);
	SizeCircle;
	wait(90);
	TShot1;
	DamageRateAtFrame(100,50,60);
	yield;
	}

//----------------------------------------------------

task TShot1
{
	attack(30,1);
	let r = 70;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;
	maple;
	wait(90);

                PatternCleansedReflection1;
                PatternCleansedReflection2;
                wait( 300 );
                PatternMove;

              task PatternMove{
              loop( 100 ){
              TMovement(50,15,4);
              if( wait( 300 )){ return; }
              }
              }

              task PatternCleansedReflection1{ 
              let angle1 = rand( 0, 360 );
              let angle2 = rand( 0, 360 );
              loop( 10000000000 ){

	                                let way = 2;
			let speed1 = 2.6;
			let shote1 = 277;
			let delay = 20;

			loop( way ){

                                                let r = 100;

                      	                let sx = ObjMove_GetX( objBoss ) + r*cos( angle1 );
                        		let sy = ObjMove_GetY( objBoss ) + r*sin( angle1 );
				
				let sht1 = TShotA2( sx, sy, speed1, angle2, 0, speed1, shote1, delay );

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

				angle2 += 360 / way;
			}
                                                angle1 += 30;
                                                angle2 += 1;
			PlaySound("Shot1",92,0);

                        if( wait( 3 ) ){ return; }

	}
}

              task PatternCleansedReflection2{ 
              let angle1 = rand( 0, 360 );
              let angle2 = rand( 0, 360 );

              loop( 1000000000 ){

	                                let way = 2;
			let speed = 1.5;
                                                let shote = 39;
			let delay = 20;

			loop( way ){

                                                let r = 100;

                      	                let sx = ObjMove_GetX( objBoss ) + r*cos( angle1 );
                        		let sy = ObjMove_GetY( objBoss ) + r*sin( angle1 );
				
				let sht1 = TShotA2( sx, sy, speed, angle2, 0, speed, shote, delay );

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

				angle2 += 360 / way;

			}
                                                angle1 += 26.33333;
                                                angle2 += 9;

			PlaySound("Shot1",92,0);

                        if( wait( 2 ) ){ return; }

	}

   }
  task CheckBounceManyTimesUpDownOnly(obj,time)
{
   while(!Obj_IsDeleted(obj) && ObjMove_GetX(obj)>0 && ObjMove_GetX(obj)<GetStgFrameWidth && ObjMove_GetY(obj)>0 && ObjMove_GetY(obj)<GetStgFrameHeight){yield;}

   if(ObjMove_GetY(obj)<0 || ObjMove_GetY(obj)>GetStgFrameHeight)
   {ObjMove_SetAngle(obj,-ObjMove_GetAngle(obj));}
 
   //ObjSound_Play( CreateShotSE[ 1 ] );
   time--;
   yield;
   if(time>0){CheckBounceManyTimesUpDownOnly(obj,time);}
}
}

//----------------------------------------------------

task SizeCircle
{
	ascent(i in 0..60)
	{
		SetCommonData("CircleSize",sin(i*1.5));
		yield;
	}
}	

//----------------------------------------------------

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		EndBoss(0);
		yield;
		CloseScript(GetOwnScriptID());
	}