
#ScriptVersion[3]
#Title["星符「ミッドナイトレヴァリエ」"]
#Text["Exルーミア最初のスペルカード：[r]星符「ミッドナイトレヴァリエ」"]
#Image["./ExRumia(星符「ミッドナイトレヴァリエ」).jpg"]
#Background["script/default_system/Default_Background_IceMountain.txt"]
#BGM[DEFAULT]
#Player[DEFAULT]

#include"script/default_system/Default_ShotConst.txt"
#include"script/default_system/Default_Effect.txt"

#include"./../../img/boss/lib_anime_Mokou.txt"
#include"./../../lib/BossCommon/BossCommon.txt"

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(224,0);
	SetItem(20,2,2);
}

@MainLoop
{
	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);
	ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey, 32);//当たり判定(自弾)登録
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 12);//当たり判定(体当たり)登録
	SetCommonData("BossPosition",[ex,ey]);
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(4600);//ライフを1500に設定
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(100);//時間制限を60秒に設定
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(30000);//スペルカードボーナスを30000に設定
	}
}

//----------------------------------------------------
//敵動作
//----------------------------------------------------
task BossWork
{
	//座標(cx, 60)へ60フレームかけて移動する
	let cx = GetStgFrameWidth() / 2;//STGシーンの中心x座標を取得
	ObjMove_SetDestAtWeight(objEnemy, cx, 112, 10,5);
	SetAction(ACT_MOVE, 60);
//	loop(60){yield;}
	CallSpellCard("「フェニックステフラ」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	loop(60){yield;}
	C;
	loop(90){yield;}
	DamageRate=[100,100];

	task C
	{
		let dir=floor(rand(0,2-0.001))*2-1;
		let Sdir=floor(rand(0,2-0.001))*2-1;
		let graadd=0;
		loop
		{

		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);
		let X=[192-192*dir,192-128*dir,192-64*dir,192+64*dir,192+128*dir,192+192*dir];
		let Y=448;
		SetAction(ACT_SHOT_B, 60);
		ascent(i in 0..6)
		{
			let Angle=atan2(Y-ey,X[i]-ex);
			let Dis=((Y-ey)^2+(X[i]-ex)^2)^0.5;
			let speed=Dis/30;
			H2(ex,ey,speed,Angle,graadd);
			wait(5);
		}
		wait(150);
		SetAction(ACT_SHOT_A, 660);
		let angle=78;
		loop(60)
		{
			ascent(i in -2..4)
			{
				let obj=CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),5.0,angle+24*i,86-graadd,0);
				ShotEffect(obj);
			}
			wait(3);
		}

		loop(60)
		{
			ascent(i in -2..4)
			{
				let obj=CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),5.0,angle+24*i,86-graadd,0);
				ShotEffect(obj);
			}
			angle+=35/60*Sdir;
			wait(3);
		}
		loop(120)
		{
			ascent(i in -2..4)
			{
				let obj=CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),5.0,angle+24*i,86-graadd,0);
				ShotEffect(obj);
			}
			angle-=35/60*Sdir;
			wait(3);
		}
		loop(60)
		{
			ascent(i in -2..4)
			{
				let obj=CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),5.0,angle+24*i,86-graadd,0);
				ShotEffect(obj);
			}
			angle+=35/60*Sdir;
			wait(3);
		}
		if(graadd==0){graadd=5;}
		else{graadd=0;}
		dir*=-1;
		Sdir*=-1;
		wait(60);
		}
		task H2(hx,hy,speed,angle,gra)
		{
			let Bspeed=speed;
			let t=0;
		//	let gra=DS_BILL_RED;
			let LaserSpeed=0;
			let angleAdd=0;
		//	Dust;
			loop(60)
			{
				speed-=Bspeed/60;
				hx+=speed*cos(angle);
				hy+=speed*sin(angle);
				BladeShot(hx,hy,angle+angleAdd,DS_BILL_RED+gra);
				angleAdd+=3;
			//	t+=1;
				yield;
			}

			loop(10)
			{
				Shot(hx,hy,rand(1.5,2.0),rand(((angle+180)+270)/2,270),9+gra);
			}
			loop(30)
			{
				Shot(hx,hy,rand(2.0,3.0),rand(((angle+180)+270)/2,270),9+gra);
			}
			loop(50)
			{
				Shot(hx,hy,rand(3.0,4.5),rand(((angle+180)+270)/2,270),9+gra);
			}
			loop(70)
			{
				Shot(hx,hy,rand(4.5,5.5),rand(((angle+180)+270)/2,270),9+gra);
			}
			loop(90)
			{
				Shot(hx,hy,rand(5.5,6.5),rand(((angle+180)+270)/2,270),9+gra);
			}
		}


		task Shot(x,y,speed,angle,gra)
		{
			let obj = ObjShot_Create(OBJ_SHOT);
			ObjShot_Regist(obj);
			ObjMove_SetPosition(obj, x, y);
			ObjMove_SetSpeed(obj, speed);
			ObjMove_SetAngle(obj, angle);
			ObjShot_SetGraphic(obj, gra);
			//ObjShot_SetDelay(obj, delay);
			ObjShot_SetAutoDelete(obj,false);
		//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

		//	ShotEffect(obj);
			let yPlus=0;
			while(!Obj_IsDeleted(obj))
			{
				ObjRender_SetY(obj,ObjRender_GetY(obj)+yPlus);
				yPlus+=0.01;
				if(ObjRender_GetY(obj)>464){break;}
				yield;
			}
			Obj_Delete(obj);
		}

			task BladeShot(x,y,angle,gra)
			{
				let obj = CreateShotA2(x, y, 0, angle, 0, 0, gra, 0);//弾を発射
				ObjShot_SetSpellResist(obj,true);
				let scale=2.5;
				ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
				let speed=0.75;
				loop(8)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=2.5/12;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
					ObjShot_SetIntersectionCircleA1(obj,scale*6);
					yield;
				}
				ObjShot_SetIntersectionEnable(obj,false);
				loop(4)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=2.5/12;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
					yield;
				}
				Obj_Delete(obj);
			}
	}

	task ShotEffect(obj)
	{
		let scale=2.0;
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjShot_SetIntersectionEnable(obj,false);
		loop(15)
		{
			if(Obj_IsDeleted(obj)){break;}
			scale-=1.0/15;
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			yield;
		}
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		ObjShot_SetIntersectionEnable(obj,true);
	}

}