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

@Initialize
{
	SetCommonData("Name","Chen");
	BossInit(384,0);
}

@MainLoop
{
	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);
	ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey, 32);//当たり判定(自弾)登録
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 8);//当たり判定(体当たり)登録
	SetCommonData("BossPosition",[ex,ey]);
	yield;
}

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

//----------------------------------------------------
//敵動作
//----------------------------------------------------
task BossWork
{
	let cx = GetStgFrameWidth() / 2;//STGシーンの中心x座標を取得
	ObjMove_SetDestAtWeight(objEnemy, cx, 112, 10,7);
	SetAction(ACT_MOVE, 60);
	SetRoll(60);

	CallSpellCard("「易・占事略决」");

	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	SetShotAutoDeleteClip(96,96,96,96);

	loop(60){yield;}
	SetAction(ACT_SHOT_A, 60);
	Summon;
	Shoot;
	loop(240){yield;}
	DamageRate=[100,100];

	task Shoot
	{
		wait(300);
		loop
		{
			Move1(60,0,150,60,30,5);
			SetAction(ACT_MOVE, 120);
			SetRoll(120);
			let way=12;
			if(GetLife<=4444){way=15;}
			if(GetLife<=3333){way=18;}
			if(GetLife<=2222){way=21;}
			if(GetLife<=1111){way=24;}
			loop(4)
			{
				let angle=rand(0,360);
				ascent(i in 0..way)
				{
					Shot(GetX,GetY,5,angle+i*360/way,DS_SCALE_RED,1);
					Shot(GetX,GetY,3.5,angle+i*360/way+360/way/3*1,DS_SCALE_ORANGE,-1);
					Shot(GetX,GetY,2.0,angle+i*360/way+360/way/3*2,DS_SCALE_YELLOW,0);
				}
				wait(30);
			}
			wait(300);
		}

		task Shot(x,y,speed,angle,gra,dir)
		{
			let bsp=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, gra);
			ObjShot_SetDelay(obj, 5);
			let count=0;
			loop(60)
			{
				if(speed>0)
				{
					speed-=bsp/60;
				}
				ObjMove_SetSpeed(obj, speed);
				yield;
			}
			wait((gra-DS_SCALE_RED)*30);
			while(!Obj_IsDeleted(obj))
			{
				if(speed<1.5)
				{
					speed+=1.5/60;
				}
				ObjMove_SetSpeed(obj, speed);
				ObjMove_SetAngle(obj, angle);
				angle+=0.3*dir;
				yield;
			}
			Obj_Delete(obj);
		}
	}
	task Summon
	{
		Enemy(-1);
		Enemy(1);
	}
}

task Enemy(num)
{
	let angle=0;
	let R=480;
	let x=GetPlayerX+R*cos(angle+90*num);
	let y=GetPlayerY+R*sin(angle+90*num);
	#include"./../../lib/ZakoCommon/ZakoCommon.txt"
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	SetLife(obj,1000);
	SetDamageRate(obj,100,100);

//	DrawEnemy(obj,RedFairy,1);
	DrawCircle(obj,0.20,255,255,255);
	EnemyResist(obj,x,y);
//	SetCollisionA(obj,0,0,32);
//	SetCollisionB(obj,0,0,16);

	loop(120)
	{		
		ObjRender_SetX(obj,GetPlayerX+R*cos(angle+90*num));
		ObjRender_SetY(obj,GetPlayerY+R*sin(angle+90*num));
		R-=360/120;
		angle+=2;
		yield;
	}
	Shot;
	while(!Obj_IsDeleted(obj))
	{		
		ObjRender_SetX(obj,GetPlayerX+R*cos(angle+90*num));
		ObjRender_SetY(obj,GetPlayerY+R*sin(angle+90*num));
		angle+=2;
		yield;
	}

	task Shot
	{
		wait(30+num*15);
		while(!Obj_IsDeleted(obj))
		{
			wait(60);
			loop(5)
			{
			CreateShotA1(ObjRender_GetX(obj),ObjRender_GetY(obj),1,GetAngleToPlayer(obj),DS_RICE_S_RED+2.5+2.5*num,0);
			wait(1);
			}
		}
		
	}
}