	let csd = GetCurrentScriptDirectory;

	SetRateScoreSystemEnable(false);
	SetDefaultStatusVisible(false);
//////////////////ハイスコア名前空間///////////////////////////////////////////////
	let Player1Hiscore=[];
	let Player1AllPhoto=[];
	let Player1HiPhoto=[];
	let Player1FirstClearPhoto=[];
	let Player1Challenge=[];
	let Player1FirstClearChallenge=[];

	let Player2Hiscore=[];
	let Player2AllPhoto=[];
	let Player2HiPhoto=[];
	let Player2FirstClearPhoto=[];
	let Player2Challenge=[];
	let Player2FirstClearChallenge=[];

	ascent(let k in 0..100)
	{
		Player1Hiscore = Player1Hiscore ~ [k];
		Player1AllPhoto = Player1AllPhoto ~ [100+k];
		Player1HiPhoto=Player1HiPhoto ~ [10000+k];
		Player1FirstClearPhoto=Player1FirstClearPhoto ~ [100+k+0.5];
		Player1Challenge=Player1Challenge ~ [1000+k];
		Player1FirstClearChallenge=Player1FirstClearChallenge ~ [1500+k];

		Player2Hiscore = Player2Hiscore ~ [k+0.1];
		Player2AllPhoto = Player2AllPhoto ~ [100+k+0.1];
		Player2HiPhoto=Player2HiPhoto ~ [10000+k+0.1];
		Player2FirstClearPhoto=Player2FirstClearPhoto ~ [100+k+0.6];
		Player2Challenge=Player2Challenge ~ [1000+k+0.1];
		Player2FirstClearChallenge=Player2FirstClearChallenge ~ [1500+k+0.1];
	}

	let SpellCardScScript=[];
	loop(101)
	{
		SpellCardScScript=SpellCardScScript~[csd~"SpellCard\None.txt"];
	}

		let ShootFlag=[];
		let FlagLevelNum=[];
		loop(20)
		{
			ShootFlag=ShootFlag~[false];
			FlagLevelNum=FlagLevelNum~[3];
		}

	let TopicAya=[];
	let TopicHatate=[];
	ascent(let i in 0..100)
	{
		TopicAya=TopicAya ~ ["十分な写真が撮れたわ\n後は記事を書くだけね"];
		TopicHatate=TopicHatate ~ ["十分な写真が撮れたね\n後は記事を書くだけよ"];
	}

	let SpellNorma=[];
	ascent(let i in 0..100)
	{
		SpellNorma=SpellNorma ~ [50000];
	}

/////////////////////////////////////////////////////////////////////////////////

///////////プレイ回数部///////////////////////////////////////////////////////////
let NsUpTime = "UP_TIME";
let NsPlayTime = "PLAY_TIME";
//////////////////////////////////////////////////////////////////////////////////////////


// w フレームだけ待つ
function wait(w) 
{
    loop(w) { yield; }
}

function WaitForZeroEnemy()//敵数が0になるまで待機する関数
{
	while(GetEnemyNum() != 0){yield;}
}

///////////////////////////////////////////////////////////////////////////////////////////
	let imgLetter =csd ~ "img/border.png"; 
	let DefinedPlayer1="AYA.txt";
	let DefinedPlayer2="HATATE.txt";
/*	let DefinedPlayer3="MarisaA.txt";
	let DefinedPlayer4="MarisaB.txt";
	let DefinedPlayer5="USER_PLAYER";
*/
/*	let DrawDefinedPlayer1="博麗霊夢　A";
	let DrawDefinedPlayer2="博麗霊夢　B";
	let DrawDefinedPlayer3="霧雨魔理沙　A";
	let DrawDefinedPlayer4="霧雨魔理沙　B";
*/
	let SelectedCharacter=GetPlayerScriptName;

////////////////////////////////////////////////////////////////////////////////////////////

//スコアのセーブファイル

let savePathstage = GetCurrentScriptDirectory~"SaveData.dat";//ステージで読み込む
let savePath = GetCurrentScriptDirectory~"SaveData.dat";//スペルで読み込む

/////////////////////////////////////////////////////////////////////////////////////////////
//名前空間
let NsScore = "SAVE_SCORE";	//スコア
let NsHi = "HI_SCORE";	//ハイスコア(NsScore)
let isScore = IsCommonDataAreaExists(NsScore);
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////

let NsGetSpell = "GET_SPELL";	//スペカ取得枚数(Common)
let NsIsReplay = "IS_REPLAY";	//リプレイかどうかセーブ関係(Common)
let NsIsReplayJudgment = "IS_REPLAY_JUDGMENT";//リプレイかどうかリトライ関係(Common)	

let NsDefeatFrame = "DEFEAT_FRAME";	//撃破フレーム(Common)
let NsDefeatPosX = "DEFEAT_POSX";	//撃破位置(Common)
let NsDefeatPosY = "DEFEAT_POSY";	//撃破位置(Common)
let NsBossFrame = "BOSS_FRAME";	//ボス攻撃開始からのフレーム(Common)

///////////////////////////////////////////////////////////////////////////////////////////////

//ボス再生に使用するコモンエリアのロード
function LoadBossAreas()
{
	CreateCommonDataArea(NsScore);
	LoadCommonDataEx(NsScore,savePath);
	SetCommonData(NsGetSpell,0);
	let isRep = IsReplay();
	SetCommonData(NsIsReplay,isRep);
}



//ボス再生に使用するコモンエリアのセーブ、削除
function DeleteBossAreas()
{
	if(GetCommonDataDefault(NsIsReplay,true) == false)
	{
		SaveCommonDataEx(NsScore,savePath);
	}
	ClearCommonDataEx(NsScore);
	DeleteCommonData(NsGetSpell);
	DeleteCommonData(NsDefeatFrame);
	DeleteCommonData(NsDefeatPosX);
	DeleteCommonData(NsDefeatPosY);
	DeleteCommonData(NsBossFrame);
	DeleteCommonData(NsIsReplay);
}


	function NumToString(let num)
	{
		if(num==0)
		{
			num=0.1;
		}
		let leng = trunc(log10(num))+1;//整数部分の桁数を求める
		let string = ToString(num);//数字を文字列に変える
		let str = " ";
			times(12-leng)
			{
				string = str ~ string;//桁揃え用のスペースを先頭につける。
			} 
		return string[0..12];//文字列をスライシングして返す
	}

	function NumToStringNoComplete(let num)
	{
		if(num==0)
		{
			num=0.1;
		}
		let leng = trunc(log10(num))+1;//整数部分の桁数を求める
		let string = ToString(num);//数字を文字列に変える
		return string[0..leng];//文字列をスライシングして返す
	}

////////////////////////////////////////////////////////////////////////////////////////////
task DisPlayNumber(let x,let y,let number,let number2)
{
let num=[];
ascent(let k in 0..11)
{
num = num ~ [k];
}
	num[0]=trunc(number);
	num[1]=trunc(number%10);
	num[2]=trunc(number%100/10);
	num[3]=trunc(number%1000/100);
	num[4]=trunc(number%10000/1000);
	num[5]=trunc(number%100000/10000);
	num[6]=trunc(number%1000000/100000);
	num[7]=trunc(number%10000000/1000000);
	num[8]=trunc(number%100000000/10000000);
	num[9]=trunc(number%1000000000/100000000);
	num[10]=trunc(number%10000000000/1000000000);


	ascent(let i in 1..10)
	{
		if(num[0]>=10^(i-1))
		{
			DisplayNumLetter2(x-(i-1)*7,y,num[i],255,255,255,155,250,255);
		}
	}
	if(num[0]==0)
	{
		DisplayNumLetter2(x-1,y,0,255,255,255,155,250,255);
	}
}

task DisPlayScoreNumber(let x,let y,let number,let number2)
{
if(number2!=0)
{
	number+=1000000;
}
let num=[];
ascent(let k in 0..11)
{
num = num ~ [k];
}
	num[0]=trunc(number);
	num[1]=trunc(number%10);
	num[2]=trunc(number%100/10);
	num[3]=trunc(number%1000/100);
	num[4]=trunc(number%10000/1000);
	num[5]=trunc(number%100000/10000);
	num[6]=trunc(number%1000000/100000);
	num[7]=trunc(number%10000000/1000000);
	num[8]=trunc(number%100000000/10000000);
	num[9]=trunc(number%1000000000/100000000);
	num[10]=trunc(number%10000000000/1000000000);


	ascent(let i in 1..10)
	{
		if(num[0]>=10^(i-1))
		{
			DisplayNumLetter(x-(i-1)*12,y,num[i],255,255,255,255,255,255);
		}
	}
	if(num[0]==0)
	{
		DisplayNumLetter(x,y,0,255,255,255,255,255,255);
	}
}

task DisPlayScoreNumber2(let x,let y,let number,let number2)
{
let num=[];
ascent(let k in 0..11)
{
num = num ~ [k];
}
	num[0]=trunc(number);
	num[1]=trunc(number%10);
	num[2]=trunc(number%100/10);
	num[3]=trunc(number%1000/100);
	num[4]=trunc(number%10000/1000);
	num[5]=trunc(number%100000/10000);
	num[6]=trunc(number%1000000/100000);
	num[7]=trunc(number%10000000/1000000);
	num[8]=trunc(number%100000000/10000000);
	num[9]=trunc(number%1000000000/100000000);
	num[10]=trunc(number%10000000000/1000000000);


	ascent(let i in 1..10)
	{
		if(num[0]>=10^(i-1))
		{
			DisplayNumLetter(x-(i-1)*12,y,num[i],255,255,255,255,255,255);
		}
	}
	if(num[0]==0)
	{
		//DisplayNumLetter(x,y,0,255,255,255,255,255,255);
	}
}

task DisplayNumLetter(let x,let y,let num,UR,UG,UB,DR,DG,DB)
{
		let scx=0.8;
		let scy=1;
		let obj0 = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj0,imgLetter);
		ObjEffect_SetPrimitiveType(obj0, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj0, ADD); 
		ObjEffect_CreateVertex(obj0, 4);
		ObjEffect_SetVertexXY(obj0, 0, -7, -8);
		ObjEffect_SetVertexXY(obj0, 1, 7,  -8);
		ObjEffect_SetVertexXY(obj0, 2, 7, 8);
		ObjEffect_SetVertexXY(obj0, 3,  -7,  8);
		
		ObjEffect_SetVertexUV(obj0, 0,  2+14*num,  114);
		ObjEffect_SetVertexUV(obj0, 1,  14+14*num, 114);
		ObjEffect_SetVertexUV(obj0, 2, 14+14*num,  131);
		ObjEffect_SetVertexUV(obj0, 3, 2+14*num, 131);
		
		ObjEffect_SetScale(obj0, scx,scy);
		Obj_SetPosition(obj0,x,y);
		ObjEffect_SetLayer(obj0,8);
			if(GetCommonDataDefault("Shooting",false)==true)
			{
				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj0,i,0,255,255,255);
				}
			}
			if(GetPlayerY<=GetCenterY/3)
			{
				ascent(let i in 0..4)
				{
				ObjEffect_SetVertexColor(obj0,i,50,255,255,255);
				}
			}
		wait(1);
		Obj_Delete(obj0);
}


task DisplayNumLetter2(let x,let y,let num,UR,UG,UB,DR,DG,DB)
{
		let scx=0.5;
		let scy=0.7;
		let obj0 = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj0,imgLetter);
		ObjEffect_SetPrimitiveType(obj0, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj0, ADD); 
		ObjEffect_CreateVertex(obj0, 4);
		ObjEffect_SetVertexXY(obj0, 0, -7, -8);
		ObjEffect_SetVertexXY(obj0, 1, 7,  -8);
		ObjEffect_SetVertexXY(obj0, 2, 7, 8);
		ObjEffect_SetVertexXY(obj0, 3,  -7,  8);
		
		ObjEffect_SetVertexUV(obj0, 0,  2+14*num,  114);
		ObjEffect_SetVertexUV(obj0, 1,  14+14*num, 114);
		ObjEffect_SetVertexUV(obj0, 2, 14+14*num,  131);
		ObjEffect_SetVertexUV(obj0, 3, 2+14*num, 131);
		
		ObjEffect_SetScale(obj0, scx,scy);
		Obj_SetPosition(obj0,x,y);
		ObjEffect_SetLayer(obj0,8);

				ObjEffect_SetVertexColor(obj0,0,255,UR,UG,UB);
				ObjEffect_SetVertexColor(obj0,1,255,UR,UG,UB);
				ObjEffect_SetVertexColor(obj0,2,255,DR,DG,DB);
				ObjEffect_SetVertexColor(obj0,3,255,DR,DG,DB);
		wait(1);
		Obj_Delete(obj0);
}

task BerDisplay(y,Alpha,R,G,B)//resultの/を表示
{
		let scx=0.5;
		let scy=0.5;
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgLetter);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -6, -11);
		ObjEffect_SetVertexXY(obj, 1, 6,  -11);
		ObjEffect_SetVertexXY(obj, 2, 6, 11);
		ObjEffect_SetVertexXY(obj, 3,  -6,  11);
		
		ObjEffect_SetVertexUV(obj, 0,  51,  26);
		ObjEffect_SetVertexUV(obj, 1,  63, 26);
		ObjEffect_SetVertexUV(obj, 2, 63,  48);
		ObjEffect_SetVertexUV(obj, 3, 51, 48);

		ObjEffect_SetVertexColor(obj,0,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,1,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,2,Alpha,R,G,B);
		ObjEffect_SetVertexColor(obj,3,Alpha,R,G,B);

		ObjEffect_SetLayer(obj,7);
		Obj_SetPosition(obj,353,y+5);

		ObjEffect_SetScale(obj, scx,scy);

		yield;
		Obj_Delete(obj);
}

sub ShootFlagTask//次レベルへのノルマ達成したかを判断するタスク
{
let Flag=[];
loop(20)
{
	Flag=Flag~[0];
}
ascent(let j in 2..10)
{
	ascent(let i in 1..10)
	{
	if(SelectedCharacter==DefinedPlayer1)
	{
	if(GetCommonDataDefaultEx(NsScore,Player1Hiscore[i+(j-1)*10],0)!=0)
	{
		Flag[j]=Flag[j]+1;
	}
	}
	if(SelectedCharacter==DefinedPlayer2)
	{
	if(GetCommonDataDefaultEx(NsScore,Player2Hiscore[i+(j-1)*10],0)!=0)
	{
		Flag[j]=Flag[j]+1;
	}
	}
	}
}

ascent(let i in 1..20)
{
	if(Flag[i]>=FlagLevelNum[i])
	{
		ShootFlag[i]=true;
	}
}
}

function AllScore
{
let num=0;
ascent(let i in 0..100)
{
	if(GetCommonDataDefaultEx(NsScore,Player1Hiscore[i],0)!=0)
	{
	num+=GetCommonDataDefaultEx(NsScore,Player1Hiscore[i],0);
	}
}
return(num);
}

function AllSceneNum
{
let num=0;
ascent(let i in 0..100)
{
	if(SpellCardScScript[i]!=SpellCardScScript[0])
	{
	num+=1;
	}
}
return(num);
}

function SuccessSceneNum
{
let num=0;
ascent(let i in 0..100)
{
	if(SelectedCharacter==DefinedPlayer1)
	{
		if(GetCommonDataDefaultEx(NsScore,Player1Hiscore[i],0)!=0)
		{
			num+=1;
		}
	}
	if(SelectedCharacter==DefinedPlayer2)
	{
		if(GetCommonDataDefaultEx(NsScore,Player2Hiscore[i],0)!=0)
		{
			num+=1;
		}
	}
}
return(num);
}

function DrawSentence(let text,let x, let y, let lineSpace, let fontSize,let alpha){

	let leng = length(text)-1;
	let line = 0;
	let lineStart = 0;
	let topicText;

	ascent(i in 0..leng){
		let checkText = text[i..i+2];
		if(checkText == "\n"){
			topicText = text[lineStart..i];
			DrawText(topicText, x, y + (lineSpace * line),fontSize, alpha);
			line ++;
			lineStart = i+2;
		}
	}

	if(lineStart < leng){
		topicText = text[lineStart..length(text)];
		DrawText(topicText, x, y + (lineSpace * line),fontSize,alpha);
	}

}//end function
