#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell9"]
#Text["Spell9"]
#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 v = 0.3;
let SoulMove = -1;
let objScene=GetEnemyBossSceneObjectID();
let arr = [1,6,4,2,3,5,0];
@Initialize
{
SetBoss(true);
SetShotAutoDeleteClip(32,32,32,32);
}

@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(2000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3000000);
	}
}

//----------------------------------------------------
task mainTask{
	DamageRateAtFrame(50,0,300);
	DamageRateAtFrame(75,0,1380);
	magiccircle(objBoss,0.8,true);
	ObjMove_SetDestAtWeight(objBoss,stgx,130,10,7);
	Cutin("Possession\"Overflowing Emotions\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(90);
	smaple(1,60,360,1.5,1,30);
	wait(15);
	smaple(0,60,360,1.5,1,30);
	wait(75);
	RandomMovement;
	TMain1;
	wait(240);
	TMain2;
	wait(240);
	TMain3;
	wait(240);
	TMain4;
	}
//----------------------------------------------------

task RandomMovement{
	wait(240);
	while(!Obj_IsDeleted(objBoss)){
	TMovement(35,5,3);
	wait(300);
	}
}

task TMain1{
	let ene = fam(-30,stgy,500,0.5,3,true); // Normal
	Control(ene,-30,1);
	ene = fam(414,stgy,500,0.5,3,true);
	Control(ene,414,2);
		task Control(ene,sx,type){
		PlaySound("Eff5",95,0);
		if(type==1){ObjMove_SetDestAtWeight(ene,stgx+120,150,8,7);}
		if(type==2){ObjMove_SetDestAtWeight(ene,stgx-120,150,8,7);}
		wait(120);
			let c = 0;
			while(!Obj_IsDeleted(ene)){
				PlaySound("Shot1",95,0);
				PlaySound("BulletWave",90,75);
				ascent(i in 0..20){
				let shot = ShotA2(ObjMove_GetX(ene)+60*cos(i*18+c),ObjMove_GetY(ene)+60*sin(i*18+c),1,i*18+c,0.015,4,65,0,8);
				ObjMove_AddPatternA2(shot,75,NO_CHANGE,NO_CHANGE,-0.04,0,0.75);
				}
				c+=8;
				wait(90);
			}
			wait(60);
			ene = fam(sx,stgy,400,0.5,3,true);
			Control(ene,sx,type);
		}
	}
	
task TMain2{
	let ene = fam(-30,stgy+140,500,0.5,2,true); // Sad
	Control(ene,-30,1);
	ene = fam(414,stgy+140,500,0.5,2,true);
	Control(ene,414,2);
		task Control(ene,sx,type){
		PlaySound("Eff5",95,0);
		if(type==1){ObjMove_SetDestAtWeight(ene,stgx+40,60,8,7);}
		if(type==2){ObjMove_SetDestAtWeight(ene,stgx-40,60,8,7);}
		wait(120);
			let c = 0;
			let dir = 0;
			while(!Obj_IsDeleted(ene)){
				PlaySound("Shot6",95,0);
				BShot(dir);
				BShot(180-dir);
				if(c<=18){dir+=10;}
				else if(c<36){dir-=10;}
				else if(c>=36){c=0;}
				c++;
				wait(15);
			}
			wait(60);
			ene = fam(sx,stgy+50,400,0.5,2,true);
			Control(ene,sx,type);
				task BShot(dir){
					let shot = ShotOA1(ene,2,dir,100,0,0);
					DelayShot(shot,0,2,0,12,0);
					/*while(ObjMove_GetX(shot)>0 && ObjMove_GetX(shot)<384){yield;}
					PlaySound("BulletWave",90,0);
					ObjMove_SetAngle(shot,180-ObjMove_GetAngle(shot));
					DelayShot(shot,103,2,0,12,0);
					ObjMove_AddPatternA2(shot,0,NO_CHANGE,NO_CHANGE,-0.02,0,1);*/
				}
		}
	}
	
task TMain3{
	let ene = fam(-30,stgy,500,0.5,1,true); // Angry
	Control(ene,-30,1);
	ene = fam(414,stgy,500,0.5,1,true);
	Control(ene,414,2);
		task Control(ene,sx,type){
		PlaySound("Eff5",95,0);
		if(type==1){ObjMove_SetDestAtWeight(ene,stgx+150,90,8,7);}
		if(type==2){ObjMove_SetDestAtWeight(ene,stgx-150,90,8,7);}
		wait(60);
			let c = 0;
			while(!Obj_IsDeleted(ene)){
				TCharge02(ene,2,60,255,0,0);
				wait(60);
				ascent(i in 0..5){
				ascent(j in 0..3){
				Laser(GetAngleToPlayer(ene)-30+j*30);
				}
				wait(10);
				}
				wait(150);
			}
			wait(60);
			ene = fam(sx,stgy,400,0.5,1,true);
			Control(ene,sx,type);
				task Laser(dir){
				PlaySound("Laser2",90,0);
				let obj = CreateStraightLaserA1(ObjMove_GetX(ene),ObjMove_GetY(ene),dir,0,15,30,3,60);
					ascent(i in 0..30){
					ObjLaser_SetLength(obj,i*20);
					if(Obj_IsDeleted(ene)){Obj_Delete(obj);}
					yield;
					}
					loop(60){
					if(Obj_IsDeleted(ene)){Obj_Delete(obj);}
					yield;
					}
					descent(i in 0..20){
					ObjLaser_SetRenderWidth(obj,i);
					if(Obj_IsDeleted(ene)){Obj_Delete(obj);}
					yield;
					}
				}
		}
	}
	
task TMain4{
	let ene = fam(-30,0,500,0.5,4,true); // Fox
	Control(ene,-30,1);
	ene = fam(414,0,500,0.5,4,true);
	Control(ene,414,2);
		task Control(ene,sx,type){
		PlaySound("Eff5",95,0);
		if(type==1){ObjMove_SetDestAtWeight(ene,stgx+55,220,8,7);}
		if(type==2){ObjMove_SetDestAtWeight(ene,stgx-55,220,8,7);}
		wait(120);
			let c = 0;
			let s = rand(-1,1);
			if(s>=0){s=1;}
			if(s<0){s=-1;}
			while(!Obj_IsDeleted(ene)){
				TCharge02(ene,2,60,255,255,0);
				wait(60);
				let d = rand(0,70);
				ascent(n in 0..12){
					PlaySound("BulletWave",95,0);
					ascent(i in 0..5){
					let shot = ShotOA1(ene,1.2,i*360/5+d,338,0,8);
					ObjMove_SetAngularVelocity(shot,2*s);
					ObjMove_AddPatternA2(shot,rand(90,100),NO_CHANGE,NO_CHANGE,0,0,0);
					}
				wait(10);
				}
				s = -s;
				wait(180);
			}
			wait(60);
			ene = fam(sx,stgy,400,0.5,4,true);
			Control(ene,sx,type);
		}
	}

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

task TRender
{
	DrawBoss;
}

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

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