
#ScriptVersion[3]
#Title["SP1L"]
#Text["SP1L"]
#Background["./BG.txt"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/ZUNShot_Const.txt"
#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 fog = 0;
let s = 1;
let objScene=GetEnemyBossSceneObjectID();
let arr = [1,6,4,2,3,5,0];
@Initialize
{
SetBoss(true);
SetCommonData("Bomb",1);
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),25);
	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(60);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3000000);
	}
}

//----------------------------------------------------
task mainTask{
	DamageRateAtFrame(50,0,240);
	DamageRateAtFrame(75,0,1380);
	magiccircle(objBoss,0.8,true);
	ObjMove_SetDestAtWeight(objBoss,stgx,130,10,7);
	Cutin("Light Sign\"Pagoda Pillar [Lunatic]\"",15,"SHOU");
	ObjEnemyBossScene_StartSpell(objScene);
	wait(90);
	TShot1;
	}
//----------------------------------------------------

task TShot1{
	let p = 0;
	PlaySound("Boon1",100,0);
	ascent(i in 0..5){
	PlaySound("Laser2",100,75);
	FireLaser(i*46+stgx,448+25,270,i);
	if(i!=0){
	FireLaser(-i*46+stgx,448+25,270,i);
	}
	wait(10);
	}
	wait(200);
	TAccel(35,5,0.1,60);
	wait(200);
	s = -s;
	while(!Obj_IsDeleted(objBoss)){
		p  = rand(-15,15);
		PlaySound("Boon1",100,0);
		ascent(i in 0..5){
		PlaySound("Laser2",100,75);
		FireLaser(i*46+stgx+p,-25,90,i);
		if(i!=0){
		FireLaser(-i*46+stgx+p,-25,90,i);
		}
		wait(10);
		}
		wait(240);
		AccelMove(objBoss,stgx,130,0.1,60);
		wait(240);
		s = -s;
		p  = rand(-15,15);
		PlaySound("Boon1",100,0);
		ascent(i in 0..5){
		PlaySound("Laser2",100,75);
		FireLaser(i*46+stgx+p,448+25,270,i);
		if(i!=0){
		FireLaser(-i*46+stgx+p,448+25,270,i);
		}
		wait(10);
		}
		wait(200);
		TAccel(35,5,0.1,60);
		wait(200);
		s = -s;
		}
}

task FireLaser(x,y,dir,num){
	let ang = num*90*s;
	let angular = rand(43,47);
	let test = PagodarLaser(x,y,dir,1000,75,210,"RED");
	wait(165);
	y -= 50*sin(dir);
	ascent(i in 0..30){
	PlaySound("BulletWave",95,0);
	let shot = ScalingBullet(x,y,0,ang,376,60,0.85,0,20);
	ObjMove_AddPatternA2(shot,0,NO_CHANGE,NO_CHANGE,0.005,0,1);
	ObjMove_AddPatternA2(shot,90,NO_CHANGE,NO_CHANGE,0.0075,0,2);
	y += 19*sin(dir);
	ang += angular;
	yield;
	}
}
	
task TLaser(p,color){
		ascent(i in -1..1){
		PlaySound("Laser2",95,0);
		let shot = CurvyLaser(GetEnemyX,GetEnemyY,3,90+i*p+p/2,5,35,color,0);
		Homing(shot,0.5,0,0);
		ObjMove_AddPatternA2(shot,0,NO_CHANGE,NO_CHANGE,-3/60,-3,1);
		ObjMove_AddPatternA2(shot,60,NO_CHANGE,NO_CHANGE,3/60,-0.5,6);
		}
		wait(90);
	}

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

task TRender
{
	DrawBoss;
}

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

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