
#ScriptVersion[3]
#Title["Rod Sign\"Falling Rod\""]
#Text["Easy"]
#Background["./BG.txt"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#include"./Functions/Index.txt"
#include"./SetMidBoss.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);
}

@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(1500);
	}
	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,140,10,7);
	Cutin("Rod Sign\"Falling Rod\"",15,"NAZRIN");
	ObjEnemyBossScene_StartSpell(objScene);
	wait(90);
	TShot1;
	}
//----------------------------------------------------

task TShot1{
	let s = 1;
	while(!Obj_IsDeleted(objBoss)){
	maple(2);
	wait(30);
	Action(90);
	wait(30);
		PlaySound("Laser2",98,0);
		ascent(i in -6..7){
		if(ObjEnemy_GetInfo(objBoss,INFO_LIFE)<1){break;}
		let shot = CurvyLaser(GetEnemyX,GetEnemyY,4,270+i*8,10,30,506,0);
		ObjMove_AddPatternB2(shot,0,NO_CHANGE,NO_CHANGE,0,0.05,0,0.1);
		ObjMove_AddPatternB2(shot,60,NO_CHANGE,NO_CHANGE,0,0.06,0,6);
		Manage(shot,i);
		}
		wait(120);
		if(s==1){TAccel(35,5,0.1,90);}
		else{ObjMove_SetDestAtWeight(objBoss,stgx,140,10,7);}
		wait(120);
		s = -s;
		}
		task Manage(shot,num){
		wait(105);
		let c = 0;
			while(!Obj_IsDeleted(shot) && !Obj_IsDeleted(objBoss)){
				if(c%6==0){
				ascent(i in 0..2){
				let obj = ShotA2(ObjMove_GetX(shot),ObjMove_GetY(shot),0,i*180+rand(-3,3),0.005,5,64,0,8);
				ObjMove_AddPatternA2(obj,60,NO_CHANGE,NO_CHANGE,0.01,0,1.25);
				}
				}
				c++;
				if(ObjEnemy_GetInfo(objBoss,INFO_LIFE)<1){break;}
				if(ObjMove_GetY(shot)>448 || ObjMove_GetX(shot)<0 || ObjMove_GetX(shot)>384){
						PlaySound("water",100,0);
						loop(15){
						ShotOA1(shot,rand(0.5,1.25),rand(0,360),250,0,8);
						}
						Obj_Delete(shot);
					}
				yield;
			}
		}
	}

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

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));}
		let dis = 0;
		let px = GetEnemyX;
		let py = GetEnemyY;
		ClearBullet(90,10);
		TAccel(50,10,0.02,120);
		MapleExplode(180,1,2,5);
		PlaySound("enemoff",95,0);
		wait(105);
		PlaySound("enemoff",100,0);
		MapleExplode(20,50,1,6);
		Obj_Delete(objBoss);
		wait(30);
		SetAutoDeleteObject(true);
		loop(180){yield;}
		CloseScript(GetOwnScriptID());
		return;
	}