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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(192,0);
	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(6000);//ライフを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,5);
	SetAction(ACT_MOVE, 60);
//	loop(60){yield;}
	CallSpellCard("「ソーラライズレーザー」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	loop(60){yield;}
//	C;
	Solar;
	loop(90){yield;}
	DamageRate=[100,100];

	task Solar
	{
		let x=0;
		let y=0;
		let cx=ObjMove_GetX(objEnemy);
		let cy=ObjMove_GetY(objEnemy);
		let length=0;		
		let yspeed=0;
		loop(60)
		{
			let x=cx+rand(-8,8);
			let y=cy+rand(-8,8);
			loop(8)
			{
			IceEffect(x, y, rand(0, 360), length, length*0.5, 30);
			}
			cy+=yspeed;
			yspeed-=0.2;
			length+=2;
			yield;
		}
		wait(30);
		let grad=6;
		let wt=9;
		wtc;
		loop
		{
		Laser(rand(0,192),-32,90+rand(-grad,grad));
		wait(wt);
		Laser(rand(192,384),-32,90+rand(-grad,grad));
		wait(wt);
		}
		task wtc
		{
		loop
		{
			if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=4500){wt=8;}
			if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=3000){wt=7;}
			if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)<=1500){wt=5;}
			grad=(1-(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)/6000))*30+6;
			yield;
		}
		}
	}

	task Laser(x,y,Langle)
	{
			let length=0;
			let width=5;
			let obj = CreateStraightLaserA1(x, y, Langle, 0, 0, 900, DS_BEAM_ORANGE, 0);
			ObjLaser_SetLength(obj,length);
			ObjStLaser_SetSource(obj,false);
			let r=0;
			let scale=0;

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

			loop(10)
			{
				length+=600/10;
				ObjLaser_SetLength(obj,length);
				yield;
			}

			let d=rand(-64,64);
			loop(10)
			{
			Shot(x+d*cos(Langle),y+d*sin(Langle),0,Langle+90,1);
			d+=64;
			Shot(x+d*cos(Langle),y+d*sin(Langle),0,Langle-90,-1);
			d+=64;
			}

			let Alpha=1;
			loop(30)
			{
				width+=10/30;
				Alpha-=1/30;
				ObjLaser_SetRenderWidth(obj, width);
			//	ObjRender_SetAlpha(obj, Alpha);
				ObjRender_SetColor(obj, 255*Alpha, 255*Alpha, 255*Alpha);
				yield;
			}
			Obj_Delete(obj);

		task Shot(x,y,speed,angle,dir)
		{
			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, DS_STAR_S_ORANGE);
			//ObjShot_SetDelay(obj, delay);

		//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
			D;

			ShotEffect(obj);
			loop(30){yield;}
			while(!Obj_IsDeleted(obj))
			{
				if(speed<1.0)
				{
				speed+=1.0/120;
				}
				ObjMove_SetSpeed(obj, speed);
				ObjMove_SetAngle(obj, angle);
				angle+=0.1*dir;
				yield;
			}
			Obj_Delete(obj);

			task D
			{
				ObjShot_SetAutoDelete(obj,false);
				wait(240);
				ObjShot_SetAutoDelete(obj,true);
			}
		}
	}

	task IceEffect(x, y, angle, leng, wid, time)
	{
		let obj1 = CreateStraightLaserA1(x, y, angle, 0, 2*wid, 30, DS_ICE_ORANGE, 0);
		ObjShot_SetIntersectionEnable(obj1,false);
		ObjStLaser_SetSource(obj1, false);
		let color = [255,255,255];
		ascent(i in 1 .. time+1)
		{
			ObjLaser_SetLength(obj1,leng+2*leng*i/time);
			ObjLaser_SetRenderWidth(obj1, 2*wid*(time-i)/time);
			ObjRender_SetColor(obj1, color[0]*(time-i)/time, color[1]*(time-i)/time, color[2]*(time-i)/time);
			yield;
		}
		Obj_Delete(obj1);
	}


	task ShotEffect(obj)
	{
		let scale=2.0;
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjShot_SetIntersectionEnable(obj,false);
		loop(30)
		{
			if(Obj_IsDeleted(obj)){break;}
			scale-=1.0/30;
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			yield;
		}
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		ObjShot_SetIntersectionEnable(obj,true);
	}
}