#“Œ•û’e–‹•—[Single]
#ScriptVersion[3]
#Title["Spell3"]
#Text["Spell3"]
#BGM["./Magician.mp3"]
#Background["./BG.txt"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Player["./MoF_Reimu/Reimu.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"script/Marisa/Shot/Default_ShotConst.txt"
#include"script/Default_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 s = 1;
let objScene=GetEnemyBossSceneObjectID();
let arr = [1,6,4,2,3,5,0];

@Initialize
{
SetBoss;
}

@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(1850);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3000000);
	}
}

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,0.8,true);
	wait(45);
	Cutin("Love Sign\"Familiar Spark\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	ObjMove_SetDestAtWeight(objBoss,stgx,150,10,7);
	wait(60);
	TBoss;
	wait(120);
	ObjEnemy_SetDamageRate(objBoss,50,25);
	}
//----------------------------------------------------

task TBoss{
	let m = 0;
	let s = 1;
	while(!Obj_IsDeleted(objBoss)){
	maple(2);
	wait(50);
	ascent(i in 0..6){
	let shot = ShotOA1(objBoss,0,0,251+i,0,8);
	Manage(shot,i,-1);
	}
	wait(90);
	TShot1(stgx-125,60);
	wait(350);
	AccelMove(objBoss,stgx+50,rand(130,150),0.1,30);
	ascent(n in 0..10){
	PlaySound("Shot8",95,0);
	let hshot = ShotOA1(objBoss,4,n*36,251,0,8);
	ManageH(hshot);
	wait(5);
	if(n==5){wait(30);}
	}
	wait(40);
	maple(2);
	wait(50);
	AccelMove(objBoss,stgx,150,0.1,30);
	ascent(i in 0..6){
	let shot = ShotOA1(objBoss,0,0,251+i,0,8);
	Manage(shot,i,1);
	}
	wait(90);
	TShot1(stgx+125,60);
	wait(380);
	AccelMove(objBoss,stgx-50,rand(130,150),0.1,30);
	ascent(n in 0..10){
	PlaySound("Shot8",95,0);
	let hshot = ShotOA1(objBoss,4,n*36,251,0,8);
	ManageH(hshot);
	wait(5);
	if(n==5){wait(30);}
	}
	m++;
	wait(60);
	ascent(n in 0..20){
	PlaySound("Shot8",95,0);
	let hshot = ShotOA1(objBoss,2+n/5,n*18*s,251,0,8);
	ManageH(hshot);
	wait(5);
	}
	s = -s;
	}
		task ManageH(obj){
		let c = 0;
		ManageAcc;
		ObjRender_SetAlpha(obj,0);
		while(!Obj_IsDeleted(obj)){
			if(c%2==0){
			ObjShot_SetGraphic(obj,251+(c/3)%7);
			RStar(obj,c*1,ObjMove_GetSpeed(obj)/12+1,20);
			}
		c++;
		yield;
		}
			task ManageAcc{
			ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,-4/60,0,0);
			wait(60);
			ObjMove_SetAngle(obj,GetAngleToPlayer(obj));
			Homing(obj,0.25);
			ObjMove_AddPatternA2(obj,0,NO_CHANGE,NO_CHANGE,0.05,0,10);
			}
		}
		task Manage(shot,num,way){
			let c = 0;
			let r = 0;
			let v = 2.5;
			let s = 1;
			let count = 0;
			ObjShot_SetSpellResist(shot,true);
			while(!Obj_IsDeleted(shot)){
			ObjMove_SetPosition(shot,GetEnemyX+r*1.5*cos(num*60+c*2*way),GetEnemyY+r*1.25*sin(num*60+c*2*way));
			if(c%2==0){RStar(shot,c*1,1,50);}
			if(c>=30 && c%6==0){
			PlaySound("BulletWave",90,0);
			ShotOA1(shot,v,GetAngleToPlayer(shot)+rand(-count,count)+45+c*7,41+num,0,8);
			ShotOA1(shot,v,GetAngleToPlayer(shot)+rand(-count,count)-45-c*7,41+num,0,8);
			count+=0.5;
			v-= 0.05;
			}
			if(c>210){ObjShot_FadeDelete(shot);}
			if(c<=120){r+=1;}
			if(c>120){r-=1;}
			c+=1;
			yield;
			}
		}
	}

task TShot1(px,py){
	maple(2);
	wait(50);
	PlaySound("Eff5",95,0);
	let m_ene = fam(GetEnemyX,GetEnemyY,1000,0,false);
	Manage(m_ene,px,py);
		task Manage(m_ene,px,py){
			let rc = false;
			ascent(i in 0..6){
			let ene = fam(ObjMove_GetX(m_ene),ObjMove_GetY(m_ene),1000,arr[i],false);
			Control(ene,i);
			}
			wait(30);
			ObjMove_SetDestAtWeight(m_ene,px,py,10,5);
			wait(45);
			Bright(m_ene,60);
			PlaySound("Charge3",95,0);
			TCharge01(m_ene,3,90,255,128,92);
			//wait(50);
			TMovement(50,5,5,);
			//PlaySound("Laser6",95,0);
			let dir = 0;
			ascent(i in 0..3){
			dir = GetAngleToPlayer(m_ene)-5+i*5;
			let obj = CreateStraightLaserA1(ObjMove_GetX(m_ene),ObjMove_GetY(m_ene),GetAngleToPlayer(m_ene)-5+i*5,0,60,210,149,100);
			SetLaser(obj);
			DelayShot(dir,100);
			}
			task DelayShot(dir,t){
					wait(t);
					CreateStraightLaserA1(ObjMove_GetX(m_ene),ObjMove_GetY(m_ene),dir,500,60,0,149,0);
			}
			wait(300);
			ObjMove_SetDestAtWeight(m_ene,GetEnemyX,GetEnemyY,10,5);
			rc = true;
			wait(60);
			Obj_Delete(m_ene);
				task SetLaser(obj){
					let count = 0;
					let w = 0;
					CheckLaser;
						task CheckLaser{
							PlaySound("Charge4",100,90);
							while(!Obj_IsDeleted(obj)){ // fire 180
							if(ObjLaser_GetLength(obj)<500){ObjLaser_SetLength(obj,ObjLaser_GetLength(obj)+20);}
							if(count>100 && count<=250){
							ObjLaser_SetRenderWidth(obj,w+rand(-w/30,w/30));
							ObjLaser_SetIntersectionWidth(obj,w*0.5);
							w++;
							}
							if(count>250){
							ObjLaser_SetRenderWidth(obj,w+rand(-w/30,w/30));
							ObjLaser_SetIntersectionWidth(obj,w*0.5);
							w -= 3.45;
							}
							if(count>265){ObjShot_FadeDelete(obj);}
							ObjMove_SetPosition(obj,ObjMove_GetX(m_ene),ObjMove_GetY(m_ene));
							if(count%5==0){
							let dummy =  ShotOA1(m_ene,0,0,211+count%6,0,8);
							ObjShot_SetDeleteFrame(dummy,0);
							}
							count++;
							yield;
						}
					}
				}
			task Control(ene,num){
				let r = 0;
				let c = 0;
				let count = 0;
				let v = 4;
				while(!Obj_IsDeleted(m_ene)){
				ObjMove_SetPosition(ene,ObjMove_GetX(m_ene)+r*cos(num*60+c*5),ObjMove_GetY(m_ene)+r*sin(num*60+c*5));
				c+=1;
				if(c>160 && c%3==0 && c<320){
				r+=0.05;
				ShotOA1(ene,v,num*60+count*11,251+count%7,0,12);
				v-=0.06;
				count++;
				}
				if(r<30 && rc==false){r+=1;}
				if(r>0 && rc==true){r-=1;}
				yield;
				}
				Obj_Delete(ene);
			}
		}
	}
	
task ManageShot(shot){
	ObjShot_SetAutoDelete(shot,false);
	ascent(i in 0..6){
	let ene = fam(ObjMove_GetX(shot),ObjMove_GetY(shot),100,arr[i],false);
	Control(ene,i);
	}
	wait(240);
	Obj_Delete(shot);
		task Control(ene,num){
				let r = 0;
				let c = 0;
				let count = 0;
				while(!Obj_IsDeleted(shot)){
					ObjMove_SetPosition(ene,ObjMove_GetX(shot)+r*1.25*cos(num*60+c*3),ObjMove_GetY(shot)+r*sin(num*60+c*3));
					if(c>90 && c%5==0){
					PlaySound("BulletWave",90,0);
					StarShot;
					count++;
					}
					c+=1;
					if(r<120){r+=0.5;}
					yield;
					}
					Obj_Delete(ene);
				task StarShot{
				let s_shot = ShotA2(ObjMove_GetX(ene),ObjMove_GetY(ene),1,getAtanAngle(ene,shot)+180,-0.02,0,251+count%7,0,8);
				Cluster(getAtanAngle(ene,shot)+180,count%7);
					task Cluster(dir,count){
					wait(30);
					if(!Obj_IsDeleted(s_shot)){
					fragment(s_shot,0,1);
					ShotA2(ObjMove_GetX(s_shot),ObjMove_GetY(s_shot),0,dir+count*11,0.01,1,131+count,0,8);
					Obj_Delete(s_shot);
					}
					}
				}
		}
	}
	


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

task TRender
{
	DrawBoss;
}

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

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT) +ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0)
		{AddScore(ObjEnemyBossScene_GetInfo(objScene,INFO_SPELL_SCORE));}
		EndBoss(1);
		wait(60);
		CloseScript(GetOwnScriptID());
		return;
	}