#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell2"]
#Text["Spell2"]
#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(2222);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3000000);
	}
}

//----------------------------------------------------
task mainTask{
	//SetCommonData("Difficulty","Extra");
	DamageRateAtFrame(50,0,240);
	DamageRateAtFrame(75,0,1380);
	magiccircle(objBoss,0.8,true);
	ObjMove_SetDestAtWeight(objBoss,stgx,135,10,7);
	Cutin("Hannya Sign\"Burning Kabuki\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(30);
	Fam;
	wait(60);
	if(GetLevel=="Normal"){
	TShot1;
	}
	else if(GetLevel=="Extra"){
	TShot2;
	}
	}
//----------------------------------------------------

task TShot1{
	let way = 1;
	let r = 0;
	while(!Obj_IsDeleted(objBoss)){
	CurveCharge;
	wait(75);
	descent(n in 0..3){
		PlaySound("Shot6",95,0);
		ascent(a in 0..2){
			ascent(i in 0..20){
			let ang = i*18;
			ShotA1(GetEnemyX+60*cos(ang),GetEnemyY+60*sin(ang),1.5+n/4+a,ang+angleToPlayer,301,0,12);
			}
		}
		PlaySound("Shot6",95,0);
		ascent(a in 0..2){
			ascent(i in 0..20){
			let ang = i*18;
			ShotA1(GetEnemyX+60*cos(ang),GetEnemyY+60*sin(ang),1.5+n/4+a,ang+n*8*way,301,0,12);
			}
		}
		way = -way;
		wait(30);
	}
		ascent(n in 0..75){
		PlaySound("BulletWave",95,0);
		r = rand(-90,90);
		let ang = rand(0,360);
		ShotA1(GetEnemyX+r*cos(ang),GetEnemyY+r*sin(ang),rand(1,3),240-n*3+rand(-10,10),round(rand(91,92)),0,8);
		ShotA1(GetEnemyX+r*cos(ang),GetEnemyY+r*sin(ang),rand(1,3),-60+n*3+rand(-10,10),round(rand(91,92)),0,8);
		wait(2);
		}
		ascent(n in 0..24){
		PlaySound("Enep1",90,0);
		r = rand(-n*10,n*10);
		let ang = rand(0,360);
		ascent(a in 0..2){
			ascent(i in 0..3){
			let obj = ShotA1(GetEnemyX+r,GetEnemyY+rand(-40,-20),2+a*2,0,371,0,8);
			ObjMove_SetAngle(obj,GetAngleToPlayer(obj)-25+i*25);
			ShotA1(GetEnemyX+r,GetEnemyY+rand(-40,-20),rand(1,2),rand(0,360),371,0,8);
			}
		}
		wait(6);
		}
		wait(45);
		TAccel(35,5,0.1,30);
		wait(45);
		}
	}

task TShot2{
	let way = 1;
	while(!Obj_IsDeleted(objBoss)){
	ObjMove_SetDestAtWeight(objBoss,stgx,135,10,7);
	CurveCharge;
	wait(75);
	ascent(i in 0..1){
	LineBullet(GetEnemyX,GetEnemyY,angleToPlayer+60,6,45,true);
	LineBullet(GetEnemyX,GetEnemyY,angleToPlayer-60,6,45,true);
	}
	let dir = angleToPlayer;
	ascent(n in 0..18){
		ascent(a in 0..8){
		let ang = dir+n*10;
		ShotA1(GetEnemyX+30*cos(ang),GetEnemyY+30*sin(ang),0.75+a/2,ang,108,0,8);
		ang = dir-n*10;
		if(n!=0){ShotA1(GetEnemyX+30*cos(ang),GetEnemyY+30*sin(ang),0.75+a/2,ang,108,0,8);}
		}
		wait(4);
	}
	wait(90);
	TAccel(30,5,0.1,30);
	wait(90);
	smaple(0,90,50,-2,1,45);
	wait(75);
	LineBullet(0,GetEnemyY+50,0,7,65,true);
	LineBullet(stgx*2,GetEnemyY+50,180,7,65,true);
	wait(75);
	ascent(n in 0..18){
		ascent(i in 0..7){
		let shot = ShotA2(GetEnemyX,GetEnemyY,4,angleToPlayer-90+i*30,-4/60,0,203,0,8);
		DelayAim(shot,i);
		}
		wait(10);
	}
	wait(45);
	TAccel(30,5,0.1,30);
	wait(60);
	smaple(0,240,50,1.5,1,45);
	smaple(0,240,50,-1.5,1,45);
	wait(75);
	let p = rand(-25,25);
	ascent(n in 0..7){
	if(way==1){LineBullet(GetEnemyX,GetEnemyY,n*360/7+p,12,30,false);}
	else{
	LineBullet(GetEnemyX,GetEnemyY,-n*360/7+p+180,12,30,false);
	}
	wait(15);
	}
	wait(30);
		descent(n in 0..36){
		PlaySound("Shot1",90,0);
			ascent(a in 0..10){
			if(way==1){ShotOA1(objBoss,0.5+a/2.5,n*10,103,0,8);}
				else{
				ShotOA1(objBoss,0.5+a/2.5,-n*10+180,103,0,8);
				}
			}
			wait(5);
		}
	wait(60);
	way *= -1;
	}
		task DelayAim(shot,num){
		wait(60);
		ObjMove_AddPatternA2(shot,0,1,GetAngleToPlayer(shot),0.05,0,5);	
		}
		
			task LineBullet(px,py,ang,v,time,type){
				ascent(n in 0..time){
					if(!Obj_IsDeleted(objBoss)){
					PlaySound("BulletWave",90,0);
					px += v*cos(ang);
					py += v*sin(ang);
					let shot = ShotA2(px,py,2.5,n*25+90,-2.5/40,-2.5,302,0,8);
					Manage(shot,ang+30,n);
					shot = ShotA2(px,py,2.5,-n*25+90,-2.5/40,-2.5,302,0,8);
					Manage(shot,ang-30,n);
					wait(3);
					}
				}
				task Manage(shot,ang,num){
				wait(40);
					if(!Obj_IsDeleted(shot)){
					PlaySound("Enep1",90,0);
					spongy(shot,0.1,15);
					ShotA2(ObjMove_GetX(shot),ObjMove_GetY(shot),0,ObjMove_GetAngle(shot),0.035,rand(0.75,5),371,0,8);
					if(num%10==0 && type==true){
					ascent(a in 0..10){
					ShotA2(ObjMove_GetX(shot),ObjMove_GetY(shot),0,ang,0.005+a/200,5,371,0,8);
					ShotA2(ObjMove_GetX(shot),ObjMove_GetY(shot),0,ang+180,0.005+a/200,5,371,0,8);
					}
					}
					Obj_Delete(shot);
					}
				}
			}
	}
	
	task CurveCharge{
	PlaySound("Charge2",90,0);
	Bright(objBoss,60);
	TCharge02(objBoss,4,60,255,0,255);
	DCharge(2,1,75,40,30,0);
	DCharge(-2,1,65,40,30,0);
	
	}
	
task Fam{
	ascent(i in 0..9){
	let ene = fam(GetEnemyX,GetEnemyY,25000,0.5,1,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());
	}