#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Clownpiece Bonus Spell 1"]
#Text["Clownpiece Bonus Spell 1"]
#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(1500);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(45);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,1,-1);
	DamageRateAtFrame(50,25,240);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,7);
	Cutin("Star Sign \"The Fault in Our Stars\"",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	wait(75);
	TShot1;
	wait(1200);
	DamageRateAtFrame(75,40,0);
	}
//----------------------------------------------------

task TShot1
{
	StartUp;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		attack(30,1);
		LaserSet;
		wait(120);
		TMovement(30,5,5);
		wait(120);
	}
	task LaserSet
	{
		let w = 1;
		let py = rand(-20,20);
		ascent(i in 0..4)
		{
			PlaySound("Laser2",90,0);
			ascent(j in 2..12)
			{
				AmericaLaser(GetEnemyX+i*85,-j*95*w,90,1);
				AmericaLaser(GetEnemyX+i*85,-j*95*w,90,-1);
				if(i!=0)
				{
					AmericaLaser(GetEnemyX-i*85,-j*95*w,90,1);
					AmericaLaser(GetEnemyX-i*85,-j*95*w,90,-1);
				}
			}
			wait(10);
		}
		wait(35);
		PlaySound("Boon1",100,0);
		task AmericaLaser(px,py,angle,way)
		{
			let laser = CreateStraightLaserA1(px,py,angle,100,20,210,1003,0);
			ObjShot_SetAutoDelete(laser,false);
			MoveLaser;
			wait(75);
			task MoveLaser
			{
				let count = 0;
				while(!Obj_IsDeleted(laser))
				{
					if(count>75)
					{
						ObjMove_SetX(laser,ObjMove_GetX(laser)+(0.3+0.05*Level)*way);
					}
					ObjMove_SetY(laser,ObjMove_GetY(laser)+8*w);
					count++;
					yield;
						
				}
			}
		}
	}
}

task StartUp
{
	wait(180);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		ascent(n in 0..7)
		{
			PlaySound("BulletWave",95,0);
			TShotA2(GetEnemyX+n*32,0,0.5,90+rand(-3,3),0.01,rand(1.5,2.5),770,10);
			if(n>0)
			{TShotA2(GetEnemyX-n*32,0,0.5,90+rand(-3,3),0.01,rand(1.5,2.5),770,10);}
			wait(12-Level*3);
		}
		descent(n in 0..7)
		{
			PlaySound("BulletWave",95,0);
			TShotA2(GetEnemyX+n*32,0,0.5,90+rand(-3,3),0.01,rand(1.5,2.5),770,10);
			if(n>0)
			{TShotA2(GetEnemyX-n*32,0,0.5,90+rand(-3,3),0.01,rand(1.5,2.5),770,10);}
			wait(12-Level*3);
		}
	}
}



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

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