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

let amplitude=30;

@Initialize
{
	BossInit(384,96);
}

@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(9000);//ライフを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,5);
	SetAction(ACT_MOVE, 120);
	CallSpellCard("「位相調律（ウェイブシフター）」");

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

	loop(60){yield;}
	Shoot;
	wait(90);
	DamageRate=[100,100];
	if(GetCommonData("PlayerCharacter",0)==0)
	{
	//	DamageRate=[125,125];
	}

	task Shoot
	{
		loop
		{
			let dir=floor(rand(0,2-0.001))*2-1;
			SetAction(ACT_SHOT_B, 60);
			ascent(i in 0..9)
			{
				Enemy(GetX,GetY,i,1,dir);
				Enemy(GetX,GetY,i,-1,dir);
				wait(3);
			}
			if(amplitude<90)
			{
				amplitude+=15;
			}
			wait(450);
		}

	}

}

task Enemy(x,y,num,dir,dir2)
{
	#include"./../../lib/ZakoCommon/ZakoCommon.txt"
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	SetLife(obj,250);
	SetDamageRate(obj,100,100);

	DrawCircle(obj,0.20,255,255,255);
	EnemyResist(obj,x,y);

	let ex=192+192*dir*dir2;
	let ey=0+480/8*num;
	ObjMove_SetDestAtWeight(obj, ex, ey, 10,7);

	wait(105-num*3);

	if(dir==1)
	{
		Shot1;
		Move1;
	}
	else
	{
		Shot2;
		Move2;
	}
	wait(360);
	Obj_Delete(obj);
	task Shot1
	{
		while(!Obj_IsDeleted(obj))
		{
			CreateShotA1(ObjRender_GetX(obj),ObjRender_GetY(obj),2,90+dir*dir2*90,DS_MISSILE_RED,0);
			wait(5);
		}
	}

	task Move1
	{
		let Mangle=0;
		while(!Obj_IsDeleted(obj))
		{
			ObjRender_SetY(obj,ey+amplitude*sin(Mangle));
			Mangle++;
			yield;
		}
	}

	task Shot2
	{
		while(!Obj_IsDeleted(obj))
		{
			CreateShotA1(ObjRender_GetX(obj),ObjRender_GetY(obj),2,90+dir*dir2*90,DS_MISSILE_BLUE,0);
			wait(15);
		}
	}

	task Move2
	{
		let Mangle=0;
		while(!Obj_IsDeleted(obj))
		{
			ObjRender_SetY(obj,ey+amplitude*sin(Mangle));
			Mangle--;
			yield;
		}
	}

	while(!Obj_IsDeleted(obj))
	{
		yield;
	}


	task S0
	{
		while(!Obj_IsDeleted(obj))
		{
			let angle=GetAngleToPlayer(obj);
			loop(3)
			{
				if(Obj_IsDeleted(obj)){break;}
				if(GetObjectDistance(obj,GetPlayerObjectID)>30)
				{
					let obj2=CreateShotA1(ObjRender_GetX(obj),ObjRender_GetY(obj),3,angle,DS_MISSILE_RED,0);
				}
				wait(3);
			}
			wait(60);
		}
	}

	task S1
	{
		while(!Obj_IsDeleted(obj))
		{
			let angle=rand(0,360);
			if(GetObjectDistance(obj,GetPlayerObjectID)>30)
			{
				ascent(i in 0..20)
				{
					let obj2=CreateShotA1(ObjRender_GetX(obj),ObjRender_GetY(obj),1.0,angle+i*18,DS_MISSILE_BLUE,0);
				}
			}
			wait(90);
		}
	}

	task S2
	{
		while(!Obj_IsDeleted(obj))
		{
			let angle=rand(0,360);
			if(Obj_IsDeleted(obj)){break;}
			if(GetObjectDistance(obj,GetPlayerObjectID)>30)
			{
				let obj2=CreateShotA1(ObjRender_GetX(obj),ObjRender_GetY(obj),2,angle,DS_MISSILE_BLUE,0);
			}
			wait(3);
		}
	}

	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);
	}
}