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

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

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

task TShot1
{
	attack(0.5,1);
	let r = 90;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;
                maple;
	wait(80);
                PatternBlack2;
                wait( 120 );
                PatternBlack1;

              task PatternBlack1{ 
              loop( 100000 ){
              loop( 1 ){

	                                let way = 1;
			let shote = 257;
			let delay = 30;
	                                let angle = rand( 215, 325 );

			loop( way ){

                                                let ux = rand( 2, 3 )*cos( angle );
                                                let uy = rand( 2, 3 )*sin( angle );

				let sx = ObjMove_GetX( objBoss );
				let sy = ObjMove_GetY( objBoss );
				
				let sht = TShotA2( sx, sy, rand( 6, 10 ), angle, -0.5, 1, shote, delay );
                                                                ObjMove_AddPatternB2( sht, 0 , ux, uy, 0, rand( 0.02, 0.04 ), 5, 5, );

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

   }



                                   task PatternBlack2{
                                   loop( 100 ){
                                                let angle1 = GetAngleToPlayer( objBoss ) + 90;
                                                let angle2 = GetAngleToPlayer( objBoss ) - 90;
			let angle3 = GetAngleToPlayer( objBoss );
                                                loop( 12 ){
                                                              PatternBlack( angle1, angle2, angle3 );
                                                              if( wait( 7 )){ return; }
                                                                }
                                                              wait( 100 );
			              TMovement(50,15,4);
                                                              if( wait( 80 )){ return; }
                                                                }
                                 }
		task PatternBlack( angle1, angle2, angle3 ){ 
                                loop( 1 ){

                                                let speed = 10;
			let way = 1;
			let delay = 20;

			let shote1 = 4;
			let shote2 = 5;
			let shote3 = 7;
			let shote4 = 9;
			let shote5 = 11;
			let shote6 = 10;
			let shote7 = 14;
			let shote8 = 15;
			let shote9 = 3;

                                                let rdelay = 2;

			loop( way ){

                                                let r1 = 0;
                                                let r2 = 15;
                                                let r3 = 30;
                                                let r4 = 45;
                                                let r5 = 60;
                                                
			let sx1 = ObjMove_GetX( objBoss ) + r5*cos( angle1 );
			let sy1 = ObjMove_GetY( objBoss ) + r5*sin( angle1 );
			let sx2 = ObjMove_GetX( objBoss ) + r4*cos( angle1 );
			let sy2 = ObjMove_GetY( objBoss ) + r4*sin( angle1 );
			let sx3 = ObjMove_GetX( objBoss ) + r3*cos( angle1 );
			let sy3 = ObjMove_GetY( objBoss ) + r3*sin( angle1 );
			let sx4 = ObjMove_GetX( objBoss ) + r2*cos( angle1 );
			let sy4 = ObjMove_GetY( objBoss ) + r2*sin( angle1 );
			let sx5 = ObjMove_GetX( objBoss ) + r1*cos( angle3 );
			let sy5 = ObjMove_GetY( objBoss ) + r1*sin( angle3 );
			let sx6 = ObjMove_GetX( objBoss ) + r2*cos( angle2 );
			let sy6 = ObjMove_GetY( objBoss ) + r2*sin( angle2 );
			let sx7 = ObjMove_GetX( objBoss ) + r3*cos( angle2 );
			let sy7 = ObjMove_GetY( objBoss ) + r3*sin( angle2 );
			let sx8 = ObjMove_GetX( objBoss ) + r4*cos( angle2 );
			let sy8 = ObjMove_GetY( objBoss ) + r4*sin( angle2 );
			let sx9 = ObjMove_GetX( objBoss ) + r5*cos( angle2 );
			let sy9 = ObjMove_GetY( objBoss ) + r5*sin( angle2 );

			    let sht5 = TShotA2( sx5, sy5, 0, angle3, 0.12, speed, shote5, delay );
                                                    wait( rdelay );
			    let sht4 = TShotA2( sx4, sy4, 0, angle3, 0.12, speed, shote4, delay );
			    let sht6 = TShotA2( sx6, sy6, 0, angle3, 0.12, speed, shote6, delay );
                                                    wait( rdelay );
			    let sht3 = TShotA2( sx3, sy3, 0, angle3, 0.12, speed, shote3, delay );
			    let sht7 = TShotA2( sx7, sy7, 0, angle3, 0.12, speed, shote7, delay );
                                                    wait( rdelay );
			    let sht2 = TShotA2( sx2, sy2, 0, angle3, 0.12, speed, shote2, delay );
			    let sht8 = TShotA2( sx8, sy8, 0, angle3, 0.12, speed, shote8, delay );
    		                    wait( rdelay );
			    let sht1 = TShotA2( sx1, sy1, 0, angle3, 0.12, speed, shote1, delay );
			    let sht9 = TShotA2( sx9, sy9, 0, angle3, 0.12, speed, shote9, delay );
				
                                                                ObjShot_SetSpellResist( sht1, true );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );
                                                                ObjShot_SetSpellResist( sht2, true );
				NotifyEventAll( EV_USER + 40, [ sht2, delay ] );
                                                                ObjShot_SetSpellResist( sht3, true );
				NotifyEventAll( EV_USER + 40, [ sht3, delay ] );
                                                                ObjShot_SetSpellResist( sht4, true );
				NotifyEventAll( EV_USER + 40, [ sht4, delay ] );
                                                                ObjShot_SetSpellResist( sht5, true );
				NotifyEventAll( EV_USER + 40, [ sht5, delay ] );
                                                                ObjShot_SetSpellResist( sht6, true );
				NotifyEventAll( EV_USER + 40, [ sht6, delay ] );
                                                                ObjShot_SetSpellResist( sht7, true );
				NotifyEventAll( EV_USER + 40, [ sht7, delay ] );
                                                                ObjShot_SetSpellResist( sht8, true );
				NotifyEventAll( EV_USER + 40, [ sht8, delay ] );
                                                                ObjShot_SetSpellResist( sht9, true );
				NotifyEventAll( EV_USER + 40, [ sht9, delay ] );
				
				angle3 += 360 / way;
			}
			PlaySound("Shot1",92,0);
            if( wait( 6 ) ){ return; }

	}

   }
}

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

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