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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(0,64);
	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(4400);//ライフを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,4);
	SetAction(ACT_MOVE, 60);

//	loop(60){yield;}
	CallSpellCard("「トリッキーグリッド」");

//	SetAction(ACT_SPELL, 60);
//	loop(12){yield;}

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

	B;
	wait(240);
	C;
	DamageRate=[100,100];

	task C
	{
	loop
	{
		SetAction(ACT_SHOT_B, 60);
		let angle=GetAngleToPlayer(objEnemy);
		ascent(i in 0..12)
		{
		CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),3.0,angle+30*i,165,0);
		}
		ascent(i in 0..18)
		{
		CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),2.0,angle+20*i+10,165,0);
		}
		ascent(i in 0..30)
		{
		CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),1.0,angle+6.0+12*i,165,0);
		}
		wait(60);
		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);
		let mx= ex+rand(-120,120);
		let my= ey+rand(-20,20);
		while(mx<64 || mx>320){mx=ex+rand(-120,120);}
		while(my<80 || my>160){my=ey+rand(-20,20);}
		ObjMove_SetDestAtWeight(objEnemy,mx, my, 30,2.0);
		SetAction(ACT_MOVE, 75);
		wait(150);
	}
	}

	task B
	{
		let grad=0;
		let gra=0;
		GradChange;
		loop
		{
		ascent(i in 0..10)
		{
		Shot(i*80,241+(gra+i)%7,1,0);
		Shot(i*80,241+(gra-i+8)%7,-1,0);
		Shot(i*80,241+(gra+i)%7,1,90);
		Shot(i*80,241+(gra-i+8)%7,-1,90);
		}
		//gra+=1;
		loop(50*2){yield}
		}
		
		task GradChange
		{
		wait(300*1.5);
		let graddir=1;
		if(GetPlayerX>192){graddir=-1;}
		let gradplus=0.1;
		loop
		{
			grad+=gradplus*graddir;
			if(gradplus<0.5)
			{
			gradplus+=0.0001;
			}
			yield;
		}
		}

		task Shot(height,gra,dir,grad2)
		{
		let time=0;
		let x=ObjRender_GetX(objEnemy);
		let y=ObjRender_GetY(objEnemy);

		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, gra);
		//ObjShot_SetDelay(obj, delay);
		ObjShot_SetAutoDelete(obj,false);
		let gradangle=80+rand(0,8);

		let scale=4.0;
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		let R=320;
		//while(!Obj_IsDeleted(obj))
		loop(360*2)
		{
			x=196+(R*cos(grad+grad2)+(R-time)*cos(grad+grad2+90)-((time*2)*0+height)*cos(grad+grad2))*dir;
			y=224+(R*sin(grad+grad2)+(R-time)*sin(grad+grad2+90)-((time*2)*0+height)*sin(grad+grad2))*dir;
			ObjMove_SetPosition(obj, x, y);
			time+=64/40/2;
			yield;
		}
		Obj_Delete(obj);
		}

	}
}