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

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(160,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(5600);//ライフを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,3);
	SetAction(ACT_MOVE, 60);
//	loop(60){yield;}
	CallSpellCard("「アンカーメイルストロム」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	wait(60);
	DR;
	let dir=floor(rand(0,2-0.001))*2-1;
	loop
	{
	T_anchor(dir);
	wait(60+44*10);
	dir*=-1;
	}

	task DR
	{
		wait(120);
		DamageRate=[100,100];
	}

	task T_anchor(dir)
	{
		let X=ObjMove_GetX(objEnemy);
		let Y=ObjMove_GetY(objEnemy);
		let Angle=rand(0,360);
		ascent(i in 0..10)
		{
		anchor(Angle+i*36);
		}

		task anchor(angle)
		{
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"../../img/effect/ikari.png");
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjPrim_SetVertexCount(obj, 4);
	//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
	//	ObjRender_SetBlendType(obj, BLEND_SUBTRACT);
	//	ObjRender_SetBlendType(obj, BLEND_MULTIPLY);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetVertexPosition(obj, 0, -64, -64, -0);
		ObjPrim_SetVertexPosition(obj, 1, -64, 64, -0);
		ObjPrim_SetVertexPosition(obj, 2, 64, -64, 0);
		ObjPrim_SetVertexPosition(obj, 3, 64,64, 0);

		ObjPrim_SetVertexUVT(obj, 0, 0, 0);
		ObjPrim_SetVertexUVT(obj, 1, 0, 128);
		ObjPrim_SetVertexUVT(obj, 2, 128, 0);
		ObjPrim_SetVertexUVT(obj, 3, 128, 128);
		let scale=0;
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		let Alpha=255;
		ObjRender_SetColor(obj,Alpha,Alpha,Alpha);
		ObjRender_SetPosition(obj,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),0);
		ObjRender_SetAngleZ(obj,angle+90);
		let speed=0;
		loop(15)
		{
			scale+=1/15;
			ObjRender_SetScaleXYZ(obj,scale,1,1);
			yield;
		}
		let R=0;
		let Rs=0;
		let ox=ObjRender_GetX(obj)-10*cos(angle);
		let oy=ObjRender_GetY(obj)-10*sin(angle);
		loop(105)
		{
			ObjRender_SetPosition(obj,X+R*cos(angle),Y+R*sin(angle),0);
			if(ox!=ObjRender_GetX(obj) &&  oy!=ObjRender_GetY(obj))
			{
			ObjRender_SetAngleZ(obj,atan2(oy-ObjRender_GetY(obj),ox-ObjRender_GetX(obj))-90);
			}
			ox=ObjRender_GetX(obj);
			oy=ObjRender_GetY(obj);
			R+=Rs;
			Rs+=0.075;
			angle+=0.75*dir;
			SetShotIntersectionCircle(ox,oy,32);
			yield;
		}
		Mael(R,angle);
		Obj_Delete(obj);
		}

	task Mael(R,angle)
	{
		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);
		let x=ex+R*cos(angle);
		let y=ey+R*sin(angle);
		let RandAngle=0;
		loop(18)
		{
			loop(6)
			{
				MaelS(x,y,R+rand(-RandAngle,RandAngle),angle+rand(-RandAngle,RandAngle));
				wait(4);
			}
			RandAngle+=2;
			wait(20);
		}

		task MaelS(x,y,R,angle)
		{
		let BaseR=R;
			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, 14);
			//ObjShot_SetDelay(obj, delay);
			ObjShot_SetAutoDelete(obj,false);
			loop(240)
			{
				ObjRender_SetPosition(obj,ex+R*cos(angle),ey+R*sin(angle),0);
				R-=BaseR/240;
				angle-=0.5*dir;
				yield;
			}
			Obj_Delete(obj);
		}
	}

	}
/*
	task A(dir)
	{
		if(dir==1)
		{
		ObjMove_SetDestAtWeight(objEnemy, 12, 112, 10,7);
		wait(60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,0,768,5,158,60);
		wait(30);
		StartSlow(TARGET_ALL,60);
		ObjMove_SetDestAtFrame(objEnemy,372,112,10);
		Shot;

		wait(120);

		ObjMove_SetDestAtWeight(objEnemy, 340, 12, 10,7);
		wait(60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,90,768,5,158,60);
		wait(30);
		StartSlow(TARGET_ALL,60);
		ObjMove_SetDestAtFrame(objEnemy,340,444,10);
		Shot2;

		wait(120);
		let y=400;
		ObjMove_SetDestAtWeight(objEnemy, 372, y, 10,7);
		wait(60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,180,768,5,158,60);
		wait(30);
		StartSlow(TARGET_ALL,60);
		ObjMove_SetDestAtFrame(objEnemy,12,y,10);
		Shot3(y);

		wait(120);
		let x=28;
		ObjMove_SetDestAtWeight(objEnemy, x, 444, 10,7);
		wait(60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,270,768,5,158,60);
		wait(30);
		StartSlow(TARGET_ALL,60);
		ObjMove_SetDestAtFrame(objEnemy,x,12,10);
		Shot4(x);

		task Shot
		{
			let angle=rand(0,360);
			ascent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(12+j*10,112,5-4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(12+j*10,112,rand(0,360));
			}
			yield;
			}
		}

		task Shot2
		{
			let angle=rand(0,360);
			ascent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(340,12+j*12,5-4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(340,12+j*12,rand(0,360));
			}
			yield;
			}
		}

		task Shot3(y)
		{
			let angle=rand(0,360);
			descent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(12+j*10,y,1+4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(12+j*10,y,rand(0,360));
			}
			yield;
			}
		}

		task Shot4(x)
		{
			let angle=rand(0,360);
			descent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(x,12+j*12,1+4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(x,12+j*12,rand(0,360));
			}
			yield;
			}
		}

		}
		else
		{
		ObjMove_SetDestAtWeight(objEnemy, 372, 112, 10,7);
		wait(60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,180,768,5,158,60);
		wait(30);
		StartSlow(TARGET_ALL,60);
		ObjMove_SetDestAtFrame(objEnemy,12,112,10);
		Shot;

		wait(120);

		ObjMove_SetDestAtWeight(objEnemy, 28, 12, 10,7);
		wait(60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,90,768,5,158,60);
		wait(30);
		StartSlow(TARGET_ALL,60);
		ObjMove_SetDestAtFrame(objEnemy,28,444,10);
		Shot2;

		wait(120);
		let y=400;
		ObjMove_SetDestAtWeight(objEnemy, 12, y, 10,7);
		wait(60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,0,768,5,158,60);
		wait(30);
		StartSlow(TARGET_ALL,60);
		ObjMove_SetDestAtFrame(objEnemy,372,y,10);
		Shot3(y);

		wait(120);
		let x=340;
		ObjMove_SetDestAtWeight(objEnemy, x, 444, 10,7);
		wait(60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,270,768,5,158,60);
		wait(30);
		StartSlow(TARGET_ALL,60);
		ObjMove_SetDestAtFrame(objEnemy,x,12,10);
		Shot4(x);

		task Shot
		{
			let angle=rand(0,360);
			descent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(12+j*10,112,1+4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(12+j*10,112,rand(0,360));
			}
			yield;
			}
		}

		task Shot2
		{
			let angle=rand(0,360);
			ascent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(28,12+j*12,5-4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(28,12+j*12,rand(0,360));
			}
			yield;
			}
		}

		task Shot3(y)
		{
			let angle=rand(0,360);
			ascent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(12+j*10,y,5-4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(12+j*10,y,rand(0,360));
			}
			yield;
			}
		}

		task Shot4(x)
		{
			let angle=rand(0,360);
			descent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(x,12+j*12,1+4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(x,12+j*12,rand(0,360));
			}
			yield;
			}
		}

		}

		task S(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, 86);
			//ObjShot_SetDelay(obj, delay);
			//ObjShot_SetAutoDelete(obj,false);
			loop(60)
			{
				angle+=360/60;
				ObjMove_SetAngle(obj, angle);
				yield;
			}
		}

		task HomingShot(x,y,angle)
		{
			let LaserSpeed=3;
			loop(30)
			{
				Homing;
				Homing;

				x+=LaserSpeed*cos(angle);
				y+=LaserSpeed*sin(angle);
				if(x<-64){break;}
				if(x>448){break;}
				LaserSpeed-=2.5/30;
				BladeShot(x,y,angle,81);
				yield;
			}
			loop(105)
			{
				Homing;
				Homing;

				x+=LaserSpeed*cos(angle);
				y+=LaserSpeed*sin(angle);
				if(x<-64){break;}
				if(x>448){break;}
				BladeShot(x,y,angle,81);
				yield;
			}
			loop(75)
			{
				Homing;

				x+=LaserSpeed*cos(angle);
				y+=LaserSpeed*sin(angle);
				if(x<-64){break;}
				if(x>448){break;}
				if(y<-32){break;}
				LaserSpeed+=9/60;
				BladeShot(x,y,angle,81);
				yield;
			}
			loop(75)
			{
				x+=LaserSpeed*cos(angle);
				y+=LaserSpeed*sin(angle);
				if(x<-64){break;}
				if(x>448){break;}
				if(y<-32){break;}
				LaserSpeed+=6/60;
				BladeShot(x,y,angle,81);
				yield;
			}
			function Homing
			{
				let ToPlayerAngle=atan2(GetPlayerY-y,GetPlayerX-x);
				let judgangle=sin(ToPlayerAngle-angle);
				let ShiftAngle=absolute(ToPlayerAngle-angle);
				if(judgangle>0)
				{
					angle+=1.0;
				}
				else
				{
					angle-=1.0;
				}
			}

			task BladeShot(x,y,angle,gra)
			{
				let obj = CreateShotA2(x, y, 0, angle, 0, 0, gra, 0);//弾を発射
				ObjShot_SetSpellResist(obj,true);
				let scale=2.5;
				ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
				let speed=0.75;
				loop(10)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=2.5/15;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
					ObjShot_SetIntersectionCircleA1(obj,scale*3);
					yield;
				}
				ObjShot_SetIntersectionEnable(obj,false);
				loop(5)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=2.5/15;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
					yield;
				}
				Obj_Delete(obj);
			}

		}

		task NoticeLaser(x,y,Lspeed,Langle,Slength,width,graphic,delay)
		{
			let obj = CreateStraightLaserA1(x, y, Langle, Lspeed, width, Slength, graphic, 0);
			ObjLaser_SetLength(obj,Slength);
			ObjShot_SetIntersectionEnable(obj,false);
			ObjShot_SetAutoDelete(obj,false);
			wait(delay);
			Obj_Delete(obj);
		}
	}

	task FreezeShot(x,y,speed)
	{
	let angle=90;
	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, 29);
	ObjShot_SetAutoDelete(obj,true);
	ShotEffect(obj);
	}

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

	task B
	{
		loop(240){yield;}
		WShot;
		loop(30){yield;}
		loop
		{
		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);
		let mx= ex+rand(-120,120);
		let my= ey+rand(-20,20);
		while(mx<64 || mx>320){mx=ex+rand(-120,120);}
		while(my<80 || my>160){my=ey+rand(-20,20);}
		ObjMove_SetDestAtWeight(objEnemy,mx, my, 30,2.0);
		SetAction(ACT_MOVE, 75);
		loop(120){yield;}
		WShot;
		loop(30){yield;}
		}

		task WShot
		{

			let angle=GetAngleToPlayer(objEnemy);
			let life=ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			let way=floor((4000-life)/500)+4;
			ascent(i in -way..way+1)
			{
			let obj=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1.25,angle+i*2.5,21,0);
			ShotEffect(obj);
			}

		}
	}
*/

}