
#ScriptVersion[3]
#Title["SP4L"]
#Text["SP4L"]
#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);
}

@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(2225);
	}
	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("Perfect Sanctification [Lunatic]",15,"SHOU");
	ObjEnemyBossScene_StartSpell(objScene);
	wait(90);
	TShot1;
	}
//----------------------------------------------------

task TShot1{
	let d = 0;
	PlaySound("Boon1",100,0);
	PlaySound("Laser2",95,120);
	ascent(i in 0..9){
	Plate(GetEnemyX,GetEnemyY,360/9*i,0,1);
	}
	wait(480);
	while(!Obj_IsDeleted(objBoss)){
	d = rand(0,30);
	PlaySound("Boon1",100,0);
	PlaySound("Laser2",95,120);
	ascent(i in 0..9){
	Plate(GetEnemyX,GetEnemyY,360/9*i+d,0,-1);
	}
	wait(240);
	TMovement(35,5,2);
	wait(240);
	PlaySound("Boon1",100,0);
	PlaySound("Laser2",95,120);
	ascent(i in 0..9){
	Plate(GetPlayerX,GetPlayerY,360/9*i+d,0,1);
	}
	wait(240);
	TMovement(35,5,2);
	wait(240);
	}
}

task Plate(x,y,num,type,way){
	let dir = num;
	let shot = PagodarLaser(GetEnemyX+60*cos(dir),GetEnemyY+60*sin(dir),dir,1000,120,300,"YELLOW");
	let p = [0,0];
	let px = 0;
	let py = 0;
		px = GetPlayerX;
		py = GetPlayerY;
		descent(i in 0..120){
		if(type==0){
		px = GetEnemyX;
		py = GetEnemyY;
		dir += i/60*way;
		ObjMove_SetPosition(shot,GetEnemyX+i/2*cos(dir),GetEnemyY+i/2*sin(dir));
		}
		if(type==1){
		dir -= i/60;
		ObjMove_SetPosition(shot,px+i/2*cos(dir),py+i/2*sin(dir));
		}
		ObjMove_SetAngle(shot,dir);
		yield;
		}
		wait(60);
		let s = 1;
		ascent(n in 0..24){
			if(Obj_IsDeleted(objBoss)){break;}
			PlaySound("BulletWave",95,0);
			if(type==0){
			let obj = ShotA2(GetEnemyX+n*18*cos(dir+360/18+360/36*s),GetEnemyY+n*18*sin(dir+360/18+360/36*s),0,dir+360/18+360/36*s+180,0.02,4,346,0,12);
			obj = ShotA2(GetEnemyX+n*18*cos(dir+360/18+360/36*s),GetEnemyY+n*18*sin(dir+360/18+360/36*s),0,dir+360/18+360/36*s,0.02,4,346,0,12);
			}
			if(type==1){
			let obj = ShotA2(px+n*18*cos(dir+360/18+360/36*s),py+n*18*sin(dir+360/18+360/36*s),0,dir+360/18+360/36*s+180,0.02,4,346,0,12);
			obj = ShotA2(px+n*18*cos(dir+360/18+360/36*s),py+n*18*sin(dir+360/18+360/36*s),0,dir+360/18+360/36*s,0.02,4,346,0,12);
			}
			s = -s;
			wait(1+n%2);
		}
		p = GetLineBorderPoint(px, py, px+1000*cos(dir), py+1000*sin(dir));
		
		CreateLooseLaserA1(px,py,1.5,dir+360/18,100,20,119,0);
		CreateLooseLaserA1(px,py,1.5,dir+360/18+360/18,100,20,119,0);
		if(!Obj_IsDeleted(objBoss)){
		ascent(i in 0..12){
			ascent(j in 0..4){
			let r = ShotA2(p[0],p[1],0,i*30+j*2.25,0.01,1.75,346,0,12);
			}
		}
		ascent(i in 0..24){
		ShotA2(p[0],p[1],0.5+(i%2)*0.75,i*15,0,0,55,0,8);
		}
		}
}


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

task TRender
{
	DrawBoss;
}

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

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT) +ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0)
		{AddScore(ObjEnemyBossScene_GetInfo(objScene,INFO_SPELL_SCORE));}
		let dis = 0;
		let px = GetEnemyX;
		let py = GetEnemyY;
		ClearBullet(90,10);
		TAccel(50,10,0.02,120);
		MapleExplode(180,1,2,5);
		PlaySound("enemoff",95,0);
		wait(105);
		PlaySound("enemoff",100,0);
		MapleExplode(20,50,1,6);
		Obj_Delete(objBoss);
		wait(30);
		SetAutoDeleteObject(true);
		loop(240){yield;}
		CloseScript(GetOwnScriptID());
		return;
	}