#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(2500);
	}
	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,120,10,7);
	Cutin("Joyous Semblance\"!?!?!?\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(30);
	//SetShotAutoDeleteClip(32,32,32,32);
	Fam;
	wait(60);
	TShot1;
	wait(360);
	TAim;
	}
//----------------------------------------------------

task TAim{
		while(!Obj_IsDeleted(objBoss)){
		PlaySound("Shot6",90,0);
		ascent(i in 0..12){
		let shot = ShotA2(GetEnemyX,GetEnemyY,3,GetAngleToPlayer(objBoss)+i*30,-3/90,0,74,0,12);
		ObjMove_AddPatternA2(shot,90,0,NO_CHANGE,0.02,0,5);
		}
		wait(60);
		}
	}

task TShot1{
	let time = 0;
	let c = 255;
	TWeb(30);
	wait(255);
	TAccel(20,2.5,0.1,60);
	wait(255);
	TWeb(0);
	wait(255);
	TAccel(20,2.5,0.1,60);
	wait(255);
	let ang = 20;
		while(!Obj_IsDeleted(objBoss)){
		TWeb(ang);
		wait(c);
		TAccel(20,2.5,0.1,60);
		wait(c);
		ang+=20;
		c -= 10;
		}
		task Web(x,y,dir,sig,num,t,time){
		let px = x;
		let py = y;
			ascent(n in 0..num){
			PlaySound("Shot5",90,0);
			time+= 8-t;
			px += 13*cos(dir);
			py += 13*sin(dir);
			let shot = ShotA2(px,py,0,dir,0,0,106+t*0,0,12);
			Manage(shot,dir,time,n);
			wait(8-t);
			}
			if(t>=0){
			ascent(i in 0..t*4){
			ascent(j in 0..3){
			let shot = ShotA2(px,py,0,0,0,2,153,0,12);
			ObjMove_AddPatternA2(shot,0,0,angleToEnemy(shot)+360/(t*4)*i-1+j*1+45,0.004,0,0.75);
			}
			}
				if(t>0){
				Web(px,py,dir+30,0,7-1,t-1,time);
				Web(px,py,dir-30,0,7-1,t-1,time);
				}
			}
		}
			task TWeb(dir){
				smaple(0,210,50,-1.5,1,45);
				smaple(0,-80,50,1.5,1,45);
				wait(75);
				ascent(i in 0..6){
				Web(GetEnemyX+5*cos(i*60+dir),GetEnemyY+5*sin(i*60+dir),i*60+dir,0,6,3,0);
				}
			}
			
								task Manage(shot,dir,time,num){
								let w = 330-time*2;
								PlaySound("Eff1",85,w);
					DelayShot(shot,90,2,0,18,w);
					if(GetCommonData("Effect",2)!=0){
					fragment(shot,0.1,1);
					}
					ObjShot_SetSpellResist(shot,true);
					ObjMove_AddPatternA2(shot,w+30,0,dir,0.01,rand(-0.1,0.1),1.5);
					ObjMove_AddPatternA2(shot,w+40,NO_CHANGE,NO_CHANGE,0.005,0,1.5);
						wait(w);
						ObjShot_SetSpellResist(shot,false);
						if(num%2==0){
						if(GetCommonData("Effect",2)!=0){
						//spongy(shot,0.1,10);
						}
						//Obj_Delete(shot);
						}
					}
					
	}
	
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());
		return;
	}