#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["YukaNon01"]
#Text["YukaNon01"]
#Background["./NoobSystem/Default_Background_IceMountain.txt"]
#BGM["./Novum.mp3"]
#System["./NoobSystem/Default_System2.txt"]
#Player[DEFAULT]

#include"./Shot/AllStarShot_Const.dnh"
#include"./NoobSystem/Default_Effect.txt"
#include"./Function/Basic.txt"
#include"./Function/SoundFunctions.txt"
#include"./Function/EffectFunctions.txt"
#include"./Animations.txt"

let objEnemy;
let cx = GetStgFrameWidth/2;
let ct = GetStgFrameHeight/2;
@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy, 0, 0);
	TWork;
	TAnimate("Yuka",GetCurrentScriptDirectory~"dot_yuka.png");
	TEnd;
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),18);
	ObjEnemy_SetIntersectionCircleToShot(objEnemy,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),24);
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(2250);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(40);
	}
}

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

task TWork
{
	ObjMove_SetPosition(objEnemy,-GetStgFrameWidth,0);
	yield;
	ObjMove_SetDestAtWeight(objEnemy, GetStgFrameWidth/2, 120, 10,10);
	DamageRateAtFrame(100, 50,180);
	wait(120);
	PlaySound("Charge2",100,0);
	SakuraCharge("YELLOW");
	wait(60);
	PelletBurst(170,3);
	wait(180);
	BorderMove(90,GetStgFrameWidth-90,90,150,10,5);
	PelletBurst(150,5);
	wait(180);
	let start = 150;
	let num = 5;
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
		start -= 40;
		num++;
		BorderMove(90,GetStgFrameWidth-90,90,150,10,5);
		PelletBurst(start,num);
		wait(180);
	}
}

task PelletBurst(start,num)
{
	ascent(n in 0..12)
	{
		let randangle = rand(-8,8);
		PlaySound("Shot1",96,0);
		ascent(i in 0..20)
		{
			let angle = i*18+randangle;
			let obj = CreateShotA2(GetEnemyX,GetEnemyY,3.35,angle,0,0,62,8);
			//ObjMove_AddPatternA2(obj,30,NO_CHANGE,NO_CHANGE,0.04,0,6);
		}
		wait(6);
	}
	FlowerBurst(start,num);
}

task FlowerBurst(start,num)
{
	ascent(i in 0..num)
	{
		PlaySound("Shot5",100,0);
		FlowerCore(start+i*100);
		wait(10);
	}
	task FlowerCore(angle)
	{
		let core = CreateShotA1(GetEnemyX,GetEnemyY,4,angle,282,12);
		let scatter = false;
		ObjShot_SetSpellResist(core,true);
		ascent(i in 0..15)
		{
			FlowerBullet(i*24,20);
		}
		while(ObjMove_GetX(core)>0 && ObjMove_GetX(core)<GetStgFrameWidth && ObjMove_GetY(core)>0){yield;}
		if(ObjMove_GetX(core)<0 || ObjMove_GetX(core)>GetStgFrameWidth){ObjMove_SetAngle(core,180-ObjMove_GetAngle(core));}
		if(ObjMove_GetY(core)<0){ObjMove_SetAngle(core,-ObjMove_GetAngle(core));}
		ObjMove_AddPatternA2(core,0,NO_CHANGE,NO_CHANGE,-4/60,0,0);
		wait(60);
		if(ObjMove_GetY(core)>GetStgFrameHeight){Obj_Delete(core);}
		scatter = true;
		PlaySound("BulletWave",100,0);
		ObjMove_AddPatternA2(core,0,NO_CHANGE,GetAngleToPlayer(core),0.03,0,3);
		task FlowerBullet(angle2,r)
		{
			let obj = CreateShotA1(ObjMove_GetX(core)+r*cos(angle2),ObjMove_GetY(core)+r*sin(angle2),0,angle2,63,12);
			ObjShot_SetSpellResist(obj,true);
			while(!Obj_IsDeleted(core) && scatter==false && !Obj_IsDeleted(obj))
			{
				ObjMove_SetPosition(obj,ObjMove_GetX(core)+r*cos(angle2),ObjMove_GetY(core)+r*sin(angle2));
				ObjMove_SetAngle(obj,angle2);
				angle2+=ObjMove_GetSpeed(core);
				yield;
			}
			if(ObjMove_GetY(obj)>GetStgFrameHeight){Obj_Delete(obj);}
			ObjMove_AddPatternA2(obj,0,0,angle2,0.03,0,3);
		}
	}
}


//----------------------------------------------------
task TEnd
{
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
		yield;
	}

	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);
	TExplosionA(ex, ey, 10, 0.6);
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	Obj_Delete(objEnemy);

	loop(30)
	{
		DeleteShotAll(TYPE_ALL, TYPE_IMMEDIATE);
		yield;
	}

	CloseScript(GetOwnScriptID());
}
