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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(224,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(6600);//ライフを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,2.0);
	SetAction(ACT_MOVE, 105);
//	loop(60){yield;}
	CallSpellCard("「ブルーカーバンクル」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	wait(90);
	C;
	B;
	DamageRate=[100,100];
	task C
	{
		let waittime=240;
		let dir=floor(rand(0,2-0.001))*2-1;
		let way=6;
		loop
		{
		let angle=rand(0,360);
		ascent(i in 0..way)
		{
		Shot(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),angle+i*360/way,dir);
		}
		wait(waittime);
		let life=ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
		if(life<5280){waittime=210;}
		if(life<3960){waittime=180;}
		if(life<2640){waittime=150;}
		dir*=-1;
		}
		task Shot(x,y,Angle,dir)
		{
			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, DS_BALL_L_BLUE);
		//	ObjShot_SetDelay(obj, delay);
			ShotEffect(obj);
			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
			ObjShot_SetAutoDelete(obj,false);
			BitShot;
			loop(360)
			{
				ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
				ObjMove_SetPosition(obj, x+R*cos(Angle), y+R*sin(Angle));
				R+=1;
				Angle+=0.5*dir;
				yield;
			}

			Obj_Delete(obj);

			task BitShot
			{
				wait(30);
				while(!Obj_IsDeleted(obj))
				{
					loop(5)
					{
					ascent(i in -2..2)
					{
					Shot(ObjRender_GetX(obj),ObjRender_GetY(obj),1.5,Angle-210+i*60);
					}
					wait(3);
					}
					wait(30);
				}

				task Shot(x,y,speed,angle)
				{
				let dis=((x-GetPlayerX)^2+(y-GetPlayerY)^2)^0.5;
				if(dis<=48){break;}
				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, 46);
			//	ObjShot_SetDelay(obj, delay);
				ShotEffect(obj);
				ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

				while(!Obj_IsDeleted(obj))
				{
					yield;
				}

				Obj_Delete(obj);
				}

			}

		}

	}

	task B
	{
		wait(240);
		let waittime=300;
		loop
		{
			ascent(i in 0..6)
			{
			Laser(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),GetAngleToPlayer(objEnemy)+i*60);
			}
			wait(waittime);
			let life=ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			if(life<5500){waittime=255;}
			if(life<4400){waittime=210;}
			if(life<3300){waittime=165;}
			if(life<2200){waittime=120;}
		}
		task Laser(x,y,Langle)
		{
			let length=0;
			let width=5;
			let obj = CreateStraightLaserA1(x, y, Langle, 0, 0, 900, DS_BEAM_BLUE, 0);

			ObjLaser_SetLength(obj,length);
			ObjStLaser_SetSource(obj,false);
			let r=0;
			let scale=0;

			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
			ObjShot_SetIntersectionEnable(obj,false);
			ObjLaser_SetRenderWidth(obj, width);

			let speed=2;
			let Bspeed=speed;
			let Mangle=90;
			let LanglePlus=6;
			let BLanglePlus=LanglePlus;
			loop(45)
			{
				length+=600/45;
				ObjLaser_SetLength(obj,length);
				yield;
			}
			loop(15)
			{
				width+=20/15;
				ObjLaser_SetRenderWidth(obj, width);
				yield;
			}
			ObjLaser_SetIntersectionWidth(obj,10);
			ObjShot_SetIntersectionEnable(obj,true);

			loop(105){yield;}

			ObjShot_SetIntersectionEnable(obj,false);
			loop(15)
			{
				width-=20/15;
				ObjLaser_SetRenderWidth(obj, width);
				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);
	}

}