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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(-64,48);
	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(4200);//ライフを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,8);
	SetAction(ACT_MOVE, 60);
//	loop(60){yield;}
	CallSpellCard("「天白風縛刃」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	wait(60);
	let dir=floor(rand(0,2-0.001))*2-1;
	T_Slash(dir,0);
	A;
	loop
	{
	loop(600){yield;}
	dir*=-1;
	T_Slash(dir,1);
	}

	task T_Slash(dir,slow)
	{
		SetAction(ACT_SHOT_B, 120);
		let X=192+rand(-128,128);
		let Y=rand(224+64,448-40);
		let R=300;
		let Angle=rand(0,360);
		let waittime=180;
		loop(90)
		{
			Slash(X,Y,Angle,R,1*dir,waittime,1);
			Slash(X,Y,Angle+180,R,1*dir,waittime,1);
			Slash(X,Y,Angle+90,R,1*dir,waittime,0);
			Slash(X,Y,Angle+270,R,1*dir,waittime,0);
			R-=240/90;
			Angle-=6*dir;
			waittime-=2;
			wait(2);
		}

		task Slash(X,Y,Angle,R,dir,waittime,flag)
		{
		let sX = X+500*cos(Angle)+R*cos(Angle+90*dir);
		let sY = Y+500*sin(Angle)+R*sin(Angle+90*dir);
		let angle=Angle+180*dir;

		loop(4)
		{
	//	SparkLaser(sX,sY,20,angle,180,18,146,0,0,waittime);
		loop(2){yield;}
		}
		loop(1)
		{
		SparkLaser(sX,sY,20,angle,180,18,146,0,1*flag,waittime);
		loop(2){yield;}
		}
		}


		task SparkLaser(x,y,Lspeed,Langle,Slength,width,graphic,delay,flag,waittime)
		{
			let length=0;
			let obj = CreateStraightLaserA1(x, y, Langle, Lspeed, width, Slength, DS_KNIFE_KOUMA_GREEN, 0);
			ObjShot_SetAutoDelete(obj,false);
			let r=0;
			wait(delay);
			loop(Slength/Lspeed)
			{
				if(Obj_IsDeleted(obj)){break;}
				ObjLaser_SetLength(obj,length);
				length+=Lspeed;
			//	Lspeed+=0.05;
				yield;
			}
			let count=floor(rand(0,100))*0;

			loop(60)
			{
				if(Obj_IsDeleted(obj)){break;}
				if(flag && count%10==5){
				ascent(i in 0..1)
				{
				LaserShot(x+r*cos(Langle),y+r*sin(Langle),Langle+90+i,waittime);
				LaserShot(x+r*cos(Langle),y+r*sin(Langle),Langle-90+i,waittime);

				}
				}
				ObjRender_SetPosition(obj,x+r*cos(Langle),y+r*sin(Langle),0);
				r+=Lspeed;
			//	Lspeed+=0.05;
				//Langle+=0.6;
				count+=1;
				yield;
			}
			ObjShot_SetAutoDelete(obj,true);
			Obj_Delete(obj);
		}

	task LaserShot(x,y,angle,waittime)
	{
		let obj = CreateShotA2(x, y, 0, angle, 0, 0, DS_ICE_GREEN, 0);//弾を発射
		let scale=4.0;
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		let speed=0;
		ObjShot_SetAutoDelete(obj,false);
		loop(15)
		{
			if(Obj_IsDeleted(obj)){break;}
			scale-=3.0/15;
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			ObjMove_SetSpeed(obj,speed);
			yield;
		}
		wait(15*0+waittime);
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		loop(60)
		{
			if(Obj_IsDeleted(obj)){break;}
			ObjMove_SetSpeed(obj,speed);
			speed+=1.25/60;
			yield;
		}
		wait(120);
		ObjShot_SetAutoDelete(obj,true);
	}

	}

	task A
	{
	wait(210);
	DamageRate=[100,100];
	loop
	{
		let angle=rand(0,360);
		let angle2=rand(0,360);
		ascent(j in 0..8)
		{
		ascent(i in 0..8)
		{
		Shot(ObjRender_GetX(objEnemy)+60*cos(angle2+i*45),ObjRender_GetY(objEnemy)+60*sin(angle2+i*45),1.0,angle+j*45)
		}
		}
		wait(150);
	}
	task Shot(x,y,speed,angle)
	{
		let obj = ObjShot_Create(OBJ_SHOT);
		ObjShot_Regist(obj);
		ObjMove_SetPosition(obj, x, y);
		ObjMove_SetSpeed(obj, speed);
		ObjMove_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, 17);
		//ObjShot_SetDelay(obj, delay);
		//ObjShot_SetAutoDelete(obj,false);

		ShotEffect(obj);

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

	}

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