
#ScriptVersion[3]
#Title["DoremyS4"]
#Text["DoremyS4"]
#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(1600);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(75);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,1,-1);
	DamageRateAtFrame(20,30,300);
	ObjMove_SetDestAtWeight(objBoss,stgx,140,10,7);
	Cutin("Greenish Dream 'Foggy Fairy Dance'",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;
	PlaySound("Charge3",100,0);
	wait(120);
	MapleExplode(GetEnemyX,GetEnemyY,1.5,"GREEN");
	wait(20);
	MapleExplode(GetEnemyX,GetEnemyY,1.5,"GREEN");
	wait(20);
	MapleExplode(GetEnemyX,GetEnemyY,1.5,"GREEN");
	wait(20);
	MapleExplode(GetEnemyX,GetEnemyY,1.5,"GREEN");
	wait(10);
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		//--------------------------Moon---------------------//
		ALaserSet;
		ALaserSet;
		MoonWave(1);
		ALaserSet;
		wait(30);
		TMovement(35,5,5);
		wait(30);
		ALaserSet;
		MoonWave(-1);
		wait(35);
		//----------------------------------------------------//
		ObjMove_SetDestAtWeight(objBoss,stgx,120,10,15);
		wait(30);
		TMovement(35,5,5);
		ALaserSet;
		wait(45);
		DeleteAllSound;
	}
}

function MoonWave(way)
{
	let r = 35;
	let num = 5;
	ascent(n in 0..90)
	{
		PlaySound("BulletWave",95,0);
		ascent(i in 0..num)
		{
			ascent(j in 0..6)
			{
				let angle = i*360/num*way+j*(0.2+n/12)*way+n*2*way;
				TShotA2(GetPlayerX+r*cos(angle),GetPlayerY+r*sin(angle),15,angle,15,5,11,8);
			}
		}
		wait(2);
	}
}

function MoonWave2(way)
{
	let r = 30;
	let num = 2;
	ascent(n in 0..90)
	{
		PlaySound("BulletWave",95,0);
		ascent(i in 0..num)
		{
			ascent(j in 0..2)
			{
				let angle = i*360/num*way+j*(0.2+n/12)*way+n*2*way;
				TShotA2(GetEnemyX+r*cos(angle),GetEnemyY+r*sin(angle),15,angle,15,5,296,8);
			}
		}
		wait(10);
	}
}

task ALaserSet
{
	ascent(i in 0..4)
	{
		PlaySound("Shot6",100,0);
		CShot(GetEnemyX,GetEnemyY,5.3-i/2.5,rand(0,360)+i*8,796,8);
		CShot(GetEnemyX,GetEnemyY,5.3-i/2.5,rand(0,360)-i*8,796,8);
		CShot(GetEnemyX,GetEnemyY,5.3-i/2.5,rand(0,360)+i*8,796,8);
		CShot(GetEnemyX,GetEnemyY,5.3-i/2.5,rand(0,360)-i*8,796,8);
		wait(5);
	}
	task CShot(x,y,v,angle,color,delay)
	{
		let core = TShotA1(x,y,v,angle,color,delay);
		wait(50);
		
		if(!Obj_IsDeleted(core))
		{
			PlaySound("Shot6",100,0);
			ALaser(ObjMove_GetX(core),ObjMove_GetY(core));
			Obj_Delete(core);
		}
		task ALaser(ax,ay)
		{
			let laser = CreateStraightLaserA1(ax,ay,90,99,9,99,1011,0);
			DummyDelay(ax,ay,120);
			ObjShot_SetIntersectionEnable(laser,false);
			ascent(i in 0..90) // 60
			{
				ObjLaser_SetLength(laser,i*9);
				wait(i%2);
			}
			PlaySound("Laser3",100,0);
			ascent(i in 0..20) // 50
			{
				if(i==10){ObjShot_SetIntersectionEnable(laser,true);}
				ObjLaser_SetRenderWidth(laser,i);
				ObjLaser_SetIntersectionWidth(laser,i);
				yield;
			}
			wait(40); // 90
			descent(i in 0..10)
			{
				ObjLaser_SetRenderWidth(laser,i);
				ObjLaser_SetIntersectionWidth(laser,i-5);
				yield;
			}			
		}
			task DummyDelay(ax,ay,time)
			{	
				ascent(i in 0..time)
				{
					let stick = TShotA1(ax,ay,0,0,1011,2+(i)%3);
					ObjShot_SetDeleteFrame(stick,0);
					yield;
				}
			}
	}
}

task CheckNearPlayer(obj)
{
	wait(11);
	if(GetDistance(ObjMove_GetX(obj),ObjMove_GetY(obj),GetPlayerX,GetPlayerY)<20)
	{
		Obj_Delete(obj);
	}
}

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

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