
#ScriptVersion[3]
#Title["KurojiN3"]
#Text["KurojiN3"]
#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(4200);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(58);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(0);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,6);
	SetCommonData("Scroll",1);
	SetCommonData("ForceLifebar",1);
	wait(180);
	DamageRateAtFrame(122,5,0);
	TShot1;
	SetCommonData("ForceLifebar",0);
	}
//----------------------------------------------------

task TShot1
{
	while( !Obj_IsDeleted( objBoss )){
	PatternKurojiNon1;	
	wait( 30 );
	Warp1;
	wait( 330 );
	PatternKurojiNon2;
	Warp2;
	wait( 120 );
	}

}
	
	task Warp1{
	loop( 11 ){
	ObjMove_SetPosition( objBoss, rand( 30, GetStgFrameWidth - 30 ), rand( 40, GetStgFrameHeight / 2 - 50 ));
	wait( 30 );
	}
	}

	task Warp2{
	loop( 60 ){
	ObjMove_SetPosition( objBoss, rand( 40, GetStgFrameWidth - 40 ), rand( 50, GetStgFrameHeight / 2 - 30 ));
	wait( 2 );
	}
	}

              task PatternKurojiNon1{ 
	loop( 180 ){

			let angle = GetAngleToPlayer( objBoss );
              			let speed = 5.6;
	                                	let way = 1;
                                                	let shote = 51;
			let delay = 20;

			loop( way ){

                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle + 2, 0, speed, shote, delay );
				let sht2 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				let sht3 = TShotA2( sx, sy, speed, angle - 2, 0, speed, shote, delay );

				angle += 360 / way;

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

	}

   }

              task PatternKurojiNon2{ 
	loop( 40 ){

              			let speed = 27;
	                                	let way = round( rand( 2, 3 ));
                                                	let shote = 53;
			let delay = 20;

			loop( way ){

			let angle = rand( 0, 360 );
                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = TShotA2( sx, sy, speed, angle, -3.5, 1, shote, delay );
				ObjShot_SetSpellResist( sht1, true );
				Reflect( sht1, -10, 0, 1 );

				angle += 360 / way;

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

	}

   }

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

}

	task StartCountDown
	{
		wait((58*60) - (10*60));
		loop(10)
		{
			PlaySound("time",100,0);
			wait(60);
		}

	}

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

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