
#ScriptVersion[3]
#Title["SP3"]
#Text["SP3"]
#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("Life",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(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("Holy Sign\"Heaven's Gate [Hard]\"",15,"SHOU");
	ObjEnemyBossScene_StartSpell(objScene);
	wait(90);
	TShot1;
	wait(240);
	TShot2;
	}
//----------------------------------------------------

task TShot1{
		let d = 120;
		while(!Obj_IsDeleted(objBoss)){
		PLaser(0,0);
		wait(d);
		if(d>90){d-=10;}
		PLaser(384,180);
		wait(d);
		if(d>90){d-=10;}
		}
	}
	
task TShot2{
	maple(3);
	wait(110);
	while(!Obj_IsDeleted(objBoss)){
	ascent(n in 0..30){
		ascent(i in 0..2){
		PlaySound("Laser2",94,0);
		let shot = CurvyLaser(GetEnemyX,GetEnemyY,4,i*180+n*17,5,30,510,0);
		ObjMove_AddPatternA2(shot,0,NO_CHANGE,NO_CHANGE,-0.06,1,0.5);
		ObjMove_AddPatternA2(shot,75,NO_CHANGE,NO_CHANGE,0.04,0.25,5);
		}
		if(n==10){RandomBullet(n,1);}
		wait(10);
	}
	TMovement(35,5,1);
	maple(2);
	wait(60);
	ascent(n in 0..30){
		ascent(i in 0..2){
		PlaySound("Laser2",94,0);
		let shot = CurvyLaser(GetEnemyX,GetEnemyY,4,i*180-n*17,5,30,510,0);
		ObjMove_AddPatternA2(shot,0,NO_CHANGE,NO_CHANGE,-0.06,-1,0.5);
		ObjMove_AddPatternA2(shot,75,NO_CHANGE,NO_CHANGE,0.04,-0.25,5);
		}
		if(n==10){RandomBullet(n,-1);}
		wait(10);
	}
	ObjMove_SetDestAtWeight(objBoss,stgx,130,10,3);
	maple(2);
	wait(60);
	}
}

task RandomBullet(num,s){
	let dir = num*17;
	ascent(n in 0..50){
		PlaySound("BulletWave",95,0);
		ascent(i in 0..2){
		let shot = ShotA2(GetEnemyX+75*cos(i*180+dir),GetEnemyY+75*sin(i*180+dir),1.5,i*180+dir,0.02,rand(2.5,3.5),305,0,12);
		ObjMove_SetAngularVelocity(shot,0.5*-s);
		}
		dir += 17*s;
		wait(5);
	}
}

task PLaser(x,dir){
	PlaySound("Boon1",100,0);
	let pag = PagodarLaser(x,0,dir,1000,999,360,"GREEN");
	let t = 2;
	while(!Obj_IsDeleted(pag)){
	if(ObjMove_GetY(pag)>GetPlayerY && t == 2){
	PlaySound("Laser2",95,0);
	Obj_SetValue(pag,"time",1);
	t = 1.25;
	}
	ObjMove_SetY(pag,ObjMove_GetY(pag)+t);
	yield;
	}
	Obj_Delete(pag);
}

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

task TRender
{
	DrawBoss;
}

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

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