
#ScriptVersion[3]
#Title["DoremyS3"]
#Text["DoremyS3"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Background["./BG.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/AllStarShot_Const.dnh"
#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 action = false;
let objScene=GetEnemyBossSceneObjectID();
let color = [276,277,278];
let color2 = [51,53,55];
let dcolor = [308,309,310];
@Initialize
{
SetBoss("Doremy",true);
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),18);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(1800);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(75);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,1,-1);
	DamageRateAtFrame(20,30,180);
	ObjMove_SetDestAtWeight(objBoss,stgx,140,10,7);
	Cutin("Reddish Dream 'Projectile Masquerade'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "Butterfly.mp3");
	wait(105);
	TShot1;
	wait(1200);
	DamageRateAtFrame(75,40,0);
	}
//----------------------------------------------------

task TShot1
{
        attack(90,1);
	let s = 1;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		MapleExplode(GetEnemyX,GetEnemyY,1.5,"RED");
		wait(20);
		MapleExplode(GetEnemyX,GetEnemyY,1.5,"RED");
		wait(20);
		MapleExplode(GetEnemyX,GetEnemyY,1.5,"RED");
		wait(20);
                StarSpread;
		MoonSet;
		wait(270);
		TMovement(35,10,5);
		wait(270);
		s = -s;
	}
}

task StarSpread
{
	let angle = [10,10,10];
	wait(60);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		let result = GetAngleToPlayer(objBoss)+rand(-5,5);
		ascent(i in 0..20)
		{
			PlaySound("Shot1",85,0);
			TShotA1(GetEnemyX+30*cos(i*rand(0,360)+result),GetEnemyY+30*sin(i*angle+result),2,i*angle+result,613,12);
			wait(2);
		}
		result = GetAngleToPlayer(objBoss)+rand(-5,5);
		descent(i in 0..20)
		{
			PlaySound("Shot1",85,0);
			TShotA1(GetEnemyX+30*cos(i*rand(0,360)+result),GetEnemyY+30*sin(i*angle+result),2,i*angle+result,614,12);
			wait(2);
		}
	}
}

task MoonSet
{
	let num = 2;
	let pspeed = 4;
	let wtime = 99;
	wait(60);
		MapleExplode(GetEnemyX,GetEnemyY,1.5,"RED");
	wait(70);
	let r = 75;
	let count = 0;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		let result = rand(-9,9);
		PlaySound("Shot1",100,0);
		ascent(i in 0..num)
		{
			let angle = i*360/num+result;
			BounceStar(GetEnemyX+r*cos(angle),GetEnemyY+r*sin(angle),2,angle,799,6);
		}
		count++;
                wait(wtime);
	}
	task BounceStar(x,y,v,angle2,color,delay)
	{
		let obj = TShotA1(x,y,v,angle2,color,delay);
		while(ObjMove_GetY(obj)>0 && ObjMove_GetX(obj)>0 && ObjMove_GetX(obj)<384 && ObjMove_GetY(obj)<448){yield;}
		if(ObjMove_GetY(obj)<=448 && !Obj_IsDeleted(obj))
		{
			let result = rand(pspeed,pspeed*1.5);
			PlaySound("Laser3",95,0);
			let dir = GetAngleToPlayer(obj)+rand(-2,2);
			let laser = CreateLooseLaserA1(ObjMove_GetX(obj),ObjMove_GetY(obj),result,dir,100,20,800,0);
			ObjMove_AddPatternA2(laser,1,result/5,NO_CHANGE,result/60,0,result);


			effbreak(obj,1,15);
			Obj_Delete(obj);
		}
	}
}


		task HeadM(obj2)
		{
			let c2 = 0;
			ObjRender_SetScaleXYZ(obj2,1.25,1.25,0);
			ObjShot_SetSpellResist(obj2,true);
			while(!Obj_IsDeleted(obj2))
			{
				let co = 206+48*sin(c2);
				ObjRender_SetColor(obj2,co,co,co);
				c2+=30;
				yield;
			}
		}
		task LaserM(l,v)
		{
			ObjMove_SetY(l,ObjMove_GetY(l)-50*sin(ObjMove_GetAngle(l)));
			ObjMove_SetX(l,ObjMove_GetX(l)-50*cos(ObjMove_GetAngle(l)));
			ObjMove_SetSpeed(l,50);
			yield;
			ObjMove_SetSpeed(l,v);
		}



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

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