
#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_StarSaphire.txt"
#include"./../../lib/BossCommon/BossCommon.txt"

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(384,80);
	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(3600);//ライフを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, 144, 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];

	while(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)>=1800){yield;}
	D;
	task D
	{
		loop
		{
			let angle=rand(0,360);
			ascent(i in 0..24)
			{
			Shot(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),1,angle+i*15);
			}
			wait(120);
		}

		task Shot(x,y,speed,angle)
		{
			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, DS_STAR_M_SKY);
			//ObjShot_SetDelay(obj, delay);

		//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

			ShotEffect(obj);

			while(!Obj_IsDeleted(obj))
			{
				yield;
			}
			Obj_Delete(obj);
		}
	}

	task C
	{
		loop
		{
			H2(rand(0,384),0,rand(75,105));
			wait(10);
		}
		task H2(hx,hy,angle)
		{
			let t=0;
			let gra=DS_STAR_M_RED+5;
			let LaserSpeed=0;
			let angleAdd=0;
			Dust;
			loop(120)
			{
				hx+=LaserSpeed*cos(angle);
				hy+=LaserSpeed*sin(angle);
				LaserSpeed+=8/60;
				BladeShot(hx,hy,angle+angleAdd,gra+t%7);
				angleAdd+=3;
			//	t+=1;
				yield;
			}

			task Dust
			{
				let wt=10;
				if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=1800){wt=8;}
				if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=900){wt=6;}
				loop(120/wt)
				{
					Shot(hx,hy,1.5,angle+180+rand(-30,30));
					wait(wt);
				}
			}
		}


		task Shot(x,y,speed,angle)
		{
			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, DS_STAR_S_BLUE);
			//ObjShot_SetDelay(obj, delay);

		//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

			ShotEffect(obj);
			ObjShot_SetAutoDelete(obj,false);
			wait(30);
			ObjShot_SetAutoDelete(obj,true);
			while(!Obj_IsDeleted(obj))
			{
				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=1.5;
				ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
				let speed=0.75;
				loop(8)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=1.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-=1.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);
	}
}