
#ScriptVersion[3]
#Title["ClownpieceS4"]
#Text["ClownpieceS4"]
#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 action = false;
let mon;
let objScene=GetEnemyBossSceneObjectID();
@Initialize
{
SetBoss("Clownpiece",true);
}

@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(15);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(13131313);
	}
		case(EV_REQUEST_IS_DURABLE_SPELL)
	{
		SetScriptResult(true);
	}
}

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,1,-1);
	DamageRateAtFrame(0,0,0);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,7);
	if(Level==0){Cutin("\"Inferno Moon Orbit\"",15,"SHINKI");}
	if(Level==1){Cutin("\"Abyssal Inferno Eclipse\"",15,"SHINKI");}
	if(Level==2){Cutin("\"Apollo Maze\"",15,"SHINKI");}
	ObjEnemyBossScene_StartSpell(objScene);
	wait(90);
	TShot1;
	}
//----------------------------------------------------

task TShot1
{
	let count = 0;
	RayCharge("PINK",3,90);
	PlaySound("Charge3",100,0);
	wait(120);
	PlaySound("Boon1",100,0);
	MapleExplode2(GetEnemyX,GetEnemyY,1.5,"PINK2");
	ascent(i in 0..1)
	{
		MoonAroundPlayer(i*180);
	}
	ascent(i in 0..36)
	{
		let r = 30;
		ascent(j in 0..12)
		{
			let angle = i*10;
			TShotA1(GetEnemyX+r*cos(angle),GetEnemyY+r*sin(angle),0.5+j/2.5,angle,163,12);
		}
	}
	ObjMove_SetY(objBoss,-200);
	wait(150);
	RayCharge2(mon,"RED",3,90);
	PlaySound("Charge3",100,0);
	wait(120);
	let speed = [1.5,2,2.25][Level];
	ascent(n in 0..2)
	{
		ascent(i in 0..45)
		{
			PlaySound("Shot6",90,0);
			TShotA1(0,0,speed,90-i*2,833,12);
			TShotA1(384,0,speed,i*2+90,833,12);
			wait(2);
		}
		descent(i in 0..45)
		{
			PlaySound("Shot6",90,0);
			TShotA1(0,0,speed,90-i*2,833,12);
			TShotA1(384,0,speed,i*2+90,833,12);
			wait(2);
		}
	}
	wait(120);
	speed = [1.25,1.7,1.9][Level];
	ascent(n in 0..2)
	{
		ascent(i in 0..30)
		{
			PlaySound("Shot6",92,0);
			TShotA1(0,0,speed,90-i*3,833,12);
			TShotA1(384,0,speed,i*3+90,833,12);
			TShotA1(0,448,speed,i*3+270,833,12);
			TShotA1(384,448,speed,270-i*3,833,12);
			wait(3);
		}
		descent(i in 0..30)
		{
			PlaySound("Shot6",92,0);
			TShotA1(0,0,speed,90-i*3,833,12);
			TShotA1(384,0,speed,i*3+90,833,12);
			TShotA1(0,448,speed,i*3+270,833,12);
			TShotA1(384,448,speed,270-i*3,833,12);
			wait(3);
		}
	}
	wait(120);
	RayCharge2(mon,"RED",3,90);
	PlaySound("Charge3",100,0);
	wait(120);
	
	ascent(n in 0..2)
	{
		ascent(i in 0..45)
		{
			PlaySound("Shot1",92,0);
			PlaySound("BulletWave",92,90);
			let v = [2.25,3,3.5][Level];
			let obj = TShotA2(i*384/45+rand(-1,1),0,v,90,-v/30,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			obj = TShotA2(384-i*384/45+rand(-1,1),448,v,270,-v/30,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			wait(1+i%2);
		}
		descent(i in 0..45)
		{
			PlaySound("Shot1",92,0);
			PlaySound("BulletWave",92,90);
			let v = [2.25,3,3.5][Level];
			let obj = TShotA2(i*384/45+rand(-1,1),0,v,90,-v/20,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			obj = TShotA2(384-i*384/45+rand(-1,1),448,v,270,-v/20,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			wait(1+i%2);
		}
	}
	wait(60);
	ascent(n in 0..2)
	{
		ascent(i in 0..45)
		{
			PlaySound("Shot1",92,0);
			PlaySound("BulletWave",92,90);
			let v = [2.25,3,3.5][Level];
			let obj = TShotA2(0,i*448/45+rand(-1.5,1.5),v,0,-v/20,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			obj = TShotA2(384,448-i*448/45+rand(-1.5,1.5),v,180,-v/20,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			wait(1+i%2);
		}
		descent(i in 0..45)
		{
			PlaySound("Shot1",92,0);
			PlaySound("BulletWave",92,90);
			let v = [2.25,3,3.5][Level];
			let obj = TShotA2(0,i*448/45+rand(-1.5,1.5),v,0,-v/30,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			obj = TShotA2(384,448-i*448/45+rand(-1.5,1.5),v,180,-v/30,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			wait(1+i%2);
		}
	}
	wait(75);
	ascent(n in 0..2)
	{
		ascent(i in 0..30)
		{
			PlaySound("Shot1",92,0);
			PlaySound("BulletWave",92,90);
			let v = [1.5,2,2.25][Level];
			let obj = TShotA2(0,i*448/30+rand(-1.5,1.5),v,0,-v/30,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			obj = TShotA2(384,448-i*448/30+rand(-1.5,1.5),v,180,-v/30,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			obj = TShotA2(i*384/30+rand(-1,1),0,v,90,-v/30,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			obj = TShotA2(384-i*384/30+rand(-1,1),448,v,270,-v/30,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			wait(2);
		}
		descent(i in 0..30)
		{
			PlaySound("Shot1",92,0);
			PlaySound("BulletWave",92,90);
			let v = [2.5,3,3.5][Level];
			let obj = TShotA2(0,i*448/30+rand(-1.5,1.5),v,0,-v/30,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			obj = TShotA2(384,448-i*448/30+rand(-1.5,1.5),v,180,-v/30,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			obj = TShotA2(i*384/30+rand(-1,1),0,v,90,-v/30,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			obj = TShotA2(384-i*384/30+rand(-1,1),448,v,270,-v/30,v/10,832,12);
			ObjMove_AddPatternA2(obj,90,NO_CHANGE,NO_CHANGE,v/60,0,v);
			wait(2);
		}
	}
	wait(120);
	RayCharge2(mon,"RED",3,90);
	PlaySound("Charge3",100,0);
	wait(120);
	count = 0;
	StartCountDown;
	speed = [1.2,1.4,1.6][Level];
	while(count<180)
	{
		let r = 300;
		PlaySound("Shot6",92,0);
		ascent(i in 0..6)
		{
			let angle = i*60+count*0.75;
			let obj = TShotA1(stgx+r*cos(angle),stgy+r*sin(angle),speed,angle+180,832,12);
			Prevent(obj,60);
			angle = i*60-count*0.75;
			obj = TShotA1(stgx+r*cos(angle),stgy+r*sin(angle),speed,angle+180,832,12);
			Prevent(obj,60);
		}
		if(count>20 && count%20==0)
		{
			PlaySound("Shot1",92,0);
			ascent(i in 0..45)
			{
				let angle = i*8+count;
				let obj = TShotA1(stgx+r*cos(angle),stgy+r*sin(angle),speed,angle+180,833,12);
				Prevent(obj,60);
			}			
		}
		if(count>120 && count%20==10)
		{
			PlaySound("Shot1",92,0);
			ascent(i in 0..45)
			{
				let angle = i*8+count;
				let obj = TShotA1(stgx+r*cos(angle),stgy+r*sin(angle),speed+0.4*speed,angle+180,834,12);
				Prevent(obj,60);
			}			
		}
		wait(5);
		count++;
	}
	ObjEnemy_SetLife(objBoss,0);
	task Prevent(obj,time)
	{
		ObjShot_SetAutoDelete(obj,false);
		wait(time);
		ObjShot_SetAutoDelete(obj,true);
	}
	task StartCountDown
	{
		wait(300);
		loop(5)
		{
			PlaySound("time1",100,0);
			wait(60);
		}
		loop(5)
		{
			PlaySound("time2",100,0);
			wait(60);
		}
	}
}


task MoonAroundPlayer(angle)
{
	mon = Moon(GetEnemyX,GetEnemyY,1);
	let count = 0;
	let r = 0;
	while(!Obj_IsDeleted(mon))
	{
		if(count<180)
		{
			r = 105+350*cos(count/2);
		}
		if(GetVirtualKeyState(VK_SLOWMOVE)!=KEY_HOLD)
		{
			angle+=2;
		}
		else
		{
			angle+=0.5;
		}
		count++;
		ObjMove_SetPosition(mon,GetPlayerX+r*cos(angle),GetPlayerY+r*sin(angle));
		//ObjMove_SetDestAtWeight(mon,GetPlayerX+r*cos(angle),GetPlayerY+r*sin(angle),10,20);
		CheckBullet;
		yield;
	}
	
	task CheckBullet
	{
		let arr = GetShotIdInCircleA2(ObjMove_GetX(mon),ObjMove_GetY(mon),58,TARGET_ENEMY);
		ascent(i in 0..length(arr))
		{
				effbreak(arr[i],0.8,10);
				PlaySound("Sbreak",90,0);
				Obj_Delete(arr[i]);
		}
	}
	
}


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

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