
#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(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(192,0);
	SetItem(20,2,2);
}

@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(7100);//ライフを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, 144, 10,4);
//	SetAction(ACT_MOVE, 60);
//	loop(60){yield;}
	CallSpellCard("「幻想千本桜」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	loop(60){yield;}
	C;
	loop(90){yield;}
	DamageRate=[100,100];

	task C
	{
		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);
		let R=40;
		let PAngle=90;
		let Angle=0;
		loop(1)
		{
		SetAction(ACT_SHOT_A, 240);
		S1;
		wait(240);
		S2;
		wait(30);
		S2_2;
		wait(360);
		SetAction(ACT_SHOT_B, 240);
		S3;
		wait(480);
		}
		loop
		{
		SetAction(ACT_SHOT_A, 240);
		S1;
		wait(240);
		S2;
		wait(30);
		S2_2;
		wait(360);
		SetAction(ACT_SHOT_B, 240);
		S3;
		wait(480);
		}

		task S1
		{
		loop(20)
		{
			ascent(i in 0..8)
			{
			let X=ex+R/3*cos(PAngle)*cos(Angle+i*45)-R*sin(PAngle)*sin(Angle+i*45);
			let Y=ey+R/3*sin(PAngle)*cos(Angle+i*45)+R*cos(PAngle)*sin(Angle+i*45);
			Shot(X,Y,rand(1,3),rand(245,295));
			}
			Angle+=5;
			wait(15);
		}
		}

		task S2
		{
			let x=16;
			let y=448;
			loop(14)
			{
				let angle=rand(0,360);
				let angle2=rand(0,360);
				ascent(i in 0..5)
				{
					Shot2(x,y,2,angle+i*72);
					Shot2(368,y,2,angle2+i*72);
				}
				y-=30;
				wait(8);
			}
			loop(90)
			{
				let angle=rand(0,360);
				let angle2=rand(0,360);
				x=rand(16,180);
				y=rand(16,64);
				let x2=rand(368,208);
				ascent(i in 0..5)
				{
					Shot2(x,y,2,angle+i*72);
					Shot2(x2,y,2,angle2+i*72);
				}
				wait(8);
			}
		}
		task S2_2
		{
			let x=48;
			let y=448;
			loop(14)
			{
				let angle=rand(0,360);
				let angle2=rand(0,360);
				ascent(i in 0..5)
				{
					Shot2(x,y,2,angle+i*72);
					Shot2(368-32,y,2,angle2+i*72);
				}
				y-=30;
				wait(8);
			}
			loop(90)
			{
				let angle=rand(0,360);
				let angle2=rand(0,360);
				x=rand(16,180);
				y=rand(16,64);
				let x2=rand(368,208);
				ascent(i in 0..5)
				{
					Shot2(x,y,2,angle+i*72);
					Shot2(x2,y,2,angle2+i*72);
				}
				wait(8);
			}
		}

		task S3
		{
			loop(15)
			{
				let ex = ObjMove_GetX(objEnemy);
				let ey = ObjMove_GetY(objEnemy);
				let angle=rand(0,360);
				ascent(i in 0..10)
				{
					Shot3(ex,ey,3,angle+i*36,1);
					Shot3(ex,ey,3,angle+i*36,-1);
				}
				wait(20);
			}
		}

		task Shot3(x,y,speed,angle,dir)
		{
			let Bangle=angle;
			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_GREEN);
			//ObjShot_SetDelay(obj, delay);

		//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

			ShotEffect(obj);
			let ay=0;
			let ZAngle=rand(0,360);
			loop(60)
			{
				ObjMove_SetX(obj,ObjRender_GetX(obj)+speed*cos(Bangle));
				ObjMove_SetY(obj,ObjRender_GetY(obj)+speed*sin(Bangle));
				ObjMove_SetAngle(obj, ZAngle);
				ZAngle+=6;
				Bangle+=1.5*dir;
				speed-=2.0/60;
				yield;
			}
			while(!Obj_IsDeleted(obj))
			{
				ObjMove_SetX(obj,ObjRender_GetX(obj)+speed*cos(Bangle));
				ObjMove_SetY(obj,ObjRender_GetY(obj)+speed*sin(Bangle));
				ObjMove_SetAngle(obj, ZAngle);
				ZAngle+=6;
				yield;
			}
			Obj_Delete(obj);
		}

		task Shot2(x,y,speed,angle)
		{
			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, 87);
			//ObjShot_SetDelay(obj, delay);

		//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

			ShotEffect(obj);
			loop(10)
			{
				speed-=Bspeed/10;
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			wait(150);
			while(!Obj_IsDeleted(obj))
			{
				if(speed<1.5)
				{
				speed+=Bspeed/10;
				}
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			Obj_Delete(obj);
		}

		task Shot(x,y,speed,angle)
		{
			let Bangle=angle;
			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_PURPLE);
			//ObjShot_SetDelay(obj, delay);

		//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);

			ShotEffect(obj);
			let ay=0;
			let ZAngle=rand(0,360);
			while(!Obj_IsDeleted(obj))
			{
				ObjMove_SetX(obj,ObjRender_GetX(obj)+speed*cos(Bangle));
				ObjMove_SetY(obj,ObjRender_GetY(obj)+speed*sin(Bangle));
				ObjMove_SetY(obj,ObjRender_GetY(obj)+ay);
				ObjMove_SetAngle(obj, ZAngle);
				ZAngle+=6;
				ay+=0.02;
				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);
	}
}