#TouhouDanmakufu[Plural]
#ScriptVersion[3]
#Title["Seasoned Alice Boss Fight"]
#Text[""]
#Background["./BG.txt"]
#Player["./player/Ultima's DDC Reimu B/ReimuH.dnh", "./player/gt_medicine/PracticeP.txt"]
#System["./System/Default_System.txt"]

let dir = GetCurrentScriptDirectory();
		
	let bgm = ObjSound_Create;
		ObjSound_Load(bgm, dir ~ "./bgm/Boss.ogg");
		ObjSound_SetRestartEnable(bgm, true);
		ObjSound_SetVolumeRate(bgm, 100);
		ObjSound_SetLoopEnable(bgm, true);
//

@Initialize{
	SetCommonData("Fall", true);
	ObjSound_Play(bgm);
	TPlural;
	SetPlayerLife(5);
	SetPlayerSpell(3);
}

@Event{
	alternative(GetEventType())
	case(EV_PAUSE_ENTER){
		ObjSound_Stop(bgm);
	}
	case(EV_PAUSE_LEAVE){
		ObjSound_Play(bgm);
	}
}

@MainLoop{
	if(GetKeyState(KEY_A) == KEY_HOLD && GetKeyState(KEY_S) == KEY_PUSH){
		SetPlayerInvincibilityFrame(9999999);
	}
	yield;
}

task TPlural{
	BGMName("BGM - Doll Judgement");
	wait(60 * 4);
	
	loop(60){yield;}
	
	ObjSound_Play(bgm);
	
	let obj = ObjEnemyBossScene_Create();
	
	/* ObjEnemyBossScene_Add(obj, 0, dir ~ "./scripts/Non01.txt"); 
	ObjEnemyBossScene_Add(obj, 0, dir ~ "./scripts/Spell01.txt");
	ObjEnemyBossScene_Add(obj, 1, dir ~ "./scripts/Non02.txt"); 
	ObjEnemyBossScene_Add(obj, 1, dir ~ "./scripts/Spell02.txt"); */
	
	ascent(i in 0..4){
		ObjEnemyBossScene_Add(obj, i, dir ~ "./scripts/Non" ~ vtos("02d", i+1) ~ ".txt"); 
		ObjEnemyBossScene_Add(obj, i, dir ~ "./scripts/Spell" ~ vtos("02d", i+1) ~ ".txt"); 
	}
	ObjEnemyBossScene_Add(obj, 5, dir ~ "./scripts/Spell05.txt"); 
	
	ObjEnemyBossScene_LoadInThread(obj);
	ObjEnemyBossScene_Regist(obj);
	
	while(!Obj_IsDeleted(obj)){
		yield;
	}
	
	CloseScript(GetOwnScriptID());
}

task BGMName(text){
	let objText = ObjText_Create();
	ObjText_SetText(objText, text);
	
	ObjText_SetFontSize(objText, 10);
	ObjText_SetFontBold(objText, true);
	ObjText_SetFontColorTop(objText, 255, 255, 255);
	ObjText_SetFontColorBottom(objText, 255, 255, 255);
	ObjText_SetFontBorderType(objText, BORDER_FULL);
	ObjText_SetFontBorderColor(objText, 0, 0, 0);
	ObjText_SetFontBorderWidth(objText, 2);
	
	ObjText_SetMaxWidth(objText, 1337);
	
	Obj_SetRenderPriority(objText, 0.01);
	
	ObjRender_SetX(objText, 31);
	ObjRender_SetY(objText, GetStgFrameHeight+40);
	
	let y = 21;
	loop(30){
		ObjSound_SetRestartEnable(bgm, true);
		//ObjSound_SetRestartEnable(bgm2, true);
		ObjRender_SetY(objText, ObjRender_GetY(objText)-(y/30));
		yield;
	}
	
	wait(60*3);
	
	loop(30){
		ObjRender_SetY(objText, ObjRender_GetY(objText)+(y/30));
		yield;
	}
	
	Obj_Delete(objText);
}

function wait(n){loop(n){yield;}}