#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["AkyuSpell01"]
#Text["AkyuSpell01"]
#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"
#include"./Cutin/Cutin.txt"

let objEnemy;
let cx = GetStgFrameWidth/2;
let ct = GetStgFrameHeight/2;
let cswap = false;
let cstart = false;
let bossbullet = false;
let objScene;
@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy, 0, 0);
	TWork;
	TAnimate("Akyu",GetCurrentScriptDirectory~"dot_akyu.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(2000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3000000);
	}
}

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

task TWork
{
	yield;
	BossBullet;
	let cutinimage = GetCurrentScriptDirectory~"null.png";
	ObjCutin_SetSpellcardS4("Wall of Knowledge", cutinimage, NAZRIN, 240, 104, 104);
	ObjMove_SetDestAtWeight(objEnemy, GetStgFrameWidth/2, 120, 10,10);
	DamageRateAtFrame(50, 25,300);
	wait(30);
	objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	ObjCutin_LaunchS3(YABUSAME, cutinimage, "Normal");
	wait(90);
	PlaySound("Charge2",100,0);
	SakuraCharge("ORANGE");
	wait(30);
	ascent(i in -2..8)
	{
		PillarSet(i*90+5,( (|i|)%2-0.5)*2);
	}
	wait(60);
	bossbullet = true;
	wait(60);
	cstart = true;
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
		wait(120);
		PlaySound("Charge2",100,0);
		SakuraCharge("ORANGE");
		wait(60);
		PlaySound("Eff1",100,0);
		cswap = true;
		yield;
		cswap = false;
		wait(60);
		BorderMove(90,GetStgFrameWidth-90,90,150,10,5);
		wait(60);
	}
}

task BossBullet
{
	let count = 0;
	while(bossbullet==false){yield;}
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
		PlaySound("Shot6",90,0);
		ascent(i in 0..15)
		{
		let angle = i*24+count*10.7;
		CreateShotA2(GetEnemyX+30*cos(angle),GetEnemyY+30*sin(angle),4,angle,-4/60,1.25,112,12);
		CreateShotA2(GetEnemyX+30*cos(angle),GetEnemyY+30*sin(angle),4,angle-3.5,-4/60,1.25,112,12);
		CreateShotA2(GetEnemyX+30*cos(angle),GetEnemyY+30*sin(angle),4,angle+3.5,-4/60,1.25,112,12);
		}
		count++;
		wait(60);
	}
}

task PillarSet(px,type)
{
	ascent(i in -20..20)
	{
		PillarBullet(i*46*type+GetStgFrameHeight/2,type);
		PillarBullet(i*46*type+GetStgFrameHeight/2,type*-1);
		wait(3);
	}
	task PillarBullet(py,way)
	{
		let obj = CreateShotA1(px,py,0,0,46.5+type/2,60);
		let way2 = 1;
		let count = 0;
		ObjShot_SetAutoDelete(obj,false);
		ObjShot_SetSpellResist(obj,true);
		while(cstart==false){yield;}
		while(!Obj_IsDeleted(obj))
		{
			ObjMove_SetY(obj,ObjMove_GetY(obj)+type*way);
			if(cswap==true)
			{
				SwapPlace(type*way*way2);
				way = -way;
				count++;
				if(count%2==0){way2*=-1;}
			}
			yield;
		}
		task SwapPlace(tw)
		{
			let here = ObjMove_GetX(obj);
			ascent(i in 0..240)
			{
				ObjMove_SetX(obj,here+tw*90*sin(i/(8/3)));
				yield;
			}
		}
	}
}


//----------------------------------------------------
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);
	if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT) +ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0)
	{
		AddScore(ObjEnemyBossScene_GetInfo(objScene,INFO_SPELL_SCORE));
	}
	loop(30)
	{
		DeleteShotAll(TYPE_ALL, TYPE_IMMEDIATE);
		yield;
	}

	CloseScript(GetOwnScriptID());
}
