
#ScriptVersion[3]
#Title["DoremyS3"]
#Text["DoremyS3"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Background["./BG.txt"]
#Player["./MoF_Reimu/Reimu.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(2250);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(45);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,1,-1);
	DamageRateAtFrame(50,25,240);
	ObjMove_SetDestAtWeight(objBoss,stgx,140,10,7);
	Cutin("Dream Sign\"Deja vu\"",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	Sound(GCSD ~ "Butterfly.mp3");
	wait(105);
	TShot1;
	wait(1200);
	DamageRateAtFrame(75,40,0);
	}
//----------------------------------------------------

task TShot1
{
	let s = 1;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0)
	{
		maple;
		wait(70);
		FullLaser(s);
		wait(270);
		TMovement(35,10,5);
		wait(270);
		s = -s;
	}
}

task FullLaser(s)
{
	ascent(n in 0..12+Level*6)
	{
		ascent(i in 0..2)
		{
			let angle = n*50+i*180;
			let dir = n*50-180+35*s+i*180;
			let r = 60;
			HeadLaser(GetEnemyX+r*cos(angle),GetEnemyY+r*sin(angle),1.5,angle,dir,r,2,0);
			if(n%2==0){HeadLaser(GetPlayerX+r*cos(angle),GetPlayerY+r*sin(angle),1.5,angle,dir,r,1,1);}
		}
		wait(9-Level*3);
	}
	task HeadLaser(x,y,v,angle,dir,r,rnum,type)
	{
		let color = [748,1027];
		if(type==1)
		{
			color = [749,1030];
			if(rnum!=1)
			{
				dir = GetPointAngle(GetPlayerX,GetPlayerY,x,y);
			}
		}
		PlaySound("Laser3",100,0);
		let obj = TShotA1(x,y,v,dir,color[0],12);
		ObjShot_SetIntersectionEnable(obj,false);
		let count = 0;
		let laser = CreateLooseLaserA1(x,y,v,dir,105,15,color[1],12);
		ObjLaser_SetIntersectionWidth(laser,10);
		ObjLaser_SetInvalidLength(obj,50,10);
		ObjShot_SetSpellResist(obj,true);
		wait(13);
		while(ObjMove_GetX(obj)>0 && ObjMove_GetX(obj)<384 && ObjMove_GetY(obj)>0 && ObjMove_GetY(obj)<448 && !Obj_IsDeleted(obj))
		{
			ObjRender_SetColor(obj,128+128*sin(count%180),128+128*sin(count%180),128+128*sin(count%180));
			count += 30;
			yield;
		}
		if(ObjMove_GetX(obj)<0 || ObjMove_GetX(obj)>384 && !Obj_IsDeleted(obj))
		{
			if(rnum>0){HeadLaser(ObjMove_GetX(obj),ObjMove_GetY(obj),v+0.35,0,180-dir,0,rnum-1,type);Obj_Delete(obj);}
		}
		if(ObjMove_GetY(obj)<0 || ObjMove_GetY(obj)>448 && !Obj_IsDeleted(obj))
		{
			if(rnum>0){HeadLaser(ObjMove_GetX(obj),ObjMove_GetY(obj),v+0.35,0,-dir,0,rnum-1,type);Obj_Delete(obj);}
		}
	}
}


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

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