
#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_Rumia.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(3000);//ライフを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, 80, 10,7);
	SetAction(ACT_MOVE, 60);
//	loop(60){yield;}
	CallSpellCard("「ブラックアウトキャノピー」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	wait(60);

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

	DarkEffect;
	DarkEffect;

	wait(30);
	A(dir);
	wait(90);
	B;
	wait(30);
	DamageRate=[100,100];

	task DarkEffect
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"../../img/effect/White.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);
		Obj_SetRenderPriorityI(obj,70);
		ObjRender_SetAngleZ(obj,0);
		let y=0;
		ObjPrim_SetVertexPosition(obj, 0, 0, 0, -0);
		ObjPrim_SetVertexPosition(obj, 1, 0, y, -0);
		ObjPrim_SetVertexPosition(obj, 2, 384, 0, 0);
		ObjPrim_SetVertexPosition(obj, 3, 384,y, 0);

		ObjPrim_SetVertexUVT(obj, 0, 0, 0);
		ObjPrim_SetVertexUVT(obj, 1, 0, 32);
		ObjPrim_SetVertexUVT(obj, 2, 32, 0);
		ObjPrim_SetVertexUVT(obj, 3, 32, 32);
		let Alpha=0;

		ObjPrim_SetVertexColor(obj,1,Alpha,Alpha,Alpha);
		ObjPrim_SetVertexColor(obj,3,Alpha,Alpha,Alpha);

		ObjRender_SetPosition(obj,0,0,0);

		loop(120)
		{
			ObjPrim_SetVertexPosition(obj, 0, 0, 0, -0);
			ObjPrim_SetVertexPosition(obj, 1, 0, y, -0);
			ObjPrim_SetVertexPosition(obj, 2, 384, 0, 0);
			ObjPrim_SetVertexPosition(obj, 3, 384,y, 0);
			y+=1;
			yield;
		}
		loop
		{
			ObjPrim_SetVertexPosition(obj, 0, 0, 0, -0);
			ObjPrim_SetVertexPosition(obj, 1, 0, y, -0);
			ObjPrim_SetVertexPosition(obj, 2, 384, 0, 0);
			ObjPrim_SetVertexPosition(obj, 3, 384,y, 0);
			if(y<324)
			{
			y+=0.2;
			}
			yield;
		}
		Obj_Delete(obj);
	}

	task A(dir)
	{
		loop
		{
			Laser(rand(0-32,192),0,rand(80,100),2,10,90);
			wait(18);
			Laser(rand(192,384+32),0,rand(80,100),2,10,90);
			wait(18);
		}

		task Laser(x,y,Langle,Lspeed,width,Slength)
		{
			let length=0;
			let obj = CreateStraightLaserA1(x, y, Langle, Lspeed, width, 900, DS_SCALE_BLUE, 0);
			ObjLaser_SetLength(obj,Slength);
			ObjStLaser_SetSource(obj,false);
			let r=0;
			let scale=0;

			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
			ObjShot_SetIntersectionEnable(obj,false);
			loop(5)
			{
				if(Obj_IsDeleted(obj)){break;}
				scale+=1.0/5;
				ObjRender_SetScaleXYZ(obj,scale,1,1);
				ObjLaser_SetLength(obj,Slength*scale);
				ObjLaser_SetRenderWidth(obj,width);
				yield;
			}
			loop(15)
			{
				if(Obj_IsDeleted(obj)){break;}
				scale-=1.0/15;
				ObjRender_SetScaleXYZ(obj,scale,1,1);
				ObjLaser_SetLength(obj,Slength*scale);
				ObjLaser_SetRenderWidth(obj,width);
				yield;
			}
			if(!Obj_IsDeleted(obj)){ObjRender_SetBlendType(obj, BLEND_ALPHA);}
			ObjShot_SetIntersectionEnable(obj,true);

			loop(Slength/Lspeed)
			{
				ObjLaser_SetLength(obj,length);
				length+=Lspeed;
				Lspeed+=0.05;
				yield;
			}

			let cy=rand(0,64);
			while(!Obj_IsDeleted(obj))
			{
				ObjRender_SetPosition(obj,x+r*cos(Langle),y+r*sin(Langle),0);
				r+=Lspeed;
				yield;
			}
			Obj_Delete(obj);
		}
	}

	task B
	{
		let waittime=65;
		loop
		{
			let num=floor(rand(0,4-0.001));
			alternative(num)
			case(0){Shot1;}
			case(1){Shot2;}
			case(2){Shot3;}
			case(3){Shot4;}
			wait(waittime);
		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);
		let mx= ex+rand(-120,120);
		let my= ey+rand(-20,20);
		while(mx<64 || mx>320){mx=ex+rand(-120,120);}
		while(my<80 || my>144){my=ey+rand(-20,20);}
		ObjMove_SetDestAtWeight(objEnemy,mx, my, 30,2.0);
		SetAction(ACT_MOVE, 75);
			let life=ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			if(life<1000)
			{
			waittime=35;
			}
			else if(life<2000)
			{
			waittime=50;
			}
			wait(waittime);
		}
		task Shot1
		{
			let angle=GetAngleToPlayer(objEnemy);
			ascent(j in 0..5)
			{
			ascent(i in -2..2)
			{
				CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),2+j,angle+i*3+1.5,41,0);
			}
			}
		}
		task Shot2
		{
			loop(3)
			{
			let angle=GetAngleToPlayer(objEnemy);
			loop(5)
			{
			ascent(i in 0..30)
			{
				CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),3,angle+i*12,44,0);
			}
			wait(3);
			}
			wait(10);
			}
		}
		task Shot3
		{
			loop(6)
			{
			let angle=rand(0,360);
			ascent(i in 0..36)
			{
				CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),3,angle+i*10,43,0);
			}
			wait(15);
			}
		}
		task Shot4
		{
			let angle=rand(0,360);
			ascent(j in 0..10)
			{
			ascent(i in 0..10)
			{
				CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1.5,angle+i*36+1.5*j,42,0);
				CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1.0,angle+i*36+18+1.5*j,42,0);
			}
			}
		}
	}
}