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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(384,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(3800);//ライフを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
	{
	loop
	{
	let sx=ObjMove_GetX(objEnemy);
	let sy=ObjMove_GetY(objEnemy);
	let Bangle = atan2(GetPlayerY-sy,GetPlayerX-sx)+72;

	loop(2)
	{
	SetAction(ACT_SHOT_B, 30);
	wait(15);
	Blade(Bangle);	
	wait(150);
	}
	SetAction(ACT_SHOT_B, 30);
	wait(15);
	Blade(Bangle);	
	wait(90);

	Fire;
	wait(360);
	wait(30);

	task Fire
	{
	let dir=floor(rand(0,2-0.001))*2-1;
	loop(7)
	{
	let sx=ObjMove_GetX(objEnemy);
	let sy=ObjMove_GetY(objEnemy);
	let angle=rand(0,360);
	ascent(i in 0..36)
	{
	FireShot(sx,sy,0,angle+i*10,dir);
	}
	wait(60);
	dir*=-1;
	}
	}

	task Rise(x)
	{
		ascent(i in 0..40)
		{
			Shot(x+i*10,448,rand(0.5,1.5),rand(265,280));
			Shot(x-i*10,448,rand(0.5,1.5),rand(265,280));
			Shot(x-i*10,448,rand(0.5,1.5),rand(265,280));
			Shot(x+i*10,448,rand(1.5,2.5),rand(265,280));
			Shot(x-i*10,448,rand(1.5,2.5),rand(265,280));
			wait(1);
		}
/*
		ascent(i in 0..8)
		{
			ascent(j in -1..2)
			{
				ascent(k in 0..3)
				{
				Shot(x+i*60+j*6,448,0.5+0.5*k,270);
				Shot(x-i*60+j*6,448,0.5+0.5*k,270);
				}
			}
			wait(5);
		}	
*/
	}

	task Shot(x,y,speed,angle)
	{
		let time=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, 11);
		//ObjShot_SetDelay(obj, delay);
		//ObjShot_SetAutoDelete(obj,false);

		let scale=4.0;
	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		let R=0;

	//	let angle=atan2(1/3*sin(PAngle)*cos(Angle)+1*cos(PAngle)*sin(Angle),1/3*cos(PAngle)*cos(Angle)-1*sin(PAngle)*sin(Angle));
		ObjMove_SetAngle(obj, angle);

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

	task Blade(angle)
	{
		let leng = 1152;
		let width = 12;
		let widthPlus = 2;
		let gra = DS_ICE_YELLOW;
		let Langle = GetAngleToPlayer(objEnemy);
		if(sin(90-Langle)>=sin(30))
		{
			Langle=60;
		}
		else if (sin(90-Langle)<=sin(-30))
		{
			Langle=120;
		}
		LaserObject( sx-512*sin(Langle+90), sy+512*cos(Langle+90), leng-512, width,  Langle, gra,60);
		ascent(i in 1..20)
		{
		LaserObject( sx+i*4*cos(Langle+90)-512*sin(Langle+90),sy+i*4*sin(Langle+90)+512*cos(Langle+90), leng-512+0*i, width,  Langle, gra,60+i*3);
		LaserObject( sx-i*4*cos(Langle+90)-512*sin(Langle+90),sy-i*4*sin(Langle+90)+512*cos(Langle+90), leng-512+0*i, width,  Langle, gra,60+i*3);
		wait(1);
		}
		let Rx=sx-(448-sy)/cos(Langle-90)*sin(Langle-90);
		Rise(Rx);
	}

	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);
	}

	task FireShot(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_RED);
	//	ObjShot_SetDelay(obj, delay);

		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

		let obj2 = ObjShot_Create(OBJ_SHOT);
		ObjShot_Regist(obj2);
		ObjMove_SetPosition(obj2, x, y);
		ObjMove_SetSpeed(obj2, speed);
		ObjMove_SetAngle(obj2, angle);
		ObjShot_SetGraphic(obj2, DS_BALL_M_ORANGE);

		ShotEffect(obj);
		let Rs=3;
		while(!Obj_IsDeleted(obj))
		{
			ObjMove_SetPosition(obj2, x+R*cos(angle), y+R*sin(angle));
			ObjMove_SetPosition(obj, x+R*cos(angle), y+R*sin(angle));
			ObjShot_SetDelay(obj2, 15);
			R+=Rs;
			angle+=0.3*dir;
			if(Rs>1){Rs-=2.5/60;}
			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);
	}
}