script_enemy_main
{

	#include_function".\..\function\glo_enemydrop.txt";
	#include_function".\stage3_Boss_Info.txt";

	sfx01 = "t";

	sfx43 = "t";

	sfx50 = "t";
	sfx51 = "t";

	#include_function".\..\function\soundfx.txt";

	ng_timeset = 70;
	ng_spellcard = 1;



	let ng_num = 0;

	let frame1 = 0;
	let frame2 = 0;




//-------------------------------------------------------------------------------------------------
// Any Task

	function FireBlast(posX, posY)
	{
	ng_num = rand(0,360);
	Explosion01(posX, posY, 5, 0.04, 60);
	ascent (i in 0..8)
		{
		CreateShotA(1, posX, posY, 60);
		SetShotDataA(1, 0, 0, i*45, 0, 0, 0, RED01);
		SetShotDataA(1, 60, 0, ng_num+(i*45), 0, 0.01, 1, RED21);
		FireShot(1);
		}
	}


	task FireWave(posX, posY, speed, angle, pulsewait) 
	{
	let obj = Obj_Create(OBJ_SHOT);

	Obj_SetPosition(obj, posX, posY);
	Obj_SetAngle(obj, angle);
	Obj_SetSpeed(obj, speed);
	ObjShot_SetGraphic(obj, RED05);
	ObjShot_SetDelay(obj, 0);
	Obj_SetAlpha(obj, 0);
	Obj_SetCollisionToPlayer(obj, false);
 	ObjShot_SetBombResist(obj, true);

	while(Obj_BeDeleted(obj)==false) 
		{
		Wait(pulsewait);
		FireBlast(Obj_GetX(obj),  Obj_GetY(obj));
		yield;
		}
	}


	function Wait(num)
	{
	loop(num)	{	yield;	}
	}



//---------------------------------------------------------------

	@Initialize
	{
	SetInvincibility(60);
	SetLife(400);
	SetDamageRate(0,0);
	SetTimer(ng_timeset);
	SetScore(800000);

	SetMovePosition02(GetCenterX, GetClipMinY + 60, 30);
	CutIn(YOUMU, "Fire Esper "\""Chain Eruption"\", BossCutin, BCR_x1, BCR_y1, BCR_x2, BCR_y2);


	LoadGraphic(BossSprite);

	// Fever score decrease if this is not survival card.
	SetCommonData("ng_feverdecrease", 1);

//	Concentration01(90);
//	PlaySE(GetCurrentScriptDirectory~"..\sfx\Charge.wav");

	}

//---------------------------------------------------------------

	@MainLoop 
	{
	SFU_GloBossCounter;

	SetCollisionA(GetX, GetY, 32);
	SetCollisionB(GetX, GetY, 16);

	SetShotDirectionType(ABSOLUTE);

//----------------------
// Attack script below
//----------------------

	if (ng_sframe == 60)
	{
	ng_start = 1;
	frame1 = 0;
	frame2 = 0;
	}



	if ((ng_start == 1) && (frame1 == 1))
	{
	PlaySE(GetCurrentScriptDirectory~"..\sfx\Charge.wav");
	}
	if ((ng_start == 1) && (frame1 == 30))
	{
	Concentration01(60);
	}



// Lunatic
if (GetCommonData("CD_gamemode") == 2)
{
	if ((ng_start == 1) && (frame1 == 90))
	{
	PlaySE(sfx43);
	FireBlast(GetX, GetY);
	ascent(i in 0..15)
		{
		FireWave(GetX, GetY, 3, GetAngleToPlayer+(i*24), 25);
		}
	}
}
else
{
	if ((ng_start == 1) && (frame1 == 90))
	{
	PlaySE(sfx43);
	FireBlast(GetX, GetY);
	ascent(i in 0..8)
		{
		FireWave(GetX, GetY, 3, GetAngleToPlayer+(i*45), 25);
		}
	}
}




	if ((ng_start == 1) && (frame1 == 300))
	{
	MotionBlur(SHOT, 90, 200);
	frame1 = 0;
	}





	if (ng_bossmframe == 120)
	{
	SetMovePositionRandom01(rand_int(25,75), rand_int(5,10), 30, GetClipMinX+100, 100, GetClipMaxX-100, 90);
	ng_bossmframe = 0;
	}



	frame1++;
	frame2++;


//----------------------
// Attack script above
//----------------------

	#include_function".\..\function\glo_timernotice.txt";
	yield;
	}

//---------------------------------------------------------------

	@DrawLoop
	{
	SetTexture(BossSprite);
	SetGraphicAngle(0, 0, 0);
	SetGraphicScale(1, 1);
	#include_function".\..\function\boss_draw.txt";
	}

//---------------------------------------------------------------

	@BackGround
	{
	LoadGraphic(BossBG1);
	SetTexture(BossBG1);
	SetGraphicRect( 0, 0, 256, 256);
	SetGraphicScale(1.8, 1.8);
	SetGraphicAngle(0, 0, 0);
	SetAlpha(255);
	DrawGraphic(GetCenterX, GetCenterY);
	}

//---------------------------------------------------------------

	@Finalize
	{
	loop (30)	{	EnemyDropItem(1, 25);	}
	if(GotSpellCardBonus)
		{	
		PlaySE(GetCurrentScriptDirectory~"..\sfx\SpellBonus.wav");
		AddScore(ng_spellbonus * (GetCommonDataDefault("CD_FeverMultiplyUse",1)-1))
		}
	DeleteGraphic(BossSprite);
	DeleteGraphic(BossBG1);
	SFX_Delete;
    	}
}
