#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Hecatia Overdrive 2"]
#Text["Hecatia Overdrive 2"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Background["./BG.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss2.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 objScene=GetEnemyBossSceneObjectID();
@Initialize
{
SetBoss("Hecatia Lapislazuli",true);
SetPlayerLife(0);
SetPlayerSpell(0);
}

@MainLoop
{
	if(GetPlayerState==STATE_END){CloseStgScene();}
	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(2000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(50);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,15);
	SetCommonData("CircleSize",0);
	magiccircle(objBoss,1,-1);
	DamageRateAtFrame(50,25,180);
	SetForm(2);
	Cutin("\"Blue Horizon [Overdrive]\"",15,"SHINKI");EarthSet;
	ObjEnemyBossScene_StartSpell(objScene);
	wait(1500);
	DamageRateAtFrame(75,40,0);
	yield;
	}

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

task EarthSet
{
	let py = stgy;
	let sy = stgy-10;
	let sx = stgx;
	let c = 0;
	let wtime = 40;
	let wtime2 = 45;
	wait(60);
	maple;
	wait(70);
	MShot;
	wait(180);
	SShot;
	task MShot
	{
		while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
		{
			PlaySound("Shot9",100,0);
			EShot(0,stgy+sy*sin(c),1.5,0,834,15,1);
			EShot(0,stgy-sy*sin(c),1.5,0,834,15,1);
			EShot2(stgx+sx*sin(c),0,1.5,90,834,15,1);
			EShot2(stgx-sx*sin(c),0,1.5,90,834,15,1);
			wait(wtime);
			c+=8;
			PlaySound("Shot9",100,0);
			EShot(384,stgy+sy*sin(c),1.5,180,834,15,-1);
			EShot(384,stgy-sy*sin(c),1.5,180,834,15,-1);
			wait(wtime);
			c+=8;
		}
	}
	task SShot
	{
		let count = 0;
		let rnum = 11;
		while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
		{
			PlaySound("Shot1",95,0);
			let r = 45;
			let result = rand(-6,6);
			ascent(i in -rnum..rnum+1)
			{
				let angle = GetAngleToPlayer(objBoss)+180+i*330/(rnum*2-1);
				BounceStar(GetEnemyX+r*cos(angle),GetEnemyY+r*sin(angle),2,angle,167,8);
			}
			count++;
			if(count%5==0)
			{
				TMovement(40,5,4);
			}
			wait(wtime2);
		}
		task BounceStar(x,y,v,angle,color,delay)
		{
			let obj = TShotA1(x,y,v,angle,color,delay);
			while(ObjMove_GetY(obj)>0){yield;}
			PlaySound("BulletWave",95,0);
			ObjMove_SetAngle(obj,-ObjMove_GetAngle(obj));
			ObjShot_SetGraphic(obj,166);
		}
	}
	task EShot(x,y,v,angle,color,delay,type)
	{
		let dir;
		let result = 4;
		let obj = TShotA1(x,y,v,angle,color,delay);
		while( (type==1 && ObjMove_GetX(obj)<GetPlayerX) || (type==-1 && ObjMove_GetX(obj)>GetPlayerX) ){yield;}
		if(ObjMove_GetY(obj)<GetPlayerY){dir=90;}
		else{dir=270;}
		PlaySound("Laser3",95,0);
		let laser = CreateLooseLaserA1(ObjMove_GetX(obj),ObjMove_GetY(obj),4,dir,100,20,1022,0);
		ObjMove_AddPatternA2(laser,1,result/5,NO_CHANGE,result/30,0,result);
		let dummy = TShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj)-0*sin(dir),4,dir,746,0);
		ObjMove_AddPatternA2(dummy,1,result/5,NO_CHANGE,result/30,0,result);
		HeadM(dummy);
		LaserM(laser,4);
		effbreak(obj,1,15);
		Obj_Delete(obj);
	}
	
	task EShot2(x,y,v,angle,color,delay,type)
	{
		let dir;
		let result = 4;
		let obj = TShotA1(x,y,v,angle,color,delay);
		while( ObjMove_GetY(obj)<GetPlayerY){yield;}
		if(ObjMove_GetX(obj)<GetPlayerX){dir=0;}
		else{dir=180;}
		PlaySound("Laser3",95,0);
		let laser = CreateLooseLaserA1(ObjMove_GetX(obj),ObjMove_GetY(obj),4,dir,100,20,1022,0);
		ObjMove_AddPatternA2(laser,1,result/5,NO_CHANGE,result/30,0,result);
		let dummy = TShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj)-0*sin(dir),4,dir,746,0);
		ObjMove_AddPatternA2(dummy,1,result/5,NO_CHANGE,result/30,0,result);
		HeadM(dummy);
		LaserM(laser,4);
		effbreak(obj,1,15);
		Obj_Delete(obj);
	}
}

		task HeadM(obj2)
		{
			let c2 = 0;
			ObjRender_SetScaleXYZ(obj2,1.25,1.25,0);
			ObjShot_SetSpellResist(obj2,true);
			while(!Obj_IsDeleted(obj2))
			{
				let co = 206+48*sin(c2);
				ObjRender_SetColor(obj2,co,co,co);
				c2+=30;
				yield;
			}
		}
		task LaserM(l,v)
		{
			ObjMove_SetY(l,ObjMove_GetY(l)-50*sin(ObjMove_GetAngle(l)));
			ObjMove_SetX(l,ObjMove_GetX(l)-50*cos(ObjMove_GetAngle(l)));
			ObjMove_SetSpeed(l,50);
			yield;
			ObjMove_SetSpeed(l,v);
		}

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

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