
#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_Alice.txt"
#include"./../../lib/BossCommon/BossCommon.txt"
#include"./../../img/boss/lib_anime_doll.txt"

let objDoll=[];

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(384,128);
	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]);
	if(length(objDoll)>0)
	{
	DrawDoll(objDoll[0],imgBoss);
	DrawDoll(objDoll[1],imgBoss);
	}	
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(3000);//ライフを1500に設定
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);//時間制限を60秒に設定
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(30000);//スペルカードボーナスを30000に設定
	}
}

//----------------------------------------------------
//敵動作
//----------------------------------------------------
task BossWork
{
	//座標(cx, 60)へ60フレームかけて移動する
	let cx = GetStgFrameWidth() / 2;//STGシーンの中心x座標を取得
	ObjMove_SetDestAtWeight(objEnemy, cx, 128, 10,4);
	SetAction(ACT_MOVE, 80);
//	loop(60){yield;}
	CallSpellCard("「人形双糸線」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	loop(80){yield;}
	SetAction(ACT_SHOT_B, 60);
	Doll(1);
	Doll(-1);
	wait(120);
	A;
	DamageRate=[100,100];

	let dir=floor(rand(0,2-0.001))*2-1;
/*
	loop
	{

	A(dir);

	wait(420);
	dir*=-1;

	}
*/
	task A
	{
		let gra=0;
		loop(7)
		{
		let angle=GetAngleToPlayer(objEnemy);
		ascent(i in 0..8)
		{
			S(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1.0,angle+45*i,gra);
		}
		gra+=1;
		wait(120);
		}
		loop
		{
		let angle=GetAngleToPlayer(objEnemy);
		ascent(i in 0..16)
		{
			S(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1.0,angle+22.5*i,gra);
		}
		gra+=1;
		wait(120);
		}

		task S(x,y,speed,angle,t)
		{
			let R=0;
			let Bspeed=speed;
			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_BALL_M_RED+t%7);
			//ObjShot_SetDelay(obj, delay);
			ObjShot_SetAutoDelete(obj,false);
			ObjShot_SetIntersectionEnable(obj,false);
			while(!Obj_IsDeleted(obj))
			{
				yield;
			}
			Obj_Delete(obj);
		}
	}
}

task Doll(dir)
{
	#include"./../../lib/ZakoCommon/ZakoCommon.txt"
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	objDoll=objDoll~[obj];
	SetLife(obj,10000);
	ObjEnemy_AddLife(obj,-5000);
        SetDamageRate(obj,0,0);
//	DrawEnemy(obj,RedFairy,1);
//	DrawCircle(obj,0.20,153,52,0);
	EnemyResist(obj,ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy));


	ObjMove_SetDestAtFrame(obj,192+224*dir,224,30);
	ObjRender_SetScaleXYZ(obj,1.5,1.5,1.5);
	let R=224;
	let angle=90-90*dir;
	Obj_SetValue(obj,"LA",angle);
	Obj_SetValue(obj,"DIS",angle);
	loop(30)
	{
		yield;
	}
	DrawWall(obj);
	S;
//	SetCollisionA(obj,0,0,24);
//	SetCollisionB(obj,0,0,8);
	let anglePlus=0;
	while(!Obj_IsDeleted(obj))
	{
		loop(420)
		{
		ObjMove_SetPosition(obj,192+R*cos(angle),224+R*sin(angle));
		Obj_SetValue(obj,"LA",angle);
		angle+=anglePlus;
		if(anglePlus<1.25)
		{
		anglePlus+=1.25/420;
		}
		yield;
		}
		loop(156)
		{
		ObjMove_SetPosition(obj,192+R*cos(angle),224+R*sin(angle));
		Obj_SetValue(obj,"LA",angle);
		angle+=anglePlus;
		yield;
		}
		loop(840)
		{
		ObjMove_SetPosition(obj,192+R*cos(angle),224+R*sin(angle));
		Obj_SetValue(obj,"LA",angle);
		angle+=anglePlus;
		if(anglePlus>-1.25)
		{
		anglePlus-=1.25/420;
		}
		yield;
		}
		loop(156)
		{
		ObjMove_SetPosition(obj,192+R*cos(angle),224+R*sin(angle));
		Obj_SetValue(obj,"LA",angle);
		angle+=anglePlus;
		yield;
		}
		loop(420)
		{
		ObjMove_SetPosition(obj,192+R*cos(angle),224+R*sin(angle));
		Obj_SetValue(obj,"LA",angle);
		angle+=anglePlus;
		if(anglePlus<1.25)
		{
		anglePlus+=1.25/420;
		}
		yield;
		}
	}

	task S
	{
		loop
		{
			let a=GetAngleToPlayer(obj);
			loop(4)
			{//a=GetAngleToPlayer(obj);

				let objs=CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),1.5,a+30,81,0);
				ShotEffect(objs);
				let objs2=CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),1.5,a-30,81,0);
				ShotEffect(objs2);
				let objs3=CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),1.5,a+10,81,0);
				ShotEffect(objs3);
				let objs4=CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),1.5,a-10,81,0);
				ShotEffect(objs4);
				wait(3);
			}
			wait(33);
		}
	}

	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 DrawWall(Cobj)
	{
	//	DrawLineToWall(num);
		let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"../../img/effect/Thunder.png");
		ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjPrim_SetVertexCount(obj, 4);
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		Obj_SetRenderPriorityI(obj,30);
		ObjRender_SetAngleZ(obj,0);

		ObjPrim_SetVertexPosition(obj, 0, -12, 0, -0);
		ObjPrim_SetVertexPosition(obj, 1, 12, 0, -0);
		ObjPrim_SetVertexPosition(obj, 2, 12, 448, 0);
		ObjPrim_SetVertexPosition(obj, 3, -12, 448, 0);

		ObjPrim_SetVertexUVT(obj, 0, 0, 0);
		ObjPrim_SetVertexUVT(obj, 1, 48, 0);
		ObjPrim_SetVertexUVT(obj, 2, 48, 512);
		ObjPrim_SetVertexUVT(obj, 3, 0, 512);

		ObjRender_SetColor(obj,152*0.5,53*0.5,0*0.5);

		while(!Obj_IsDeleted(obj))
		{
		ObjRender_SetPosition(obj,ObjRender_GetX(Cobj),ObjRender_GetY(Cobj),0);
		ObjRender_SetAngleZ(obj,Obj_GetValue(Cobj,"LA")+90);
		let y=rand(0,512);
		ObjPrim_SetVertexUVT(obj, 0, 0, 0+y);
		ObjPrim_SetVertexUVT(obj, 1, 48, 0+y);
		ObjPrim_SetVertexUVT(obj, 2, 48, 512+y);
		ObjPrim_SetVertexUVT(obj, 3, 0, 512+y);
	//	SetShotIntersectionLine(ObjRender_GetX(Cobj),ObjRender_GetY(Cobj),ObjRender_GetX(Cobj)+224*cos(Obj_GetValue(Cobj,"LA")+180),ObjRender_GetY(Cobj)+224*sin(Obj_GetValue(Cobj,"LA")+180),4);
		yield;
		}
	}