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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(64,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(6600);//ライフを1500に設定
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);//時間制限を60秒に設定
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(30000);//スペルカードボーナスを30000に設定
	}
}

//----------------------------------------------------
//敵動作
//----------------------------------------------------
task BossWork
{
	//座標(cx, 60)へ60フレームかけて移動する
	let cx = GetStgFrameWidth() / 2;//STGシーンの中心x座標を取得
	ObjMove_SetDestAtWeight(objEnemy, cx, 128, 10,7);
	SetAction(ACT_MOVE, 60);
//	loop(60){yield;}
	CallSpellCard("「封返しの雷弾」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	A;
	loop(90){yield;}
	SetAction(ACT_SHOT_A, 12000);
	DamageRate=[100,100];

	task A
	{
		let wt=120;
		loop
		{
		let dir=floor(rand(0,2-0.001))*2-1;
		let angle=rand(0,360);
		let Tx=rand(0+64,384-64);
		let Ty=rand(0+64,448-64);
	//	let Tx=GetPlayerX;
	//	let Ty=GetPlayerY;
		ascent(i in 0..24)
		{
			S(Tx,Ty,0,angle+15*i,dir,i);
		}
			wait(wt);
			if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=5280){wt=90;}
			if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=4620){wt=75;}
			if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=3960){wt=60;}
			if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=2640){wt=45;}
		}

		task S(x,y,speed,angle,dir,num)
		{
			let R=512;
			let Bspeed=speed;
			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_BALL_S_PURPLE);
			//ObjShot_SetDelay(obj, delay);
			ObjShot_SetAutoDelete(obj,false);
			//ObjShot_SetIntersectionEnable(obj,false);
			ObjRender_SetBlendType(obj, BLEND_ALPHA);
			ShotEffect(obj);

			let obj2 = ObjShot_Create(OBJ_SHOT);
			ObjRender_SetBlendType(obj2, BLEND_ADD_RGB);
			ObjShot_Regist(obj2);
			ObjShot_SetGraphic(obj2, 14);
			ObjShot_SetAutoDelete(obj2,false);
		//	ObjRender_SetBlendType(obj2, BLEND_ALPHA);
			ShotEffect(obj2);

			loop(512)
			{
				R-=1;
				ObjMove_SetPosition(obj, x+R*cos(angle), y+R*sin(angle));
				ObjMove_SetPosition(obj2, x+R*cos(angle), y+R*sin(angle));
				ObjShot_SetDelay(obj2,5);
				angle+=0.4*dir;
				yield;
			}
			if(num==0){
			S2(ObjRender_GetX(obj),ObjRender_GetY(obj),0,GetAngleToPlayer(obj));
			S2_2(ObjRender_GetX(obj),ObjRender_GetY(obj),0,GetAngleToPlayer(obj));
			}
			Obj_Delete(obj);
			Obj_Delete(obj2);
		}

		task S2(x,y,speed,angle)
		{
			let R=0;
			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_BALL_L_PURPLE);
			//ObjShot_SetDelay(obj, delay);
			ObjShot_SetAutoDelete(obj,false);
			ShotEffect(obj);
			loop(60)
			{
				speed+=2/60;
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			while(!Obj_IsDeleted(obj))
			{
				speed+=2/60;
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			Obj_Delete(obj);
		}
		task S2_2(x,y,speed,angle)
		{
			let R=0;
			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_BALL_L_BLUE);
			//ObjShot_SetDelay(obj, delay);
			ObjShot_SetAutoDelete(obj,false);
			ShotEffect(obj);
			loop(60)
			{
				speed+=2/60;
				ObjMove_SetPosition(obj, ObjMove_GetX(obj)+speed*cos(angle), ObjMove_GetY(obj)+speed*sin(angle));
				ObjShot_SetDelay(obj, 90);
				yield;
			}
			while(!Obj_IsDeleted(obj))
			{
				speed+=2/60;
				ObjMove_SetPosition(obj, ObjMove_GetX(obj)+speed*cos(angle), ObjMove_GetY(obj)+speed*sin(angle));
				ObjShot_SetDelay(obj, 90);
				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);
	}

	task ShotEffect2(obj)
	{
		let scale=2.5;
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjShot_SetIntersectionEnable(obj,false);
		ObjRender_SetColor(obj,100,100,100);
		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);
	}
}