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

@Initialize
{
	SetShotAutoDeleteClip(128,128,128,128);
//	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(6000);//ライフを1500に設定
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(100);//時間制限を60秒に設定
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(30000);//スペルカードボーナスを30000に設定
	}
}

//----------------------------------------------------
//敵動作
//----------------------------------------------------
let HoleFlag=0;
let HolePosition=[0,0];

task BossWork
{
	//座標(cx, 60)へ60フレームかけて移動する
	let cx = GetStgFrameWidth() / 2;//STGシーンの中心x座標を取得
	ObjMove_SetDestAtWeight(objEnemy, cx, 128, 10,7);
	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;
	DistanceChange;
	loop(90){yield;}
	DamageRate=[100,100];



	task DistanceChange
	{
		let Radius=180;
		let RadiusB=240;
		let RadiusP=72;;
		let RadiusAngle=90;
		let Intence=1;
		loop
		{
			Radius=RadiusB+RadiusP*cos(RadiusAngle);
			let ex = ObjMove_GetX(objEnemy);
			let ey = ObjMove_GetY(objEnemy);
			let px = GetPlayerX;
			let py = GetPlayerY;
			let dis=((ey-py)^2+(ex-px)^2)^0.5;
			let angle=atan2(ey-py,ex-px);
			let speed=(dis-Radius)/100*Intence;
			ObjRender_SetX(GetPlayerObjectID,ObjRender_GetX(GetPlayerObjectID)+speed*cos(angle));
			ObjRender_SetY(GetPlayerObjectID,ObjRender_GetY(GetPlayerObjectID)+speed*sin(angle));
			RadiusAngle+=1;
			Intence+=0.002;
			yield;
		}
	}

	task C
	{

		S;
		G;
		Move;

		task G
		{
		let wt=8;
		loop
		{
		if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=4000){wt=6;}
		if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=2000){wt=4;}
		SetAction(ACT_SHOT_A, 120);
		loop(120/wt)
		{
			let ex = ObjMove_GetX(objEnemy);
			let ey = ObjMove_GetY(objEnemy);
			Ghost(ex,ey,0.75,rand(0,360),DS_BALL_M_BLUE);
			wait(wt);
		}
		wait(120);
		}
		}

		task S
		{

		loop
		{
			Shot(rand(0-64,384+64),rand(-16,0),rand(1,2.5),rand(80,100),DS_RICE_S_BLUE);
			wait(3);
			Shot(rand(0-64,384+64),rand(-16,0),rand(1,2.5),rand(80,100),DS_RICE_S_BLUE);
			wait(2);
		}

		}

		task Ghost(x,y,speed,angle,gra)
		{
			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-8);
			//ObjShot_SetDelay(obj, delay);
		//	ObjShot_SetAutoDelete(obj,false);
		//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

			ShotEffect(obj);

			let obj2 = ObjShot_Create(OBJ_SHOT);
			ObjShot_Regist(obj2);
			ObjMove_SetPosition(obj2, x, y);
			ObjMove_SetSpeed(obj2, speed);
			ObjMove_SetAngle(obj2, angle);
			ObjShot_SetGraphic(obj2, gra-8+1);

			let Count=0;
			let Wide=0;
			let WideAngle=rand(0,360);
			let BaseAngle=angle;
			while(!Obj_IsDeleted(obj))
			{
				if(Wide<90){
				Wide+=0.2;}
				angle=BaseAngle+Wide*cos(WideAngle);
				ObjMove_SetAngle(obj, angle);
				ObjMove_SetPosition(obj2, ObjRender_GetX(obj), ObjRender_GetY(obj));
				ObjShot_SetDelay(obj2, 5);
				WideAngle+=2;
				yield;
			}
			Obj_Delete(obj);
			Obj_Delete(obj2);
		}

		task Move
		{
			wait(120);
			loop
			{

			let ex = ObjMove_GetX(objEnemy);
			let ey = ObjMove_GetY(objEnemy);
			let mx= ex+rand(-150,150);
			let my= ey+rand(-30,30);
			while(mx<64 || mx>320){mx=ex+rand(-150,150);}
			while(my<64 || my>128){my=ey+rand(-30,30);}
			ObjMove_SetDestAtWeight(objEnemy,mx, my, 20,2.0);
			SetAction(ACT_MOVE, 75);
			wait(240);
			}
		}

		task Bomb(x,y,speed,angle,gra)
		{
			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);
		//	ObjShot_SetAutoDelete(obj,false);
			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

			ShotEffect(obj);
			let Bspeed=speed;
			loop(120)
			{
				ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
				speed-=Bspeed/120;
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			x=ObjRender_GetX(obj);
			y=ObjRender_GetY(obj);
			speed=1;
			angle=rand(0,360);
			ascent(i in 0..8)
			{
				ascent(j in 0..4)
				{
			Shot(x,y,speed+0.5*j,angle+i*45,gra);
				}
			}
			Obj_Delete(obj);
		}

		task Shot(x,y,speed,angle,gra)
		{
			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-8);
			//ObjShot_SetDelay(obj, delay);
		//	ObjShot_SetAutoDelete(obj,false);
		//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

			ShotEffect(obj);
			let Count=0;
			while(!Obj_IsDeleted(obj))
			{
				yield;
			}
			Obj_Delete(obj);
		}

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