
#ScriptVersion[3]
#Title["ClownpieceN2"]
#Text["ClownpieceN2"]
#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 objScene=GetEnemyBossSceneObjectID();
@Initialize
{
SetBoss("Clownpiece",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(3500);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(40);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,15);
	magiccircle(objBoss,1,-1);
	wait(75);
	TShot1;
	DamageRateAtFrame(100,50,60);
	yield;
	}

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

task TShot1
{
	maple;
	wait(30);
	StarSpread;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		attack(30,1);
		wait(35);
		ALaserSet;
		wait(120);
		TMovement(35,10,5);
		wait(120);
	}
}

task StarSpread
{
	wait(60);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		let result = GetAngleToPlayer(objBoss)+rand(-5,5);
		ascent(i in -7..8)
		{
			PlaySound("Shot1",85,0);
			TShotA1(GetEnemyX+30*cos(i*10+result),GetEnemyY+30*sin(i*10+result),2.75+Level*0.25,i*10+result,270,12);
			if(Level==0){wait(2);}
			if(Level==1){wait(1+i%2);}
			if(Level==2){wait(1);}
		}
		result = GetAngleToPlayer(objBoss)+rand(-5,5);
		descent(i in -7..8)
		{
			PlaySound("Shot1",85,0);
			TShotA1(GetEnemyX+30*cos(i*10+result),GetEnemyY+30*sin(i*10+result),2.75+Level*0.25,i*10+result,270,12);
			if(Level==0){wait(2);}
			if(Level==1){wait(1+i%2);}
			if(Level==2){wait(1);}
		}
	}
}

task ALaserSet
{
	ascent(i in 0..5)
	{
		PlaySound("Shot6",100,0);
		CShot(GetEnemyX,GetEnemyY,3.3-i/2.5,210+i*8,778,8,1);
		CShot(GetEnemyX,GetEnemyY,3.3-i/2.5,330-i*8,778,8,1);
		wait(5);
	}
	wait(45);
	ascent(i in 0..4+Level)
	{
		PlaySound("Shot6",100,0);
		CShot(GetEnemyX,GetEnemyY,1.5+i/2.5,200-i*12,776,8,2);
		CShot(GetEnemyX,GetEnemyY,1.5+i/2.5,340+i*12,776,8,2);
		wait(15);
	}
	task CShot(x,y,v,angle,color,delay,type)
	{
		let core = TShotA1(x,y,v,angle,color,delay);
		let dir = 90;
		let lcolor = 1007;
		let plus = 0;
		wait(50);
		if(type==2)
		{
			dir = GetAngleToPlayer(core);
			lcolor = 1003;
			plus = 30;
		}
		if(!Obj_IsDeleted(core))
		{
			PlaySound("Shot6",100,0);
			ALaser(ObjMove_GetX(core),ObjMove_GetY(core));
			Obj_Delete(core);
		}
		task ALaser(ax,ay)
		{
			let laser = CreateStraightLaserA1(ax,ay,dir,0,5,80+plus,lcolor,0);
			DummyDelay(ax,ay,color,90+plus);
			ObjShot_SetIntersectionEnable(laser,false);
			ascent(i in 0..60) // 60
			{
				ObjLaser_SetLength(laser,i*9);
				wait(i%2);
				if(type==2){wait(i%2);}
			}
			PlaySound("Laser3",100,0);
			ascent(i in 5..20) // 50
			{
				if(i==10){ObjShot_SetIntersectionEnable(laser,true);}
				ObjLaser_SetRenderWidth(laser,i);
				ObjLaser_SetIntersectionWidth(laser,i);
				yield;
			}
			wait(40); // 90
			descent(i in 0..20)
			{
				ObjLaser_SetRenderWidth(laser,i);
				ObjLaser_SetIntersectionWidth(laser,i-5);
				yield;
			}			
		}
			task DummyDelay(ax,ay,color,time)
			{	
				ascent(i in 0..time)
				{
					let stick = TShotA1(ax,ay,0,0,color,2+(i)%3);
					ObjShot_SetDeleteFrame(stick,0);
					yield;
				}
			}
	}
}

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

task SizeCircle
{
	ascent(i in 0..60)
	{
		SetCommonData("CircleSize",sin(i*1.5));
		yield;
	}
}	

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

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