#ScriptVersion[3]
#Title["AoPステージ"]
#Text["AoP"]
#System["./../system/System.txt"]

@Initialize
{
	TStage();
}

@MainLoop
{
	yield;
}

@Finalize
{
}


task TStage
{
	if(IsReplay)
	{
		LoadCommonDataAreaFromReplayFile("");
		SetAreaCommonData("TUNING","PlayerCharacter",GetCommonData("PlayerCharacter",0));
	}
	else
	{
		SaveCommonDataAreaToReplayFile("");
	}

	SetPlayerClip(12,16,GetStgFrameWidth-12,GetStgFrameHeight-16);
	let dir = GetCurrentScriptDirectory();

	//ボス再生
	let path = dir ~ "Plural.txt";
	let idScript = LoadScript(path);
	SetPlayerLife(0);
	SetPlayerSpell(0);
//	loop(60){yield;}//1秒くらいあれば、コンパイル完了すると思われる。
	StartScript(idScript);

	//敵ボスシーンが終了するまで待機
	while(!IsCloseScript(idScript) && GetPlayerState() != STATE_END)
	{
		yield;
	}

	//〜〜〜敵の出現やボスの出現を繰り返す。

	if(!IsReplay)
	{
	if(GetAreaCommonData("TUNING","PlayerCharacter",0)==0)
	{
		let array=GetAreaCommonData("SPELL_RECORD","Reimu_Score",[]);
		if(array[GetCommonData("SpellNumber",9)]<GetScore)
		{
		array[GetCommonData("SpellNumber",9)]=GetScore;
		}
		SetAreaCommonData("SPELL_RECORD","Reimu_Score",array);
	}
	else if(GetAreaCommonData("TUNING","PlayerCharacter",0)==1)
	{
		let array=GetAreaCommonData("SPELL_RECORD","Marisa_Score",[]);
		if(array[GetCommonData("SpellNumber",9)]<GetScore)
		{
		array[GetCommonData("SpellNumber",9)]=GetScore;
		}
		SetAreaCommonData("SPELL_RECORD","Marisa_Score",array);
	}
	}

	loop(45){yield;}

    //ステージ終了
	CloseStgScene();
}

