
#ScriptVersion[3]
#Title["SP2"]
#Text["SP2"]
#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 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(1750);
	}
	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,140,10,7);
	Cutin("Buddhist Art\"Sacred Vajra [Hard]\"",15,"SHOU");
	ObjEnemyBossScene_StartSpell(objScene);
	wait(120);
	TShot1;
	}
//----------------------------------------------------

task TShot1{
	let d = 0;
	let s = 1;
	while(!Obj_IsDeleted(objBoss)){
	SpearLaser(900,120,1,1,1);
	SpearLaser(0,300,0,1,1);
	wait(165);
	TAccel(35,5,0.1,45);
	wait(120);
	SpearLaser(900,60,1,-1,1);
	SpearLaser(0,240,0,-1,1);
	wait(240);
	ObjMove_SetDestAtWeight(objBoss,stgx,140,10,2);
	maple(3);
	wait(110);
	SpearLaser(900,120,1,1,2);
	SpearLaser(0,300,0,1,2);
	SpearLaser(900,60,1,-1,2);
	SpearLaser(0,240,0,-1,2);
	wait(180);
	TAccel(35,5,0.1,45);
	wait(90);
		ascent(n in 0..12){
			PlaySound("BulletWave",95,0);
			d = rand(-7,7);
			ascent(i in 0..15){
			ShotA1(GetEnemyX,GetEnemyY,0.5+n/3,i*24+d+angleToPlayer,344,0,8);
			}
			wait(8);
		}
	wait(120);
	}
	}
	
task SpearLaser(l,dir,type,way,time){
	let p = [0,0];
	let s = 1;
	PlaySound("Boon1",100,0);
	PlaySound("Laser2",95,60);
	let shot = PagodarLaser(GetEnemyX,GetEnemyY,dir,l,60,270,"AQUA");
	wait(60);
		ascent(n in 0..105){
		if(n%time==0){
		PlaySound("BulletWave",92,0);
		ObjMove_SetAngle(shot,dir);
		p = GetLineBorderPoint(GetEnemyX, GetEnemyY, GetEnemyX+1000*cos(dir), GetEnemyY+1000*sin(dir));
		if(type!=0){
		ShotA1(p[0],p[1],rand(1,1.5),n*rand(43,47),381,0,8);
			if(n%10==0){
				ascent(i in 0..7){
				//ShotA2(p[0],p[1],0,getDotAngle(GetEnemyX,GetEnemyY,p[0],p[1])+i*360/7,0.015,2,344,0,8);
				}
			}
		}
		}
		dir += n/35*way;
		yield;
		}
		descent(n in 0..105){
		if(n%2==0){
		PlaySound("BulletWave",92,0);
		ObjMove_SetAngle(shot,dir);
		p = GetLineBorderPoint(GetEnemyX, GetEnemyY, GetEnemyX+1000*cos(dir), GetEnemyY+1000*sin(dir));
		if(type!=0){
		ShotA1(p[0],p[1],rand(1,1.5),n*rand(43,47),381,0,8);
			if(n%10==0){
				ascent(i in 0..7){
				//ShotA2(p[0],p[1],0,getDotAngle(GetEnemyX,GetEnemyY,p[0],p[1])+i*360/7,0.015,2,344,0,8);
				}
			}
		}
		}
		dir += n/35*way;
		yield;
		}
	}

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

task TRender
{
	DrawBoss;
}

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

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