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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(0,128);
	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(6400);//ライフを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, 112, 10,5);
	SetAction(ACT_MOVE, 75);
//	loop(60){yield;}
	CallSpellCard("「善悪を正す御光」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	loop(75){yield;}
	C;
	S;
	loop(90){yield;}
	DamageRate=[100,100];


	task S
	{
		wait(240);
		loop
		{
		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);
			descent(j in 0..18)
			{
				ascent(i in -2..3)
				{	
				Shot(ex,ey,9.5-0.5*j,GetAngleToPlayer(objEnemy)+(53-3.0*j)*i);
				}
				wait(5);
			}
		wait(150);
		}

		task Shot(x,y,speed,angle)
		{
			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, 164);
			ObjShot_SetDelay(obj, 5);

		//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

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

	task C
	{
		//let Laser1=[];
		let Laser2=[];
		let way=6;
		let signalY=0;
		loop
		{
		signalY=0;
		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);
		let angle=360/way+180/way+rand(-45/way,45/way);
		SetAction(ACT_SHOT_B, 60);
		ascent(i in 0..way)
		{
		Laser(ex,ey,angle+i*360/way,1);
		Laser(ex,ey,angle+i*360/way+180,-1);
		}
		wait(90);
		loop(120)
		{
			signalY+=4.0;
			yield;
		}
		wait(90);
		loop(way)
		{
		//	Laser1= erase(Laser1,0);
			Laser2= erase(Laser2,0);
		}
		if(way<12)
		{
		way+=1;
		}
		}

		task Laser(x,y,Langle,dir)
		{
			let length=0;
			let width=5;
			let obj = CreateStraightLaserA1(x, y, Langle, 0, 0, 900, DS_BEAM_RED+(1-dir)*2.5, 0);
			if(dir==1)
			{
			//	Laser1=Laser1~[obj];
			}
			else
			{
				Laser2=Laser2~[obj];
			}
			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+80*dir;
			let LanglePlus=6;
			let BLanglePlus=LanglePlus;
			loop(120)
			{
				if(length<600)
				{
				length+=300/10;
				}
				Langle+=LanglePlus*dir;
				ObjStLaser_SetAngle(obj,Langle);
				ObjLaser_SetLength(obj,length);
				ObjRender_SetX(obj,ObjRender_GetX(obj)+speed*cos(Mangle));
				ObjRender_SetY(obj,ObjRender_GetY(obj)+speed*sin(Mangle));
				speed-=Bspeed/120;
				LanglePlus-=BLanglePlus/120;
				yield;
			}
			loop(15)
			{
				width+=20/15;
				ObjLaser_SetRenderWidth(obj, width);
				yield;
			}
			ObjLaser_SetIntersectionWidth(obj,10);
			ObjShot_SetIntersectionEnable(obj,true);
			Shot(ObjRender_GetX(obj),ObjRender_GetY(obj),4,Langle,dir);
			loop(150){yield;}

			ObjShot_SetIntersectionEnable(obj,false);
			loop(15)
			{
				width-=15/15;
				ObjLaser_SetRenderWidth(obj, width);
				yield;
			}
			Obj_Delete(obj);
		}
		
		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_BLUE);
			//ObjShot_SetDelay(obj, delay);

		//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
			Obj_SetVisible(obj,false);
			let ColFlag=0;

			while(!Obj_IsDeleted(obj))
			{
				ColFlag=0;
				if(dir==1)
				{
				ascent(j in 0..length(Laser2))
				{
					if(IsIntersected_Obj_Obj(obj,Laser2[j]))
					{
					let sa1=rand(0,360);
					ascent(i in 0..30)
					{
					let sa2=sa1+i*12;
					Shot2(ObjRender_GetX(obj)+10*cos(sa2),ObjRender_GetY(obj)+10*sin(sa2),0.8,sa2+180);
					}
					ColFlag=1;
					}
				}
				}
				if(ColFlag)
				{
					wait(10);
				}
				yield;
			}
			Obj_Delete(obj);
		}

		task Shot2(x,y,speed,angle)
		{
			while(signalY<y){yield;}
			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_SS_PURPLE);
			//ObjShot_SetDelay(obj, delay);

		//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

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

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

	task ShotEffect(obj)
	{
		let scale=2.0;
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjShot_SetIntersectionEnable(obj,false);
		loop(30)
		{
			if(Obj_IsDeleted(obj)){break;}
			scale-=1.0/30;
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			yield;
		}
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		ObjShot_SetIntersectionEnable(obj,true);
	}
}