#“Œ•û’e–‹•—[Single]
#ScriptVersion[3]
#Title["Spell2"]
#Text["Spell2"]
#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 Nuclear = GCSD~"img/Nuclear.png";
@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(2121);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3000000);
	}
}

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,0.8,true);
	wait(45);
	Cutin("Light Sign\"Shoot the World\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	ObjMove_SetDestAtWeight(objBoss,stgx,150,10,7);
	wait(75);
	StarFall;
	wait(120);
	ObjEnemy_SetDamageRate(objBoss,50,25);
	}
//----------------------------------------------------

task StarFall{
	let shot;
	let px = stgx/4;
	let arr = [1,6,4,2,3,5,0];
	let s = 1;
	while(!Obj_IsDeleted(objBoss)){
	maple(2);
	wait(50);
	ascent(n in 0..9){
	PlaySound("byoro07",90,0);
	shot = ShotA2(GetEnemyX,GetEnemyY,3,-120+n*15,-2/60,0,251,0,0);
	Manage(shot,1);
	shot = ShotA2(GetEnemyX,GetEnemyY,3,-60-n*15,-2/60,0,251,0,0);
	Manage(shot,-1);
	}
	wait(90);
	TMovement(50,5,5);
	wait(60);
	maple(2);
	wait(45);
	PlaySound("byoro07",90,0);
	ascent(i in 0..7){
	enemy = fam(GetEnemyX,GetEnemyY,300,arr[i],false);
	Control(enemy,i,s);
	}
	loop(3){
	wait(75);
	TMovement(50,5,5);
	wait(70);
	}
	PlaySound("Shot6",95,0);
	ascent(i in 0..48){
	shot = ShotA2(GetEnemyX,GetEnemyY,4,i*7.5,-4/60,1,259,0,12);
	ObjMove_AddPatternA2(shot,60,NO_CHANGE,i*7.5,0.02,0,1+0.1*sin(i*180+90));
	}
	wait(25);
	AccelMove(objBoss,stgx,150,0.2,30);
	wait(20);
	s = -s;
	}
		task Control(ene,num,way){
		let sw = 1;
		let ang = 0;
		ascent(i in 0..60){
		ang+=6*way;
		ObjMove_SetPosition(ene,GetEnemyX+i*2*cos(360/7*num+ang),GetEnemyY+i*2*sin(360/7*num+ang));
		yield;
		}
		ascent(i in 0..90){
		ang+=4*way;
		ObjMove_SetPosition(ene,GetEnemyX+120*cos(360/7*num+ang),GetEnemyY+120*sin(360/7*num+ang));
		if(i%10==0){AimLaser(GetAngleToPlayer(ene));}
		yield;
		}
		descent(i in 60..120){
		ang+=5*way;
		ObjMove_SetPosition(ene,GetEnemyX+i*cos(360/7*num+ang),GetEnemyY+i*sin(360/7*num+ang));
		yield;
		}
		ascent(i in 60..180){
		ang+=3*way;
		ObjMove_SetPosition(ene,GetEnemyX+60*cos(360/7*num+ang),GetEnemyY+60*sin(360/7*num+ang));
		if(i%10==0 && i<=150){
		AimLaser(angleToEnemy(ene)+90*sw);
		sw = -sw;
		}
		yield;
		}
		ascent(i in 30..90){
		ang-=5*way;
		ObjMove_SetPosition(ene,GetEnemyX+i*2*cos(360/7*num+ang),GetEnemyY+i*2*sin(360/7*num+ang));
		yield;
		}
		ascent(i in 0..12){
		ascent(a in 0..4){
		ShotA2(ObjMove_GetX(ene),ObjMove_GetY(ene),0,i*30+angleToEnemy(ene),0.015+a/800,4,31+num,0,4+a*3);
		}
		}
		ObjEnemy_SetLife(ene,0);
			task AimLaser(dir){
			PlaySound("byoro07",90,0);
			let obj = CreateStraightLaserA1(ObjMove_GetX(ene),ObjMove_GetY(ene),dir,0,20,30,141+num,60);
			SetLaser(obj);
			 task SetLaser(obj){
				ascent(i in 0..80){
				let dummy =  ShotOA1(obj,0,0,21+num,0,6);
				ObjShot_SetDeleteFrame(dummy,0);
				if(Obj_IsDeleted(ene)){Obj_Delete(obj);}
				if(ObjLaser_GetLength(obj,)<400){ObjLaser_SetLength(obj,i*15);}
				ObjLaser_SetRenderWidth(obj,rand(18,21));
				yield;
				}
			 }
			}
		}
	
		task Manage(shot,way){
		let c = 0;
		let count = 0;
		ObjRender_SetAlpha(shot,0);
		Angular;
		task Angular{
		ObjMove_SetAngularVelocity(shot,1*way);
		wait(60);
		ObjMove_AddPatternA2(shot,0,NO_CHANGE,NO_CHANGE,0.075,1*way,6);
		}
		while(!Obj_IsDeleted(shot)){
		if(c%3==0){
		ObjShot_SetGraphic(shot,251+count%7);
		RStar(shot,c*1,ObjMove_GetSpeed(shot)/4+1,50);
		count++;
		}
		if(ObjMove_GetX(shot)<0){
		Burst(0);
		}
		if(ObjMove_GetX(shot)>stgx*2){
		Burst(180);
		}
		if(ObjMove_GetY(shot)<0){
		Burst(90);
		}
		c++;
		yield;
		}
			task Burst(dir){
			PlaySound("Shot6",95,0);
			ascent(i in 0..6){
			ascent(a in 0..5){
			let obj = ShotOA1(shot,5,dir+a*31*way+i*60+ObjMove_GetAngle(shot),91+a,0,8);
			ObjMove_AddPatternA2(obj,0,5,NO_CHANGE,-0.15,0,0.5+a/6);
			}
			}
			Obj_Delete(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;
	}
