
#ScriptVersion[3]
#Title["HecatiaS1"]
#Text["HecatiaS1"]
#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);
SetCommonData("Bomb",1);
}

@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(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);
	if(GetForm()==0){Cutin("Otherworld \"Hellish Glory Maelstrom\"",15,"SHINKI");HellSet2;}
	if(GetForm()==1){Cutin("Moon \"Astrological Stars\"",15,"SHINKI");MoonSet;}
	if(GetForm()==2){Cutin("Earth\"Blue Horizon\"",15,"SHINKI");EarthSet;}
	ObjEnemyBossScene_StartSpell(objScene);
	wait(1200);
	DamageRateAtFrame(75,40,0);
	yield;
	}

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

task HellSet2
{
	let r = 30;
	let num = [16,16,20][Level];
	let num2 = [120,160,200][Level];
	let curve = [0.4,0.4,0.5][Level];
	let acc = [0.04,0.04,0.05][Level];
	let multi = [10,10,10][Level];
	
	let c = 0;
	let c2 = 0;
	let count = 0;
	wait(60);
	maple;
	wait(70);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		PlaySound("Shot1",92,0);
		PlaySound("BulletWave",92,60);
		ascent(i in 0..num)
		{
			let angle = i*360/num+180/num+c+count;
			TrickyBullet(GetEnemyX+r*cos(angle),GetEnemyY+r*sin(angle),1,angle,833,acc,curve*sin(count*10),12);
		}
		//count++;
		wait(9);
		PlaySound("Shot1",95,0);
		PlaySound("BulletWave",95,60);
		ascent(i in 0..num2)
		{
			let angle = i*360/(num2)+c2+count;
			if(i%20>8-Level && i%20<12+Level)
			{
				TrickyBullet(GetEnemyX+r*cos(angle),GetEnemyY+r*sin(angle),1,angle,832,acc,curve*sin(count*10),12);
			}
		}
		count++;
		c+=180/num;
		c2+=multi*360/(num2);
		wait(9);
	}
		task TrickyBullet(x,y,v,angle,color,acc,ang,delay)
		{
			let obj = TShotA2(x,y,v,angle,0,0,color,delay);
			wait(60);
			
			ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,acc,ang,10);
			wait(90);
			ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,acc,0,10);
		}
}

task HellSet
{
	let c = 0;
	let r = 0;
	let way = 1;
	let wnum = [4,5,6][Level];
	let wang = [1.25,1,1][Level];
	let wc = [1.75,1.75,1.5][Level];
	let wdegree = [0.4,0.5,0.6][Level];
	wait(60);
	maple;
	wait(70);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		PurpleT;
		wait(420);
		MapleExplode(GetEnemyX,GetEnemyY,1.5,"PINK2");
		RedT;
		wait(420);
		MapleExplode(GetEnemyX,GetEnemyY,1.5,"PINK2");
		way = -way;
	}
	task RedT
	{
		r = 0;
		ascent(m in 0..24)
		{
			ascent(n in 0..10)
			{
				r+=1;
				PlaySound("Shot6",95,0);
				ascent(i in 0..wnum)
				{
					let angle = i*360/wnum+c*way;
					TrickyBullet(GetEnemyX+r*cos(angle),GetEnemyY+r*sin(angle),3,angle+180,832,10);
				}
				c+=wc;
				wait(1);
			}
			c+=10;
		}
	}
	task PurpleT
	{
		r = 0;
		ascent(m in 0..24)
		{
			ascent(n in 0..10)
			{
				r+=1;
				PlaySound("Shot6",95,0);
				ascent(i in 0..wnum)
				{
					let angle = i*360/wnum-c*way*wang;
					TrickyBullet(GetEnemyX+r*cos(angle),GetEnemyY+r*sin(angle),3,angle+180,833,10);
				}
				c+=12+wdegree*sin(r*1.5);
				wait(1);
			}
		}
	}
		task TrickyBullet(x,y,v,angle,color,delay)
		{
			let obj = TShotA2(x,y,v,angle,0,0.3,color,delay);
			ObjShot_SetAutoDelete(obj,false);
			while(!Obj_IsDeleted(obj))
			{
				ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,3/30,0,3);
				wait(30);
				ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,-3/30,0,0.3);
				wait(30);
				ObjShot_SetAutoDelete(obj,true);
			}
		}
}

task MoonSet
{
	let num = [15,20,25][Level];
	let pspeed = [2,2.25,2.5][Level];
	let wtime = [120,110,100][Level];
	wait(60);
	maple;
	wait(70);
	let r = 75;
	let count = 0;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		let result = rand(-9,9);
		PlaySound("Shot1",100,0);
		ascent(i in 0..num)
		{
			let angle = i*360/num+result;
			BounceStar(GetPlayerX+r*cos(angle),GetPlayerY+r*sin(angle),2,angle,167,6);
		}
		count++;
		if(count%2==0)
		{
			TMovement(40,5,4);
		}
		wait(wtime);
	}
	task BounceStar(x,y,v,angle2,color,delay)
	{
		let obj = TShotA1(x,y,v,angle2,color,delay);
		while(ObjMove_GetY(obj)>0 && ObjMove_GetX(obj)>0 && ObjMove_GetX(obj)<384 && ObjMove_GetY(obj)<448){yield;}
		if(ObjMove_GetY(obj)<=448 && !Obj_IsDeleted(obj))
		{
			let result = rand(pspeed,pspeed*1.5);
			PlaySound("Laser3",95,0);
			let dir = GetAngleToPlayer(obj)+rand(-2,2);
			let laser = CreateLooseLaserA1(ObjMove_GetX(obj),ObjMove_GetY(obj),result,dir,100,20,1022,0);
			ObjMove_AddPatternA2(laser,1,result/5,NO_CHANGE,result/60,0,result);
			let dummy = TShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),result,dir,746,0);
			ObjMove_AddPatternA2(dummy,1,result/5,NO_CHANGE,result/60,0,result);
			HeadM(dummy);
			LaserM(laser,result);
			effbreak(obj,1,15);
			Obj_Delete(obj);
		}
	}
}

task EarthSet
{
	let py = stgy;
	let sy = stgy-10;
	let c = 0;
	let wtime = [50,45,40][Level];
	let wtime2 = [75,60,45][Level];
	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);
			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 = [10,16,22][Level];
		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%(4+Level)==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 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());
	}