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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	SetCommonData("Name","Chen");
	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, 8);//当たり判定(体当たり)登録
	SetCommonData("BossPosition",[ex,ey]);
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(2500);//ライフを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,7);
	SetAction(ACT_MOVE, 60);
	SetRoll(60);

//	loop(60){yield;}
	CallSpellCard("「吉祥天女法」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

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

	task Move
	{
loop
{
		let Angle=GetAngleToPlayer(objEnemy);
		let ex = ObjMove_GetX(objEnemy)+10*cos(Angle);
		let ey = ObjMove_GetY(objEnemy)+10*sin(Angle);

		loop
		{
			ex+=cos(Angle);
			ey+=sin(Angle);
			if(ex<0){break;}
			if(ex>384){break;}
			if(ey<0){break;}
			if(ey>448){break;}
		}

		ObjMove_SetDestAtFrame(objEnemy, ex,ey, 30);
		SetAction(ACT_MOVE, 30);
		SetRoll(30);
		wait(90);
		loop(5)
		{
		Angle=GetAngleToPlayer(objEnemy);
		ex = ObjMove_GetX(objEnemy)+10*cos(Angle);
		ey = ObjMove_GetY(objEnemy)+10*sin(Angle);

		loop
		{
			ex+=cos(Angle);
			ey+=sin(Angle);
			if(ex<0){break;}
			if(ex>384){break;}
			if(ey<0){break;}
			if(ey>448){break;}
		}

		ObjMove_SetDestAtFrame(objEnemy, ex,ey, 30);
		SetAction(ACT_MOVE, 30);
		SetRoll(30);
		wait(30);
		}
		ObjMove_SetDestAtWeight(objEnemy, cx, 112, 10,7);
		SetAction(ACT_MOVE, 90);
		SetRoll(90);
		wait(120+120+60);
}
	}

	task C
	{
		Shot;

		task Shot
		{
loop
{
			let PAngle=0;
			let Angle=0;
			loop(10)
			{
			ascent(i in 0..5)
			{
				PAngle=72*i;
				let R=10;
				let X=ObjMove_GetX(objEnemy)+R*cos(PAngle)*cos(Angle)-R*sin(PAngle)*sin(Angle);
				let Y=ObjMove_GetY(objEnemy)+R*sin(PAngle)*cos(Angle)+R*cos(PAngle)*sin(Angle);
				let SA=atan2(ObjMove_GetY(objEnemy)-Y,ObjMove_GetX(objEnemy)-X)+180;
				S(X,Y,0,SA);
			}
			Angle+=10;
			wait(3);
			}
			wait(60);
			loop(70)
			{
			ascent(i in 0..5)
			{
				PAngle=72*i;
				let R=10;
				let X=ObjMove_GetX(objEnemy)+R*cos(PAngle)*cos(Angle)-R*sin(PAngle)*sin(Angle);
				let Y=ObjMove_GetY(objEnemy)+R*sin(PAngle)*cos(Angle)+R*cos(PAngle)*sin(Angle);
				let SA=atan2(ObjMove_GetY(objEnemy)-Y,ObjMove_GetX(objEnemy)-X)+180;
				S(X,Y,0,SA);
			}
			Angle+=12;
			wait(3);
			}
			wait(60+10*0);
			loop(12)
			{
			ascent(i in 0..30)
			{
				Angle=GetAngleToPlayer(objEnemy)+12*i;
				let R=10;
				let X=ObjMove_GetX(objEnemy);
				let Y=ObjMove_GetY(objEnemy);
				S2(X,Y,5,Angle);
			}
			wait(5);
			}
			wait(120);
}

			task S(x,y,speed,angle)
			{
			let obj = ObjShot_Create(OBJ_SHOT);
			ObjShot_Regist(obj);
			ObjMove_SetPosition(obj, x, y);
			ObjMove_SetSpeed(obj, 0);
			ObjMove_SetAngle(obj, angle);
			ObjShot_SetGraphic(obj, DS_SCALE_RED);
			//ObjShot_SetDelay(obj, delay);
		//	ObjShot_SetAutoDelete(obj,false);
			ShotEffect(obj);
			while(!Obj_IsDeleted(obj))
			{
				if(speed<1.2)
				{
					speed+=1.2/240;
				}
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			Obj_Delete(obj);
			}

			task S2(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, DS_RICE_M_BLUE);
			//ObjShot_SetDelay(obj, delay);
		//	ObjShot_SetAutoDelete(obj,false);
			ShotEffect(obj);
			while(!Obj_IsDeleted(obj))
			{

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

}