
#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_Lily.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(5000);//ライフを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, 128, 10,4);

	CallSpellCard("「スプリング・エフェメラル」");

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

	loop(60){yield;}

	Shoot;
	wait(180);
	Spring;
	DamageRate=[100,100];

	task Spring
	{
		loop
		{
			let angle=rand(0,360);
			let x=rand(0,388);
			let ry=rand(0.5,2);
			ascent(i in 0..5)
			{
				Petal(x,448,1,angle+i*72,ry);
			}
			wait(24);
		}
		task Petal(x,y,speed,angle,ry)
		{
			let Bspeed=speed;
			let obj = ObjShot_Create(OBJ_SHOT);
			ObjShot_Regist(obj);
			ObjMove_SetPosition(obj, x, y);
			ObjMove_SetSpeed(obj, speed*0);
			ObjMove_SetAngle(obj, angle);
			ObjShot_SetGraphic(obj, DS_RICE_S_WHITE);
			//ObjShot_SetDelay(obj, delay);

			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

			ShotEffect(obj);
			loop(10)
			{
				ObjRender_SetY(obj,ObjRender_GetY(obj)-ry);
				yield;
			}
			wait(30);
			loop(10)
			{
				speed-=Bspeed/10;
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			wait(90);
			while(!Obj_IsDeleted(obj))
			{
				if(speed<1.0)
				{
				speed+=Bspeed/15;
				}
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			Obj_Delete(obj);
		}
	}

	task Shoot
	{
		loop
		{
			let angle=rand(0,360);
			loop(10)
			{
				ascent(i in 0..12)
				{
					Shot(GetX,GetY,2,angle+i*30,DS_RICE_S_PURPLE,5,1);
					Shot(GetX,GetY,2,angle+i*30+15,DS_RICE_S_PURPLE,5,-1);
				}
				wait(3);
			}
			wait(180);
		}
		task Shot(x,y,speed,angle,gra,delay,dir)
		{
			let Bangle=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, gra);
			ObjShot_SetDelay(obj, delay);

		//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

		//	ShotEffect(obj);
			let ap=0.5;
			while(!Obj_IsDeleted(obj))
			{
				ObjMove_SetAngle(obj, angle);
				angle+=ap*dir;
				yield;
			}
			Obj_Delete(obj);
		}		
	}

	task ShotEffect(obj)
	{
		let scale=2.0;
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjShot_SetIntersectionEnable(obj,false);
		loop(15)
		{
			if(Obj_IsDeleted(obj)){break;}
			scale-=1.0/15;
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			yield;
		}
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		ObjShot_SetIntersectionEnable(obj,true);
	}
}