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

@Initialize
{
	BossInit(160,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,GetStgFrameHeight() / 2, 10,4);
	SetAction(ACT_MOVE, 90);
	CallSpellCard("「彷徨える幽霊船」");

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

	Field;
	wait(180);
	Shoot(0);
	wait(120);
	WaterShot;
	DamageRate=[100,100];
	while(GetLife>=2800){yield;}
	Shoot(1);

	task WaterShot
	{
		loop
		{
			ascent(i in -15..16)
			{
				ascent(j in 0..3)
				{
					CreateShotA1(GetX,GetY,1.5,GetAngleToPlayer(objEnemy)+3*i+j*120,DS_BALL_BS_BLUE,10);
					CreateShotA1(GetX,GetY,1,GetAngleToPlayer(objEnemy)+3*i+j*120+60,DS_BALL_BS_BLUE,10);
				}
			}
			wait(210);
		}
	}

	task Shoot(num)
	{
		SetAction(ACT_SHOT_B, 60);
		ShipBullet(GetX,GetY);

		task ShipBullet(x,y)
		{
			let obj = ObjShot_Create(OBJ_SHOT);
			ObjShot_Regist(obj);
			ObjMove_SetPosition(obj, x, y);
			ObjShot_SetGraphic(obj, DS_BALL_L_BLUE);
			if(num==1){ObjShot_SetGraphic(obj, DS_BALL_L_ORANGE);}
			ObjShot_SetDelay(obj, 5);
			ObjShot_SetAutoDelete(obj,false);
			let xspeed=0;
			let yspeed=0;
			let speed=0;
			let angle=GetAngleToPlayer(obj);
			let ex=0;
			let ey=0;
			let as=0.05;
			let count=-60;
			let psFlag=0;
			loop
			{
				angle=GetAngleToPlayer(obj);
				if(absolute(atan2(yspeed,xspeed)-GetAngleToPlayer(obj))>=90)
				{
					xspeed*=0.98;
					yspeed*=0.98;
				}
				xspeed+=as*cos(angle);
				yspeed+=as*sin(angle);
				if(xspeed>5){xspeed=5;}	
				if(yspeed>5){yspeed=5;}	
				ObjRender_SetX(obj,ObjRender_GetX(obj)+xspeed);
				ObjRender_SetY(obj,ObjRender_GetY(obj)+yspeed);
				if(((ObjRender_GetY(obj)-GetStgFrameHeight() / 2)^2+(ObjRender_GetX(obj)-GetStgFrameWidth() / 2)^2)^0.5>=240 && psFlag==0)
				{
					psFlag=1;
					xspeed=-xspeed/2;
					yspeed=-yspeed/2;
					ascent(i in 0..72)
					{
						CreateShotA1(ObjRender_GetX(obj),ObjRender_GetY(obj),2,5*i,DS_BALL_S_SKY,5);
					}
				}
				else
				{
					psFlag=0;
				}
				if(count%60==0)
				{
					let sa=0;
					ascent(i in 0..12)
					{
						let o=CreateShotA1(ObjRender_GetX(obj),ObjRender_GetY(obj),1.5,sa+30*i,DS_BALL_S_BLUE,5);
						if(num==1){ObjShot_SetGraphic(o,DS_BALL_S_ORANGE);}
					}
				}
				count++;
				yield;
			}
			Obj_Delete(obj);
		}
	}
	task Field
	{
		SetAction(ACT_SHOT_A, 60);
		let angle=rand(0,360);
		ascent(i in 0..60)
		{
			Shot(GetX,GetY,6,angle+i*3,i);
			Shot(GetX,GetY,6,angle+i*3+180,i);
			Shot(GetX,GetY,6.5,angle-i*3,i);
			Shot(GetX,GetY,6.5,angle-i*3+180,i);
			wait(1);
		}
		ObjMove_SetDestAtWeight(objEnemy, cx,144, 20,0.8);
		SetAction(ACT_MOVE, 60);

		task Shot(x,y,speed,angle,w)
		{
			let obj = ObjShot_Create(OBJ_SHOT);
			ObjShot_Regist(obj);
			ObjMove_SetPosition(obj, x, y);
			ObjMove_SetSpeed(obj, 0);
			ObjMove_SetAngle(obj, angle);
			ObjShot_SetGraphic(obj, DS_BALL_BS_SKY);
			ObjShot_SetDelay(obj, 5);
			ObjShot_SetIntersectionEnable(obj,false);
			ObjRender_SetAlpha(obj,150);
			ObjShot_SetAutoDelete(obj,false);
			let msp=speed;
			loop(90)
			{
				speed-=msp/90;
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			wait(90-w);
			let R=240;
			let dir=1;
			if(msp==6){dir=-1;R=260;}
			let ap=0;
			let count=0;
			loop
			{
				ObjRender_SetX(obj,GetStgFrameWidth()/2+R*cos(angle));
				ObjRender_SetY(obj,GetStgFrameHeight() / 2+R*sin(angle));
				if(ap<1){ap+=1/60;}
				angle+=ap*dir;
				if((count+w)%10==0)
				{
					CreateShotA1(ObjRender_GetX(obj),ObjRender_GetY(obj),2,angle,DS_BALL_S_SKY,15);
				}
				count++;
				yield;
			}
			Obj_Delete(obj);
		}
	}
}