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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	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(6400);//ライフを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, 128, 10,7);
	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];
	let way=8;
	loop
	{
	SetAction(ACT_SHOT_B, 60);
	A(way,dir);

	wait(420);
	dir*=-1;
	if(way<16)
	{
		way+=2;
	}
	}

	task A(way,dir)
	{
		let angle=rand(0,360);
		ascent(i in 0..way)
		{
			S(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),3,angle+360/way*i+180/way);
			S(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),6,angle+360/way*i);
		}

		task S(x,y,speed,angle)
		{
			let R=0;
			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_BUTTERFLY_BLUE);
			if(dir==1){ObjShot_SetGraphic(obj, DS_BUTTERFLY_PURPLE);}
			//ObjShot_SetDelay(obj, delay);
			ObjShot_SetAutoDelete(obj,false);
			ShotEffect(obj);
			loop(90)
			{
				speed-=Bspeed/90;
				R+=speed;
				ObjMove_SetPosition(obj, x+R*cos(angle), y+R*sin(angle));
				yield;
			}
			loop(30)
			{
				yield;
			}
			ObjShot_SetIntersectionEnable(obj,false);
			Obj_SetVisible(obj,false);
			ascent(i in 0..8)
			{
			SC(obj,i*45);
			}
			loop(600-60)
			{
				angle+=0.2*dir;
				ObjMove_SetPosition(obj, x+R*cos(angle), y+R*sin(angle));
				yield;
			}
			loop(150)
			{
				speed+=Bspeed/90;
				R+=speed;
				angle+=0.2*dir;
				ObjMove_SetPosition(obj, x+R*cos(angle), y+R*sin(angle));
				yield;
			}
			Obj_Delete(obj);
		}

		task SC(Cobj,angle)
		{
			let R=0;
			let obj = ObjShot_Create(OBJ_SHOT);
			ObjShot_Regist(obj);
			ObjMove_SetPosition(obj,ObjMove_GetX(Cobj),ObjMove_GetY(Cobj));
		//	ObjMove_SetSpeed(obj, speed);
			ObjMove_SetAngle(obj, angle);
			ObjShot_SetGraphic(obj, DS_BUTTERFLY_BLUE);
			if(dir==1){ObjShot_SetGraphic(obj, DS_BUTTERFLY_PURPLE);}
			//ObjShot_SetDelay(obj, delay);
			ObjShot_SetAutoDelete(obj,false);
			loop(300)
			{
				ObjMove_SetPosition(obj,ObjMove_GetX(Cobj)+R*cos(angle),ObjMove_GetY(Cobj)+R*sin(angle));
				ObjMove_SetAngle(obj, angle-90*dir);
				R+=0.6;
				angle-=0.5*dir;
				yield;
			}
			loop(300-60)
			{
				ObjMove_SetPosition(obj,ObjMove_GetX(Cobj)+R*cos(angle),ObjMove_GetY(Cobj)+R*sin(angle));
				ObjMove_SetAngle(obj, angle-90*dir);
				R-=0.6;
				angle-=0.5*dir;
				yield;
			}
			loop(150)
			{
				ObjMove_SetPosition(obj,ObjMove_GetX(Cobj)+R*cos(angle),ObjMove_GetY(Cobj)+R*sin(angle));
				ObjMove_SetAngle(obj, angle-90*dir);
			//	R-=0.6;
				angle-=0.5*dir;
				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 ShotEffect(obj)
	{
		let scale=2.0;
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjShot_SetIntersectionEnable(obj,false);
		loop(30)
		{
			if(Obj_IsDeleted(obj)){break;}
			scale-=1.0/30;
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			yield;
		}
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		ObjShot_SetIntersectionEnable(obj,true);
	}
}