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

@Initialize
{
	BossInit(384,0);
}

@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
{
	let cx = GetStgFrameWidth() / 2;//STGシーンの中心x座標を取得
	ObjMove_SetDestAtWeight(objEnemy, cx, 144, 10,7);
	SetAction(ACT_MOVE, 75);
	CallSpellCard("「白兎跋扈」");

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

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

	task Move
	{
		wait(32+90);
		loop
		{
			Move1(50,10,150,30,30,4);
			SetAction(ACT_MOVE, 75);
			wait(32+210);
		}
	}

	task Shoot
	{
		let way=6;
		loop
		{
			if(GetLife<=4200){way=8;}
			if(GetLife<=2800){way=10;}
			if(GetLife<=1400){way=12;}
			let angle=rand(0,360);
			SetAction(ACT_SHOT_B, 60);
			loop(8)
			{
				ascent(i in 0..way)
				{
					if(absolute(cos(angle+i*360/way))>0.17)
					{
						Shot(GetX,GetY,3,angle+i*360/way,DS_RICE_M_WHITE,5);
					}
				}
				wait(4);
			}
			wait(210);
		}

		task Shot(x,y,speed,angle,gra,delay)
		{
			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);
			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
			ObjShot_SetAutoDelete(obj,false);
			let yspeed=speed*sin(angle);
			let xspeed=speed*cos(angle);
			let Rcount=0;
			loop
			{
				if(ObjRender_GetX(obj)>=388 && Rcount<2)
				{
					ObjRender_SetX(obj,388+(388-ObjRender_GetX(obj)));
					xspeed*=-1;
					Rcount++;
				}
				if(ObjRender_GetX(obj)<=0 && Rcount<2)
				{
					ObjRender_SetX(obj,0+(0-ObjRender_GetX(obj)));
					xspeed*=-1;
					Rcount++;
				}
				if(ObjRender_GetY(obj)>=448)
				{
					ObjRender_SetY(obj,480+(480-ObjRender_GetY(obj)));
					yspeed*=-1;
				}
				let dx=ObjRender_GetX(obj);
				let dy=ObjRender_GetY(obj);
				ObjRender_SetX(obj,dx+xspeed);
				ObjRender_SetY(obj,dy+yspeed);
				ObjMove_SetAngle(obj, atan2(yspeed,xspeed));
				yspeed+=0.03;
				yield;
			}
			Obj_Delete(obj);
		}
	}
}