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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(384,64);
	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(5200);//ライフを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,7);
	SetAction(ACT_MOVE, 60);
//	loop(60){yield;}
	CallSpellCard("「アラウンドフレア」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	loop(60){yield;}

	let dir=floor(rand(0,2-0.001))*2-1;

	DR;
	loop
	{
	SetAction(ACT_SHOT_A, 60);
	C(dir);
	wait(415);
	dir*=-1;
	}

	task DR
	{
	loop(120){yield;}
	DamageRate=[100,100];
	}

	task C(dir)
	{
		let RandAngle=rand(0,360);
		let ShotRandAngle=rand(0,360);
		Sun(RandAngle,1);
		Sun(RandAngle+180,0);

		task Sun(angle,flag)
		{
		let x=ObjMove_GetX(objEnemy);
		let y=ObjMove_GetY(objEnemy);
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"../../img/effect/Flare.png");
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	//	ObjRender_SetBlendType(obj, BLEND_SUBTRACT);
	//	ObjRender_SetBlendType(obj, BLEND_MULTIPLY);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetVertexPosition(obj, 0, -128, -128, -0);
		ObjPrim_SetVertexPosition(obj, 1, -128, 128, -0);
		ObjPrim_SetVertexPosition(obj, 2, 128, -128, 0);
		ObjPrim_SetVertexPosition(obj, 3, 128,128, 0);

		ObjPrim_SetVertexUVT(obj, 0, 256, 0);
		ObjPrim_SetVertexUVT(obj, 1, 256, 256);
		ObjPrim_SetVertexUVT(obj, 2, 512, 0);
		ObjPrim_SetVertexUVT(obj, 3, 512, 256);
		let scale=0;
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		let Alpha=255;
		ObjRender_SetColor(obj,Alpha,Alpha,Alpha);
		ObjRender_SetPosition(obj,x,y,0);

		T_Shot(obj,ShotRandAngle);

		loop(15)
		{
			scale+=0.6/15;
			ObjRender_SetScaleXYZ(obj,scale,scale,1);
			SetShotIntersectionCircle(ObjRender_GetX(obj),ObjRender_GetY(obj),64*scale);
			yield;
		}
		let R=0;
		loop(480)
		{
			ObjRender_SetPosition(obj,x+R*cos(angle),y+R*sin(angle),0);
			angle+=0.75*dir;
			if(R<320)
			{
			R+=1;
			}
			SetShotIntersectionCircle(ObjRender_GetX(obj),ObjRender_GetY(obj),64*scale);
			yield;
		}
		loop(320)
		{
			ObjRender_SetPosition(obj,x+R*cos(angle),y+R*sin(angle),0);
			angle+=0.75*dir;
			R-=1;
			SetShotIntersectionCircle(ObjRender_GetX(obj),ObjRender_GetY(obj),64*scale);
			yield;
		}
		loop(15)
		{
			scale-=0.6/15;
			ObjRender_SetScaleXYZ(obj,scale,scale,1);
			SetShotIntersectionCircle(ObjRender_GetX(obj),ObjRender_GetY(obj),64*scale);
			yield;
		}
		if(flag)
		{
			let aaa=GetAngleToPlayer(obj);
			loop(6)
			{
			ascent(i in 0..24)
			{
				SunShot(ObjRender_GetX(obj),ObjRender_GetY(obj),0,aaa+i*15);
			}
			wait(5);
			}
		}

		Obj_Delete(obj);
		}

		task SunShot(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_BALL_M_YELLOW);
	//	ObjShot_SetDelay(obj, delay);

		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

		ShotEffect(obj);
		while(!Obj_IsDeleted(obj))
		{
			speed+=0.05;
			ObjMove_SetSpeed(obj, speed);
			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
			yield;
		}
		Obj_Delete(obj);
		}

		task T_Shot(Cobj,Cangle)
		{
			wait(15);
			loop(175)
			{
			Shot(Cangle);
			Shot(Cangle+180);
			Cangle+=10*dir;
			wait(5);
			}

			task Shot(angle)
			{
			let R=48;
			let speed=0;
			let obj = ObjShot_Create(OBJ_SHOT);
			ObjShot_Regist(obj);
			ObjMove_SetPosition(obj, ObjRender_GetX(Cobj)+R*cos(angle), ObjRender_GetY(Cobj)+R*sin(angle));
			ObjMove_SetSpeed(obj, speed);
			ObjMove_SetAngle(obj, angle);
			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
			ObjShot_SetGraphic(obj, 14);
			//ObjShot_SetDelay(obj, delay);
			ObjShot_SetAutoDelete(obj,false);
			ShotEffect(obj);
			loop(60)
			{
				speed+=1/60;
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			loop(120)
			{
				yield;
			}
			ObjShot_SetAutoDelete(obj,true);
			while(!Obj_IsDeleted(obj)){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);
	}
}