#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Unused Spell Card"]
#Text["You may try it if you want :)"]
#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);
}

@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(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,150,10,7);
	Cutin("? Sign\"!?!?!?\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(30);
	//Fam;
	wait(60);
	TShot1;
	TShot3;
	wait(300);
	TShot2;
	wait(240);
	}
//----------------------------------------------------

task TShot3{
	let n = 0;
	while(!Obj_IsDeleted(objBoss)){
	PlaySound("Shot1",90,0);
		ascent(i in 0..12){
			ascent(j in 0..6){
			let shot = ShotOA1(objBoss,0.5,i*30+j*3+n*15,115,0,8);
			ObjShot_SetSpellResist(shot,true);
			ObjRender_SetColor(shot,128,192,255);
			}
		}
	n++;
	wait(120);
	}
	}

task TShot2{
	let m = 0;
	while(!Obj_IsDeleted(objBoss)){
	TAccel(15,5,0.1,30);
	DDCharge((m%2+1));
	wait(75);
	Laser;
		task Laser{
			ascent(n in 0..4){
			Tail(GetEnemyX+n*60,n,m);
			if(n!=0){Tail(GetEnemyX-n*60,n,m);}
			wait(10);
			}
		}
	wait(240);
	m++;
	}
			task Tail(px,num,m){
			let ang = 0;
			if(m%2==1){ang=getDotAngle(GetPlayerX,GetPlayerY,px,0);}
			else{ang = 90;}
			PlaySound("Boon2",90,0);
			let obj = CreateStraightLaserA1(px,0,ang,0,50,0,19,90-num*10);
				ascent(i in 0..45){
				ObjLaser_SetLength(obj,i*12);
				yield;
				}
				wait(90-(45+num*10));
				ObjLaser_SetRenderWidth(obj,25);
				PlaySound("Boon1",90,0);
				obj = CreateStraightLaserA1(px,0,ang,0,25,75,18,0);
				ObjRender_SetColor(obj,128,128,255);
				ObjLaser_SetLength(obj,555);
				yield;
				loop(37){
				ObjLaser_SetRenderWidth(obj,rand(23,27));
				wait(2);
				}
				descent(i in 0..25){
				ObjLaser_SetRenderWidth(obj,i);
				yield;
				}
			}
	}
	
	task DDCharge(type){
		PlaySound("Charge2",90,0);
		if(type==1){
		ascent(i in 0..60){
		Doteff2(GetEnemyX,0,30+rand(-20,20),300,1.25,0,"AQUA",60);
		Doteff2(GetEnemyX,0,30+rand(-20,20),300,1.25,0,"PURPLE",60);
		yield;
		}
		}
		if(type==2){
		ascent(i in 0..60){
		Doteff2(GetEnemyX,0,150+rand(-20,20),300,-1.25,0,"AQUA",60);
		Doteff2(GetEnemyX,0,150+rand(-20,20),300,-1.25,0,"PURPLE",60);
		yield;
		}
		}
	}

task TShot1{
		let n = 0;
		maple(1);
		wait(75);
		while(!Obj_IsDeleted(objBoss)){
			PlaySound("Shot6",90,0);
			ascent(j in 0..5){
			let obj = ShotA2(0,j*100+40*sin(n*27),0.5,sin(n*27)*10,0.0075,5,82,0,12);
			}
			wait(10);
			PlaySound("Shot6",90,0);
			ascent(j in 0..5){
			let obj = ShotA2(stgx*2,j*100+40*sin(n*27+180),0.5,sin(-n*27+180)*10+180,0.0075,5,84,0,12);
			}
			wait(10);
			n++;
		}
	}
	
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<90){r++;}
			ObjMove_SetPosition(ene,GetEnemyX+r*cos(ang+c),GetEnemyY+r*sin(ang+c));
			c+=1;
			yield;
			}
		}
	}

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

task TRender
{
	DrawBoss;
}

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

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