	let csd				= GetCurrentScriptDirectory();
	let LAST_SPELL		= false;
	
	#include"../../system/Load_AllTexture.dnh"
	
@Initialize{
	SetAutoDeleteObject(true);

	TBackground();
	TSpellSelectStageScene();

	SetAreaCommonData("Score","high_score",0);
	SetScriptResult("");
}

@MainLoop{
	yield;
}

@Finalize{
	PlaySEsP(csd~"../se/menucancel.wav");
}

task PlaySEsP(se){
	let sid		= ObjSound_Create;
	let SE		= GetAreaCommonData("Option","SE_Volume",100);
	
	ObjSound_Load(sid,se);
	ObjSound_SetVolumeRate(sid,SE);
	ObjSound_SetLoopEnable(sid,false);
	ObjSound_Play(sid);
	loop(180){yield;}
	Obj_Delete(sid);
}

task TBackground(){
	//攚宨
	let csd 	= GetCurrentScriptDirectory();
	let alpha1	= 0;
	let alphaA	= 0;
	let alpha2	= 0;
	let alphaB	= 0;
	let alpha3	= 0;
	let alphaC	= 0;
	let move1	= 0;
	let moveA	= 0;
	let move2	= 0;
	let moveB	= 0;
	let move3	= 0;
	let moveC	= 0;
	let flg		= 0;
	let ctr		= 0;
	let Ssector	= GetAreaCommonData("System","S_sector",0);
	let eflg	= GetAreaCommonData("System","title_end",false);
	let ssp		= GetCommonData("SetSpellPlacticeFrag", false );

	let objImage = ObjPrim_Create(OBJ_SPRITE_2D); //2D僗僾儔僀僩僆僽僕僃僋僩惗惉
	Obj_SetRenderPriorityI(objImage, 33); //昤夋桪愭搙傪愝掕
	ObjPrim_SetTexture(objImage, csd~"../img/title/title01_d.png"); //僥僋僗僠儍傪愝掕
	ObjSprite2D_SetSourceRect(objImage, 0, 0, 640, 480);
	ObjSprite2D_SetDestRect(objImage, 0, 0, 640, 480);
	ObjRender_SetAlpha(objImage, alpha1);
	
	let objText = ObjPrim_Create(OBJ_SPRITE_2D); //2D僗僾儔僀僩僆僽僕僃僋僩惗惉
	ObjRender_SetPosition(objText,0,0,0);
	Obj_SetRenderPriorityI(objText, 34); //昤夋桪愭搙傪愝掕
	ObjPrim_SetTexture(objText, csd~"../img/title/sl01.png"); //僥僋僗僠儍傪愝掕
	ObjSprite2D_SetSourceRect(objText, 0, 128*2, 256, 128*3);
	ObjSprite2D_SetDestRect(objText, 0, 0, 256, 128);
	ObjRender_SetAlpha(objText, alpha1);
	
	let objText2 = ObjPrim_Create(OBJ_SPRITE_2D); //2D僗僾儔僀僩僆僽僕僃僋僩惗惉
	ObjRender_SetPosition(objText2,0,0,0);
	Obj_SetRenderPriorityI(objText2, 34); //昤夋桪愭搙傪愝掕
	ObjPrim_SetTexture(objText2, csd~"../img/title/sl01.png"); //僥僋僗僠儍傪愝掕
	ObjSprite2D_SetSourceRect(objText2, 0, 128*4, 256, 128*5);
	ObjSprite2D_SetDestRect(objText2, 0, 0, 256, 128);
	ObjRender_SetAlpha(objText2, alpha2);
	
	let objWindw = ObjPrim_Create(OBJ_SPRITE_2D); //2D僗僾儔僀僩僆僽僕僃僋僩惗惉
	ObjRender_SetPosition(objWindw,320,410,0);
	Obj_SetRenderPriorityI(objWindw, 35); //昤夋桪愭搙傪愝掕
	ObjPrim_SetTexture(objWindw, csd~"../img/title/white.png"); //僥僋僗僠儍傪愝掕
	ObjSprite2D_SetSourceRect(objWindw, 0, 0, 590, 120);
	ObjSprite2D_SetDestCenter(objWindw);
	ObjRender_SetColor(objWindw,0,0,0);
	ObjRender_SetAlpha(objWindw, alpha1);
	
	while(alpha1<255 && eflg==false){
		eflg	= GetAreaCommonData("System","title_end",false);
		alphaA+=5;
		alpha1=255*sin(alphaA);
		ObjRender_SetAlpha(objImage, alpha1);
		ObjRender_SetAlpha(objText, alpha1);
		ObjRender_SetAlpha(objWindw, alpha1/1.5);
		yield;
	}
	while(Ssector!=3 && eflg==false){
		eflg	= GetAreaCommonData("System","title_end",false);
		Ssector	= GetAreaCommonData("System","S_sector",0);
		ssp		= GetCommonData("SetSpellPlacticeFrag", false );
		ctr++;
		
		//僗僥乕僕慖戰仺僞僀僩儖傊栠傞帪偺僉儍儞僙儖
		if(Ssector==0&&ctr>1&&GetVirtualKeyState(VK_CANCEL)==KEY_PULL){
			SetAreaCommonData("System","S_sector",3);
			break;
		}
		if(Ssector==0){
			move1=0;
			moveA=0;
			move2=0;
			moveB=0;
			move3=0;
			moveC=0;
			alpha2=0;
			alphaB=0;
		}
		else if(Ssector==1){
			if( !ssp ){
				if(move1<256){moveA+=5;}
				move1=256*sin(moveA);
				move3=0;
				moveC=0;
				ObjRender_SetX(objText, -move1);
				ObjRender_SetX(objText2, -move3);
				if(alpha2<255){alphaB+=5;}
				alpha2=255*sin(alphaB);
				ObjRender_SetAlpha(objText2, alpha2);
				ObjRender_SetAlpha(objWindw, 255/1.5);
			}
			else{
				move1 = 256;
				move3 = 0;
				moveC = 0;
				ObjRender_SetX(objText, -move1);
				ObjRender_SetX(objText2, -move3);
				alpha2 = 255;
				ObjRender_SetAlpha(objText2, alpha2);
				ObjRender_SetAlpha(objWindw, 255/1.5);
			}
		}
		else if(Ssector==2){
			if(move2>=256){
				SetAreaCommonData("System","S_sector",0);
			}
			if(move2<256){moveB+=5;}
			move2=256*sin(moveB);
			ObjRender_SetX(objText, -move1+move2);
			if(alpha2>0){alphaB+=10;}
			alpha2=255*sin(alphaB);
			ObjRender_SetAlpha(objText2, alpha2);
		}
		else if(Ssector==4){
			if(move3<256){moveC+=5;}
			move3=256*sin(moveC);
			ObjRender_SetX(objText2, -move3);
			ObjRender_SetAlpha(objWindw, 255/1.5-(move3-1)/1.5);
		}
		yield;
	}
	while(alpha1>0 && eflg==false){
		eflg	= GetAreaCommonData("System","title_end",false);
		alphaA+=5;
		alpha1=255*sin(alphaA);
		ObjRender_SetAlpha(objImage, alpha1);
		ObjRender_SetAlpha(objText, alpha1);
		ObjRender_SetAlpha(objWindw, alpha1/1.5);
		yield;
	}
	SetAreaCommonData("System","S_sector",0);
	SetAreaCommonData("System","R_sector",0);
	SetAreaCommonData("System","select",0);
	SetAreaCommonData("System","select2",0);
	CloseScript(GetOwnScriptID());
}
//----------------------------------------------------
// 僗僥乕僕慖戰
//----------------------------------------------------
task TSpellSelectStageScene{
	let csd 	= GetCurrentScriptDirectory();
	let ctr		= 0;
	let ctr2	= 0;
	let cc		= 0;
	let stc		= GetCommonData("SelectPlace2", 0);
	let i		= 0;
	let j1		= 0;
	let j2		= 0;
	let j3		= 0;
	let escape	= 0;
	let Ssector	= GetAreaCommonData("System","S_sector",0);
	let sth		= ["STAGE1",
					"STAGE2",
					"STAGE3",
					"STAGE4",
					"STAGE5",
					"STAGE6",
					"EXTRA",
					"Hidden SpellCard"];
	let spR		= [0,0,0,0,0,0,0,0,0];//僗僥乕僕枅偺夝曻棪丂彮悢愗幪偰
	let spG		= [0,0,0,0,0,0,0,0,0];//僗僥乕僕枅偺庢摼棪
	let spA		= 0;//慡懱僋儕傾棪丂彫悢愗幪偰
	let Release	= 7;//夝曻儗儀儖 stage-1
	let eflg	= GetAreaCommonData("System","title_end",false);
	let ssp		= GetCommonData("SetSpellPlacticeFrag", false );

	//丂夝曻棪偺寁嶼
	let history	= [GetAreaCommonData("spell_counter","play_stage1",0),
					GetAreaCommonData("spell_counter","play_stage2",0),
					GetAreaCommonData("spell_counter","play_stage3",0),
					GetAreaCommonData("spell_counter","play_stage4",0),
					GetAreaCommonData("spell_counter","play_stage5",0),
					GetAreaCommonData("spell_counter","play_stage6",0),
					GetAreaCommonData("spell_counter","play_stage7",0),
					GetAreaCommonData("spell_counter","play_stage8",0),
					GetAreaCommonData("spell_counter","play_stage8",0)
					];
	
	//丂僗僥乕僕暿
	loop( length(spR) ){
		loop( length(history[i]) ){
			if( history[i][j1] > 0 ){ j2++; }
			j1++;
		}
		if( i == 2 ){
			spR[i]	= j2 / ( length(history[i]) - 4 )*100;
		}
		else if( i == 7 ){
			spR[i]	= j2 / ( length(history[i]) - 1 )*100;
		}
		else{
			spR[i]	= j2 / length(history[i])*100;
		}
		j1		= 0;
		j2		= 0;
		i++;
	}
	i	= 0;
	j1	= 0;
	j2	= 0;
	
	//丂摑寁
	loop( length(spR) - 1 ){
		if( spR[i] >= 100 ){ j1++; }
		i++;
	}
	spA = j1 / ( length(spR) - 1 ) * 100;
	i	= 0;
	
	if( spR[6] >= 100 ){ LAST_SPELL = true; }
	
	while( !eflg ){
		eflg	= GetAreaCommonData("System","title_end",false);
		Ssector	= GetAreaCommonData("System","S_sector",0);
		ssp		= GetCommonData("SetSpellPlacticeFrag", false );
		if(Ssector==0){
			ctr++;
			if(ctr==1){
				SetAreaCommonData("System","select",stc);
				loop(Release+1){
					_DrawText(180,60+24*i,255,255,255,i,sth[i],16,1);
					i++;
				}
				i=0;
				cc=0;
				
				let get_r = "此Stage的SpellCard解放率";
				get_r = get_r ~ vtos("3d",spR[stc]) ~ "%";
				_DrawText2(40,310+48,32,255,255,443,get_r,12);
				
				let get_c = "     总计SpellCard解放率";
				get_c = get_c ~ vtos("3d",spA) ~ "%";
				_DrawText2(40,330+48,255,255,32,443,get_c,12);
				if( spA >= 100 ){
					_DrawText3(316,328+32,255,255,255,443,"全部SpellCard已解放，恭喜",14);
				}
			}
			
			if( ssp ){
				ctr=0;
				SetAreaCommonData("System","select2",1);
				SetAreaCommonData("System","S_sector",1);
				TSpellSelectSpellScene(stc+1);
			}
			
			if( ctr > 1 && GetVirtualKeyState( VK_UP ) == KEY_PUSH ){
				stc--;
				if( stc < 0 ){ stc = Release; }
				ctr = 0;
				SetSelectPlace2(stc);
				SetSelectPlace3([0,0]);
				SetAreaCommonData("System","select",stc);
				PlaySEsP(csd~"../se/menuselect.wav");
			}
			if( ctr > 1 && GetVirtualKeyState( VK_DOWN ) == KEY_PUSH ){
				stc++;
				if( stc > Release ){ stc = 0; }
				ctr = 0;
				SetSelectPlace2(stc);
				SetSelectPlace3([0,0]);
				SetAreaCommonData("System","select",stc);
				PlaySEsP(csd~"../se/menuselect.wav");
			}
			if( ctr > 6 && GetVirtualKeyState( VK_OK ) == KEY_PULL ){
				ctr = 0;
				SetAreaCommonData("System","select2",1);
				SetAreaCommonData("System","S_sector",1);
				TSpellSelectSpellScene(stc+1);
				PlaySEsP(csd~"../se/menudecide.wav");
			}
			//丂挿墴偟偱憹尭
			if( GetVirtualKeyState( VK_UP ) == KEY_HOLD ){
				ctr2++;
				if( ctr2 >= 30 && ctr2 %6 == 0 ){
					stc--;
					if(stc<0){stc=Release;}
					ctr=0;
					SetSelectPlace2(stc);
					SetSelectPlace3([0,0]);
					SetAreaCommonData("System","select",stc);
					PlaySEsP(csd~"../se/menuselect.wav");
				}
			}
			else if( GetVirtualKeyState( VK_DOWN ) == KEY_HOLD ){
				ctr2++;
				if( ctr2 >= 30 && ctr2 %6 == 0 ){
					stc++;
					if(stc>Release){stc=0;}
					ctr=0;
					SetSelectPlace2(stc);
					SetSelectPlace3([0,0]);
					SetAreaCommonData("System","select",stc);
					PlaySEsP(csd~"../se/menuselect.wav");
				}
			}
			else{
				ctr2	= 0;
			}
		}
		else if( Ssector == 4 ){
			ctr++;
			if( ctr > 1 && GetVirtualKeyState(VK_CANCEL) == KEY_PULL ){
				ctr = 0;
				SetAreaCommonData("System", "S_sector", 1 );
				SetAreaCommonData("System", "R_sector", 2 );
			}
		}
		yield;
	}
}
//----------------------------------------------------
// 僗儁僇慖戰
//----------------------------------------------------
task TSpellSelectSpellScene(type){
	let csd 	= GetCurrentScriptDirectory();
	let ctr		= 0;
	let ctr2	= 0;
	let ctrx	= 0;
	let cc		= 0;
	let stcC	= GetCommonData("SelectPlace3",[0,0]);
	let stcx	= stcC[0];
	let stcy	= stcC[1];
	let i		= 0;
	let escape	= 0;
	let Ssector	= GetAreaCommonData("System","S_sector",0);
	let play_spell;
	let get_spell;
	let INDEX_ListMax;	//丂儁乕僕悢嵟戝抣
	let snh;			//丂spell柤
	let noh;			//丂僫儞僶乕
	let dih;			//丂擄堈搙
	let sch;			//丂僐儊儞僩
	let sth;			//丂棫偪奊
	let eflg	= GetAreaCommonData("System","title_end",false);
	
	//攝楍傪include
	#include"./SpellName_mpp.dnh"
	#include"./SpellNameComment_mpp.dnh"
	
	alternative(type)
	case(1){
		INDEX_ListMax = 1;
		snh=snpath1;
		noh=nopath1;
		dih=dipath1;
		sch=scpath1;
		sth=stpath1;
		SetAreaCommonData("System","stg_ST",1);
	}
	case(2){
		INDEX_ListMax = 1;
		snh=snpath2;
		noh=nopath2;
		dih=dipath2;
		sch=scpath2;
		sth=stpath2;
		SetAreaCommonData("System","stg_ST",2);
	}
	case(3){
		INDEX_ListMax = 1;
		snh=snpath3;
		noh=nopath3;
		dih=dipath3;
		sch=scpath3;
		sth=stpath3;
		SetAreaCommonData("System","stg_ST",3);
	}
	case(4){
		INDEX_ListMax = 1;
		snh=snpath4;
		noh=nopath4;
		dih=dipath4;
		sch=scpath4;
		sth=stpath4;
		SetAreaCommonData("System","stg_ST",4);
	}
	case(5){
		INDEX_ListMax = 1;
		snh=snpath5;
		noh=nopath5;
		dih=dipath5;
		sch=scpath5;
		sth=stpath5;
		SetAreaCommonData("System","stg_ST",5);
	}
	case(6){
		INDEX_ListMax = 2;
		snh=snpath6;
		noh=nopath6;
		dih=dipath6;
		sch=scpath6;
		sth=stpath6;
		SetAreaCommonData("System","stg_ST",6);
	}
	case(7){
		INDEX_ListMax = 1;
		snh=snpath7;
		noh=nopath7;
		dih=dipath7;
		sch=scpath7;
		sth=stpath7;
		SetAreaCommonData("System","stg_ST",7);
	}
	case(8){
		INDEX_ListMax = 4;
		snh=snpath8;
		noh=nopath8;
		dih=dipath8;
		sch=scpath8;
		sth=stpath8;
		SetAreaCommonData("System","stg_ST",8);
	}
	
	CreateCommonDataArea("spell_counter");
	LoadCommonDataAreaA1("spell_counter");
	SetAreaCommonData("System","select",stcy);
	SetAreaCommonData("System","select2",stcx);
	
	while( !eflg ){
		eflg	= GetAreaCommonData("System","title_end",false);
		Ssector	= GetAreaCommonData("System","S_sector",0);
		if( Ssector == 1 ){
			ctr++;
			ctrx++;
			if( ctr == 1 ){
				alternative(type)
				case(1){
					play_spell	= GetAreaCommonData("spell_counter","play_stage1",0);
					get_spell	= GetAreaCommonData("spell_counter","get_stage1",0);
				}
				case(2){
					play_spell	= GetAreaCommonData("spell_counter","play_stage2",0);
					get_spell	= GetAreaCommonData("spell_counter","get_stage2",0);
				}
				case(3){
					play_spell	= GetAreaCommonData("spell_counter","play_stage3",0);
					get_spell	= GetAreaCommonData("spell_counter","get_stage3",0);
				}
				case(4){
					play_spell	= GetAreaCommonData("spell_counter","play_stage4",0);
					get_spell	= GetAreaCommonData("spell_counter","get_stage4",0);
				}
				case(5){
					play_spell	= GetAreaCommonData("spell_counter","play_stage5",0);
					get_spell	= GetAreaCommonData("spell_counter","get_stage5",0);
				}
				case(6){
					play_spell	= GetAreaCommonData("spell_counter","play_stage6",0);
					get_spell	= GetAreaCommonData("spell_counter","get_stage6",0);
				}
				case(7){
					play_spell	= GetAreaCommonData("spell_counter","play_stage7",0);
					get_spell	= GetAreaCommonData("spell_counter","get_stage7",0);
				}
				case(8){
					play_spell	= GetAreaCommonData("spell_counter","play_stage8",0);
					get_spell	= GetAreaCommonData("spell_counter","get_stage8",0);
				}
				
				loop( length(snh) - stcx*12 ){
					if( cc >= 12 ){ break; }
					cc++;
				}
				escape=cc-1;
				loop( cc ){
					DrawText(180,60+24*i,255,255,255,i,snh[stcx*12+i],14,play_spell[stcx*12+i]);
					i++;
				}
				i = 0;
				cc = 0;
				DrawTexture([160,320],[1,1],sth[stcx*12+stcy],play_spell[stcx*12+stcy]);
				DrawText2(44,365,255,255,255,i,noh[stcx*12+stcy],15);
				if( play_spell[stcx*12+stcy] == 0 ){
					//丂枹僾儗僀側傜丠傪昞帵
					DrawText2(128,365,255,255,255,i,"？？？？？？？？",15);
				}
				else{
					DrawText2(128,365,255,255,255,i,snh[stcx*12+stcy],15);
				}
				
				let get_pnum = "挑戦回数　";
				get_pnum = get_pnum ~ IntToString(play_spell[stcx*12+stcy]);
				DrawText2(44,385,32,255,255,0,get_pnum,12);
				
				let get_gnum = "取得回数　";
				get_gnum = get_gnum ~ IntToString(get_spell[stcx*12+stcy]);
				DrawText2(156,385,255,255,32,0,get_gnum,12);
				
				let get_prob = "取得確率　";
				get_prob = get_prob ~ IntToString(get_spell[stcx*12+stcy]/play_spell[stcx*12+stcy]*100) ~ "%";
				DrawText2(268,385,32,255,32,0,get_prob,12);
				
				let get_diff = "　難易度　";
				get_diff = get_diff ~ dih[stcx*12+stcy];
				DrawText2(380,385,255,32,255,0,get_diff,12);
				SetAreaCommonData("System","擄堈搙",dih[stcx*12+stcy]);
				
				let get_page = "Page";
				get_page = get_page ~ IntToString(stcx+1) ~ "/";
				get_page = get_page ~ IntToString(INDEX_ListMax+1);
				DrawText2(510,30,255,255,255,0,get_page,14);
				
				if( type==6 && stcx==0 && stcy<=1 ){
					//丂旤彮彈
					if( play_spell[stcx*12+stcy] == 0 ){
						DrawText2(44,410,255,255,255,0,"まだ1度も見た事がないよ！",14);
					}
					else{
						DrawText2(44,410,255,255,255,0,sch[stcx*12+stcy],22);
					}
				}
				else{
					if( play_spell[stcx*12+stcy] == 0 ){
						if( type == 8 && stcx == 4 && LAST_SPELL ){
							DrawText2(44,410,255,255,255,0,"挑戦者募集中だってさ",14);
						}
						else{
							DrawText2(44,410,255,255,255,0,"まだ1度も見た事がないよ！",14);
						}
					}
					else{
						DrawText2(44,410,255,255,255,0,sch[stcx*12+stcy],14);
					}
				}
			}
			if(ctrx==1){
				if(stcx<INDEX_ListMax){
					DrawPage(620,40,0.2,255,255,255,stcx,"RIGHT");
				}
				if(stcx>0){
					DrawPage(400,40,0.2,255,255,255,stcx,"LEFT");
				}
			}
			if(ctr>1&&GetVirtualKeyState(VK_UP)==KEY_PUSH){
				stcy--;
				if(stcy<0){stcy=escape;}
				ctr=0;
				SetSelectPlace3([stcx,stcy]);
				SetAreaCommonData("System","select",stcy);
				PlaySEsP(csd~"../se/menuselect.wav");
			}
			if(ctr>1&&GetVirtualKeyState(VK_DOWN)==KEY_PUSH){
				stcy++;
				if(stcy>escape){stcy=0;}
				ctr=0;
				SetSelectPlace3([stcx,stcy]);
				SetAreaCommonData("System","select",stcy);
				PlaySEsP(csd~"../se/menuselect.wav");
			}
			if(stcx>0&&ctr>1&&GetVirtualKeyState(VK_LEFT)==KEY_PUSH){
				stcx--;
				stcy=0;
				ctr=0;
				ctrx=0;
				SetSelectPlace3([stcx,stcy]);
				SetAreaCommonData("System","select",stcy);
				SetAreaCommonData("System","select2",stcx);
				PlaySEsP(csd~"../se/menuselect.wav");
			}
			if(stcx<INDEX_ListMax&&ctr>1&&GetVirtualKeyState(VK_RIGHT)==KEY_PUSH){
				stcx++;
				stcy=0;
				ctr=0;
				ctrx=0;
				SetSelectPlace3([stcx,stcy]);
				SetAreaCommonData("System","select",stcy);
				SetAreaCommonData("System","select2",stcx);
				PlaySEsP(csd~"../se/menuselect.wav");
			}
			if( ctr > 16 && GetVirtualKeyState(VK_CANCEL) == KEY_PULL ){
				SetAreaCommonData("System","S_sector",2);
				SetCommonData("SetSpellPlacticeFrag", false );
				PlaySEsP(csd~"../se/menucancel.wav");
				SetSelectPlace3([0,0]);
				ctr = 0;
				break;
			}
			if( ctr > 16 && GetVirtualKeyState(VK_OK) == KEY_PULL ){
				if( play_spell[stcx*12+stcy] == 0 ){
					if( type == 8 && stcx == 4 && LAST_SPELL ){
						SetAreaCommonData("System","S_sector",4);
						SetAreaCommonData("System","R_sector",1);
						CallPlayerSelect(stcx*12+stcy);
						PlaySEsP(csd~"../se/menudecide.wav");
					}
					else{
						PlaySEsP(csd~"../se/menucancel.wav");
					}
				}
				else{
					SetAreaCommonData("System","S_sector",4);
					SetAreaCommonData("System","R_sector",1);
					CallPlayerSelect(stcx*12+stcy);
					PlaySEsP(csd~"../se/menudecide.wav");
				}
				ctr = 0;
			}
			//丂挿墴偟偱憹尭
			if( GetVirtualKeyState( VK_UP ) == KEY_HOLD ){
				ctr2++;
				if( ctr2 >= 30 && ctr2 %6 == 0 ){
					stcy--;
					if(stcy<0){stcy=escape;}
					ctr=0;
					SetSelectPlace3([stcx,stcy]);
					SetAreaCommonData("System","select",stcy);
					PlaySEsP(csd~"../se/menuselect.wav");
				}
			}
			else if( GetVirtualKeyState( VK_DOWN ) == KEY_HOLD ){
				ctr2++;
				if( ctr2 >= 30 && ctr2 %6 == 0 ){
					stcy++;
					if(stcy>escape){stcy=0;}
					ctr=0;
					SetSelectPlace3([stcx,stcy]);
					SetAreaCommonData("System","select",stcy);
					PlaySEsP(csd~"../se/menuselect.wav");
				}
			}
			else{
				ctr2 = 0;
			}
		}
		else if(Ssector==4){
			ctr=0;
			ctrx=0;
		}
		yield;
	}
	SetAreaCommonData("System","select",0);
	SetAreaCommonData("System","select2",0);
}

//丂stage慖戰梡
task _DrawText(x,y,r,g,b,num,char_text,size,counter){
	let id				= ObjText_Create();
	let INDEX_ACTIVE	= 0;
	let INDEX_WAIT		= 1;
	let alpha1			= 0;
	let alphaA			= 0;
	let cc				= 0;
	let stc				= GetAreaCommonData("System","select",0);
	let stc2			= GetAreaCommonData("System","select2",0);
	let slt				= GetAreaCommonData("System","select",0);
	let slt2			= GetAreaCommonData("System","select2",0);
	let Ssector			= GetAreaCommonData("System","S_sector",0);
	let eflg			= GetAreaCommonData("System","title_end",false);
	
	ObjRender_SetPosition(id,x,y,0);
	if(counter==0){
		ObjText_SetText(id,"丠丠丠丠丠丠丠丠");
	}
	else{
		ObjText_SetText(id,char_text);
	}
	ObjText_SetFontType(id,"俵俽 僑僔僢僋");
	ObjText_SetFontSize(id,size);
	ObjText_SetHorizontalAlignment(id,ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(id,450);
	ObjText_SetFontBorderWidth(id,1);
	ObjText_SetFontBorderType(id,BORDER_FULL);
	ObjText_SetFontBorderColor(id,10,10,10);
	ObjText_SetFontColorTop(id,r,g,b);
	ObjText_SetFontColorBottom(id,r,g,b);
	Obj_SetRenderPriorityI(id,35);
	ObjRender_SetAlpha(id,255-alpha1);
	
	while(eflg==false){
		slt		= GetAreaCommonData("System","select",0);
		slt2	= GetAreaCommonData("System","select2",0);
		Ssector	= GetAreaCommonData("System","S_sector",0);
		eflg	= GetAreaCommonData("System","title_end",false);
		
		if(stc!=slt||stc2!=slt2||Ssector==1||Ssector==2||Ssector==3||Ssector==4){break;}
		
		cc+=4;
		if(num == slt){
			ObjText_SetFontColorTop(id,r,g,b);
			ObjText_SetFontColorBottom(id,128+64*sin(cc),255,255);
		}
		else{
			ObjText_SetFontColorTop(id,128,128,128);
			ObjText_SetFontColorBottom(id,64,64,64);
		}
		
		yield;
	}
	while(alpha1<255 && eflg==false){
		eflg	= GetAreaCommonData("System","title_end",false);
		if(Ssector!=3&&Ssector!=2){break;}
		alphaA+=5;
		alpha1=255*sin(alphaA);
		ObjRender_SetAlpha(id,255-alpha1);
		yield;
	}
	Obj_Delete(id);
}

task _DrawText2(x,y,r,g,b,num,char_text,size){
	let id				= ObjText_Create();
	let alpha1			= 0;
	let alphaA			= 0;
	let stc				= GetAreaCommonData("System","select",0);
	let stc2			= GetAreaCommonData("System","select2",0);
	let slt				= GetAreaCommonData("System","select",0);
	let slt2			= GetAreaCommonData("System","select2",0);
	let Ssector			= GetAreaCommonData("System","S_sector",0);
	let eflg			= GetAreaCommonData("System","title_end",false);
	
	ObjRender_SetPosition(id,x,y,0);
	ObjText_SetText(id,char_text);
	ObjText_SetFontType(id,"simhei");
	ObjText_SetFontSize(id,size);
	ObjText_SetHorizontalAlignment(id,ALIGNMENT_LEFT);
	ObjText_SetMaxWidth(id,1000);
	ObjText_SetFontBorderWidth(id,1);
	ObjText_SetFontBorderType(id,BORDER_FULL);
	ObjText_SetFontBorderColor(id,10,10,10);
	ObjText_SetFontColorTop(id,r,g,b);
	ObjText_SetFontColorBottom(id,r,g,b);
	Obj_SetRenderPriorityI(id,35);
	ObjRender_SetAlpha(id,255-alpha1);
	
	while(eflg==false){
		slt		= GetAreaCommonData("System","select",0);
		slt2	= GetAreaCommonData("System","select2",0);
		Ssector	= GetAreaCommonData("System","S_sector",0);
		eflg	= GetAreaCommonData("System","title_end",false);
		
		if(stc!=slt||stc2!=slt2||Ssector==1||Ssector==2||Ssector==3||Ssector==4){break;}
		
		yield;
	}
	while(alpha1<255 && eflg==false){
		eflg	= GetAreaCommonData("System","title_end",false);
		if(Ssector!=3&&Ssector!=2){break;}
		alphaA+=5;
		alpha1=255*sin(alphaA);
		ObjRender_SetAlpha(id,255-alpha1);
		yield;
	}
	Obj_Delete(id);
}

task _DrawText3(x,y,r,g,b,num,char_text,size){
	let id				= ObjText_Create();
	let alpha1			= 0;
	let alphaA			= 0;
	let stc				= GetAreaCommonData("System","select",0);
	let stc2			= GetAreaCommonData("System","select2",0);
	let slt				= GetAreaCommonData("System","select",0);
	let slt2			= GetAreaCommonData("System","select2",0);
	let Ssector			= GetAreaCommonData("System","S_sector",0);
	let eflg			= GetAreaCommonData("System","title_end",false);
	
	ObjRender_SetPosition(id,x,y,0);
	ObjText_SetText(id,char_text);
	ObjText_SetFontType(id,"simhei");
	ObjText_SetFontSize(id,size);
	ObjText_SetHorizontalAlignment(id,ALIGNMENT_LEFT);
	ObjText_SetMaxWidth(id,1000);
	ObjText_SetFontBorderWidth(id,1);
	ObjText_SetFontBorderType(id,BORDER_FULL);
	ObjText_SetFontBorderColor(id,10,10,10);
	Obj_SetRenderPriorityI(id,35);
	ObjRender_SetAlpha(id,255-alpha1);
	
	Rainbow_T(id);
	
	while(eflg==false){
		slt		= GetAreaCommonData("System","select",0);
		slt2	= GetAreaCommonData("System","select2",0);
		Ssector	= GetAreaCommonData("System","S_sector",0);
		eflg	= GetAreaCommonData("System","title_end",false);
		
		if(stc!=slt||stc2!=slt2||Ssector==1||Ssector==2||Ssector==3||Ssector==4){break;}
		
		yield;
	}
	while(alpha1<255 && eflg==false){
		eflg	= GetAreaCommonData("System","title_end",false);
		if(Ssector!=3&&Ssector!=2){break;}
		alphaA+=5;
		alpha1=255*sin(alphaA);
		ObjRender_SetAlpha(id,255-alpha1);
		yield;
	}
	Obj_Delete(id);
}

//丂spell慖戰梡
task DrawText(x,y,r,g,b,num,char_text,size,counter){
	let id				= ObjText_Create();
	let INDEX_ACTIVE	= 0;
	let INDEX_WAIT		= 1;
	let alpha1			= 0;
	let alphaA			= 0;
	let cc				= 0;
	let stc				= GetAreaCommonData("System","select",0);
	let stc2			= GetAreaCommonData("System","select2",0);
	let slt				= GetAreaCommonData("System","select",0);
	let slt2			= GetAreaCommonData("System","select2",0);
	let Ssector			= GetAreaCommonData("System","S_sector",0);
	let eflg			= GetAreaCommonData("System","title_end",false);
	
	ObjRender_SetPosition(id,x,y,0);
	if(counter==0){
		ObjText_SetText(id,"？？？？？？？？");
	}
	else{
		ObjText_SetText(id,char_text);
	}
	ObjText_SetFontType(id,"simhei");
	ObjText_SetFontSize(id,size);
	ObjText_SetHorizontalAlignment(id,ALIGNMENT_RIGHT);
	ObjText_SetMaxWidth(id,450);
	ObjText_SetFontBorderWidth(id,1);
	ObjText_SetFontBorderType(id,BORDER_FULL);
	ObjText_SetFontBorderColor(id,10,10,10);
	ObjText_SetFontColorTop(id,r,g,b);
	ObjText_SetFontColorBottom(id,r,g,b);
	Obj_SetRenderPriorityI(id,35);
	ObjRender_SetAlpha(id,255-alpha1);
	
	while(eflg==false){
		slt		= GetAreaCommonData("System","select",0);
		slt2	= GetAreaCommonData("System","select2",0);
		Ssector	= GetAreaCommonData("System","S_sector",0);
		eflg	= GetAreaCommonData("System","title_end",false);
		
		if(stc!=slt||stc2!=slt2||Ssector==2||Ssector==3||Ssector==4){break;}
		
		cc+=4;
		if(num == slt){
			ObjText_SetFontColorTop(id,r,g,b);
			ObjText_SetFontColorBottom(id,128+64*sin(cc),255,255);
		}
		else{
			ObjText_SetFontColorTop(id,128,128,128);
			ObjText_SetFontColorBottom(id,64,64,64);
		}
		
		yield;
	}
	while(alpha1<255 && eflg==false){
		eflg	= GetAreaCommonData("System","title_end",false);
		if(Ssector!=3&&Ssector!=2){break;}
		alphaA+=5;
		alpha1=255*sin(alphaA);
		ObjRender_SetAlpha(id,255-alpha1);
		yield;
	}
	Obj_Delete(id);
}

task DrawText2(x,y,r,g,b,num,char_text,size){
	let id				= ObjText_Create();
	let alpha1			= 0;
	let alphaA			= 0;
	let stc				= GetAreaCommonData("System","select",0);
	let stc2			= GetAreaCommonData("System","select2",0);
	let slt				= GetAreaCommonData("System","select",0);
	let slt2			= GetAreaCommonData("System","select2",0);
	let Ssector			= GetAreaCommonData("System","S_sector",0);
	let eflg			= GetAreaCommonData("System","title_end",false);
	
	ObjRender_SetPosition(id,x,y,0);
	ObjText_SetText(id,char_text);
	ObjText_SetFontType(id,"simhei");
	ObjText_SetFontSize(id,size);
	ObjText_SetHorizontalAlignment(id,ALIGNMENT_LEFT);
	ObjText_SetMaxWidth(id,1000);
	ObjText_SetFontBorderWidth(id,1);
	ObjText_SetFontBorderType(id,BORDER_FULL);
	ObjText_SetFontBorderColor(id,10,10,10);
	ObjText_SetFontColorTop(id,r,g,b);
	ObjText_SetFontColorBottom(id,r,g,b);
	Obj_SetRenderPriorityI(id,35);
	ObjRender_SetAlpha(id,255-alpha1);
	
	while(eflg==false){
		slt		= GetAreaCommonData("System","select",0);
		slt2	= GetAreaCommonData("System","select2",0);
		Ssector	= GetAreaCommonData("System","S_sector",0);
		eflg	= GetAreaCommonData("System","title_end",false);
		
		if(stc!=slt||stc2!=slt2||Ssector==2||Ssector==3||Ssector==4){break;}
		
		yield;
	}
	while(alpha1<255 && eflg==false){
		eflg	= GetAreaCommonData("System","title_end",false);
		if(Ssector!=3&&Ssector!=2){break;}
		alphaA+=5;
		alpha1=255*sin(alphaA);
		ObjRender_SetAlpha(id,255-alpha1);
		yield;
	}
	Obj_Delete(id);
}

task DrawText3(x,y,r,g,b,num,char_text,size){
	let id				= ObjText_Create();
	let alpha1			= 0;
	let alphaA			= 0;
	let stc				= GetAreaCommonData("System","select",0);
	let stc2			= GetAreaCommonData("System","select2",0);
	let slt				= GetAreaCommonData("System","select",0);
	let slt2			= GetAreaCommonData("System","select2",0);
	let Ssector			= GetAreaCommonData("System","S_sector",0);
	let eflg			= GetAreaCommonData("System","title_end",false);
	
	ObjRender_SetPosition(id,x,y,0);
	ObjText_SetText(id,char_text);
	ObjText_SetFontType(id,"俵俽 僑僔僢僋");
	ObjText_SetFontSize(id,size);
	ObjText_SetHorizontalAlignment(id,ALIGNMENT_LEFT);
	ObjText_SetMaxWidth(id,1000);
	ObjText_SetFontBorderWidth(id,1);
	ObjText_SetFontBorderType(id,BORDER_FULL);
	ObjText_SetFontBorderColor(id,10,10,10);
	Obj_SetRenderPriorityI(id,35);
	ObjRender_SetAlpha(id,255-alpha1);
	
	Rainbow_T(id);
	
	while(eflg==false){
		slt		= GetAreaCommonData("System","select",0);
		slt2	= GetAreaCommonData("System","select2",0);
		Ssector	= GetAreaCommonData("System","S_sector",0);
		eflg	= GetAreaCommonData("System","title_end",false);
		
		if(stc!=slt||stc2!=slt2||Ssector==2||Ssector==3||Ssector==4){break;}
		
		yield;
	}
	while(alpha1<255 && eflg==false){
		eflg	= GetAreaCommonData("System","title_end",false);
		if(Ssector!=3&&Ssector!=2){break;}
		alphaA+=5;
		alpha1=255*sin(alphaA);
		ObjRender_SetAlpha(id,255-alpha1);
		yield;
	}
	Obj_Delete(id);
}

task DrawPage(x,y,sca,r,g,b,num,char_v){
	let csd 	= GetCurrentScriptDirectory();
	let id		= ObjPrim_Create(OBJ_SPRITE_2D);
	let eflg	= GetAreaCommonData("System","title_end",false);
	let Ssector	= GetAreaCommonData("System","S_sector",0);
	let cc		= 0;
	
	ObjRender_SetPosition(id,x,y,0);
	ObjPrim_SetTexture(id,csd~"../img/title/page.png");
	ObjRender_SetBlendType(id,BLEND_ALPHA);
	Obj_SetRenderPriorityI(id,35);
	ObjRender_SetScaleXYZ(id,sca,sca,0);
	ObjRender_SetColor(id,r,g,b);
	ObjRender_SetAlpha(id,255);
	ObjSprite2D_SetSourceRect(id,0,1,128,128);
	ObjSprite2D_SetDestCenter(id);

	while(eflg==false){
		let slt		= GetAreaCommonData("System","select2",0);
		eflg	= GetAreaCommonData("System","title_end",false);
		Ssector	= GetAreaCommonData("System","S_sector",0);
		
		if(num!=slt || Ssector==2 || Ssector==3 || Ssector==4){
			break;
		}
		
		cc+=8;
		if(char_v== "LEFT"){
			ObjRender_SetPosition(id,x-2*sin(cc),y,0);
			ObjRender_SetAngleXYZ(id,0,0,-90);
		}else if(char_v== "RIGHT"){
			ObjRender_SetPosition(id,x+2*sin(cc),y,0);
			ObjRender_SetAngleXYZ(id,0,0,90);
		}
		
		yield;
	}
	Obj_Delete(id);
}

task DrawTexture(pos,sca,texture,counter){
	let id				= [ObjPrim_Create(OBJ_SPRITE_2D),ObjPrim_Create(OBJ_SPRITE_2D)];
	let alpha1			= 0;
	let alphaA			= 0;
	let stc				= GetAreaCommonData("System","select",0);
	let stc2			= GetAreaCommonData("System","select2",0);
	let slt				= GetAreaCommonData("System","select",0);
	let slt2			= GetAreaCommonData("System","select2",0);
	let Ssector			= GetAreaCommonData("System","S_sector",0);
	let eflg			= GetAreaCommonData("System","title_end",false);
	let i				= 0;
	
	if(counter==0){
		ObjPrim_SetTexture(id[0],chara_tex[34+6]);
		ObjPrim_SetTexture(id[1],chara_tex[34+6]);
	}
	else{
		ObjPrim_SetTexture(id[0],texture);
		ObjPrim_SetTexture(id[1],texture);
	}
	
	ObjRender_SetPosition(id[0],pos[0]-32,pos[1],0);
	ObjRender_SetPosition(id[1],pos[0],pos[1],0);
	
	loop(2){
		ObjRender_SetBlendType(id[i],BLEND_ALPHA);
		Obj_SetRenderPriorityI(id[i],34);
		ObjRender_SetScaleXYZ(id[i],sca[0],sca[1],0);
		ObjSprite2D_SetSourceRect(id[i],0,0,512,512);
		ObjSprite2D_SetDestCenter(id[i]);
		i++;
	}
	i=0;
	
	ObjRender_SetColor(id[0],0,64,32);
	ObjRender_SetColor(id[1],255,255,255);
	ObjRender_SetAlpha(id[0],255);
	ObjRender_SetAlpha(id[1],255);
	
	if(counter!=0){
		
	}else{

	}

	while(!eflg){
		slt		= GetAreaCommonData("System","select",0);
		slt2	= GetAreaCommonData("System","select2",0);
		Ssector	= GetAreaCommonData("System","S_sector",0);
		eflg	= GetAreaCommonData("System","title_end",false);
		
		if(stc!=slt||stc2!=slt2||Ssector==2||Ssector==3||Ssector==4){break;}
		
		yield;
	}
	while(alpha1<255 && eflg){
		alphaA+=5;
		alpha1=255*sin(alphaA);
		ObjRender_SetAlpha(id[0],255-alpha1);
		ObjRender_SetAlpha(id[1],255-alpha1);
		yield;
	}
	Obj_Delete(id[0]);
	Obj_Delete(id[1]);
}

task CallPlayerSelect(n){
	let csd 			= GetCurrentScriptDirectory();
	let pathScript		= csd ~ "./Package_PlayerSelectScene.dnh";
	
	SetSpellPlactice();
	
	//丂婲摦嫋壜偲婲摦僗儁儖
	SetAreaCommonData("System","stflg",true);
	SetAreaCommonData("System","spell_ST",n);
	
	let idScript = LoadScript(pathScript);
	StartScript(idScript);
}

task Rainbow_T(id){
	let eflg	= GetAreaCommonData("System","title_end",false);
	let Ssector	= GetAreaCommonData("System","S_sector",0);
	let r		= 0;
	let g		= 0;
	let b		= 255;
	let hex		= 15;
	let rgb		= [r,g,b];
	let rainbow	= "AQUA";
	
	while(eflg==false && Ssector!=2 && Ssector!=3 && Ssector!=4){
		eflg	= GetAreaCommonData("System","title_end",false);
		Ssector	= GetAreaCommonData("System","S_sector",0);
		
		if(rainbow=="AQUA"){
			if(g<255){
				g+=hex;
			}
			if(g>=255){
				rainbow="GREEN";
			}
		}
		if(rainbow=="GREEN"){
			if(b>0){
				b-=hex;
			}
			if(b<=0){
				rainbow="YELLOW";
			}
		}
		if(rainbow=="YELLOW"){
			if(r<255){
				r+=hex;
			}
			if(r>=255){
				rainbow="RED";
			}
		}
		if(rainbow=="RED"){
			if(g>0){
				g-=hex;
			}
			if(g<=0){
				rainbow="PURPLE";
			}
		}
		if(rainbow=="PURPLE"){
			if(b<255){
				b+=hex;
			}
			if(b>=255){
				rainbow="BLUE";
			}
		}
		if(rainbow=="BLUE"){
			if(r>0){
				r-=hex;
			}
			if(r<=0){
				rainbow="AQUA";
			}
		}
		ObjText_SetFontColorTop(id,255,255,255);
		ObjText_SetFontColorBottom(id,r,g,b);
		
		yield;
	}
}

//丂侾偼stage practice偱偟傛偆偪偆
task SetSelectPlace2(num2){
	SetCommonData("SelectPlace2", num2);
}

task SetSelectPlace3(num3){
	SetCommonData("SelectPlace3", num3);
}

//丂僾儔僋僥傿僗偐傜婣偭偰偒偰丄僾儔僋僥傿僗夋柺傪婲摦偡傞堊偺嫟捠曄悢
task SetSpellPlactice(){
	SetCommonData("SetSpellPlacticeFrag", true );
}