#TouhouDanmakufu[Stage]
#Title["Shou 2"]
#Text["Difficulty: Lukewarm and[r]Slug-ish"]
#ScriptVersion[3]
#System["./default_system/Default_System.txt"]
#include "./default_system/MS_Index.txt"

@Initialize{
SetPlayerLife(3);
SetCommonData("IsStage", true);
SetCommonData("MusicProgress", 0);
STAGE;
StageBackground;
BGM;
}

@MainLoop{
if(GetPlayerState()==STATE_END){
	loop(120){yield;}
	CloseStgScene();
}
yield;
}

@Finalize{}

task BGM{
while(GetCommonData("MusicProgress", 0)==0){yield;}

	let obj	= ObjSound_Create();
	ObjSound_Load(obj,GetCurrentScriptDirectory ~ "Default_System/se/boss.ogg");
	ObjSound_SetSoundDivision(obj,SOUND_BGM);
	ObjSound_SetVolumeRate(obj,80);
	ObjSound_SetLoopEnable(obj,true);
	ObjSound_SetRestartEnable(obj,true);
	ObjSound_SetLoopTime(obj,60+41.221,60*3+20.747);
	ObjSound_Play(obj);
	
while(GetCommonData("MusicProgress", 0)==1){yield;}

let volume = ObjSound_GetVolumeRate(obj);
while(volume>0){
	volume--;
	ObjSound_SetVolumeRate(obj,volume);
	wait(3);
}

}

task DeathSoundLoop{
	loop{
	while(GetCommonData("deathsound",0) < 1){yield;}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/death2.wav", 100);
	SetCommonData("deathsound",0);
	yield;
	}
}

task STAGE{
    let obj=ObjEnemyBossScene_Create();
    ObjEnemyBossScene_Add(obj,0,GetCurrentScriptDirectory ~ "./NS1.txt");
	ObjEnemyBossScene_Add(obj,0,GetCurrentScriptDirectory ~ "./SP1.txt");
    ObjEnemyBossScene_Add(obj,1,GetCurrentScriptDirectory ~ "./NS2.txt");
	ObjEnemyBossScene_Add(obj,1,GetCurrentScriptDirectory ~ "./SP4actually2.txt");
    ObjEnemyBossScene_Add(obj,2,GetCurrentScriptDirectory ~ "./NS3.txt");
	ObjEnemyBossScene_Add(obj,2,GetCurrentScriptDirectory ~ "./SP5actually3.txt");
	ObjEnemyBossScene_Add(obj,3,GetCurrentScriptDirectory ~ "./NS4.txt");
	ObjEnemyBossScene_Add(obj,3,GetCurrentScriptDirectory ~ "./SP2.txt");
	ObjEnemyBossScene_Add(obj,4,GetCurrentScriptDirectory ~ "./SP3.txt");
	ObjEnemyBossScene_Add(obj,5,GetCurrentScriptDirectory ~ "./SP6.txt");
    ObjEnemyBossScene_LoadInThread(obj);
	ObjEnemyBossScene_Regist(obj);
	TimerCountdown(obj);
	DeathSoundLoop;
	
    while(!Obj_IsDeleted(obj)){
        yield;
    }
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/death.wav", 100);
	SetCommonData("MusicProgress", 2);
	
	wait(60*5);
	CloseStgScene;
}