#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Clownpiece Overdrive"]
#Text["Clownpiece Overdrive"]
#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);
SetPlayerLife(0);
SetPlayerSpell(0);
}

@MainLoop
{
	if(GetPlayerState==STATE_END){CloseStgScene();}
	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(55);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,1,-1);
	DamageRateAtFrame(50,20,180);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,7);
	Cutin("\"River Styx Prison [Overdrive]\"",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	wait(60);
	TShot1;
	wait(1800);
	DamageRateAtFrame(75,20,0);
	}
//----------------------------------------------------

task TShot1
{
	let count = 0;
	maple;
	wait(70);
	LaserSet;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		count++;
		if(count%240==0)
		{
			TMovement(40,5,5);
		}
		yield;
	}
	task LaserSet
	{
		while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
		{
			let w;
			let time = 5+ObjEnemy_GetInfo(objBoss,INFO_LIFE)/1000;
			let jcount = 6;
			let px = rand(-40,40);
			let maxx = 60+4*80+px;
			w = 1;
			ascent(i in 0..6)
			{
				PlaySound("Laser3",85,0);
				ascent(j in 1..jcount)
				{
					AmericaLaser(60+i*80+px,j*100*-1,90,j,w);
				}
				wait(time);
			}
			w = -1;
			ascent(i in 0..6)
			{
				PlaySound("Laser3",85,0);
				ascent(j in 1..jcount)
				{
					AmericaLaser(maxx-(60+i*80+px),j*100*-1,90,j,w);
				}
				wait(time);
			}
		}
	}
		task AmericaLaser(px,py,angle,num,w)
		{
			let laser = CreateStraightLaserA1(px,py,angle,107,20,180,1003,0);
			ObjShot_SetAutoDelete(laser,false);
			MoveLaser(laser,w);
		}
		task MoveLaser(laser,w)
		{
			while(!Obj_IsDeleted(laser))
			{
				ObjMove_SetX(laser,ObjMove_GetX(laser)-0.5*w);
				ObjMove_SetY(laser,ObjMove_GetY(laser)+9);
				yield;
			}
		}
}



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

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