
#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_Iku.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(3900);//ライフを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, 112, 10,2);
	SetAction(ACT_MOVE, 60);
//	loop(60){yield;}
	CallSpellCard("「裁きの天雷」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	loop(90){yield;}
	C;
	wait(120);
	DamageRate=[100,100];
	loop
	{
	SetAction(ACT_THORN, 360);
	thunder;
	wait(480);
	}

	task C
	{
		let cx=192;
		let cy=464;
		loop
		{
			LightShot(cx,cy,1);
			wait(2);
		}

		task LightShot(x,y,dir)
		{
		let cx=x;
		let Xwide=224;
		let Xangle=rand(0,360);
		x=Xwide*cos(Xangle);
		let obj = ObjShot_Create(OBJ_SHOT);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjShot_Regist(obj);
		ObjMove_SetPosition(obj, x, y);
	//	ObjMove_SetSpeed(obj, speed);
	//	ObjMove_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, 14);
		ObjShot_SetAutoDelete(obj,false);
		let gradangle=80+rand(0,8);
	//	ShotEffect(obj);
		let AlphaAngle=rand(0,360);
		let Alpha=absolute(cos(AlphaAngle));
		let Alpha2=absolute(cos(AlphaAngle));
	//	LightShot2(obj,AlphaAngle+90);
		ObjRender_SetColor(obj,255*Alpha,255*Alpha,255*Alpha);

		let obj2 = ObjShot_Create(OBJ_SHOT);
		ObjRender_SetBlendType(obj2, BLEND_ADD_RGB);
		ObjShot_Regist(obj2);
		ObjShot_SetGraphic(obj2, 15);
		ObjShot_SetAutoDelete(obj2,false);
		ShotEffect(obj);
		ShotEffect(obj2);

		loop(240)
		{
			x=192+Xwide*cos(Xangle);
			y-=512/240;
			Xangle+=0.5*dir;
			ObjMove_SetPosition(obj, x, y);
			ObjRender_SetColor(obj,255*Alpha,255*Alpha,255*Alpha);
		//	ObjRender_SetScaleXYZ(obj,1*Alpha,1*Alpha,1*Alpha);

			ObjMove_SetPosition(obj2, x, y);
		//	ObjRender_SetColor(obj2,255*Alpha2,255*Alpha2,255*Alpha2);
		//	ObjRender_SetScaleXYZ(obj2,1*Alpha2,1*Alpha2,1*Alpha2);

			Alpha=absolute(cos(AlphaAngle));
			Alpha2=absolute(cos(AlphaAngle+90));
			AlphaAngle+=3;
			ObjShot_SetDelay(obj,5);
			yield;
		}
		Obj_Delete(obj);
		Obj_Delete(obj2);
		}

	task LightShot2(Cobj,AlphaAngle)
	{
		let obj = ObjShot_Create(OBJ_SHOT);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjShot_Regist(obj);
		ObjShot_SetGraphic(obj, 11);
		ObjShot_SetAutoDelete(obj,false);
		let Alpha=0;
		loop(240)
		{
			ObjMove_SetPosition(obj, ObjRender_GetX(Cobj), ObjRender_GetY(Cobj));
			ObjRender_SetColor(obj,255*Alpha,255*Alpha,255*Alpha);
			Alpha=absolute(cos(AlphaAngle));
			AlphaAngle+=3;
			yield;
		}
		Obj_Delete(obj);
	}

	}

	task thunder
	{
		let x=0;
		let y=0;
		let cx=ObjMove_GetX(objEnemy);
		let cy=-64;
		let length=30;

		loop(300)
		{
			let x=cx+rand(-8,8);
			let y=cy+rand(-8,8);
			loop(8)
			{
			IceEffect(x, y, rand(0, 180), length, 50, 30);
			}
			length+=108/300;
			yield;
		}

		loop(15)
		{
			let x=cx+rand(-8,8);
			let y=cy+rand(-8,8);
			loop(8)
			{
			IceEffect(x, y, rand(0, 180), length, 50, 30);
			}
			length-=0.3*24;
			yield;
		}
		wait(30);
		Lightning(cx);
	}

	task IceEffect(x, y, angle, leng, wid, time)
	{
		let obj1 = CreateStraightLaserA1(x, y, angle, 0, 2*wid, 30, DS_ICE_BLUE, 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 Lightning(bx)
	{
		loop(30)
		{
			let X=192+rand(-16,16);
			let A=90+rand(-45,45);
			Light(X,0,A,0);
			LightEffect(X,0,A,0);
		}
		
		ascent(i in 0..45)
		{
			LightShot(192,-64,1,i*8);
			LightShot(192,-64,2,i*8);
			LightShot(192,-64,3,i*8);
		}

		task Light(x,y,angle,c)
		{
			let obj1 = CreateStraightLaserA1(x, y, angle, 0, 5, 30, DS_BEAM_BLUE, 0);
		//	ObjShot_SetIntersectionEnable(obj1,false);
			ObjStLaser_SetSource(obj1, false);
			ObjShot_SetAutoDelete(obj1,false);
			ObjLaser_SetLength(obj1,32);
			ObjLaser_SetRenderWidth(obj1, 10);
			ObjRender_SetBlendType(obj1, BLEND_ADD_RGB);
			let color = [255,255,255];

			x+=30*cos(angle);
			y+=30*sin(angle);

			loop(10)
			{
			loop
			{
				let angleP=rand(-45,45);
				angle+=angleP;
				if(angle>=45 && angle<=135){break;}
				angle-=angleP;
			}
			let jx=x+30*cos(angle);
			let jy=y+30*sin(angle);

			let Xrange=16+128*jy/512;
			if(bx-Xrange<=jx && bx+Xrange>=jx){break;}
			jx-=30*cos(angle);
			jy-=30*sin(angle);
			}
			if(c%2==0)
			{
			yield;
			}
			if(y<=512 && x>=-64 && y>=-64 && x<=512 && c<20)
			{
			Light(x,y,angle,c+1);
			LightEffect(x,y,angle,c);
			}
			wait(30);
			let time=15;
			ascent(i in 1 .. time+1)
			{
			ObjRender_SetColor(obj1, color[0]*(time-i)/time, color[1]*(time-i)/time, color[2]*(time-i)/time);
			yield;
			}
			Obj_Delete(obj1);
		}

		task LightEffect(x,y,angle,c)
		{
		let obj1 = CreateStraightLaserA1(x, y, angle, 0, 10, 32, DS_BEAM_BLUE, 0);
		ObjShot_SetIntersectionEnable(obj1,false);
		ObjStLaser_SetSource(obj1, false);
		let color = [255,255,255];
		let time=30;
		ascent(i in 1 .. time+1)
		{
			ObjLaser_SetLength(obj1,32);
			ObjLaser_SetRenderWidth(obj1, 40*(time-i)/time);
			ObjRender_SetColor(obj1, color[0]*(time-i)/time, color[1]*(time-i)/time, color[2]*(time-i)/time);
			yield;
		}
		wait(5);
		ascent(i in 1 .. time+1)
		{
			ObjLaser_SetLength(obj1,32);
			ObjLaser_SetRenderWidth(obj1, 10*(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 LightShot(x,y,speed,angle)
		{

		let obj = ObjShot_Create(OBJ_SHOT);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjShot_Regist(obj);
		ObjMove_SetPosition(obj, x, y);
		ObjMove_SetSpeed(obj, speed);
		ObjMove_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, DS_BALL_M_BLUE);
		ObjShot_SetAutoDelete(obj,false);
		let gradangle=80+rand(0,8);
	//	ShotEffect(obj);
		let AlphaAngle=rand(0,360);
		let Alpha=absolute(cos(AlphaAngle));
		let Alpha2=absolute(cos(AlphaAngle));
	//	LightShot2(obj,AlphaAngle+90);
		ObjRender_SetColor(obj,255*Alpha,255*Alpha,255*Alpha);

		let obj2 = ObjShot_Create(OBJ_SHOT);
		ObjRender_SetBlendType(obj2, BLEND_ADD_RGB);
		ObjShot_Regist(obj2);
		ObjShot_SetGraphic(obj2, DS_BALL_M_PURPLE);
		ObjShot_SetAutoDelete(obj2,false);
		ShotEffect(obj);
		ShotEffect(obj2);

		loop(240)
		{
			speed+=0.05;
			x=ObjRender_GetX(obj)+speed*cos(angle);
			y=ObjRender_GetY(obj)+speed*sin(angle);

			ObjMove_SetPosition(obj, x, y);
			ObjRender_SetColor(obj,255*Alpha,255*Alpha,255*Alpha);
		//	ObjRender_SetScaleXYZ(obj,1*Alpha,1*Alpha,1*Alpha);

			ObjMove_SetPosition(obj2, x, y);
		//	ObjRender_SetColor(obj2,255*Alpha2,255*Alpha2,255*Alpha2);
		//	ObjRender_SetScaleXYZ(obj2,1*Alpha2,1*Alpha2,1*Alpha2);

			Alpha=absolute(cos(AlphaAngle));
			Alpha2=absolute(cos(AlphaAngle+90));
			AlphaAngle+=3;
			ObjShot_SetDelay(obj,15);

			yield;
		}
		Obj_Delete(obj);
		Obj_Delete(obj2);
		}
	}

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