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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(192,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(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,4);
//	SetAction(ACT_MOVE, 60);
//	loop(60){yield;}
	CallSpellCard("「シュプリームスプリング」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	loop(60){yield;}
	C;
	loop(90){yield;}
	DamageRate=[100,100];
	B;
	task C
	{
		let RingNum=5;
		Ring(6-3,180);
		Ring(6-3,0);
		task Ring(gra,a)
		{
			let cx=192;
			let cy=224;
			let cr=384;
			let ca=rand(0,360);
			let RingX=cx;
			let RingY=cy+cr*sin(ca);
			let RingPosAngle=a;
			let RingRadius=192;
			let RingRadius2=32;
			let RingBitAngle=rand(0,360);
			let speed=2.0;
			let oldX=[0,0,0,0,0,0,0,0,0];
			let oldY=[0,0,0,0,0,0,0,0,0];
			let yw=284;
			let ywplus=2;
			loop(60)
			{
				RingY=cy+yw*cos(RingPosAngle);
				ascent(i in 0..RingNum)
				{
				let DAngle=atan2(RingY+RingRadius*sin(RingBitAngle+i*360/RingNum)-oldY[i],RingX+RingRadius*cos(RingBitAngle+i*360/RingNum)-oldX[i]);
				BladeShot(RingX+RingRadius*cos(RingBitAngle+i*360/RingNum),RingY+RingRadius2*sin(RingBitAngle+i*360/RingNum),DAngle,81+gra);
				oldX[i]=RingX+RingRadius*cos(RingBitAngle+i*360/RingNum);
				oldY[i]=RingY+RingRadius*sin(RingBitAngle+i*360/RingNum);
				}
				RingBitAngle+=1.0;
			//	RingRadius-=192/60;
			//	RingRadius2-=32/60;
				yw-=ywplus;
				ywplus-=2/60;
				yield;
			}
			S;
			loop(3600)
			{
				RingY=cy+224*cos(RingPosAngle);
				ascent(i in 0..RingNum)
				{
				let DAngle=atan2(RingY+RingRadius*sin(RingBitAngle+i*360/RingNum)-oldY[i],RingX+RingRadius*cos(RingBitAngle+i*360/RingNum)-oldX[i]);
				BladeShot(RingX+RingRadius*cos(RingBitAngle+i*360/RingNum),RingY+RingRadius2*sin(RingBitAngle+i*360/RingNum),DAngle,81+gra);
				oldX[i]=RingX+RingRadius*cos(RingBitAngle+i*360/RingNum);
				oldY[i]=RingY+RingRadius*sin(RingBitAngle+i*360/RingNum);
				}
				RingBitAngle+=1.0;
				RingPosAngle+=0.5;
				yield;
			}

			task S
			{
				yield;
				loop
				{
				ascent(i in 0..RingNum)
				{
					let rx=RingX+RingRadius*cos(RingBitAngle+i*360/RingNum);
					let ry=RingY+RingRadius2*sin(RingBitAngle+i*360/RingNum);
					let dis=((rx-GetPlayerX)^2+(ry-GetPlayerY)^2)^0.5;
					if(dis>60)
					{
						ascent(j in 0..5)
						{
							Shot(rx,ry,1,RingBitAngle+i*360/RingNum+j*72);
						}
					}
				}
				wait(30);
				}
			}

		task Shot(x,y,speed,angle)
		{

		let R=0;
		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, 47);
	//	ObjShot_SetDelay(obj, delay);
		ShotEffect(obj);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);


		loop(5)
		{
			speed-=1/5;
			ObjMove_SetSpeed(obj, speed);
			yield;
		}
		loop(10)
		{
			yield;
		}
		while(!Obj_IsDeleted(obj))
		{
			if(speed<1){
			speed+=0.01;}
			ObjMove_SetSpeed(obj, speed);
			yield;
		}

		Obj_Delete(obj);
		}

		}

			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=1.5;
				ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
				let speed=0.75;
				loop(8)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=1.5/12;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
					ObjShot_SetIntersectionCircleA1(obj,scale*6);
					yield;
				}
				ObjShot_SetIntersectionEnable(obj,false);
				loop(4)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=1.5/12;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
					yield;
				}
				Obj_Delete(obj);
			}
	}

	task B
	{
		let speed=1;
		loop
		{
			ascent(i in 0..20)
			{
				Shot(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),speed,GetAngleToPlayer(objEnemy)+i*18);
			}
			wait(180);
			let life=ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			speed=6-5*(life/5200)
		}
		task Shot(x,y,speed,angle)
		{
		let BS=speed;
		let R=0;
		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, 31);
	//	ObjShot_SetDelay(obj, delay);
		ShotEffect(obj);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		loop(60)
		{
			speed-=BS/60;
			ObjMove_SetSpeed(obj, speed);
			yield;
		}
		ascent(i in 0..5)
		{
		Shot_F(ObjRender_GetX(obj),ObjRender_GetY(obj),0,GetAngleToPlayer(obj)+i*72);
		}

		Obj_Delete(obj);
		}

		task Shot_F(x,y,speed,angle)
		{
		let BS=speed;
		let R=0;
		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, 87);
	//	ObjShot_SetDelay(obj, delay);
		ShotEffect(obj);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		while(!Obj_IsDeleted(obj))
		{
			if(speed<3){
			speed+=0.025;}
			ObjMove_SetSpeed(obj, speed);
			yield;
		}
		Obj_Delete(obj);
		}
	}

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