#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["DoremyN3"]
#Text["DoremyN3"]
#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
{
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(6200);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(80);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,10);
	magiccircle(objBoss,1,-1);
	wait(60);
	TShot1;
	DamageRateAtFrame(100,50,60);
	yield;
	}

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

task TShot1
{
                //ObjPlayer_ClearIntersection(GetPlayerObjectID);
	attack( 180,1 );
	let r = 0;
	let angle = rand( 0,80 );
	let dir = 0;
	let s = 1;
	maple;
	wait( 90 );
                Pattern4951;
				task Pattern4951{
			loop( 10000 ){
			PatternWhirlpool1;
			wait( 130 );
			TMovement(50,15,4);
			wait( 70 );
                                                PatternWhirlpool2;
			wait( 60 );
			TMovement(50,15,4);
			wait( 120 );
			TMovement(50,15,4);
			wait( 60 );
                                                PatternWhirlpool3;
                                                wait( 500 );
			maple;
			wait( 90 );
			if( wait( 0 )){ return; }
            }
}

              task PatternWhirlpool1{
              loop( 10 ){
	      loop( 50 ){
	                                let way = 1;
			let speed = 2.5;
			let angle = rand( 0, 360 );
			let shote = 539;
			let delay = 20;
			loop( way ){

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

				NotifyEventAll( EV_USER + 40, [ sht, delay ] );
				angle += 360 / way;
			}

			PlaySound("Shot1",92,0);
			if( wait( 0 ) ){ return; }
		}
			if( wait( 10 ) ){ return; }
		}
	}

              task PatternWhirlpool2{
              loop( 2 ){
              let speed = 6;
              let angle = GetAngleToPlayer( objBoss ) - 27;
              loop( 2 ){
         
                     PatternWhirlpool15( speed, angle );
                     speed -= 1;
                     if( wait( 10 ) ){ return; }
	}
   
                     if( wait( 70 ) ){ return; }
	}
      }


              task PatternWhirlpool15( speed, angle ){
              ascent( i in 0..10 ){


	                	let way = 9;
			let shote1 = 809;
			let delay = 0;
                        		let duration = 20;
                       		let angular = 6.5;

			loop( way ){

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

                               			Snake( duration*0, sht1, angular, duration );
                                		Snake( duration*1, sht1, -angular, duration );
                                		Snake( duration*2, sht1, angular, duration );
                                		Snake( duration*3, sht1, -angular, duration );
                                		Snake( duration*4, sht1, angular, duration );
                                		Snake( duration*5, sht1, -angular, duration );
                                		Snake( duration*6, sht1, angular, duration );

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

				angle += 360 / way;

			}
			PlaySound("Shot1",92,0);
                        		if( wait( 5.2 ) ){ return; }
	}

   }
              task PatternWhirlpool3{
              let angle1 = 0;
	      loop( 180 ){
	                                let way = 2;
			let speed = rand( 0.5, 1.2 );
			let angle = rand( 0, 360 );
			let shote = 51;
			let delay = 20;
			loop( way ){

				let r = 80;

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

				NotifyEventAll( EV_USER + 40, [ sht, delay ] );
				angle += 360 / way;
			}
			angle1 += 1;
			PlaySound("Shot1",92,0);
			if( wait( 1 ) ){ return; }
		}
               let angle2 = 180;
	      loop( 180 ){
	                                let way = 2;
			let speed = rand( 0.5, 1.2 );
			let angle = rand( 0, 360 );
			let shote = 51;
			let delay = 20;
			loop( way ){

				let r = 80;

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

				NotifyEventAll( EV_USER + 40, [ sht, delay ] );
				angle += 360 / way;
			}
			angle2 -= 1;
			PlaySound("Shot1",92,0);
			if( wait( 1 ) ){ return; }
		}

	}

task Snake( wtime, obj, anv, time ){

      wait( wtime );
      ObjMove_SetAngularVelocity( obj, anv );
      wait( time );
      ObjMove_SetAngularVelocity( obj, 0 );
}

}

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

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