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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(384,260);
	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,3);
	SetAction(ACT_MOVE, 90);
	CallSpellCard("「ブラインドローレライ」");

/*
	loop(60){yield;}
	CallSpellCard("「ブラインドローレライ」");

	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	wait(90);
	B;
	T_Blind;
	C;
	wait(240);
	DamageRate=[100,100];

	task T_Blind
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"../../img/effect/blind.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);
		Obj_SetRenderPriorityI(GetPlayerObjectID,71);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetVertexPosition(obj, 0, -192, -224, -0);
		ObjPrim_SetVertexPosition(obj, 1, -192, 224, -0);
		ObjPrim_SetVertexPosition(obj, 2, 192, -224, 0);
		ObjPrim_SetVertexPosition(obj, 3, 192,224, 0);

		ObjPrim_SetVertexUVT(obj, 0, 0, 0);
		ObjPrim_SetVertexUVT(obj, 1, 0, 448);
		ObjPrim_SetVertexUVT(obj, 2, 384, 0);
		ObjPrim_SetVertexUVT(obj, 3, 384, 448);
		let scale=23;
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		let Alpha=255;
		ObjRender_SetColor(obj,Alpha,Alpha,Alpha);
		loop(180)
		{
			scale-=20/180;
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			ObjRender_SetPosition(obj,GetPlayerX+1,GetPlayerY-120,0);
			yield;
		}
		loop
		{
			ObjRender_SetPosition(obj,GetPlayerX+1,GetPlayerY-120,0);
			yield;
		}
		Obj_Delete(obj);
	}

	task C
	{
	let RockArray=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
	let waittime=144;
	let speed=150/waittime;
	loop
	{
		RockArray=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
		let count=3;
		while(count!=0)
		{
		let Rum=floor(rand(0,12-0.001));
		if(RockArray[Rum]!=0)
		{
			RockArray[Rum]=0;
			count-=1;
		}
		}
		ascent(i in 0..19)
		{
		if(RockArray[i]==1)
		{
		FreezeShot(20*i+12,0,speed);
		}
		}
		wait(waittime);
		if(waittime>60)
		{
		waittime-=6;
		}
		speed=150/waittime;
	}
	}

	task FreezeShot(x,y,speed)
	{
	let angle=90;
	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, 29);
	ObjShot_SetAutoDelete(obj,true);
	ShotEffect(obj);
	}

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

	task B
	{
		loop(240){yield;}
		WShot;
		loop(30){yield;}
		loop
		{
		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>160){my=ey+rand(-20,20);}
		ObjMove_SetDestAtWeight(objEnemy,mx, my, 30,2.0);
		SetAction(ACT_MOVE, 75);
		loop(120){yield;}
		WShot;
		loop(30){yield;}
		}

		task WShot
		{

			let angle=GetAngleToPlayer(objEnemy);
			let life=ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			let way=floor((3600-life)/400)+5;
			ascent(i in -way..way+1)
			{
			let obj=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1.25,angle+i*2.5,21,0);
			ShotEffect(obj);
			}

		}
	}
}