#TouhouDanmakufu[Plural]
#ScriptVersion[3]
#System["./../../system/Default_System.txt"]

#include "./../../system/functions/functions_world.txt"

let BossScene;
let MBossScene;
let EnmS = false;
let effectS = true;

@Event
{
	alternative(GetEventType())

		case(EV_PAUSE_ENTER)
			{
			PauseMusic;
			}
		case(EV_PAUSE_LEAVE)
			{
			ResumeMusic;
			}
		case(EV_PLAYER_DIE)
			{
			let shot = CreateShotA1(GetPlayerX,GetPlayerY,0,0,BUBBLE[SHOT_RED],0);
			Obj_SetValue(shot,"IS_BROKEN",true);
			Obj_SetVisible(shot,false);
			Obj_DelayDelete(shot,2);
			}
		case(EV_DEL_SHOT)
			{	
			let n = GetEventArgument(0);
			TDelShot(n[0],n[1]);
			}

}

task TMain
{
	yield;
	LoadBoss;
	SetCommonData("BGM_START",false);
	let Back = LoadScript(GetCurrentScriptDirectory ~ "boss/Background.txt");
	StartScript(Back);

	PlayMusic("bgm_Stage");
	loop(1)
		{
		let Enemy = LoadScript(GetCurrentScriptDirectory ~ "Enemy.txt");
		StartScript(Enemy);	
		loop(20){yield;}
		while(!IsCloseScript(Enemy)){yield;}
		Obj_Delete(Enemy);
		}

	ObjEnemyBossScene_Regist(BossScene);
	loop(1)
		{
		while(Obj_GetValueD(GetPlayerObjectID,"BGM_PLAY",true) == true){yield;}
		EndCurrentMusic;
		loop(120){yield;}
		while(Obj_GetValueD(GetPlayerObjectID,"BGM_PLAY",true) == false){yield;}
		}
	EndCurrentMusic;
	PlayMusic("bgm_Boss");
	while(!Obj_IsDeleted(BossScene)){yield;}

	effectS = false;
	SetCommonData("BACKGROUND_END",2);
	SetForbidPlayerShot(true);
	SetForbidPlayerSpell(true);
	loop(150){yield;}
	EndCurrentMusic;
	CloseScript(Back);
	CloseStgScene;
}
task LoadBoss
{
	BossScene = ObjEnemyBossScene_Create();
	let path = GetCurrentScriptDirectory ~ "boss/";
	ObjEnemyBossScene_Add(BossScene, 0, path ~ "Init.txt");
	ObjEnemyBossScene_Add(BossScene, 0, path ~ "Base1.txt");
	ObjEnemyBossScene_Add(BossScene, 0, path ~ "Spell1.txt");
	ObjEnemyBossScene_Add(BossScene, 1, path ~ "Base2.txt");
	ObjEnemyBossScene_Add(BossScene, 1, path ~ "Spell2.txt");
	ObjEnemyBossScene_Add(BossScene, 2, path ~ "Base3.txt");
	ObjEnemyBossScene_Add(BossScene, 2, path ~ "Spell3.txt");
	ObjEnemyBossScene_Add(BossScene, 3, path ~ "Base4.txt");
	ObjEnemyBossScene_Add(BossScene, 3, path ~ "Spell4.txt");
	ObjEnemyBossScene_Add(BossScene, 4, path ~ "Spell5.txt");
	ObjEnemyBossScene_Add(BossScene, 4, path ~ "End.txt");
	ObjEnemyBossScene_LoadInThread(BossScene);
}
task TDelShot(x,y)
{
	ascent(t in 0..60)
		{
		let array = GetShotIdInCircleA2(x,y,t*GetStgFrameHeight*1.5/60,TARGET_ENEMY);
		ascent(i in 0..length(array))
			{
			let shot = array[i];
			if(Obj_GetValueD(shot,"DELETED",false) == false)
				{
				Obj_SetValue(shot,"DELETED",true);
				ObjShot_SetDelay(shot,7);
				Obj_DelayDelete(shot,6);	
				}
			}
		yield;
		}
}