#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell6"]
#Text["Spell6"]
#Background["./BG.txt"]
#Player["./MoF_Reimu/Reimu.txt"]
#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);
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(2225);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(61);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3000000);
	}
}

//----------------------------------------------------
task mainTask{
	DamageRateAtFrame(40,0,240);
	DamageRateAtFrame(75,0,1380);
	magiccircle(objBoss,0.8,true);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,7);
	Cutin("Joy Sign\"Grand Underground Festival\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(30);
	Fam;
	wait(60);
	TShot1;
	//TExtra;
	}
//----------------------------------------------------

function TExtra{
	wait(30);
	let s = 1;
	let dir = 0;
	ascent(i in -1..1){
	PlaySound("Laser6",95,0);
	let shot = CurvyLaser(GetEnemyX,GetEnemyY,4,angleToPlayer+i*75+37.5,10,40,502+s,0);
	let curve = 1*s;
	Homing(shot,0.75,0,0);
	ObjMove_AddPatternA2(shot,0,4,NO_CHANGE,-4/60,0,1);
	ObjMove_AddPatternA2(shot,60,NO_CHANGE,NO_CHANGE,4/60,0,5);
	}
}
	

task TAim{
	let dir = 0;
	while(!Obj_IsDeleted(objBoss)){
		dir = rand(0,360);
		PlaySound("Shot1",90,0);
		AimShot(dir);
		wait(8);
	}
		task AimShot(dir){
		let v = rand(2,3);
		let shot = ShotA2(GetEnemyX,GetEnemyY,v,dir,-v/90,0,324,0,12);
		wait(90);
		PlaySound("BulletWave",90,0);
		ObjMove_AddPatternA2(shot,0,0,GetAngleToPlayer(shot),0.01,0,3);
		}
}

task TShot1{
	let px = stgx+90;
	let py = 0;
	let mv = 2;
	let sx = 0;
	let pm = rand(0,360);
	let color = [109,112];
	let t = 120;
	let s = 1;
	let count =0;
		while(!Obj_IsDeleted(objBoss)){
		smaple(0,50,360,0,1,45);
		PlaySound("Charge3",95,0);
		loop(4){
		ascent(n in 0..10){
		let laser = CreateStraightLaserA1(px+n*5,0,90,500,20,0,23,0);
		ObjRender_SetColor(laser,32,32,64);
		laser = CreateStraightLaserA1(px-n*5,0,90,500,20,0,23,0);
		ObjRender_SetColor(laser,32,32,64);
		let shot = ShotA1(px+rand(-50,50),448,0,0,342,0,8);
		ObjShot_SetDeleteFrame(shot,0);
		wait(3);
		}
		}
		TExpan(GetEnemyX,GetEnemyY,10,120,128,0,255);
		PlaySound("soul",95,0);
		SoulEffect(px);
		TLaser(0.5+0.5*s);
		ascent(n in 0..60){
		ShotB2(px+60*sin(n*10),448,rand(-1,1),-5-2*sin(n*10),0,0.03,0,rand(1,2.5),109,0,8);
		ShotB2(px-60*sin(n*10),448,rand(-1,1),-5+2*sin(n*10),0,0.03,0,rand(1,2.5),112,0,8);
		//ShotB2(px+rand(-60,60),448,rand(-1,1),rand(-3.5,-7),0,0.03,0,rand(1,3),round(rand(342,343)),0,8);
		let shot = ShotB2(px+rand(-60,60),448,rand(-1,1),rand(-3.5,-7),0,0.03,0,rand(1,3),round(rand(342,343)),0,8);
		//Manage(shot);
		if(n%30==29){TExpan(GetEnemyX,GetEnemyY,10,120,128,0,255);}
		wait(2);
		}
		TExtra;
		wait(t);
		TAccel(35,5,0.05,60);
		wait(t);
		s = -s;
		if(t>40){t-=20;}
		px = GetPlayerX;
		if(px<50){px=50;}
		if(px>334){px=334;}
		count++;
		}
		task Manage(shot){
		wait(105);
		PlaySound("BulletWave",85,0);
		DelayShot(shot,round(rand(411,412)),2.5,0,12,0);
		ObjMove_AddPatternA2(shot,0,NO_CHANGE,GetAngleToPlayer(shot),0.02,0,rand(1.5,3));
		}
}

task SoulEffect(px){
		loop(8){
		ascent(n in 0..15){
		let laser = CreateStraightLaserA1(px+n*5,0,90,500,20,0,23,0);
		ObjRender_SetColor(laser,32,32,64);
		laser = CreateStraightLaserA1(px-n*5,0,90,500,20,0,23,0);
		ObjRender_SetColor(laser,32,32,64);
		let shot = ShotA1(px+rand(-50,50),448,0,0,342,0,8);
		ObjShot_SetDeleteFrame(shot,0);
		wait(1);
		}
		}
}

task TLaser(type){
		let px = 0;
		let py = 0;
			if(type==0){
				ascent(n in 0..11){
				Laser(px,py);
				px = n*42;
				wait(10);
				}
			}
			else{
				descent(n in 0..11){
				px = n*42;
				Laser(px,py);
				wait(10);
				}
			}
		task Laser(px,py){
		let obj = CreateStraightLaserA1(px,py,90,0,10,60,5,60);
			CreateStraightLaserA1(px,py,90,0,20,0,5,60);
			ascent(i in 0..30){
			ObjLaser_SetLength(obj,i*16);
			yield;
			}
			wait(90);
			descent(i in 0..10){
			ObjLaser_SetRenderWidth(obj,i);
			yield;
			}
		}
	}

task Fam{
	ascent(i in 0..9){
	let ene = fam(GetEnemyX,GetEnemyY,25000,0.5,3,false);
	Control(ene,i);
	}
		task Control(ene,num){
			let maxa = num*40;
			let ang = 0;
			let c = 0;
			let r = 0;
			while(!Obj_IsDeleted(ene)){
			if(ang<maxa){ang += maxa/120;}
			if(r<60){r+=0.5;}
			ObjMove_SetPosition(ene,GetEnemyX+r*cos(-ang+c),GetEnemyY+r*sin(-ang+c));
			c-=0.5;
			yield;
			}
		}
	}
		

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

task TRender
{
	DrawBoss;
}

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

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