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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(192,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(2000);//ライフを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, 80, 10,3);
	SetAction(ACT_MOVE, 60);
//	loop(60){yield;}
	CallSpellCard("「デイジークローラー」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	let dir=floor(rand(0,2-0.001))*2-1;
	wait(60);
	DamageRate=[100,100];

	loop
	{
	SetAction(ACT_SHOT_A, 60);
	A(dir);

	wait(300);
	dir*=-1;
	SetAction(ACT_SHOT_A, 60);
	A(dir);

	wait(300);
	SetAction(ACT_SHOT_A, 150);
	B;

	wait(300);
	SetAction(ACT_SHOT_A, 150);
	B;

	wait(330);
	SetAction(ACT_SHOT_A, 60);
	C(0);
	wait(90);
	SetAction(ACT_SHOT_A, 60);
	C(22.5);
	wait(90);
	SetAction(ACT_SHOT_A, 60);
	C(0);

	wait(300);

	}

	task A(dir)
	{
		let angle=GetAngleToPlayer(objEnemy);
		ascent(i in 0..15)
		{
		HomingShot(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),angle+i*24*dir);
		wait(4);
		}

		task HomingShot(x,y,angle)
		{
			let LaserSpeed=rand(2,4);
			let time=rand(90,135);
			let count=1;
			loop(time)
			{
				Homing;

				x+=LaserSpeed*cos(angle);
				y+=LaserSpeed*sin(angle);
				BladeShot(x,y,angle,83);
				if(count%3==1)
				{
				S(x,y,0,angle);
				}
				count+=1;
				yield;
			}
			let Fangle=rand(0,360);
			ascent(i in 0..10)
			{
			F(x,y,Fangle+i*36);
			}
			CF(x,y);

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

			task S(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, 44);
			//ObjShot_SetDelay(obj, delay);
			//ObjShot_SetAutoDelete(obj,false);
			loop(60)
			{
				yield;
			}
			Obj_Delete(obj);
			}

			task CF(x,y)
			{
			let speed=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);
			loop(10)
			{
				yield;
			}
			loop(60)
			{
				yield;
			}
			Obj_Delete(obj);
			}

			task F(x,y,angle)
			{
			let speed=3;
			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_RICE_M_WHITE);
			//ObjShot_SetDelay(obj, delay);
			//ObjShot_SetAutoDelete(obj,false);
			loop(10)
			{
				speed-=3/10;
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			loop(60)
			{
				yield;
			}
			loop(60)
			{
				speed+=2/60;
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			}

			task BladeShot(x,y,angle,gra)
			{
				let obj = CreateShotA2(x, y, 0, angle, 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);
			}

		}
	}

	task B
	{
		loop(15)
		{
		let angle=GetAngleToPlayer(objEnemy);
		HomingShot(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),angle);
		wait(12);
		}

		task HomingShot(x,y,angle)
		{
			let LaserSpeed=rand(2,5)-0.5;
			let time=rand(90,135)-30;
			let count=1;
			loop(time)
			{
				Homing;

				x+=LaserSpeed*cos(angle);
				y+=LaserSpeed*sin(angle);
				BladeShot(x,y,angle,83);
				if(count%3==1)
				{
				S(x,y,0,angle);
				}
				count+=1;
				yield;
			}
			let Fangle=rand(0,360);
			ascent(i in 0..10)
			{
			F(x,y,Fangle+i*36);
			}
			CF(x,y);

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

			task S(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, 44);
			//ObjShot_SetDelay(obj, delay);
			//ObjShot_SetAutoDelete(obj,false);
			loop(60)
			{
				yield;
			}
			Obj_Delete(obj);
			}

			task CF(x,y)
			{
			let speed=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);
			loop(10)
			{
				yield;
			}
			loop(60)
			{
				yield;
			}
			Obj_Delete(obj);
			}

			task F(x,y,angle)
			{
			let speed=3;
			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_RICE_M_WHITE);
			//ObjShot_SetDelay(obj, delay);
			//ObjShot_SetAutoDelete(obj,false);
			loop(10)
			{
				speed-=3/10;
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			loop(60)
			{
				yield;
			}
			loop(60)
			{
				speed+=2/60;
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			}

			task BladeShot(x,y,angle,gra)
			{
				let obj = CreateShotA2(x, y, 0, angle, 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);
			}

		}
	}

	task C(angle)
	{
		ascent(i in 0..8)
		{
		HomingShot(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),angle+i*45*dir);
		}

		task HomingShot(x,y,angle)
		{
			let LaserSpeed=rand(2,4);
			let time=rand(90,150);
			let count=1;
			loop(time)
			{
				Homing;

				x+=LaserSpeed*cos(angle);
				y+=LaserSpeed*sin(angle);
				BladeShot(x,y,angle,83);
				if(count%3==1)
				{
				S(x,y,0,angle);
				}
				count+=1;
				yield;
			}
			let Fangle=rand(0,360);
			ascent(i in 0..15)
			{
			F(x,y,Fangle+i*24);
			}
			CF(x,y);

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

			task S(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, 44);
			//ObjShot_SetDelay(obj, delay);
			//ObjShot_SetAutoDelete(obj,false);
			loop(60)
			{
				yield;
			}
			Obj_Delete(obj);
			}

			task CF(x,y)
			{
			let speed=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);
			loop(10)
			{
				yield;
			}
			loop(60)
			{
				yield;
			}
			Obj_Delete(obj);
			}

			task F(x,y,angle)
			{
			let speed=3;
			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_RICE_M_WHITE);
			//ObjShot_SetDelay(obj, delay);
			//ObjShot_SetAutoDelete(obj,false);
			loop(10)
			{
				speed-=3/10;
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			loop(60)
			{
				yield;
			}
			loop(60)
			{
				speed+=2/60;
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			}

			task BladeShot(x,y,angle,gra)
			{
				let obj = CreateShotA2(x, y, 0, angle, 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);
			}

		}
	}
}