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

@Initialize
{
	BossInit(224,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(4200);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(100);
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(30000);
	}
}

//----------------------------------------------------
//敵動作
//----------------------------------------------------
task BossWork
{
	let cx = GetStgFrameWidth() / 2;//STGシーンの中心x座標を取得
	ObjMove_SetDestAtWeight(objEnemy, cx, 80, 10,7);
	SetAction(ACT_MOVE, 60);

	CallSpellCard("「ダークネスサージュ」");

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

	wait(60);

	let SurgeDis=0;
	let Range=90;

	Shoot;
	RangeChange;
	wait(120);
	DamageRate=[100,100];
	wait(120);
	DarkSurge;
	wait(240);
	Shoot2;

	task RangeChange
	{
		loop
		{
			Range=180-GetLife/4200*90;
			yield;
		}
	}
	task Shoot2
	{
		loop
		{
			let angle=GetAngleToPlayer(objEnemy);

			ascent(i in 0..6)
			{
				ascent(j in -1..i)
				{
					ascent(k in -2..3)
					{
						Shot(GetX,GetY,2,angle+1.5+j*1.5-i*0.75+k*70);
					}
				}
				wait(5);
			}
			wait(30);
		}

		task Shot(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, 5);
			let count=0;
			while(!Obj_IsDeleted(obj))
			{
				let dis=(((GetY-ObjRender_GetY(obj))^2+(GetX-ObjRender_GetX(obj))^2))^0.5;
				if(absolute(dis-SurgeDis)<=Range && count>5)
				{
					Obj_SetVisible(obj,0);
				}
				else
				{
					Obj_SetVisible(obj,1);
				}
				count++;
				yield;
			}
			Obj_Delete(obj);
		}
	}

	task DarkSurge
	{
		loop
		{
			Surge;
			wait(240);
		}
		
		task Surge
		{
			loop(180)
			{
				SurgeDis+=3;
				yield;
			}
			SurgeDis=0;
		}
	}

	task Shoot
	{
		let angle=90-2*3.5;
		loop
		{
		ascent(i in 0..12)
		{
			ascent(j in 0..8)
			{
				Shot(GetX,GetY,1,angle+i*30+j*2);
			}
		}
		angle+=45;
		wait(90);
		}

		task Shot(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_BALL_BS_PURPLE);
			ObjShot_SetDelay(obj, 5);
			let count=0;
			while(!Obj_IsDeleted(obj))
			{
				let dis=(((GetY-ObjRender_GetY(obj))^2+(GetX-ObjRender_GetX(obj))^2))^0.5;
				if(absolute(dis-SurgeDis)<=Range && count>5)
				{
					Obj_SetVisible(obj,0);
				}
				else
				{
					Obj_SetVisible(obj,1);
				}
				count++;
				yield;
			}
			Obj_Delete(obj);
		}
	}
}