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

@Initialize
{
	BossInit(0,0);
}

@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(4800);//ライフを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);
	CallSpellCard("「エコーロケーション」");

	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	let WindSpeed=0;
	let WindAngle=90;

	loop(60){yield;}
	Shoot;
	Move;
	loop(120){yield;}
	DamageRate=[100,100];
	task Move
	{
		wait(180);
		loop
		{
			Move1(10,10,100,30,20,3);
			SetAction(ACT_MOVE, 75);
			wait(240);
		}
	}


	task Shoot
	{
		let R=30;
		let angle=90;
		SetAction(ACT_SHOT_A, 60);
		loop
		{
			Shot(GetX+R*cos(angle),GetY+R*sin(angle),angle);
			Shot(GetX+R*cos(angle+180),GetY+R*sin(angle+180),angle+180);
			angle+=9;
			wait(8);
		}
		task Shot(x,y,angle)
		{
			let ba=angle;
			let obj = ObjShot_Create(OBJ_SHOT);
			ObjShot_Regist(obj);
			ObjMove_SetPosition(obj, x, y);
			ObjMove_SetSpeed(obj, 2);
			ObjShot_SetGraphic(obj, DS_BALL_S_YELLOW);
			//ObjShot_SetDelay(obj, delay);
			//ObjShot_SetAutoDelete(obj,false);

			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

			ObjMove_SetAngle(obj, angle);

			let Rcount=0;
			let EchoFlag=0;
			while(!Obj_IsDeleted(obj))
			{
				if(ObjRender_GetX(obj)>=388 && Rcount<2)
				{
					ObjRender_SetX(obj,388+(388-ObjRender_GetX(obj)));
					ObjMove_SetAngle(obj, 180-ObjMove_GetAngle(obj));
					Rcount++;
				}
				if(ObjRender_GetX(obj)<=0 && Rcount<2)
				{
					ObjRender_SetX(obj,0+(0-ObjRender_GetX(obj)));
					ObjMove_SetAngle(obj, 180-ObjMove_GetAngle(obj));
					Rcount++;
				}
				if(ObjRender_GetY(obj)<=0 && Rcount<2)
				{
					ObjRender_SetY(obj,0+(0-ObjRender_GetY(obj)));
					ObjMove_SetAngle(obj, 360-ObjMove_GetAngle(obj));
					Rcount++;
				}
				if(ObjRender_GetY(obj)>=448)
				{
					break;
				}
				if(GetObjectDistance(GetPlayerObjectID,obj)<=30 && EchoFlag==0)
				{
					EchoShot(ObjRender_GetX(objEnemy)+R*cos(ba),ObjRender_GetY(objEnemy)+R*sin(ba),0,0);
					EchoFlag=1;
				}
				yield;
			}
			Obj_Delete(obj);

		task EchoShot(x,y,da,i)
		{
			let Eangle=GetAngleToPlayer(objEnemy)+da;
			wait(5);
			let obj = ObjShot_Create(OBJ_SHOT);
			ObjShot_Regist(obj);
			ObjMove_SetPosition(obj, x, y);
			ObjMove_SetSpeed(obj, 5);
			ObjShot_SetGraphic(obj, DS_BALL_L_RED);
			ObjShot_SetDelay(obj, 5);
			//ObjShot_SetAutoDelete(obj,false);

			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

			ObjMove_SetAngle(obj,Eangle);

			let Rcount=0;
			while(!Obj_IsDeleted(obj))
			{
				if(ObjRender_GetX(obj)>=388 && Rcount<2)
				{
					ObjRender_SetX(obj,388+(388-ObjRender_GetX(obj)));
					ObjMove_SetAngle(obj, 180-ObjMove_GetAngle(obj));
					Rcount++;
				}
				if(ObjRender_GetX(obj)<=0 && Rcount<2)
				{
					ObjRender_SetX(obj,0+(0-ObjRender_GetX(obj)));
					ObjMove_SetAngle(obj, 180-ObjMove_GetAngle(obj));
					Rcount++;
				}
				if(ObjRender_GetY(obj)<=0 && Rcount<2)
				{
					ObjRender_SetY(obj,0+(0-ObjRender_GetY(obj)));
					ObjMove_SetAngle(obj, 360-ObjMove_GetAngle(obj));
					Rcount++;
				}
				yield;
			}
			Obj_Delete(obj);
		}

		}
	}
}