
#ScriptVersion[3]
#Title["SpellH"]
#Text["SpellH"]
#Background["./BG.txt"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Player["./MoF_Reimu/Reimu.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/Default_ShotConst.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(1750);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3000000);
	}
}

//----------------------------------------------------
task mainTask{
	DamageRateAtFrame(50,25,135);
	magiccircle(objBoss,0.8,true);
	wait(45);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,7);
	Cutin("Detachment\"Abandonment of Nirvana\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(90);
	TShot1;
	}
//----------------------------------------------------

task TShot1{
	let s = 1;
	while(!Obj_IsDeleted(objBoss)){
	StartSlow(TARGET_ALL,30);
	ManageSpeed(55);
	SetCommonData("petal",1);
	maple(2);
	descent(n in 1..5){
	ascent(i in 0..36){
	ShotA1(GetEnemyX+n*30*cos(i*10+n*5*s),GetEnemyY+n*30*sin(i*10+n*5*s),n,i*10,12,0,12);
	}
	ascent(a in 1..5){
	ascent(i in 0..3){
	ShotOA1(objBoss,0.5+a/1.5,angleToPlayer-30+i*30+rand(-2,2),91,0,8);
	}
	wait(2);
	}
	if(n==3){attack(40,45,1);}
	}
	wait(20);
	StopSlow(TARGET_ALL);
	SetCommonData("petal",0.25);
		ascent(n in 0..31){
		PlaySound("Shot1",90,0);
		let px = GetEnemyX+125*cos(n*8-62+30);
		let py = GetEnemyY+30*sin(n*6-30);
		let shot = ShotA1(px,py,0,0,23,0,8);
		Manage(shot,px,py,1);
		wait(n%2);
		}
		ascent(n in 0..31){
		PlaySound("Shot1",90,0);
		let px = GetEnemyX-125*cos(n*8-62+30);
		let py = GetEnemyY+30*sin(n*6-30);
		let shot = ShotA1(px,py,0,0,23,0,8);
		Manage(shot,px,py,-1);
		wait(n%2);
		}
		
		ascent(n in 0..31){
		PlaySound("Shot1",90,0);
		let px = GetEnemyX+200*cos(n*7-31);
		let py = GetEnemyY+75*sin(n*6-45)+10;
		let shot = ShotA1(px,py,0,0,23,0,8);
		Manage(shot,px,py,0);
		px = GetEnemyX-200*cos(n*7-31);
		py = GetEnemyY+75*sin(n*6-45)+10;
		shot = ShotA1(px,py,0,0,23,0,8);
		Manage(shot,px,py,0);
		wait(n%2);
		}
		wait(150);
		TAccel(50,10,0.05,120);
		if(s==1){
		descent(n in 0..20){
			PlaySound("Shot6",90,0);
			ascent(i in 0..7){
			Dagger(1+n/10,i*360/7+n*13,171);
			}
			wait(6);
		}
		}
		else{
		descent(n in 0..10){
			PlaySound("Shot6",90,0);
			ascent(i in 0..18){
			Dagger(1+n/4,i*20+n*13,176);
			}
			wait(12);
		}
		}
		wait(120);
		s = -s;
		}
			task Manage(shot,px,py,way){
			ObjShot_SetSpellResist(shot,true);
			let color = 53;
			if(way==0){color = 52;}
			wait(45);
			PlaySound("BulletWave",90,0);
			if(way!=0 && !Obj_IsDeleted(shot)){
			ascent(a in 1..9){
			ShotA2(ObjMove_GetX(shot),ObjMove_GetY(shot),0,getDotAngle(GetEnemyX,GetEnemyY-0,px,py)+180-a*1*way,0.005+a/150,5,color,0,8);
			ShotA2(ObjMove_GetX(shot),ObjMove_GetY(shot),0,getDotAngle(GetEnemyX,GetEnemyY-0,px,py)+180+a*1*way,0.005+a/150,5,color,0,8);
			}
			}
			else{
			ascent(a in 0..9){
			ShotA2(ObjMove_GetX(shot),ObjMove_GetY(shot),0.5+a/2,getDotAngle(GetEnemyX,GetEnemyY-0,px,py)+180-a*1*way,0,5,color,0,8);
			}
			}
			fragment(shot,0,1);
			Obj_Delete(shot);
			}
			task Dagger(v,dir,graphic){
			ShotOA1(objBoss,v,dir-1,graphic,0,8);
			ShotOA1(objBoss,v,dir+1,graphic,0,8);
			ShotOA1(objBoss,v,dir,graphic,0,4);
			}
	}

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

task TRender
{
	DrawBoss;
}

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

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