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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	SetCommonData("Name","Chen");
	BossInit(0,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(5600);//ライフを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(60){yield;}
	C;
	//Move;
	wait(120);
	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
	{
		Shot1;
		wait(60);
		Shot2;
		wait(120);
		Shot3;
		task Shot1
		{
		loop
		{
			let ex = ObjMove_GetX(objEnemy);
			let ey = ObjMove_GetY(objEnemy);

			let angle=270;
			let R=30;
			ascent(i in -4..5)
			{				
				let X=ex+R*cos(angle+25*i);
				let Y=ey+R*sin(angle+25*i);
				S(X,Y,5,angle+15*i);
			}
			wait(3);
		}
		}

		task Shot2
		{
		loop
		{			
			let X=rand(-16,384+16);
			let Y=0;
			S2(X,Y,rand(1,3),rand(85,95));
			wait(2);
			if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=2800)
			{
			let X=rand(-16,384+16);
			let Y=0;
			S2(X,Y,rand(1,3),rand(85,95));
			wait(1);
			}
		}
		}

		task Shot3
		{
		let way=6;
		loop
		{			
			let X = ObjMove_GetX(objEnemy);
			let Y = ObjMove_GetY(objEnemy);
			let angle=GetAngleToPlayer(objEnemy);
			loop(5)
			{
			ascent(j in -way+1..way)
			{
			ascent(i in -1..2)
			{
			S3(X,Y,7,angle+i*60+j*2);
			}
			}
			wait(2);
			}
			wait(120);
			if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=1400)
			{
				way=12;
			}
			else if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=2800)
			{
				way=10;
			}
			else if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=4200)
			{
				way=8;
			}
		}
		}

		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, DS_RICE_S_GREEN);
			//ObjShot_SetDelay(obj, delay);
			//ObjShot_SetAutoDelete(obj,false);
			ShotEffect(obj);
			while(!Obj_IsDeleted(obj))
			{
				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_S_WHITE);
			//ObjShot_SetDelay(obj, delay);
			//ObjShot_SetAutoDelete(obj,false);
			ShotEffect(obj);
			while(!Obj_IsDeleted(obj))
			{
				yield;
			}
			Obj_Delete(obj);
		}

		task S3(x,y,speed,angle)
		{
			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, DS_BILL_PURPLE);
			//ObjShot_SetDelay(obj, delay);
			//ObjShot_SetAutoDelete(obj,false);
			ShotEffect(obj);
			loop(30)
			{
				speed-=Bspeed/30;
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			while(!Obj_IsDeleted(obj))
			{
				speed+=5/60;
				ObjMove_SetSpeed(obj, speed);
				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);
	}

}