
#ScriptVersion[3]
#Title["ClownpieceS2"]
#Text["ClownpieceS2"]
#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 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(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);
	Cutin("\"Lunar Gateway\"",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	wait(75);
	TShot1;
	wait(1200);
	DamageRateAtFrame(75,20,0);
	}
//----------------------------------------------------

task TShot1
{
	StarSpread;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		attack(30,1);
		LaserSet("R");
		wait(270);
		attack(30,1);
		LaserSet("L");
		wait(135);
		TMovement(30,5,5);
		wait(135);
	}
	
	task LaserSet(way)
	{
		let w = 1;
		if(way=="L"){w = -1;}
		PlaySound("Laser6",100,0);
		let py = rand(-20,20);
		ascent(i in 0..10)
		{
			PlaySound("Laser2",100,75);
			ascent(j in 1..19)
			{
				AmericaLaser(w*384/2+384/2+j*100*w,120+i*80+py,180,j);
			}
			wait(6);
		}
		task AmericaLaser(px,py,angle,num)
		{
			let laser = CreateStraightLaserA1(px,py,angle,107,20,150,1003,75);
			ObjShot_SetAutoDelete(laser,false);
			MoveLaser;
			wait(75);
			ascent(i in 0..14)
			{
				if(num==1)
				{
					if(i<0)
					{
						ascent(i in -1..2)
						{
							let sta = TShotA2(-w*384/2+384/2,ObjMove_GetY(laser),2,0,0.02,4,162,8);
							ObjMove_SetAngle(sta,GetAngleToPlayer(sta)+i*45);
						}
					}
					if(i%(3-Level)==0)
					{
						TShotA2(-w*384/2+384/2,ObjMove_GetY(laser),1,90-90*w,0.02,4,163,8);
					}
					wait(9);
				}
			}
			task MoveLaser
			{
				while(!Obj_IsDeleted(laser))
				{
					ObjMove_SetY(laser,ObjMove_GetY(laser)-1.25-Level*0.25);
					ObjMove_SetX(laser,ObjMove_GetX(laser)-12*w);
					yield;
				}
			}
		}
	}
}

task StarSpread
{
	wait(180);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		let result = GetAngleToPlayer(objBoss)+rand(-5,5);
		ascent(i in -7..8)
		{
			PlaySound("Shot6",85,0);
			let bs = TShotA2(GetEnemyX+30*cos(i*15+result),GetEnemyY+30*sin(i*15+result),3.25,i*15+result,-0.04,1.25,167,8);
			//ObjMove_AddPatternB2(bs,1,NO_CHANGE,NO_CHANGE,NO_CHANGE,0.03,3.25*cos(i*15+result),3);
			wait(4-Level);
		}
		result = GetAngleToPlayer(objBoss)+rand(-5,5);
		descent(i in -7..8)
		{
			PlaySound("Shot6",85,0);
			let bs = TShotA2(GetEnemyX+30*cos(i*15+result),GetEnemyY+30*sin(i*15+result),3.25,i*15+result,-0.04,1.25,167,8);
			//ObjMove_AddPatternB2(bs,1,NO_CHANGE,NO_CHANGE,NO_CHANGE,0.03,3.25*cos(i*15+result),3);
			wait(4-Level);
		}
	}
}



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

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