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

@Initialize
{
	BossInit(192,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(5400);//ライフを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, 96, 10,3);

	CallSpellCard("ワンタッチ開閉唐傘」");

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

	SetShotAutoDeleteClip(64,96,64,64);

	loop(60){yield;}
	Umbrella;
	Move;
	loop(60){yield;}
	DamageRate=[100,100];

	task Move
	{
		wait(210);
		loop
		{
			Move1(5,5,80,30,30,5);
			SetAction(ACT_MOVE, 75);
			wait(360);
		}
	}

	task Umbrella
	{
		let way=8;
		loop
		{
			way=24-floor(16*GetLife/5400);
			let angle=rand(0,360);
			ascent(i in 0..way)
			{
				Open(angle+i*360/way);
			}
			wait(30);
			SetAction(ACT_SHOT_A, 150);
			wait(330);
		}

		task Open(angle)
		{
			let R=32;
			LaserObject(GetX+R*cos(angle), GetY+R*sin(angle),600, 5,angle,DS_BALL_S_WHITE);
			wait(30);
			let length=0;
			let obj = CreateStraightLaserA1(GetX+R*cos(angle), GetY+R*sin(angle), angle,length, 20, 1200,DS_BEAM_WHITE, 0);
		//	ObjShot_SetIntersectionEnable(obj,false);
			ObjStLaser_SetSource(obj, true);
			loop(12)
			{
				CreateShotA1(ObjRender_GetX(obj),ObjRender_GetY(obj),rand(1,5),angle+rand(-60,60),DS_BALL_S_BLUE,5);
			}
			loop(15)
			{
				length+=400/15;
				ObjLaser_SetLength(obj,length);
				yield;
			}
			wait(120);
			loop(15)
			{
				length-=400/15;
				ObjLaser_SetLength(obj,length);
				rainshot(ObjRender_GetX(obj)+length*cos(angle),ObjRender_GetY(obj)+length*sin(angle));
				yield;
			}
			Obj_Delete(obj);

			task rainshot(x,y)
			{
				let speed=0;
				let angle=rand(80,100);
				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, delay);
			//	ObjShot_SetAutoDelete(obj,false);
			//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
				let msp=rand(1,2);
				while(!Obj_IsDeleted(obj))
				{
					if(speed<msp)
					{
						speed+=0.01;
						ObjMove_SetSpeed(obj, speed);
					}
					yield;
				}
				Obj_Delete(obj);
			}

			task LaserObject( sx, sy, leng, width,angle, gra,)
			{
				let obj = CreateStraightLaserA1(sx, sy, angle, leng, width, 0,gra, 0);
				ObjShot_SetIntersectionEnable(obj,false);
				ObjStLaser_SetSource(obj, false);
				let color = [150,150,150];
				ObjShot_SetAutoDelete(obj,false);
				loop(30)
				{
					yield;
				}
				Obj_Delete(obj);
			}
		}
	}

}