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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(0,96);
	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, 96, 10,4);
	SetAction(ACT_MOVE, 75);
//	loop(60){yield;}
	CallSpellCard("「イリデッセントエンブレイス」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	loop(75){yield;}
	SetAction(ACT_SHOT_B, 6000);
	B(1);
	wait(180);
	DamageRate=[100,100];

	task B(dir)
	{
		let X=[180-144*dir,180-96*dir,180-48*dir,192,180+48*dir,180+96*dir,180+144*dir];
		let Y=[56,48,40,32,40,48,56];

		DragonShot(0,0,0);

		task DragonShot(x,y,num)
		{
			let sx = ObjMove_GetX(objEnemy);
			let sy = ObjMove_GetY(objEnemy);
			let wide=30;
			Shoot1;

			task Shoot1
			{

			wideC;
			let R=30;
			let wideAngle=90;
			let BaseAngle;
			let BaseAngle2;
			let count=0;
			loop
			{
				BaseAngle=10-wide;
				let angle=BaseAngle-wide*cos(wideAngle);
				BaseAngle2=170+wide;
				let angle2=BaseAngle2+wide*cos(wideAngle);
				Shooting(sx+R*cos(angle),sy+R*sin(angle),angle,floor(rand(0,7-0.001)),1*0);
				Shooting(sx+R*cos(angle2),sy+R*sin(angle2),angle2,floor(rand(0,7-0.001)),-1*0);
				wideAngle+=3;
				wait(1);
/*
				BaseAngle=10-wide;
				angle=BaseAngle-wide*cos(wideAngle);
				BaseAngle2=170+wide;
				angle2=BaseAngle2+wide*cos(wideAngle);
				Shooting(sx+R*cos(angle),sy+R*sin(angle),angle,floor(rand(0,7-0.001)),1*0);
				Shooting(sx+R*cos(angle2),sy+R*sin(angle2),angle2,floor(rand(0,7-0.001)),-1*0);
*/
				if(count%3!=0)
				{
				wideAngle+=3;
				wait(1);
				}
				count+=1;
			}
/*
			loop
			{
				let angle=rand(-wide,10);
				let waittime=4-wide/30;
				Shooting(sx+R*cos(angle),sy+R*sin(angle),angle,floor(rand(0,7-0.001)),1);
				wait(waittime);
				angle=rand(-10,wide)+180;
				Shooting(sx+R*cos(angle),sy+R*sin(angle),angle,floor(rand(0,7-0.001)),-1);
				wait(waittime);
			}
*/
			task wideC
			{
				loop
				{
					if(wide<60){wide+=0.025;}
					yield;
				}
			}
			}

			task Shooting(hx,hy,hangle,t,dir)
			{
			//	H(hx,hy,hangle,t,dir);
				Shot2(hx,hy,0,hangle,dir,t);
				wait(60);
				let x;
				let angle;
				if(hangle<=90 && hangle>=-45)
				{
					x=384+32;angle=rand(165,175);
				//	H2(x,(hangle+45)/55*448,angle,t,0);
					Shot(x,(hangle+45)/55*448,0,angle,t);
				}
				else if(hangle>90 && hangle<=225)
				{
					x=0-32;angle=rand(5,15);
				//	H2(x,(-hangle+45+180)/55*448,angle,t,0);
					Shot(x,(-hangle+45+180)/55*448,0,angle,t);
				}
				else if(hangle<=-45 && hangle>=-90)
				{
					angle=rand(85,95);
				//	H2(384+(45+hangle)/45*192,0-32,angle,t,0);
					Shot(384+(45+hangle)/45*192,0-32,0,angle,t);
				}
				else if(hangle>225 && hangle<=270)
				{
					angle=rand(85,95);
				//	H2((hangle-225)/45*192,0-32,angle,t,0);
					Shot((hangle-225)/45*192,0-32,0,angle,t);
				}
			}

			task H(hx,hy,angle,t,dir)
			{
			let gra=81+t-81+DS_STAR_S_RED;
			let LaserSpeed=0;
			loop(120)
			{
				hx+=LaserSpeed*cos(angle);
				hy+=LaserSpeed*sin(angle);
				if(x<-64){break;}
				if(x>448){break;}
				if(y<-32){break;}
				LaserSpeed+=5/60;
				BladeShot(hx,hy,angle,gra);
				angle+=0.5*dir;
				yield;
			}
			}

			task H2(hx,hy,angle,t,dir)
			{
			let gra=81+t;
			let LaserSpeed=0;
			loop(120)
			{
				hx+=LaserSpeed*cos(angle);
				hy+=LaserSpeed*sin(angle);
				if(x<-64){break;}
				if(x>448){break;}
				if(y<-32){break;}
				if(y>=480){break;}
				LaserSpeed+=4/60;
				BladeShot(hx,hy,angle,gra);
				angle+=0.5*dir;
				yield;
			}
			}

			task BladeShot(x,y,angle,gra)
			{
				let obj = CreateShotA2(x, y, 0, angle, 0, 0, gra, 0);//弾を発射
				ObjShot_SetSpellResist(obj,true);
				let scale=1.25;
				ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
				let speed=0.75;
				loop(6)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=1.25/9;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
					ObjShot_SetIntersectionCircleA1(obj,scale*3);
					yield;
				}
				ObjShot_SetIntersectionEnable(obj,false);
				loop(3)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=1.25/9;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
					yield;
				}
				Obj_Delete(obj);
			}
		}

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

	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

	//	ShotEffect(obj);
		loop(90)
		{
			speed+=1.5/90;
			ObjMove_SetSpeed(obj, speed);
			yield;
		}
		while(!Obj_IsDeleted(obj))
		{
		//	speed+=2/90;
		//	ObjMove_SetSpeed(obj, speed);
			yield;
		}
		Obj_Delete(obj);
	}

	task Shot2(x,y,speed,angle,dir,t)
	{
		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_RED+t);
	//	ObjShot_SetDelay(obj, delay);

		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

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

	}


}