
#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_Rumia.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(5400);//ライフを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,7);
	SetAction(ACT_MOVE, 60);
//	loop(60){yield;}
	CallSpellCard("「リリスの暗き月」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	wait(45);
	A;
	wait(90);
	B;
	DamageRate=[100,100];

	task A
	{
		let way=18;
		let angle;
		let dir=floor(rand(0,2-0.001))*2-1;
		loop
		{
			angle=rand(0,360);
			ascent(i in 0..way)
			{
				MainShot(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),0,270-i*360/way+angle,dir);
			}
			wait(330);
			let life=ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			if(life<=5400){way=18;}
			if(life<=4500){way=21;}
			if(life<=3600){way=24;}
			if(life<=2700){way=30;}
			angle=rand(0,360);
			ascent(i in 0..way)
			{
				MainShot(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),0,270-i*360/way+angle,-dir);
			}
			wait(330);
			life=ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			if(life<=5400){way=18;}
			if(life<=4500){way=21;}
			if(life<=3600){way=24;}
			if(life<=2700){way=30;}
		}
	task MainShot(x,y,speed,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_M_YELLOW);
		ObjShot_SetGraphic(obj, DS_BALL_M_BLUE);
	//	ObjShot_SetDelay(obj, delay);

		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

		Shot;
		let Rs=3/3;

		let BA;
		let BS;
		let ox=x+R*cos(angle);
		let oy=y+R*sin(angle);
		loop(510)
		{
		if(R<64){	R+=Rs;}
			ox=ObjRender_GetX(obj);
			oy=ObjRender_GetY(obj);
			ObjMove_SetPosition(obj, x+R*cos(angle), y+R*sin(angle));
			BA=atan2(ObjRender_GetY(obj)-oy,ObjRender_GetX(obj)-ox);
			BS=((ObjRender_GetY(obj)-oy)^2+(ObjRender_GetX(obj)-ox)^2)^0.5;
			angle+=3.45*dir;
			yield;
		}

		Obj_Delete(obj);

		task Shot
		{
			let cd=1;
			let ad=140;
			wait(60);
			let speed=1.8;
				loop(55)
				{
				CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),speed,angle+ad*dir*cd,46,0);cd*=-1;
				speed+=0.060;
				wait(8);
				}
		}
	}
	}

	task B
	{
		let waittime=150;
		loop
		{
			let sx=ObjRender_GetX(objEnemy);
			let sy=ObjRender_GetY(objEnemy);
			let Langle=GetAngleToPlayer(objEnemy);
			let width=12;
			let leng=1152;
			let gra=DS_ICE_YELLOW;
			Laser(sx-512*sin(Langle+90), sy+512*cos(Langle+90),Langle,1);
			Laser2(sx-512*sin(Langle+90), sy+512*cos(Langle+90),Langle,1);
			Laser2(sx-512*sin(Langle+90), sy+512*cos(Langle+90),Langle,-1);
			wait(60);
			LaserObject( sx-512*sin(Langle+90), sy+512*cos(Langle+90), leng-512, width,  Langle, gra,60);
			ascent(i in 1..12)
			{
			LaserObject( sx+i*1*cos(Langle+90)-512*sin(Langle+90),sy+i*1*sin(Langle+90)+512*cos(Langle+90), leng-512+0*i, width,  Langle, gra,60+i*3);
			LaserObject( sx-i*1*cos(Langle+90)-512*sin(Langle+90),sy-i*1*sin(Langle+90)+512*cos(Langle+90), leng-512+0*i, width,  Langle, gra,60+i*3);
			wait(1);
			}
			wait(waittime);
			let life=ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			if(life<=4050){waittime=120;}
			if(life<=2700){waittime=90;}
			if(life<=1350){waittime=60;}
		}
		task Laser(x,y,Langle,dir)
		{
			let length=0;
			let width=5;
			let obj = CreateStraightLaserA1(x, y, Langle, 0, 0, 900, DS_BEAM_YELLOW, 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);

			ObjShot_SetAutoDelete(obj,false);

			let speed=2;
			let Bspeed=speed;
			let Mangle=90+80*dir;
			let LanglePlus=6;
			let BLanglePlus=LanglePlus;
			loop(60)
			{
				if(length<1152)
				{
				length+=1152/60;
				}
				ObjStLaser_SetAngle(obj,Langle);
				ObjLaser_SetLength(obj,length);
				yield;
			}

			Obj_Delete(obj);
		}

		task Laser2(x,y,Langle,dir)
		{
			let dis=12*dir;
			let dx=dis*sin(Langle);
			let dy=dis*cos(Langle);
			let length=0;
			let width=5;
			let obj = CreateStraightLaserA1(x+dx, y+dy, Langle, 0, 0, 900, DS_BEAM_YELLOW, 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);

			ObjShot_SetAutoDelete(obj,false);

			let speed=2;
			let Bspeed=speed;
			let Mangle=90+80*dir;
			let LanglePlus=6;
			let BLanglePlus=LanglePlus;
			loop(60)
			{
				if(length<1152)
				{
				length+=1152/60;
				}
				dis-=8/60*dir;
				dx=dis*sin(Langle);
				dy=dis*cos(Langle);
				ObjRender_SetX(obj,x+dx);
				ObjRender_SetY(obj,y+dy);
				ObjStLaser_SetAngle(obj,Langle);
				ObjLaser_SetLength(obj,length);
				yield;
			}

			Obj_Delete(obj);
		}

	task LaserObject( sx, sy, leng, width,angle, gra, time )
	{
		let obj = CreateStraightLaserA1(sx, sy, angle, 0, width, time/2, DS_ICE_RED, 0);
		ObjStLaser_SetSource(obj, false);
		let color = [255,255,255];
		ObjShot_SetAutoDelete(obj,false);
		ascent(i in 1 .. time)
		{
			if(Obj_IsDeleted(obj)){break;}
			if(leng<1024)
			{
			leng+=12;
			}
			ObjLaser_SetLength(obj,leng);
			ObjLaser_SetRenderWidth(obj, width);
			ObjRender_SetColor(obj, color[0]*(time-i)/time, color[1]*(time-i)/time, color[2]*(time-i)/time);
			ObjLaser_SetInvalidLength(obj,leng*0.15,leng*0.15);
			if(ObjRender_GetY(obj)<0 ||1){
			ObjRender_SetY(obj,ObjRender_GetY(obj)+0.1*(120-time)*sin(angle));
			ObjRender_SetX(obj,ObjRender_GetX(obj)+0.1*(120-time)*cos(angle));
			}
			if(i>=time/2){ObjShot_SetGraphic(obj,DS_ICE_ORANGE);}
			yield;
		}
		Obj_Delete(obj);
	}

	}
}