#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["S2"]
#Text["S2"]
#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"
#BGM["./boss6.mp3"]


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(false);
}

@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(2500);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(45);
	}
}

//----------------------------------------------------
task mainTask{
	DamageRateAtFrame(100,50,120);
	Circle(64,64,64,10);
	ObjMove_SetDestAtWeight(objBoss,stgx,110,10,7);
	wait(30);
	maple(3);
	wait(90);
	TShot1;
	TShot3;
	wait(60);
	TShot2;
	}
//----------------------------------------------------

task TShot1{
	
	while(!Obj_IsDeleted(objBoss)){
	ascent(i in -1..2){
	//PlaySound("Shot1",80,0);
	let dir = i*12-30;
	let shot = ShotA1(GetEnemyX+5*cos(dir),GetEnemyY+5*sin(dir),4.5,dir-i*6,57,205,12);
	dir = i*12+210;
	shot = ShotA1(GetEnemyX+5*cos(dir),GetEnemyY+5*sin(dir),4.5,dir-i*6,57,205,12);
	//ObjMove_AddPatternA2(shot,30,NO_CHANGE,NO_CHANGE,-3.5/90,3.5-i/2,0);
	//ObjMove_AddPatternA2(shot,60,NO_CHANGE,NO_CHANGE,3.5/90,0,3.5);
	}
	wait(15);
	}
}

task TShot2{
	while(!Obj_IsDeleted(objBoss)){
		let st = rand(-5,5);
		PlaySound("BulletWave",90,0);
		ascent(i in -3..4){
		OvalShot(i*20+st+angleToPlayer,308,202);
		}
		wait(15);
		st = rand(-5,5);
		PlaySound("BulletWave",90,0);
		ascent(i in -3..4){
		OvalShot(i*20+st+angleToPlayer,310,204);
		}
		wait(15);
	}
	task OvalShot(dir,color,cloud){
	let shotc = 0;
	if(color==308){shotc = 51;}
	if(color==310){shotc = 55;}
	let shot = ShotA2(GetEnemyX,GetEnemyY,4,dir,-4/60,0,color,cloud,12);
	wait(60);
		if(!Obj_IsDeleted(shot)){
		ascent(i in 0..2){
		ShotA1(ObjMove_GetX(shot),ObjMove_GetY(shot),2.5+i/3,ObjMove_GetAngle(shot),shotc,cloud,8);
		}
		Obj_Delete(shot);
		}
	}
}

task TShot3{
	let c =0;
	let dir = 0;
	while(!Obj_IsDeleted(objBoss)){
		ascent(n in 0..5){
			PlaySound("Shot1",92,0);
			ascent(i in 0..2){
				ascent(a in 0..2){
				let dir = i*180+c;
				ShotA1(GetEnemyX+60*cos(dir),GetEnemyY+60*sin(dir),1.5+a/2,dir,280,0,8);
				}
			}
			wait(4);
			c+=4;
		}
		c+=12.5;
	}
}

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

task TRender
{
	DrawBoss;
}

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

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