#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell8"]
#Text["Spell8"]
#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(2750);
	}
	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("Remorse\"Endless Maze of Guilt\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(30);
	Fam;
	//Mask;
	wait(60);
	Maze;
	wait(240);
	//TShot1;
	}
//----------------------------------------------------

task Mask{
		smaple(0,60,40,1.5,1,45);
		wait(75);
	PlaySound("Boon1",95,0);
		Manage;
		task Manage{
		let ene = fam(GetEnemyX,GetEnemyY,25000,0.75,4,true);
		Homing(ene,1,0,0);
		let c = 0;
			while(!Obj_IsDeleted(ene)){
			ObjMove_SetSpeed(ene,0.5+0.2*sin(c));
			if(c%7==0 && c>120){TShot;}
			c++;
			yield;
			}
			task TShot{
			let dir = ObjMove_GetAngle(ene)+180;
			let v = rand(3,4);
			PlaySound("Shot1",85,0);
			let shot = ShotA2(ObjMove_GetX(ene),ObjMove_GetY(ene),2,dir,-2/60,0,120,0,0);
			DelayShot(shot,120,2,0,12,0);
			wait(120);
			effbreak(shot,0.1,1);
			Obj_Delete(shot);
			}
		}
	}

task Maze{
		let px = 0;
		let r = 0;
		let c = 1;
		let arr = [0,0,0,0,0,0,0,0,0,0];
		PlaySound("Charge2",95,0);
			if(GetCommonData("Effect",2)==2){
			ascent(i in 0..30){
			ascent(j in 0..5){
			Doteff2(j*91+rand(-20,20),0,90+rand(-20,20),470,0,0,"AQUA",90);
			Doteff2(j*91+rand(-20,20),0,90+rand(-20,20),470,0,0,"PURPLE",90);
			}
			wait(2);
			}
			}
			else if(GetCommonData("Effect",2)==1){
			ascent(i in 0..20){
			ascent(j in 0..5){
			Doteff2(j*91+rand(-20,20),0,90+rand(-20,20),470,0,0,"AQUA",90);
			Doteff2(j*91+rand(-20,20),0,90+rand(-20,20),470,0,0,"PURPLE",90);
			}
			wait(3);
			}
			}
			else if(GetCommonData("Effect",2)==0){
			ascent(i in 0..10){
			ascent(j in 0..5){
			Doteff2(j*91+rand(-20,20),0,90+rand(-20,20),470,0,0,"AQUA",90);
			Doteff2(j*91+rand(-20,20),0,90+rand(-20,20),470,0,0,"PURPLE",90);
			}
			wait(6);
			}
			}
		wait(15);
		while(!Obj_IsDeleted(objBoss)){
		ascent(p in 0..10){
		r = round(rand(0,1));
		Block(p*55,r,0);
		}
		c++;
		PlaySound("Shot6",95,10);
		if(c==7){Shot1;}
		if(c%4==0){
		TMovement(30,5,2);
		}
		wait(60);
		}
	}
	
task Shot1{
	let c = 0;
	wait(25);
	smaple(0,75,40,-1.5,1,45);
	wait(75);
		while(!Obj_IsDeleted(objBoss)){
			PlaySound("Shot9",100,0);
			ascent(i in 0..9){
			ShotA2(i*47,0,4,90+rand(-10,10),-4/60,rand(1,1.25),283,0,8);
			}
			c++;
			if(c%2==0){
			PlaySound("Shot5",98,0);
			ShotOA1(objBoss,1,angleToPlayer,314,0,8);
			}
		wait(60);
		}
	}

task Block(px,type,way){
		way = round(rand(0,1));
		if(type==0){
			ascent(i in 0..6){
			let shot = ShotA2(px,-20,0,90,0,0,104,0,0);
			Manage(shot);
			wait(12);
			}
		}
		if(type==1){
			ascent(i in 0..6){
			let shot = ShotA2(px+i*6.5+way*15.5,-20,0,90,0,0,104,0,0);
			Manage(shot);
			}
		}
			task Manage(shot){
				ObjShot_SetSpellResist(shot,true);
				let v = 1;
				while(!Obj_IsDeleted(shot)){
				ObjMove_SetY(shot,ObjMove_GetY(shot)+v);
				yield;
				}
			}
	}
	
task Fam{
	ascent(i in 0..3){
	let ene = fam(GetEnemyX,GetEnemyY,25000,0.5,4,false);
	Control(ene,i,1);
	}
	ascent(i in 0..3){
	let ene = fam(GetEnemyX,GetEnemyY,25000,0.5,4,false);
	Control(ene,i,-1);
	}
		task Control(ene,num,way){
			let maxa = num*120;
			let ang = 0;
			let c = 0;
			let r = 0;
			while(!Obj_IsDeleted(ene)){
			if(ang<maxa){ang += maxa/120;}
			if(r<45 && way==-1){r+=45/120;}
			if(r<75 && way==1){r+=75/120;}
			ObjMove_SetPosition(ene,GetEnemyX+r*cos(ang*way+c),GetEnemyY+r*sin(ang*way+c));
			c+=way+0.125;
			yield;
			}
		}
	}

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

task TRender
{
	DrawBoss;
}

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

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