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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(0,80);
	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(4400);//ライフを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, 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];

	task C
	{
		ascent(i in 0..8)
		{
			H2(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),i*45,1);
			H2(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),i*45+22.5,-1);
		}
		T_Shot2;
		task H2(hx,hy,angle,dir)
		{
			let t=0;
			let gra=DS_STAR_M_YELLOW;
			let R=0;
			let x=hx+R*cos(angle);
			let y=hy+R*sin(angle);
			T_Shot;
			loop
			{
				x=hx+R*cos(angle);
				y=hy+R*sin(angle);
			//	BladeShot(x,y,angle,gra);
			//	t+=1;
				if(R<60)
				{
				//R+=1;
				}
				angle+=0.5*dir;
				yield;
			}
			task T_Shot
			{
				loop
				{
				loop(3)
				{
					Shot(x,y,2,angle,-dir);
				////	Shot(x,y,4,angle+15);
				//	Shot(x,y,4,angle-15);
					wait(2);
				}
					wait(15);
				}
			}
		}

			task T_Shot2
			{
				let wt=120;
				let LA=rand(-5,5);
				wait(80);
				wtc;
				loop
				{
					LA=rand(-4.5,4.5);
					ascent(i in 0..11)
					{
					Laser(0,0,LA+90-9*i,10,8,200);
					wait(2);
					}
					wait(wt-2);
					LA=rand(-4.5,4.5);
					ascent(i in 0..11)
					{
					Laser(384,0,LA+90+9*i,10,8,200);
					wait(2);
					}
					wait(wt-2);
				}
				task wtc
				{
					loop
					{
					if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=3300)
					{wt=60;}
					if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=2200)
					{wt=40;}
					if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=1100)
					{wt=20;}
					yield;
					}
				}

			}

		task Shot(x,y,speed,angle,dir)
		{
			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_YELLOW);
			//ObjShot_SetDelay(obj, delay);

		//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

			ShotEffect(obj);
			while(!Obj_IsDeleted(obj))
			{
				ObjMove_SetAngle(obj, angle);
				angle+=0.5*dir;
				yield;
			}
			Obj_Delete(obj);
		}

		task Laser(x,y,Langle,Lspeed,width,Slength)
		{
			let length=0;
			let obj = CreateStraightLaserA1(x, y, Langle, Lspeed, width, 900, DS_SCALE_YELLOW, 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+=2.625/5;
				ObjRender_SetScaleXYZ(obj,scale,1,1);
				ObjLaser_SetLength(obj,Slength*scale);
				ObjLaser_SetRenderWidth(obj,width);
				yield;
			}
			loop(30)
			{
				if(Obj_IsDeleted(obj)){break;}
				scale-=2.625/30;
				ObjRender_SetScaleXYZ(obj,scale,1,1);
				ObjLaser_SetLength(obj,Slength*scale);
				ObjLaser_SetRenderWidth(obj,width);
				yield;
			}
		//	ObjRender_SetBlendType(obj, BLEND_ALPHA);
			ObjShot_SetIntersectionEnable(obj,true);

			loop(Slength/Lspeed)
			{
				ObjLaser_SetLength(obj,length);
				length+=Lspeed;
				Lspeed+=0.05;
				yield;
			}
			while(!Obj_IsDeleted(obj))
			{
				ObjRender_SetPosition(obj,x+r*cos(Langle),y+r*sin(Langle),0);
				r+=Lspeed;
				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);
	}
}