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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(384,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(6400);//ライフを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, 75);
//	loop(60){yield;}
	CallSpellCard("「カワードリーラビット」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	ReverseCircle;

	loop(75){yield;}
	SetAction(ACT_SHOT_A, 390);
	C;
	DamageRate=[50,50];
	wait(480);
	SetAction(ACT_SHOT_B, 1200);
	DamageRate=[75,75];
	A;
	wait(1320);

	B;
	DamageRate=[100,100];

	task A
	{
		let cx=ObjMove_GetX(objEnemy);
		let cy=ObjMove_GetY(objEnemy);

		ascent(i in 0..80)
		{
		Shot(i*6,0,2,90);
		}
		wait(75);
		ascent(j in 0..80)
		{
		Shot(0,j*6,2,0);
		}
		wait(75);
		ascent(i in 0..80)
		{
		Shot(i*6,448,2,270);
		}
		wait(75);
		ascent(j in 0..80)
		{
		Shot(384,j*6,2,180);
		}
		wait(180);
		ascent(i in 0..80)
		{
		Shot(i*6,0,2,90);
		}
		wait(75);
		ascent(j in 0..80)
		{
		Shot(384,j*6,2,180);
		}
		wait(75);
		ascent(i in 0..80)
		{
		Shot(i*6,448,2,270);
		}
		wait(75);
		ascent(j in 0..80)
		{
		Shot(0,j*6,2,0);
		}
		wait(180);

		ascent(i in 0..80)
		{
		Shot(i*6,0,1.5,90);
		}
		ascent(j in 0..80)
		{
		Shot(384,j*6,1.5,180);
		}
		ascent(i in 0..80)
		{
		Shot(i*6,448,1.5,270);
		}
		ascent(j in 0..80)
		{
		Shot(0,j*6,1.5,0);
		}

		task Shot(x,y,Basespeed,angle)
		{
		let R=0;
		let obj = ObjShot_Create(OBJ_SHOT);
	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjShot_Regist(obj);
		ObjMove_SetPosition(obj, x, y);
	//	ObjMove_SetSpeed(obj, speed);
		ObjMove_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, DS_BALL_S_WHITE);
	//	ObjShot_SetAutoDelete(obj,false);
		let gradangle=80+rand(0,8);
	//	ShotEffect(obj);
		let AlphaAngle=rand(0,360);
		let Alpha=absolute(cos(AlphaAngle));
		let Alpha2=absolute(cos(AlphaAngle));
	//	LightShot2(obj,AlphaAngle+90);
	//	ObjRender_SetColor(obj,255*Alpha,255*Alpha,255*Alpha);
		let speed=Basespeed;
		ObjMove_SetSpeed(obj, Basespeed);
		while(!Obj_IsDeleted(obj))
		{
			let dis=GetObjectDistance(obj,GetPlayerObjectID);
			if(dis<80)
			{
				if(speed>Basespeed/10)
				{
				speed-=Basespeed/15;
				}
			}
			else
			{
				if(speed<Basespeed)
				{
				speed+=Basespeed/15;
				}
			}
			ObjMove_SetSpeed(obj, speed);
			yield;
		}
		Obj_Delete(obj);
		}
	}

	task C
	{
		let cx=ObjMove_GetX(objEnemy);
		let cy=ObjMove_GetY(objEnemy);

		loop(360)
		{
		loop(4)
		{
		let angle=rand(0,360);
		Shot(cx,cy,rand(6,8),angle);
		}
		yield;
		}

		task Shot(x,y,Basespeed,angle)
		{
		let R=0;
		let obj = ObjShot_Create(OBJ_SHOT);
	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjShot_Regist(obj);
		ObjMove_SetPosition(obj, x, y);
	//	ObjMove_SetSpeed(obj, speed);
		ObjMove_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, DS_BALL_S_WHITE);
	//	ObjShot_SetAutoDelete(obj,false);
		let gradangle=80+rand(0,8);
	//	ShotEffect(obj);
		let AlphaAngle=rand(0,360);
		let Alpha=absolute(cos(AlphaAngle));
		let Alpha2=absolute(cos(AlphaAngle));
	//	LightShot2(obj,AlphaAngle+90);
	//	ObjRender_SetColor(obj,255*Alpha,255*Alpha,255*Alpha);
		let speed=Basespeed;
		ObjMove_SetSpeed(obj, Basespeed);
		while(!Obj_IsDeleted(obj))
		{
			let dis=GetObjectDistance(obj,GetPlayerObjectID);
			if(dis<80)
			{
				if(speed>Basespeed/10)
				{
				speed-=Basespeed/15;
				}
			}
			else
			{
				if(speed<Basespeed)
				{
				speed+=Basespeed/15;
				}
			}
			ObjMove_SetSpeed(obj, speed);
			yield;
		}
		Obj_Delete(obj);
		}
	}

	task B
	{
		let way=8;
		loop
		{
		SetAction(ACT_SHOT_A, 180);
		let cx=ObjMove_GetX(objEnemy);
		let cy=ObjMove_GetY(objEnemy);
		let angle=rand(0,360);
		loop(12)
		{
			ascent(i in 0..way)
			{
			Shot(cx,cy,6,angle+i*360/way,1,1,DS_BALL_S_YELLOW);
			}
			wait(3);
		}
		wait(36);
		loop(12)
		{
			ascent(i in 0..way)
			{
			Shot(cx,cy,6,angle+i*360/way,1,-1,DS_BALL_S_GREEN);
			}
			wait(3);
		}
		wait(36);
		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);
		let mdir=floor(rand(0,2-0.001))*2-1;
		let mx= ex+(60+rand(0,60))*mdir;
		let my= ey+rand(-20,20);
		while(mx<64 || mx>320){mdir=floor(rand(0,2-0.001))*2-1; mx=ex+(60+rand(0,60))*mdir;}
		while(my<80 || my>160){my=ey+rand(-20,20);}
		ObjMove_SetDestAtWeight(objEnemy,mx, my, 30,2.0);
		SetAction(ACT_MOVE, 75);
		wait(144);
		if(way<16)
		{
		way+=2;
		}

		}

		task Shot(x,y,Basespeed,angle,BaseanglePlus,dir,gra)
		{
		let R=0;
		let obj = ObjShot_Create(OBJ_SHOT);
	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjShot_Regist(obj);
		ObjMove_SetPosition(obj, x, y);
	//	ObjMove_SetSpeed(obj, speed);
		ObjMove_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, gra);
	//	ObjShot_SetAutoDelete(obj,false);
		let gradangle=80+rand(0,8);
	//	ShotEffect(obj);
		let AlphaAngle=rand(0,360);
		let Alpha=absolute(cos(AlphaAngle));
		let Alpha2=absolute(cos(AlphaAngle));
	//	LightShot2(obj,AlphaAngle+90);
	//	ObjRender_SetColor(obj,255*Alpha,255*Alpha,255*Alpha);
		let speed=Basespeed;
		let anglePlus=BaseanglePlus;
		ObjMove_SetSpeed(obj, Basespeed);
		let ReflectCount=0;
		let RMax=4;
		while(!Obj_IsDeleted(obj))
		{
			if(ReflectCount<RMax)
			{
			if(ObjRender_GetY(obj)<0)//上端での挙動
			{
			ObjRender_SetY(obj,ObjRender_GetY(obj));
			ObjMove_SetAngle(obj,-ObjMove_GetAngle(obj));
			ReflectCount+=1;
        		}
			if(ObjRender_GetY(obj)>GetStgFrameHeight)//上端での挙動
			{
			ObjRender_SetY(obj,GetStgFrameHeight*2-ObjRender_GetY(obj));
			ObjMove_SetAngle(obj,-ObjMove_GetAngle(obj));
			ReflectCount+=1;
        		}
			if(ObjRender_GetX(obj)<0)//左端での挙動
			{
			ObjRender_SetX(obj,ObjRender_GetX(obj));
			ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj));
			ReflectCount+=1;
        		}
			if(ObjRender_GetX(obj)>GetStgFrameWidth)//右端での挙動
			{
			ObjRender_SetX(obj,GetStgFrameWidth*2-ObjRender_GetX(obj));
			ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj));
			ReflectCount+=1;
			}
			}

			let dis=GetObjectDistance(obj,GetPlayerObjectID);
			if(dis<80)
			{
				if(speed>Basespeed/5)
				{
				speed-=Basespeed/10;
				anglePlus-=BaseanglePlus/10;
				}
			}
			else
			{
				if(speed<Basespeed)
				{
				speed+=Basespeed/10;
				anglePlus+=BaseanglePlus/10;
				}
			}

			angle=ObjMove_GetAngle(obj);
			angle+=anglePlus*dir;
			ObjMove_SetSpeed(obj, speed);
			ObjMove_SetAngle(obj, angle);


			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 ReverseCircle
	{
		C1;
		C2;

	task C1
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"../../img/effect/WhiteHole.png");
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_INV_DESTRGB);
		Obj_SetRenderPriorityI(obj,20);
		ObjRender_SetAngleZ(obj,0);

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

		ObjPrim_SetVertexUVT(obj, 0, 0, 0);
		ObjPrim_SetVertexUVT(obj, 1, 0, 128);
		ObjPrim_SetVertexUVT(obj, 2, 128, 0);
		ObjPrim_SetVertexUVT(obj, 3, 128, 128);
		let scale=1.428;
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		let Alpha=1;
		ObjRender_SetColor(obj,255*Alpha,255*Alpha,255*Alpha);

	//	ObjRender_SetPosition(obj,x,y,0);

		let s_count=0;
		while(!Obj_IsDeleted(obj))
		{
			ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
			yield;
		}
		Obj_Delete(obj);
	}

	task C2
	{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"../../img/effect/WhiteHole.png");
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_INV_DESTRGB);
		Obj_SetRenderPriorityI(obj,20);
		ObjRender_SetAngleZ(obj,0);

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

		ObjPrim_SetVertexUVT(obj, 0, 0, 0);
		ObjPrim_SetVertexUVT(obj, 1, 0, 128);
		ObjPrim_SetVertexUVT(obj, 2, 128, 0);
		ObjPrim_SetVertexUVT(obj, 3, 128, 128);
		let scale=1.408;
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		let Alpha=1;
		ObjRender_SetColor(obj,255*Alpha,255*Alpha,255*Alpha);

	//	ObjRender_SetPosition(obj,x,y,0);

		let s_count=0;
		while(!Obj_IsDeleted(obj))
		{
			ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
			yield;
		}
		Obj_Delete(obj);
	}

	}

}