#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell5"]
#Text["Spell5"]
#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{
	SetCommonData("Difficulty","Extra");
	DamageRateAtFrame(50,0,300);
	DamageRateAtFrame(75,0,1200);
	magiccircle(objBoss,0.8,true);
	ObjMove_SetDestAtWeight(objBoss,stgx,130,10,7);
	if(GetLevel=="Normal"){
	Cutin("Repression \"Loss of Feeling\"",15);
	}
	if(GetLevel=="Extra"){
	Cutin("Provocation \"Loss of Focus\"",15);
	}
	ObjEnemyBossScene_StartSpell(objScene);
	wait(30);
		Fam;
		wait(75);
		SetFocus;
		wait(180);
		if(GetLevel=="Normal"){
		//TShot1;
			ascent(i in 0..360){
			ascent(a in 0..10){
			CreateShotA1(GetEnemyX,GetEnemyY,a,i,50,12);
			}
			}
		}
		if(GetLevel=="Extra"){
		TShot2;
		}
	}
//----------------------------------------------------

task TShot1{
	let t = 155;
	let angular = 0;
	let s = 1;
	let n = 0;
	smaple(0,70,360,0,1,45);
	wait(75);
		while(!Obj_IsDeleted(objBoss)){
			PlaySound("Shot1",90,0);
			PlaySound("BulletWave",90,75);
			angular = rand(1.0,1.25)*s;
			ascent(i in 0..12){
				ascent(j in 0..8){
				let shot = ShotA2(GetEnemyX,GetEnemyY,0,i*30+j*2+n*s,3/90,1,202,0,12);
				ObjMove_SetAngularVelocity(shot,angular);
				ObjMove_AddPatternA2(shot,75,NO_CHANGE,NO_CHANGE,0.02,0,6);
				DelayShot(shot,92,2.5,0,12,75);
				}
			}
		s = -s;
		n++;
		if(t>30){t-=25;}
		wait(t);
		}
	}
	
task TShot2{
	let t = 103;
	let angular = 0;
	let s = 1;
	let n = 0;
	smaple(0,70,360,0,1,45);
	wait(75);
		while(!Obj_IsDeleted(objBoss)){
			PlaySound("Shot1",90,0);
			PlaySound("BulletWave",90,90);
			angular = rand(0.5,0.75)*s;
			ascent(i in 0..36){
			let shot = ShotA2(GetEnemyX,GetEnemyY,3,i*10+n*5,-3/90,0.5,207,0,12);
			ObjMove_SetAngularVelocity(shot,angular);
			ObjMove_AddPatternA2(shot,90,NO_CHANGE,NO_CHANGE,0.02,0,5);
			DelayShot(shot,96,2.5,0,12,90);
			}
		s = -s;
		n++;
		if(t>13){t-=10;}
		wait(t);
		}
	}

task SetFocus{
		Special;
		smaple(1,70,360,0,1,0);
		task Special{
		ascent(i in 0..60){
		if(GetLevel=="Normal"){
		Doteff(GetPlayerObjectID,rand(0,360),300+i,0,360,"PURPLE",75);
		Doteff(GetPlayerObjectID,rand(0,360),300+i,0,360,"PURPLE",75);
		}
		if(GetLevel=="Extra"){
		Doteff(GetPlayerObjectID,rand(0,360),300+i,0,360,"RED",75);
		Doteff(GetPlayerObjectID,rand(0,360),300+i,0,360,"RED",75);
		}
		wait(1);
		}
		}
	wait(75);
		PlaySound("Boon1",100,0);
		wait(60);
		ObjRender_SetColor(GetPlayerObjectID,255,0,0);
		while(!Obj_IsDeleted(objBoss)){
		if(GetLevel=="Normal"){
		SetVirtualKeyState(VK_SLOWMOVE,KEY_HOLD);
		ObjRender_SetColor(GetPlayerObjectID,255,0,255);
		}
		if(GetLevel=="Extra"){
		SetVirtualKeyState(VK_SLOWMOVE,KEY_FREE);
		ObjRender_SetColor(GetPlayerObjectID,255,0,0);
		}
		yield;
		}
	}

task Fam{
	let ene;
	ascent(i in 0..6){
	if(GetLevel=="Normal"){ene = fam(GetEnemyX,GetEnemyY,25000,0.5,2,false);}
	if(GetLevel=="Extra"){ene = fam(GetEnemyX,GetEnemyY,25000,0.5,1,false);}
	Control(ene,i);
	}
		task Control(ene,num){
			let maxa = num*60;
			let ang = 0;
			let c = 0;
			let r = 0;
			let v = 0;
			loop(155){
			if(ang<maxa){ang += maxa/120;}
			if(r<180){r+=1.05;}
			ObjMove_SetDestAtWeight(ene,GetEnemyX+r*cos(ang*-1+c*-1),GetEnemyY+r*sin(ang*-1+c*-1),10,10);
			c+=1;
			yield;
			}
			ObjRender_SetAlpha(ene,128);
			ObjRender_SetColor(ene,128,128,128);
			while(!Obj_IsDeleted(objBoss)){
			if(v<15){v+=0.25;}
			ObjMove_SetDestAtWeight(ene,GetPlayerX+r*cos(ang+c*-1),GetPlayerY+r*sin(ang+c*-1),8,v);
			if(GetLevel=="Extra"){
			c+=4;
			}
			if(GetLevel=="Normal"){
			c+=1;
			}
			yield;
			}
		}
	}

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

task TRender
{
	DrawBoss;
}

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

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