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

@Initialize
{
	BossInit(0,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(6400);//ライフを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, 128, 10,7);
	SetAction(ACT_MOVE, 60);
	CallSpellCard("「千朶万朶の死桜」");

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

	wait(60);
	Shoot;
	Move;
	wait(90);
	DamageRate=[100,100];
	task Move
	{
		wait(49*2+300);
		loop
		{
			Move1(5,5,50,30,30,5);
			SetAction(ACT_MOVE, 75);
			wait(49*2+180+240);
		}
	}

	task Shoot
	{
		let way=2;
		loop
		{
			SetAction(ACT_SHOT_A, 60);
			ascent(i in -way..way+1)
			{
				BShot(GetX,GetY,i,);
				wait(7);
			}
			wait(180);
			SetAction(ACT_SHOT_A, 60);
			ascent(i in -way..way+1)
			{
				BShot(GetX,GetY,-i);
				wait(7);
			}
			wait(282-way*2*7);
			if(way<5){way+=1;}
		}

		task BShot(x,y,n)
		{
			let obj = ObjShot_Create(OBJ_SHOT);
			ObjShot_Regist(obj);
			ObjMove_SetPosition(obj, x, y);
			ObjMove_SetSpeed(obj, 0);
			ObjShot_SetGraphic(obj,DS_BUTTERFLY_PURPLE);
			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
			ObjShot_SetAutoDelete(obj,false);
			let yspeed=rand(1.5,2);
			let xspeed=0.5*n+rand(-0.2,0.2);;
			loop
			{
				x=ObjRender_GetX(obj);
				y=ObjRender_GetY(obj);
				if(y<0){break;}
				ObjRender_SetX(obj,x+xspeed);
				ObjRender_SetY(obj,y+yspeed);
				ObjMove_SetAngle(obj, atan2(yspeed,xspeed));
				EffectShot(x,y,atan2(yspeed,xspeed));
				yspeed-=0.05;
				yield;
			}
			let angle=(GetAngleToPlayer(obj)*1+90*3)/4;
			ascent(i in 0..5)
			{
				ascent(j in -i..i+1)
				{
					CreateShotA1(x,y,3.0-i*0.5+rand(-0.5,0.5)+absolute(j)*0.2,angle+j*7,DS_RICE_S_PURPLE,5);
				}
			}
			Obj_Delete(obj);
		}

		task EffectShot(x,y,angle)
		{
			let obj = CreateShotA2(x, y, 0, angle, 0, 0, DS_BUTTERFLY_PURPLE, 0);//弾を発射
			let scale=1.0;
			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
			ObjShot_SetSpellResist(obj,true);
		//	ObjShot_SetIntersectionEnable(obj,false);
			ObjRender_SetColor(obj,30,30,30);
			loop(25)
			{
				if(Obj_IsDeleted(obj)){break;}
				scale-=1.0/30;
				ObjRender_SetScaleXYZ(obj,scale,scale,scale);
				ObjShot_SetIntersectionCircleA1(obj,10*scale);
				yield;
			}
			ObjShot_SetIntersectionEnable(obj,false);
			loop(5)
			{
				if(Obj_IsDeleted(obj)){break;}
				scale-=1.0/30;
				ObjRender_SetScaleXYZ(obj,scale,scale,scale);
				yield;
			}
			Obj_Delete(obj);
		}
	}
}