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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(320,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(4650);//ライフを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,8);
	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;
	wait(60);
	DamageRate=[100,100];
	loop
	{
	SetAction(ACT_SHOT_A, 60);
	B(1);
	wait(180);
	SetAction(ACT_SHOT_A, 60);
	B(-1);
	wait(180);
	}

	task C
	{
	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);
	let angle=0;
	let t=0;
	loop
	{
	let speed=10;
	loop(2)
	{
		S(ex,ey,speed,angle+90,t%7);
		S(ex,ey,speed,-angle+90,t%7);
		angle+=1.0;
		wait(3);
	}
	t+=1;
	angle+=5.0;
	wait(9);
	}
		task S(x,y,speed,angle,t)
		{
			let R=0;
			let Bspeed=speed;
			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, 9+t);
			//ObjShot_SetDelay(obj, delay);
			ShotEffect(obj);
			loop(30)
			{
				speed-=Bspeed/30;
				R+=speed;
				ObjMove_SetPosition(obj, x+R*cos(angle), y+R/4.0*sin(angle));
				yield;
			}
			ascent(i in 0..24)
			{
				S2(ObjRender_GetX(obj),ObjRender_GetY(obj),2.5,i*15+7.5+angle,9+t);
			}
			Obj_Delete(obj);
		}
		task S2(x,y,speed,angle,gra)
		{
			let R=0;
			let Bspeed=speed;
			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, gra);
			//ObjShot_SetDelay(obj, delay);
			ShotEffect(obj);
			loop(600)
			{
				yield;
			}
			Obj_Delete(obj);
		}
	}

	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];
		ascent(i in 0..7)
		{
		DragonShot(X[i],Y[i],i);
		wait(5);
		}

		task DragonShot(x,y,num)
		{
			let sx = ObjMove_GetX(objEnemy);
			let sy = ObjMove_GetY(objEnemy);
			let dis=((y-sy)^2+(x-sx)^2)^0.5;
			let angle=atan2(y-sy,x-sx);
			let speed=dis/30;

			ascent(i in 0..8)
			{
				S(sx,sy,speed,angle,i);
			}

			task S(cx,cy,speed,angle,num2)
			{
			let obj = ObjShot_Create(OBJ_SHOT);
			ObjShot_Regist(obj);
			ObjMove_SetPosition(obj, cx, cy);
		//	ObjMove_SetSpeed(obj, speed);
			ObjMove_SetAngle(obj, angle);
			ObjShot_SetGraphic(obj, 9+num);
			//ObjShot_SetDelay(obj, delay);
			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
			let R=60;
			let angle2=0;
			loop(30)
			{
				cx+=speed*cos(angle);
				cy+=speed*sin(angle);
				R-=2;
				ObjMove_SetPosition(obj, cx+R*cos(angle2+num2*45), cy+R*sin(angle2+num2*45));
				BlurEffect(cx+R*cos(angle2+num2*45), cy+R*sin(angle2+num2*45),9+num);
				angle2+=3;
				yield;
			}
			if(num2==0)
			{
				H(ObjRender_GetX(obj),ObjRender_GetY(obj),GetAngleToPlayer(obj),num);
			}
			Obj_Delete(obj);
			}


			task H(hx,hy,angle,t)
			{
			let gra=81+t;
			let LaserSpeed=0;
			let wide=10;
			loop(60)
			{
				Homing;

				hx+=LaserSpeed*cos(angle);
				hy+=LaserSpeed*sin(angle);
				if(x<-64){break;}
				if(x>448){break;}
				if(y<-32){break;}
				LaserSpeed+=9/60;
				BladeShot(hx,hy,angle,gra);
				yield;
			}
			loop(90)
			{
				Homing;
				Homing;

				hx+=LaserSpeed*cos(angle);
				hy+=LaserSpeed*sin(angle);
				if(x<-64){break;}
				if(x>448){break;}
				if(y<-32){break;}
				LaserSpeed+=9/60;
				BladeShot(hx,hy,angle,gra);
				yield;
			}

			function Homing
			{
				let ToPlayerAngle=atan2(GetPlayerY-hy,GetPlayerX-hx);
				let judgangle=sin(ToPlayerAngle-angle);
				let ShiftAngle=absolute(ToPlayerAngle-angle);
				if(judgangle>0)
				{
					angle+=0.4;
				}
				else
				{
					angle-=0.4;
				}
			}

			task BladeShot(x,y,angle,gra)
			{
				let obj = CreateShotA2(x, y, 0, angle, 0, 0, gra, 0);//弾を発射
				ObjShot_SetSpellResist(obj,true);
				let scale=2.0;
				ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
				let speed=0.75;
				loop(10)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=2.0/15;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
					ObjShot_SetIntersectionCircleA1(obj,scale*3);
					yield;
				}
				ObjShot_SetIntersectionEnable(obj,false);
				loop(5)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=2.0/15;
					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(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);
	}

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