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

@Initialize
{
	BossInit(80,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, 112, 10,4);
	SetAction(ACT_MOVE, 60);
	CallSpellCard("「フリーズランサー」");

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

	wait(90);
	IceBit;
	wait(30);
	DamageRate=[100,100];

	task IceBit
	{
		let dir=1;
		let way=6;
		loop
		{
			SetAction(ACT_SHOT_A, 60);
			let angle=rand(0,360);
			ascent(i in 0..way)
			{
				CreateBit(GetX,GetY,angle+i*360/way,dir);
			}
			dir*=-1;
			wait(420);
			if(GetLife<=4200){way=8;}
			if(GetLife<=2800){way=10;}
			if(GetLife<=1400){way=12;}
		}
		task CreateBit(x,y,angle,dir)
		{
			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_M_BLUE);
			ObjShot_SetDelay(obj, 5);
			let R=0;
			let count=floor(rand(-30,30))+30;
			loop(300)
			{
				ObjRender_SetX(obj,x+R*cos(angle));
				ObjRender_SetY(obj,y+R/6*sin(angle));
				if(y>20)
				{
					y-=1.5;
				}
				if(R<180)
				{
					R+=4;
				}
				if(count>60 && count%60==0)
				{
					IceShot(ObjRender_GetX(obj),ObjRender_GetY(obj));
				}
				angle+=3*dir;
				count++;
				yield;
			}
			let a=rand(0,360);
			ascent(i in 0..8)
			{
				Shot(ObjRender_GetX(obj),ObjRender_GetY(obj),0.8,a+i*45+22.5);
				Shot(ObjRender_GetX(obj),ObjRender_GetY(obj),1.2,a+i*45+11.25);
				Shot(ObjRender_GetX(obj),ObjRender_GetY(obj),1.2,a+i*45-11.25);
				Shot(ObjRender_GetX(obj),ObjRender_GetY(obj),1.6,a+i*45);
			}

			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_S_BLUE);
				ObjShot_SetDelay(obj, 15);
				let count=0;
				while(!Obj_IsDeleted(obj))
				{
					yield;
				}
				Obj_Delete(obj);
			}

			Obj_Delete(obj);

			task IceShot(x,y)
			{
				let angle=GetAngleToPlayer(objEnemy)+rand(-2,2);

				ascent(i in 0..3)
				{
					ascent(j in -1..i)
					{
						Shot(x,y,4,angle+1.5+j*1.5-i*0.75);
					}
					wait(4);
				}
				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_BLUE);
					ObjShot_SetDelay(obj, 5);
					let count=0;
					while(!Obj_IsDeleted(obj))
					{
						yield;
					}
					Obj_Delete(obj);
				}
			}
		}
	}
}