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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(160,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(3800);//ライフを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, 128, 10,5);
	SetAction(ACT_MOVE, 60);
//	loop(60){yield;}
	CallSpellCard("「マインギャラクシー」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	loop(60){yield;}

	S;
	A;
	loop(180){yield;}
	DamageRate=[100,100];

	task S
	{
	let way=2;
	loop
	{
		let R=364;
		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);
		let angle=rand(0,360);
		Shot(ex+R*cos(angle),ey+R*sin(angle),1.5,angle+180+rand(-3,3));
		wait(2);
	}

	task Shot(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_STAR_S_WHITE);
		ObjShot_SetAutoDelete(obj,false);
	//	ObjShot_SetDelay(obj, delay);

		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

	//	ShotEffect(obj);
		let flag=0;
		loop(570)
		{
			if(Obj_IsDeleted(obj)){break;}
			let dis=GetObjectDistance(obj,GetPlayerObjectID);
			if(dis<=32 && flag==0)
			{
				Explode;
				flag=1;
			}
			yield;
		}
		Obj_Delete(obj);

		task Explode
		{
			loop(30)
			{
				speed-=1.5/30;
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			let R=255;let G=255;let B=255;
			loop(60)
			{
				speed-=1.5/30;
				ObjRender_SetColor(obj,R,G,B);
				G-=255/60;
				B-=255/60;
				yield;
			}

			Sun(ObjRender_GetX(obj),ObjRender_GetY(obj));
			DFire(ObjRender_GetX(obj),ObjRender_GetY(obj));
			Obj_Delete(obj);
		}
	}

		task Sun(x,y)
		{
/*
		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_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*0;
		ObjRender_SetColor(obj,Alpha,Alpha,Alpha);
		ObjRender_SetPosition(obj,x,y,0);

	//	T_Shot(obj,ShotRandAngle);
*/
		let obj = ObjShot_Create(OBJ_SHOT);
		ObjShot_Regist(obj);
		ObjMove_SetPosition(obj, x, y);
		let scale=0;

		loop(15)
		{
			scale+=0.5/15;
			ObjRender_SetScaleXYZ(obj,scale,scale,1);
			SetShotIntersectionCircle(ObjRender_GetX(obj),ObjRender_GetY(obj),64*scale);
			yield;
		}
		loop(60)
		{
			SetShotIntersectionCircle(ObjRender_GetX(obj),ObjRender_GetY(obj),64*scale);
			yield;
		}
		loop(15)
		{
			scale-=0.5/15;
			ObjRender_SetScaleXYZ(obj,scale,scale,1);
			SetShotIntersectionCircle(ObjRender_GetX(obj),ObjRender_GetY(obj),64*scale);
			yield;
		}

		Obj_Delete(obj);
		}

	task DFire(x,y)
	{
		let a=rand(0,360);
		ascent(i in 0..5)
		{
		BladeShot(x,y,a+i*72);
		}
	task BladeShot(x,y,angle)
	{
		let obj = CreateShotA2(x, y, 0, angle, 0, 0, DS_FIRE_RED, 0);//弾を発射
		let scale=4.0*0;
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		let speed=0.75*0;
		ObjRender_SetColor(obj,50,50,50);
		loop(15)
		{
			if(Obj_IsDeleted(obj)){break;}
			scale+=4.0/15;
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			ObjMove_SetSpeed(obj,speed);
			yield;
		}
		loop(60)
		{
			yield;
		}
		loop(15)
		{
			if(Obj_IsDeleted(obj)){break;}
			scale-=4.0/15;
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			ObjMove_SetSpeed(obj,speed);
			yield;
		}

		Obj_Delete(obj);
	}
	}

	}

	task A
	{
		wait(240);
		let dir=floor(rand(0,2-0.001))*2-1;
		let way=12;
		loop
		{
			ascent(i in 0..way)
			{
				StarShot(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),i*360/way,dir);
			}
			dir*=-1;
			wait(120-30);
			let life=ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			if(life<=2850){way=18;}
			if(life<=1900){way=24;}
			if(life<=950){way=30;}
		}

		task StarShot(x,y,angle,dir)
		{
			let speed=5;
			loop(80)
			{
				BladeShot(x,y,angle,88);
				x+=speed*cos(angle);
				y+=speed*sin(angle);
				angle+=0.75*dir;
				if(y<0){break;}
				if(x<0){break;}
				if(x>384){break;}
				yield;
			}

			task BladeShot(x,y,angle,gra)
			{
				let obj = CreateShotA2(x, y, 0, angle, 0, 0, gra, 0);//弾を発射
				ObjShot_SetSpellResist(obj,true);
				ObjShot_SetAutoDelete(obj,false);
				let scale=2.0;
				ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
				let speed=0.75;
				loop(15)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=2.0/20;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
					ObjShot_SetIntersectionCircleA1(obj,scale*6);
					yield;
				}
				ObjShot_SetIntersectionEnable(obj,false);
				loop(5)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=2.0/20;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
					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);
	}
}