#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);
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(60);
	}
		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("Facade Sign\"????\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(30);
	Fam;
	wait(60);
	TShot1;
	}
//----------------------------------------------------

task TShot1{
	let px = stgx;
	let py = 0;
	let mv = 2;
	let sx = 0;
	let pm = rand(0,360);
	let color = [109,112];
	let t = 0;
		smaple(0,50,80,0,1,45);
		wait(75);
		while(!Obj_IsDeleted(objBoss)){
		let st = rand(0,360);
		PlaySound("Eff5",100,0);
		ascent(n in 0..10){
		let laser = CreateStraightLaserA1(px+n*5,0,90,500,20,0,23,0);
		ObjRender_SetColor(laser,32,32,32);
		laser = CreateStraightLaserA1(px-n*5,0,90,500,20,0,23,0);
		ObjRender_SetColor(laser,32,32,32);
		wait(3);
		}
		sx = px;
		wait(30);
		PlaySound("Eff1",95,100);
		descent(n in 40..240){
		let vx = 1.5+0.25*sin(n*137);
		PlaySound("BulletWave",90,0);
		let shot = ShotA2(px+n*vx,stgy+250*sin(n*57+st),0,0,0,0,color[n%2],0,12);
		ObjMove_AddPatternA2(shot,100,3,NO_CHANGE,-0.05,0,-mv);
		if(n%9==0){DelayShot(shot,342+(n%2),2.5,64,12,100);}
		else{DelayShot(shot,0,2.5,64,12,100);}
		shot = ShotA2(px-n*vx,stgy-250*sin(n*57+st),0,0,0,0,color[n%2],0,12);
		ObjMove_AddPatternA2(shot,100,-3,NO_CHANGE,0.05,0,mv);
		if(n%9==0){DelayShot(shot,342+(n%2),2.5,64,12,100);}
		else{DelayShot(shot,0,2.5,64,12,100);}
		mv -= 2.1/220;
		wait(n%2);
		}
			ascent(i in 0..20){
			ascent(a in 0..6){
			let shot = ShotA1(sx+50,i*23,1+a,0,188,0,9);
			//DelayShot(shot,188,2.5,0,12,0);
			shot = ShotA1(sx-50,i*23,1+a,180,188,0,9);
			//DelayShot(shot,188,2.5,0,12,0);
			}
			}
		TLaser(t%2);
		wait(120);
		TAccel(25,5,0.1,60);
		wait(120);
		mv = 2;
		px = stgx+75*sin(t*77+pm);
		t++;
		}
	}
	
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());
	}