#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell"]
#Text["Spell"]
#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("Life",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(2000);
	}
	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("Facade Sign\"Liars' Mask\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(90);
	TShot1;
	wait(300);
	TShot2;
	}
//----------------------------------------------------

task TShot1{
	let vel = 0;
	//SetCommonData("Difficulty","Extra");
		if(GetLevel=="Normal"){vel = 1.45;}
		else if(GetLevel=="Extra"){vel = 1.5;}
	smaple(0,-45,50,1.5,1,45);
	wait(75);
		while(!Obj_IsDeleted(objBoss)){
		let p = rand(-1.5,1.5);
		PlaySound("Shot1",90,0);
		PlaySound("Eff1",85,120);
		ascent(i in 0..101){
		let shot = ShotOA1(objBoss,vel,angleToPlayer+15+i*3.3+p,344,0,8);
		ObjShot_SetSpellResist(shot,true);
		}
		ascent(i in 0..10){
		let shot = ShotOA1(objBoss,vel,angleToPlayer-15+i*3.3+p,344,0,8);
		ObjMove_AddPatternA2(shot,120,NO_CHANGE,NO_CHANGE,-0.03,0,0.5);
		ObjShot_SetSpellResist(shot,true);
		DelayShot(shot,343,2,0,30,120);
		}
		wait(150);
		 p = rand(-1.5,1.5);
		PlaySound("Shot1",90,0);
		PlaySound("Eff1",85,120);
		ascent(i in 0..101){
		let shot = ShotOA1(objBoss,vel,angleToPlayer+15+i*3.3+p,344,0,8);
		ObjMove_AddPatternA2(shot,120,NO_CHANGE,NO_CHANGE,-0.03,0,0.5);
		ObjShot_SetSpellResist(shot,true);
		DelayShot(shot,343,2,0,30,120);
		}
		ascent(i in 0..10){
		let shot = ShotOA1(objBoss,vel,angleToPlayer-15+i*3.3+p,344,0,8);
		ObjShot_SetSpellResist(shot,true);
		}
		wait(75);
		TAccel(20,5,0.1,30);
		wait(75);
		}
	}
	
task TShot2{
		let t = 0;
		let m = 0;
		let color = 0;
		if(GetLevel=="Normal"){
		m = 8;
		color = 61;
		}
		else if(GetLevel=="Extra"){
		m = 9;
		color = 63;
		}
			PlaySound("Charge2",90,0);
			DCharge(-2,1,180,50,45,0);
			Bright(objBoss,60);
			TCharge02(objBoss,4,60,255,0,255);
		wait(75);
		while(!Obj_IsDeleted(objBoss)){
			let p = rand(-20,20);
			PlaySound("BulletWave",85,0);
			ascent(i in 0..m){
			let shot = ShotOA1(objBoss,2,i*360/m+p,color,0,8);
			if(GetLevel=="Extra"){
			ObjMove_SetAngularVelocity(shot,rand(-0.5,0.5));
			}
			ObjMove_SetAcceleration(shot,-0.01);
			ObjMove_AddPatternA2(shot,120,NO_CHANGE,NO_CHANGE,0.01,0,rand(2.5,3));
			}
			wait(10);
			t++;
			if(t%30==0){
			PlaySound("Charge2",90,0);
			DCharge(-2,1,180,50,45,0);
			Bright(objBoss,60);
			m++;
			}
			if(t==60){DamageRateAtFrame(75,25,0);}
			}
			task Manage(shot){
			wait(120);
			ObjMove_AddPatternA2(shot,0,NO_CHANGE,NO_CHANGE,0.01,0,rand(2.5,3));
			}
	}

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

task TRender
{
	DrawBoss;
}

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

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