
#ScriptVersion[3]
#Title["ClownpieceS3"]
#Text["ClownpieceS3"]
#Player["./MoF_Reimu/Reimu.txt"]
#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 objScene=GetEnemyBossSceneObjectID();
@Initialize
{
SetBoss("Clownpiece",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(45);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,1,-1);
	DamageRateAtFrame(50,20,240);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,7);
	if(Level==0){Cutin("Inferno Sign \"Hellfire  Drift\"",15,"SHINKI");}
	else
	{Cutin("\"Blaze Inferno\"",15,"SHINKI");}
	ObjEnemyBossScene_StartSpell(objScene);
	wait(75);
	TShot1;
	wait(1200);
	DamageRateAtFrame(75,20,0);
	}
//----------------------------------------------------

task TShot1
{
	ascent(n in 0..3)
	{
		PlaySound("Shot1",100,0);
		ascent(i in 0..10)
		{
			ascent(j in 0..20)
			{
				AFireball(j+i*36+n*12,5);
			}
		}
		wait(60);
	}
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		ascent(n in 0..2+Level)
		{
			PlaySound("Shot1",100,0);
			ascent(i in 0..120)
			{
				AFireball(i*3+angleToPlayer,4);
			}
			wait(105-Level*15);
		}
		wait(30);
			ascent(n in 0..10)
			{
				PlaySound("Shot1",95,0);
				ascent(i in 0..16+Level*4)
				{
					AFireball(i*360/(16+Level*4)+n*1.5,4.5-n/8);
					AFireball(i*360/(16+Level*4)-n*1.5,4.5-n/8);
				}
			}
		wait(120);
	}
	task AFireball(angle,v)
	{
		let fire = TShotA2(GetEnemyX,GetEnemyY,v,angle,-4/60,v/4,833,8);
		CheckGraze;
		wait(60);
		ObjMove_AddPatternA2(fire,0,NO_CHANGE,NO_CHANGE,0,0,100);
		task CheckGraze
		{
			while(!Obj_IsDeleted(fire))
			{
				let dis = GetObjectDistance(GetPlayerObjectID,fire);
				if(dis<45)
				{
					ObjRender_SetColor(fire,0,255,255);
					ObjMove_SetSpeed(fire,ObjMove_GetSpeed(fire)+0.033);
				}
				else
				{
					ObjRender_SetColor(fire,255,255,255);
				}
				yield;
			}
		}
	}
}



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

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