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

@Initialize
{
	BossInit(0,64);
}

@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, 144, 10,4);
	SetAction(ACT_MOVE, 60);

	CallSpellCard("「虹色の風」");

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

	loop(90){yield;}
	Wind;
	Move;
	loop(120){yield;}
	DamageRate=[100,100];

	task Move
	{
		wait(270);
		loop
		{
			Move1(5,5,100,30,30,0.5);
			SetAction(ACT_MOVE, 75);
			wait(510);
		}
	}

	task Wind
	{
		loop
		{
			SetAction(ACT_SHOT_B, 60);
			let angle=rand(0,360);
			let dir=1;
			ascent(i in 0..7)
			{
				WindLaser(GetX,GetY,1.5+1*i,angle+i*360/7,i,1);
				WindLaser(GetX,GetY,1.5+1*i,angle+180+i*360/7,i,1);
				WindLaser(GetX,GetY,1.5+1*i,angle+90+i*360/7,i,-1);
				WindLaser(GetX,GetY,1.5+1*i,angle+270+i*360/7,i,-1);
			}
			wait(510);
		}
		task WindLaser(x,y,speed,angle,gra,dir)
		{
			let length=120;
			let width=15;
			let obj = CreateCurveLaserA1(x, y, 0,angle,length,width, DS_BALL_S_RED+gra, 0);

			ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		//	ObjShot_SetIntersectionEnable(obj,false);

			ObjShot_SetAutoDelete(obj,false);
			loop(40)
			{
				ObjRender_SetX(obj,ObjRender_GetX(obj)+speed*cos(angle));
				ObjRender_SetY(obj,ObjRender_GetY(obj)+speed*sin(angle));
				ObjMove_SetAngle(obj,angle);
				angle+=4.5*dir;
				yield;
			}

			loop(110)
			{
				ObjRender_SetX(obj,ObjRender_GetX(obj)+speed*cos(angle));
				ObjRender_SetY(obj,ObjRender_GetY(obj)+speed*sin(angle));
				ObjMove_SetAngle(obj,angle);
				angle+=2.25*dir;
				yield;
			}
			ObjLaser_SetLength(obj,10);
			descent(i in 0..80)
			{
				ObjRender_SetX(obj,ObjRender_GetX(obj)+speed*cos(angle));
				ObjRender_SetY(obj,ObjRender_GetY(obj)+speed*sin(angle));
				ObjMove_SetAngle(obj,angle);
				angle+=2.25*dir;
				if(i%4==0)
				{
					Shot(ObjRender_GetX(obj),ObjRender_GetY(obj),gra,dir,i);
				}
				yield;
			}
			speed=6.0;
			LaserObject(ObjRender_GetX(obj), ObjRender_GetY(obj), 600, 5,angle,gra);
			ObjShot_SetIntersectionEnable(obj,false);
			let sx=ObjRender_GetX(obj);
			let sy=ObjRender_GetY(obj);
			let count=0;
			loop(12)
			{
				ObjRender_SetX(obj,ObjRender_GetX(obj)+speed*cos(angle));
				ObjRender_SetY(obj,ObjRender_GetY(obj)+speed*sin(angle));
				yield;
			}
			loop(96)
			{
				ObjRender_SetX(obj,ObjRender_GetX(obj)+speed*cos(angle));
				ObjRender_SetY(obj,ObjRender_GetY(obj)+speed*sin(angle));
				if(count%3==0)
				{
					let o=CreateShotA1(sx,sy,speed,angle,17+gra,0);
					ObjRender_SetAlpha(o,0);
				}
				count+=1;
				yield;
			}
			loop(132)
			{
				ObjRender_SetX(obj,ObjRender_GetX(obj)+speed*cos(angle));
				ObjRender_SetY(obj,ObjRender_GetY(obj)+speed*sin(angle));
				yield;
			}
			Obj_Delete(obj);

			task Shot(x,y,gra,dir,t)
			{
				let speed=0;
				wait(t);
				let angle=atan2(ObjRender_GetY(objEnemy)-y,ObjRender_GetX(objEnemy)-x);
				let obj = ObjShot_Create(OBJ_SHOT);
				ObjShot_Regist(obj);
				ObjMove_SetPosition(obj, x, y);
				ObjMove_SetSpeed(obj, 0);
				ObjMove_SetAngle(obj, angle+70*dir);
				ObjShot_SetGraphic(obj, DS_BALL_S_RED+gra);
				ObjShot_SetDelay(obj, 5);
				let count=0;
				while(!Obj_IsDeleted(obj))
				{
					if(speed<0.4+(gra)/7*1.6)
					{
						speed+=(0.4+(gra)/7*1.6)/60;
					}
					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,DS_BALL_S_RED+gra, 0);
				ObjShot_SetIntersectionEnable(obj,false);
				ObjStLaser_SetSource(obj, false);
				let color = [255,255,255];
				ObjShot_SetAutoDelete(obj,false);
				loop(30)
				{
					yield;
				}
				Obj_Delete(obj);
			}

		}

	}
}