//各種処理設定
class MyProcessing{
	constructor(){
		//話す機能用
		MyProcessing.prototype.talkStandby = false;
		MyProcessing.prototype.talkLock = false;
		MyProcessing.prototype.talkIndex = 1;
		//移動機能
		MyProcessing.prototype.moveStandby = false;
		MyProcessing.prototype.moveIndex = 0;
		MyProcessing.prototype.movedata = [];
		MyProcessing.prototype.getmoveData;
		//見る機能
		MyProcessing.prototype.lockStandby = false;
		//音楽機能
		MyProcessing.prototype.musData = [];
		MyProcessing.prototype.musIndex = 0;
		MyProcessing.prototype.musSEData = [];
		MyProcessing.prototype.musSEIndex = 0;
		MyProcessing.prototype.musSEBackIndex = false;
		MyProcessing.prototype.musVoiceData = [];
		MyProcessing.prototype.musVoiceIndex = 0;
		//保存データ
		MyProcessing.prototype.saveFlg = false;
		MyProcessing.prototype.ImageIndex = 1;
		MyProcessing.prototype.TalkNo = null;
		MyProcessing.prototype.LoadFlg = false;
		MyProcessing.prototype.LoadMusic = false;//RPGではmoveBefore音楽を鳴らしているためロード時に音楽再生しない
		MyProcessing.prototype.musStatus = false;
		MyProcessing.prototype.musSEStatus = false;
		MyProcessing.prototype.musVoiceStatus = false;
		MyProcessing.prototype.LoadIndex = 0;
		MyProcessing.prototype.LoadIndexMax = 4;
		MyProcessing.prototype.moveName = "";
		MyProcessing.prototype.character = "カズくん";
		//経過日数
		MyProcessing.prototype.Day = 1;
		//1日行動回数
		MyProcessing.prototype.DayActCount = 5;
		//衣服状態
		MyProcessing.prototype.backupWear = {};
		//野球拳用：絶対勝利フラグ
		MyProcessing.prototype.victoryFlg = false;
		//脱衣チェック初期処理無効
		MyProcessing.prototype.noneFlgInit = true;
		//タッチ・絶頂モード
		MyProcessing.prototype.OrgasmModeFlg = false;
		MyProcessing.prototype.TouchCount = 0;
		MyProcessing.prototype.TouchCount2 = 0;
		//ステータス（RPG以外）
		MyProcessing.prototype.StatusParam = {
			//ステータス名,最大値,初期値
			status1:["欲求不満",100,0],
			status2:["淫乱度",100,0],
			status3:["恐怖心",100,0],
			status4:["性感度",100,0],
			//proc 0:加算,1:減算
			Proc:function(stsname,val,proc){
				if(proc==0){
					var Data = myProc.GetStatusData(stsname);
					Data[2] = Data[2]+val;
					if(Data[2]>=Data[1])Data[2] = Data[1];
				}else{
					var Data = myProc.GetStatusData(stsname);
					Data[2] = Data[2]-val;
					if(Data[2]<=0)Data[2] = 0;
				}
				return Data[2];
			},
			Initialize:function(Param){
				Param.Proc("欲求不満",100,0);
				Param.Proc("淫乱度",100,1);
				Param.Proc("恐怖心",100,1);
				Param.Proc("性感度",100,1);
			},
			GetStatusData:function(stsname){
				for(var Param in myProc.StatusParam){
					var Data = myProc.StatusParam[Param];
					if(Data && typeof Data === 'function')continue;
					if(stsname == Data[0])return Data;
				}
			},
		}
		MyProcessing.prototype.GetStatusData = this.StatusParam.GetStatusData;
		//マップ用
		MyProcessing.prototype.MapMoveFlg = false;
		MyProcessing.prototype.MapExitFlg = true;
	}
	
	//データ読み込み
	loadData(loadOnly=false){
		myDataCtrl.SetDataName(title_str);
		myDataCtrl.Load();		
		var sData = myDataCtrl.AppSaveData;
		if(sData==null){
			for(var loop=0;loop<myProc.LoadIndexMax;loop++){
				myDataCtrl.SetSaveData("moveIndex"+loop,myProc.moveIndex);
				myDataCtrl.SetSaveData("moveName"+loop,myProc.moveName);
				myDataCtrl.SetSaveData("EventFlg"+loop,myBE.Flg);
				myDataCtrl.SetSaveData("EventEndFlg"+loop,myBE.EndFlg);
				myDataCtrl.SetSaveData("ImageIndex"+loop,myImg.imgIndex);
				myDataCtrl.SetSaveData("TalkNo"+loop,myProc.TalkNo);
				myDataCtrl.SetSaveData("talkIndex"+loop,myProc.talkIndex);
				myDataCtrl.SetSaveData("LastEventNo"+loop,myBE.LastEventNo);
				myDataCtrl.SetSaveData("musIndex"+loop,myProc.musIndex);
				myDataCtrl.SetSaveData("musStatus"+loop,myProc.musStatus);
				myDataCtrl.SetSaveData("backCorrect"+loop,myImg.backCorrect);
				myDataCtrl.SetSaveData("RpgData"+loop,myRpg.Charctor);
				myDataCtrl.SetSaveData("RpgDataB"+loop,myRpg.RestData);
				myDataCtrl.SetSaveData("RpgDataC"+loop,myRpg.MatterData);
				if(MapFlg)myDataCtrl.SetSaveData("MapData"+loop,myMap.MapData);
				myDataCtrl.SetSaveData("Status"+loop,myProc.StatusParam);
				myDataCtrl.SetSaveData("backupWear"+loop,myProc.backupWear);
				myDataCtrl.SetSaveData("Moral"+loop,myST.Moral);
				myDataCtrl.SetSaveData("Day"+loop,myProc.Day);
				myDataCtrl.SetSaveData("DayActCount"+loop,myProc.DayActCount);
				myDataCtrl.SetSaveData("saveFlg"+loop,myProc.saveFlg);
				myDataCtrl.SetSaveData("myProc_ImageIndex"+loop,myProc.ImageIndex);
			}
			myDataCtrl.Save();
			sData = myDataCtrl.AppSaveData;
		}else{
			if(loadOnly)return sData;
			//読込前初期化
			myBE.EndFlg.length = 0;
			myBE.eventList.length = 0;
			myProc.event(myST.GetEvent);			
			var idx = myProc.LoadIndex;
			if(sData["moveIndex"+idx]!=null){
				myProc.moveIndex = sData["moveIndex"+idx];
			}
			if((sData["moveName"+idx]!=null)&&(sData["moveName"+idx]!="")){
				myProc.moveName = sData["moveName"+idx];
			}			
			if(sData["EventFlg"+idx]!=null)myBE.Flg = sData["EventFlg"+idx];
			if(sData["EventEndFlg"+idx]!=null){
				myBE.EndFlg = sData["EventEndFlg"+idx];
				for(var loop in myBE.EndFlg){
					var event = myBE.getBaseEvent(loop);
					try{
						event[myBE.End] = myBE.EndFlg[loop];
					}catch(e){
						console.log(e);
					}
				}
			}
			if(sData["LastEventNo"+idx]!=null)myBE.LastEventNo = sData["LastEventNo"+idx];
			if(sData["TalkNo"+idx]!=null){
				myProc.TalkNo = sData["TalkNo"+idx];
				event = myBE.getBaseEvent(myBE.LastEventNo);
				event[myBE.Message] = myST.Talk[myProc.TalkNo];
				myProc.TalkNo = null;
			}
			if(sData["talkIndex"+idx]!=null){
				myProc.talkIndex = sData["talkIndex"+idx];
				myProc.talk();
			}
			if(sData["musIndex"+idx]!=null)myProc.musIndex = sData["musIndex"+idx];
			if(sData["musStatus"+idx]!=null){
				myProc.musStatus = sData["musStatus"+idx];
				if(myProc.LoadMusic)myProc.music(myProc.musIndex,!myProc.musStatus);
			}
			if(sData["backCorrect"+idx]!=null)myImg.backCorrect = sData["backCorrect"+idx];
			if(sData["RpgData"+idx]!=null){
				myRpg.Charctor = sData["RpgData"+idx];
				var orgData = myRpg.CharArray[0];
				
				for(var index in orgData){
					if(myRpg.Charctor[index]==undefined)myRpg.Charctor[index] = orgData[index];
				}
				/*
				if(myRpg.Charctor.RUMOR==undefined)myRpg.Charctor.RUMOR = 0;
				if(myRpg.Charctor.DEBT==undefined)myRpg.Charctor.DEBT = myRpg.CharArray[0].DEBT;
				if(myRpg.Charctor.RANK==undefined)myRpg.Charctor.RANK = myRpg.CharArray[0].RANK;
				if(myRpg.Charctor.NEXTRANKPOINT==undefined)myRpg.Charctor.NEXTRANKPOINT = parseInt(myRpg.CharArray[0].NEXTRANKPOINT);
				if(myRpg.Charctor.RANKPOINT==undefined)myRpg.Charctor.RANKPOINT = parseInt(myRpg.CharArray[0].RANKPOINT);				
				if(myRpg.Charctor.CLASS==undefined)myRpg.Charctor.CLASS = parseInt(myRpg.CharArray[0].CLASS);
				if(myRpg.Charctor.NEXTCLASS==undefined)myRpg.Charctor.NEXTCLASS = parseInt(myRpg.CharArray[0].NEXTCLASS);
				if(myRpg.Charctor.CLASSPOINT==undefined)myRpg.Charctor.CLASSPOINT = parseInt(myRpg.CharArray[0].CLASSPOINT);	
				*/				
			}
			if(sData["RpgDataB"+idx]!=null){
				myRpg.RestData = sData["RpgDataB"+idx];
				myRpg.RestDataSet("load");
			}
			if(sData["RpgDataC"+idx]!=null){
				myRpg.MatterData = sData["RpgDataC"+idx];
			}
			if(MapFlg){
				if(sData["MapData"+idx]!=null){
					myMap.MapData = sData["MapData"+idx];
				}
			}
			if(sData["Status"+idx]!=null){
				var data = sData["Status"+idx];
				for(var loop in data){
					myProc.StatusParam[loop] = data[loop];
				}
			}else{
				myProc.StatusParam.Initialize(myProc.StatusParam);			
			}
			if((myRpg.Charctor.INRAN===undefined)||(myRpg.Charctor.INRAN==null))myRpg.Charctor.INRAN = 0;
			if(sData["backupWear"+idx]!=null){
				myProc.backupWear = sData["backupWear"+idx];
				var flg = false;
				for(var loop in myProc.backupWear){
					if(loop=="kutu"){
						myProc.backupWear["inner"] = myProc.backupWear["kutu"];
						delete myProc.backupWear.kutu;
						flg = true;
					}
				}
				if(!flg){
					myProc.backupWear["inner"] = 1;
				}
				
			}
			//モラルデータ
			if(sData["Moral"+idx]!=null)myST.Moral = sData["Moral"+idx];
			if(sData["Day"+idx]!=null)myProc.Day = sData["Day"+idx];
			if(sData["DayActCount"+idx]!=null)myProc.DayActCount = sData["DayActCount"+idx];
			//画像表示は最後
			if(sData["ImageIndex"+idx]!=null){
				myImg.imgIndex = sData["ImageIndex"+idx];
				if(myImg.imgIndex.Other==1)myImg.imgIndex.Other = 0;
				var data = myProc.getmoveData(myProc.moveIndex);
				if(data!=undefined){
					myImg.SetImgPos("back",[data[2].x,data[2].y]);
					myImg.AllImageView(true,false,false);
				}
			}
			if(sData["myProc_ImageIndex"+idx]==null)sData["myProc_ImageIndex"+idx] = 0;
			myProc.ImageIndex = sData["myProc_ImageIndex"+idx];
			_self.HiddenBox("anmaku");
			this.LoadFlg = true;
		}
		return sData;
	}
	deleteData(){
		myDataCtrl.Load();
		var sData = myDataCtrl.AppSaveData;
		var idx = myProc.LoadIndex;
		//初期化
		myDataCtrl.SetSaveData("moveIndex"+idx,myProc.moveIndex);
		myDataCtrl.SetSaveData("moveName"+idx,myProc.moveName);
		myDataCtrl.SetSaveData("EventFlg"+idx,myBE.Flg);
		myDataCtrl.SetSaveData("EventEndFlg"+idx,myBE.EndFlg);
		myDataCtrl.SetSaveData("ImageIndex"+idx,myImg.imgIndex);
		myDataCtrl.SetSaveData("TalkNo"+idx,myProc.TalkNo);
		myDataCtrl.SetSaveData("talkIndex"+idx,myProc.talkIndex);
		myDataCtrl.SetSaveData("LastEventNo"+idx,myBE.LastEventNo);
		myDataCtrl.SetSaveData("musIndex"+idx,myProc.musIndex);
		myDataCtrl.SetSaveData("musStatus"+idx,myProc.musStatus);
		myDataCtrl.SetSaveData("RpgData"+idx,myRpg.Charctor);
		myDataCtrl.SetSaveData("RpgDataB"+idx,myRpg.RestData);
		myDataCtrl.SetSaveData("RpgDataC"+idx,myRpg.MatterData);
		if(MapFlg)myDataCtrl.SetSaveData("MapData"+idx,myMap.MapData);
		myDataCtrl.SetSaveData("Status"+idx,myProc.StatusParam);		
		myDataCtrl.SetSaveData("backupWear"+idx,myProc.backupWear);
		myDataCtrl.SetSaveData("Moral"+idx,myST.Moral);
		myDataCtrl.SetSaveData("Day"+idx,myProc.Day);
		myDataCtrl.SetSaveData("DayActCount"+idx,myProc.DayActCount);
		myDataCtrl.SetSaveData("backCorrect"+idx,myImg.backCorrect);		
		myDataCtrl.SetSaveData("myProc_ImageIndex"+idx,myProc.ImageIndex);
		sData["saveFlg"+idx] = false;
		myDataCtrl.Save();
	}
	//データ保存
	saveData(){
		var idx = myProc.LoadIndex;
		myRpg.RestDataSet("save");
		myDataCtrl.SetSaveData("moveIndex"+idx,myProc.moveIndex);
		myDataCtrl.SetSaveData("moveName"+idx,myProc.moveName);
		myDataCtrl.SetSaveData("EventFlg"+idx,myBE.Flg);
		myDataCtrl.SetSaveData("EventEndFlg"+idx,myBE.EndFlg);
		myDataCtrl.SetSaveData("ImageIndex"+idx,myImg.imgIndex);
		myDataCtrl.SetSaveData("TalkNo"+idx,myBE.TalkNo);
		myDataCtrl.SetSaveData("talkIndex"+idx,myProc.talkIndex);
		myDataCtrl.SetSaveData("LastEventNo"+idx,myBE.LastEventNo);
		myDataCtrl.SetSaveData("musIndex"+idx,myProc.musIndex);
		myDataCtrl.SetSaveData("musStatus"+idx,myProc.musStatus);
		myDataCtrl.SetSaveData("backCorrect"+idx,myImg.backCorrect);
		myDataCtrl.SetSaveData("RpgData"+idx,myRpg.Charctor);
		myDataCtrl.SetSaveData("RpgDataB"+idx,myRpg.RestData);
		myDataCtrl.SetSaveData("RpgDataC"+idx,myRpg.MatterData);
		console.log(JSON.stringify(myRpg.RestData));
		if(MapFlg)myDataCtrl.SetSaveData("MapData"+idx,myMap.MapData);
		myDataCtrl.SetSaveData("Status"+idx,myProc.StatusParam);		
		myDataCtrl.SetSaveData("backupWear"+idx,myProc.backupWear);
		myDataCtrl.SetSaveData("Moral"+idx,myST.Moral);
		myDataCtrl.SetSaveData("Day"+idx,myProc.Day);
		myDataCtrl.SetSaveData("DayActCount"+idx,myProc.DayActCount);
		myDataCtrl.SetSaveData("myProc_ImageIndex"+idx,myProc.ImageIndex);
		myDataCtrl.SetSaveData("saveFlg"+idx,true);
		myDataCtrl.Save();
	}
	
	//初期立ち絵設定
	SetCharctorWear(index){
		var Img = myST.Img[index];
		for(var loop in Img){
			//画像が衣服かチェック
			var WearJuge = ["seihuku","shatu","sukart","inner","burager","panty"];				
			for(var loop2 in WearJuge){
				//対象の画像が衣服なら
				if(WearJuge[loop2]==loop){
					//設定
					myImg.SetIndexPos(loop,Img[loop]);
				}
			}
		}
	}
	//初期処理用
	Initialize(){
		myProc.move();
		myProc.Status();
		myProc.NextDay();
		myProc.lock();
		myProc.sex();
		myProc.talk();
		myProc.talk2();
		myProc.OrgasmModeChange();
		myProc.Onani();
		myProc.Eat();
		myProc.makuru();
		myProc.waer();
		myProc.under();
		myProc.Kigaeru();		
		myProc.nugasu();
		myProc.Nugu();
		myProc.sounyuu();
		myProc.shasei();
		myProc.boxnone();
		myProc.Test();
		myProc.Option();
		myProc.janken();
		myProc.Lock2();
	}
	
	//話す
	talk(func = null){
		//会話機能の準備が終わっているか？
		if(!myProc.talkStandby){//終わっていないなら初期動作
			//各種機能
			this.talkData = null;
			this.talkList = null;
			this.talkFunc = null;
			this.talkExcute = null;
			this.talkDefaultFunc = null;
			this.talkStandbyFunc = null;			
			//話す処理準備
			myProc.talkStandbyFunc = function(){
				//会話内容
				this.talkData = function(){
					this.talkList = function(Index = -1){
						var data = myST.Talk;
						return Index!=-1?data[Index]:data.length;
					}
					return this.talkList();
				}
				//会話実行
				this.talkExcute = function(msg){
					var nMsg = [];
					for(var loop in msg){
						nMsg.push(msg[loop]);
					}
					myBT.messageCount = 0;
					myBT.setMessage(nMsg);
					return;
				}
				//初期処理
				this.talkDefaultFunc = function(){
					var index = 0;
					//人がいるなら
					if(myImg.GetIndexPos("body")!=0){
						//処理ごとにインデックスは別のところで設定する。
						index = myProc.talkIndex;
					}
					myProc.talkExcute(myProc.talkList(index));
				}		
				myProc.talkStandby = this.talkData();			
			}
			myProc.talkStandbyFunc();
			_self.setTimer(this.talk,100,func);
			return;
		}
		//特別な処理がないならデフォルト処理
		if(func == null)func = myProc.talkDefaultFunc;
		myBT.setCommandProcessing(myBT.CommandTalk,function(){
			myCustom.TalkProc();
		});
	}
	
	talk2(){
		//命令
		myBT.setCommandProcessing(myBT.CommandTalk2,function(){
			myCustom.Talk2Proc();
		});
	}
	
	//イベント設定
	event(func=null){
		if(func==null)return;
		var setEv = null;
		setEv = func();
		for(var loop in setEv){
			myBE.addBaseEvent(setEv[loop]());
		}
	}
	
	//シナリオ抽出
	OutPutFlg = false;
	MsgData = "";
	OutPutSinario(){
		//シナリオ抽出フラグがOFFなら抜ける
		if(!myProc.OutPutFlg)return;
		//シナリオデータ連結
		var talkData = myST.Story;
		talkData = talkData.concat(myST.Talk);
		talkData = talkData.concat(myST.EventData);
		talkData = talkData.concat(myST.TouchMsgData[0]);
		talkData = talkData.concat(myST.TouchMsgData[1]);
		//抽出
		for(var idx in talkData){
			if(isNaN(parseInt(idx)))continue;
			var length = talkData[idx].length;
			for(var idx2=0;idx2<length;idx2++){
				if(talkData[idx][idx2][0]=="FUNC"){
					talkData[idx][idx2][1]();
				}else if(Array.isArray(talkData[idx][idx2])){
					myBT.showMessage(talkData[idx][idx2][0]);
				}else{
					myBT.showMessage(talkData[idx][idx2]);
				}
			}
			myProc.MsgData+="\n";
		}
		//体タッチメッセージ抽出
		talkData = myST.TouchData[myST.TouchData.length-2]();
		for(var loop = 0;loop<4;loop++){
			var length = talkData.length;
			for(var idx=0;idx<length;idx++){
				myST.JudgValue = 0;
				if(loop==1)myST.JudgValue = 20;
				if(loop==2)myST.JudgValue = 40;
				if(loop==3)myST.JudgValue = 80;
				if(talkData[idx][0]=="FUNC"){
					talkData[idx][1]();
				}else if(Array.isArray(talkData[idx])){
					myBT.showMessage(talkData[idx][0]);
				}else{
					myBT.showMessage(talkData[idx]);
				}
			}
			myProc.MsgData+="\n";
		}
		//挿入メッセージ抽出
		talkData = myST.SounyuuMag;
		for(var loop = 0;loop<4;loop++){
			var length = talkData.length;
			for(var idx=0;idx<length;idx++){
				myST.JudgValue = 0;
				if(loop==1)myST.JudgValue = 20;
				if(loop==2)myST.JudgValue = 40;
				if(loop==3)myST.JudgValue = 80;
				if(talkData[idx][0]=="FUNC"){
					talkData[idx][1]();
				}else if(Array.isArray(talkData[idx])){
					myBT.showMessage(talkData[idx][0]);
				}else{
					myBT.showMessage(talkData[idx]);
				}
			}
			myProc.MsgData+="\n";
		}		
		myProc.MsgData+="\n";
		console.log(myProc.MsgData);
		myProc.OutPutFlg = false;
		myBT.showMessage("");
	}
	
	//衣服状態チェック
	WearBreakcheck(parts){
		if(!myRpg.FunctionFlg)return true;
		var Chr = myRpg.Charctor;
		var BrackIdx = 0;
		
		//破損なし
		if(Chr.WP>=95){
			BrackIdx = 0;
		}
		//破損なし
		else if(Chr.WP>=90){
			BrackIdx = 1;		
		}
		//破損なし
		else if(Chr.WP>=80){
			BrackIdx = 2;
		}
		//破損なし
		else if(Chr.WP>=70){
			BrackIdx = 3;
		}
		//破損なし
		else if(Chr.WP>=60){
			BrackIdx = 4;
		}
		//破損なし
		else if(Chr.WP>=50){
			BrackIdx = 5;
		}
		//破損なし
		else if(Chr.WP>=40){
			BrackIdx = 6;
		}
		//破損なし
		else if(Chr.WP>=30){
			BrackIdx = 7;
		}
		else if(Chr.WP>=20){
			BrackIdx = 8;
		}
		//破損なし
		else if(Chr.WP>=10){
			BrackIdx = 9;
		}
		//破損なし
		else if(Chr.WP>=5){
			BrackIdx = 10;
		}
		//破損なし
		else if(Chr.WP>=0){
			BrackIdx = 11;
		}
		
		if(myST.Img[BrackIdx][parts]!=0){
			myProc.backupWear[parts] = myST.Img[0][parts];
			return true;
		}else{
			return false;
		}
		
	}
	
	//画像Noからイメージ取得
	searchImageNo(index){
		for(var loop in myST.Img){
			if(myST.Img[loop].No==index)return myST.Img[loop];
		}
	}
	//画像変更
	changeImage(index,move=false,anten=true,bgImage=true){
		var Img = myProc.searchImageNo(index);
		console.log(Img);
		if(move)Img['back'] = move;
		var key = "";
		myProc.talkLock = true;
		myProc.ImageIndex = index;
		if(anten)_self.ViewBox("anmaku");
		//暗転待ち
		_self.setTimer(function(){
			for(var loop in Img){
				key = loop;
				if((!bgImage)&&(key=="back")||(key=="No"))continue;
				//脱衣状態チェック
				var noneFlg = myImg.GetIndexPos(key);
				if(myProc.noneFlgInit){
					noneFlg = true;
				}
				var noneJuge = ["seihuku","shatu","sukart","inner","burager","panty"];				
				//画像設定
				myImg.SetIndexPos(key,Img[loop]);
				if(key=="back"){
					var data = myProc.getmoveData(Img[loop]);
					var setTemp = [data[2].x,data[2].y];
					myImg.SetImgPos(key,setTemp);
				}
				//脱衣状態チェック処理
				/*for(var loop2 in noneJuge){
					//対象の画像が衣服なら
					if(noneJuge[loop2]==key){
						//来ている状態かチェックして設定する。
						if(!noneFlg)myImg.SetIndexPos(key,0);
					}
				}*/
				if(anten)myImg.ClearImage(key);
			}
			myProc.noneFlgInit = false;
			//着衣状態で表情と体を変更する。
			if(!myRpg.BindStatus){
				var inner = myImg.GetIndexPos("inner");
				var seihuku = myImg.GetIndexPos("seihuku");
				var shatu = myImg.GetIndexPos("shatu");
				var sukart = myImg.GetIndexPos("sukart");
				var panty = myImg.GetIndexPos("panty");
				var burager = myImg.GetIndexPos("burager");
				//パーツあり
				var partFlg = false;
				if(partFlg){
					//下着脱いでいる場合は赤らめる
					if(!(panty&&burager)||(!sukart)||(!shatu)){
						myImg.SetIndexPos("body_face_bk",1);
						myImg.SetIndexPos("body_face_fk",9);
					}
					//上半身裸で胸隠す
					if(!(burager||shatu||sukart||seihuku)){
						myImg.SetIndexPos("body",2);				
					}
					//全裸なら体を隠す
					if(!(burager||shatu||sukart||seihuku||panty||inner)){
						myImg.SetIndexPos("body",3);				
					}
				}
			}
			//画像描画
			myImg.AllImageView(true,false,false);
			//描画200msec待ち後暗転解除
			_self.setTimer(function(){				
				if(anten)_self.HiddenBox("anmaku")
				myProc.talkLock = false;
			},200);
		},510);
	}
	
	//衣服状態取得(村、街用)
	getInranWear(){
		var inner = myImg.GetIndexPos("inner");
		var seihuku = myImg.GetIndexPos("seihuku");
		var shatu = myImg.GetIndexPos("shatu");
		var sukart = myImg.GetIndexPos("sukart");
		var panty = myImg.GetIndexPos("panty");
		var burager = myImg.GetIndexPos("burager");
		var res = false;
		
		//スカート脱いでいる
		if(!sukart)res = true;
		if(!(seihuku||shatu||burager))res = true;
		
		return res;
	}
	
	//移動
	move(startFlg=false){
		if(!myProc.moveStandby){
			//カスタム処理の有無チェック
			if(!myCustom.moveInit){//従来処理
				//移動先データ
				if(myProc.movedata.length == 0){
					myProc.movedata = [
						[//インデックス:場所の名前
							[1,"未設定"],
							function(index,get=false){
								var tmp = myProc.movedata[0];
								for(var loop in tmp){
									if(tmp[loop] && typeof tmp[loop] === 'function')return;
									if(tmp[loop][0] == index){
										if(get)return tmp[loop];
										return tmp[loop][1]; 
									}
								}
							}
						],
						//現在の場所,[行先],{背景の表示位置}
						[1,[5],{x:-50,y:0}],//体育倉庫				
					];
				}
			}else{//カスタム処理へ
				myCustom.moveInit();
			}
			//移動データ取得関数
			myProc.GetmoveDataFunc = function(){
				return myProc.movedata[0][myProc.movedata[0].length-1];
			}
			//移動先強制設定
			myProc.moveSet = function(posKey){
				var idx = 0;
				var IndexPos = myProc.movedata[0];
				for(var loop in IndexPos){
					var posStr = IndexPos[loop][1];
					if(posStr == posKey){
						idx = IndexPos[loop][0];
						break;
					}
				}
				myProc.moveIndex = idx;
			}
			//移動先データ取得
			myProc.getmoveData = function(idx){
				var data = myProc.movedata;
				if(typeof idx==='object')idx = idx.back;
				for(var loop in data){
					if(loop==0)continue;
					if(data[loop][0]==idx){
						return data[loop];
					}
				}
			}
			if(myProc.moveName!=""){
				var func = myProc.GetmoveDataFunc();
				var Data = func(myProc.moveIndex,true);
				Data[1] = myProc.moveName;
			}
			if(startFlg)return;
			myProc.moveStandby = true;
		}
		//移動前処理
		myProc.moveBefore = function(value){
			var res = true;
			/*//街中央
			if(value==1){
				//Map脱出
				if(myMap.MapExit()){
					myProc.MapMoveFlg = false;
					myProc.MapExitFlg = false;
					myMap.MapViewFlg = false;
					myMap.MapHidden();
					myMap.chgArea();
					//時間/日数経過
					myImg.backCorrect++;
					if(myImg.backCorrect>=4){
						myImg.backCorrect = 0;
						myProc.Day++;
						myRpg.Charctor.TREASURE = false;
						myBT.showMessage("日数が経過しました。");
					}else{
						myBT.showMessage("時間が経過しました。");
					}
					myBT.chgDayTime();					
				}else if(myMap.MapViewFlg){
					myBT.showMessage("サーシャ<br>「ここは出口じゃないよ」");	
					res = false;
				}
				if(!myMap.MapViewFlg){
					//アイテム販売リスト
					myRpg.ItemBuyList = [0,1,10,13,14,15,18];					
					myRpg.RestFlg = false;
					myRpg.StoreFlg = true;
				}
			}else{
				myRpg.StoreFlg = false;				
			}
			//宿屋
			if(value==5){
				myRpg.RestFlg = false;
			}
			//宿屋・部屋
			if(value==9){
				//支払い/売春ならOK
				if(!myRpg.RestPayFlg){
					myBT.showMessage("サーシャ<br>「お金払ってないから入れないわ」");	
					res = false;
				}
				//支払い済み/売春
				else{
					myRpg.RestFlg = true;
				}
			}			
			//ダンジョン入る
			if(value==13){
				myProc.MapMoveFlg = true;
				myProc.MapExitFlg = true;
				myMap.MapView();
				myMap.SetEroEvent();
				myProc.music(0,1);
				myProc.music(2,0);
			}else{
				//遺跡から出ていたら
				if(!myMap.MapViewFlg){
					//音楽全停止→再生
					myProc.music(2,1);
					myProc.music(0,0);
				}
			}
			//路地裏
			if(value==17){
				//野宿するか
				if(myRpg.RestNojukuFlg){
					myRpg.RestFlg = true;
				}
				else{
					myRpg.RestFlg = true;
				}
			}				
			//酒場
			if(value==29){
				myRpg.RestFlg = false;
			}
			//酒場・部屋
			if(value==33){
				//支払い/売春ならOK
				if(!myRpg.RestPayFlg2){
					myBT.showMessage("サーシャ<br>「お金払ってないから入れないわ」");	
					res = false;
				}
				//支払い済み/売春
				else{
					myRpg.RestFlg = true;
				}
			}		
			//酒場
			if(value==45){
				myRpg.RestFlg = false;
			}*/		
			return res;
		}
		
		myProc.moveExceute = function(idx){
			var moveData = {back:idx}
			if(!myProc.moveBefore(idx))return;
			myProc.moveIndex = idx;
			//背景の表示位置
			var data = myProc.getmoveData(idx);
			var setTemp = [data[2].x,data[2].y];
			myImg.SetImgPos("back",setTemp);							
			//背景表示
			myST.ParamAIV[0] = moveData;
			//暗転
			myST.AntenImageView(function(){
				moveData = myST.ParamAIV[0];
				myST.CheageImage("back",moveData);
				myST.ParamAIV.length = 0;
				var funcIdx = myBE.serchExecuteEvent();
				if(funcIdx)myBE.excuteEvent(funcIdx);
				MySetting.LockCount = 0;
				//移動先名保存
				var func = myProc.GetmoveDataFunc();
				var Data = func(myProc.moveIndex,true);
				myProc.moveName = Data[1];
			},900,500);//300,250
		}		
		
		//移動メニュー
		myBT.setCommandProcessing(myBT.CommandMove,function(){
			var index = 0;
			var movedata = [];
			var temp = myProc.movedata;
			for(var loop in temp){
				if(myProc.moveIndex == temp[loop][0]){
					var temp2 = temp[loop][1];
					for(var loop2 in temp2){
						var index2 = temp2[loop2];
						var f_idx = myProc.movedata[0].length-1;
						var func = myProc.movedata[0][f_idx];
						if(myProc.moveIndex == index2){
							if(temp2[temp2.length-1] === "function"){
								if(temp2[temp2.length-1]())continue;
							}
						}
						movedata[index] = [];
						movedata[index][0] = index2;
						movedata[index][1] = func(index2);
						movedata[index][2] = myProc.moveExceute;
						index++;
					}
				}
			}
			var parent = _self.Elm("operation",_self.TypeID);
			myBT.moveMenu(parent,movedata);
		});
		//カスタムクラスで置き換え処理が必要な場合。
		if(myCustom.comanndMove == null){
			myCustom.setCommandProcessing();
		}
	}
	
	//ステータス
	Status(){
		if(myRpg.FunctionFlg)return;
		myProc.StatusMenu = "statusMenu";		
		myBT.setCommandProcessing(myBT.CommandStatus,function(){
			//通常メニュー非表示
			myBT.MenuHidden();
			var MenuItemMax = 5;
			var MenuItemIndex = 0;
			var MenuStatusPage = 0;
			var ClickFlg = true;
			//初回メニュー生成
			var StatusMenu = _self.Elm(myProc.StatusMenu,_self.TypeID);
			if((StatusMenu == undefined)||(StatusMenu == null)){
				//メニュー枠生成
				var parent = _self.Elm("operation",_self.TypeID);
				myBT.setCommonBox(parent,myProc.StatusMenu,"10px");
				_self.Elm(myProc.StatusMenu,_self.TypeID).style.width = "200px";
			}else{
				_self.ViewBox(myProc.StatusMenu);
			}
			_self.Elm(myProc.StatusMenu,_self.TypeID).innerText = "";
			for(var Param in myProc.StatusParam){
				var Data = myProc.StatusParam[Param];
				if (Data && typeof Data === 'function')continue;
				_self.Elm(myProc.StatusMenu,_self.TypeID).innerText += Data[0]+":"+Data[2]+"/"+Data[1]+"\n";
			}
			_self.Elm(myProc.StatusMenu,_self.TypeID).innerText += "※画面タッチで終了\n";			
			_self.doc.onmousedown = function(){
				if(ClickFlg){
					ClickFlg = false;
					return;
				}
				_self.HiddenBox(myProc.StatusMenu);
			}			
		});
	}
	
	//時間経過（翌日）
	NextDay(){
		myBT.setCommandProcessing(myBT.CommandNextDay,function(){
			myST.AntenImageView(function(){
				myProc.Day++;
				myProc.DayActCount = 5;
				myST.PantyWeatCount = 0;
				var Hunger = myProc.StatusParam.Proc("空腹度",20,0);
				var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
				var Msg = "女子校生はこちらを睨みつけている。";
				var MsgAddFlg = false;
				var evenIdx = 0;
				if(Hunger>=1 && Hunger<=30){
					Msg = "多少の空腹はあるのか、お腹の音が可愛く泣いている。";
				}else if(Hunger<=60){
					Msg = "さすが空腹が堪えるのか、元気がないようだ。";
				}else　if(Hunger<100){
					Msg = "空腹が限界なのか何かを懇願するようにこちらを見ている。";
				}else if(Hunger==100){
					MsgAddFlg = true;
					if(JudgeValue>85){
						evenIdx = 14;
					}else if(JudgeValue>70){
						evenIdx = 15;
					}else if(JudgeValue<70){
						evenIdx = 16;
					}
				}
				var msgList = [
					["FUNC",function(){
						_self.HiddenBox("menu1");
						myBT.showMessage("時間経過。<br>行動回数5回に回復。<br>");
					}],
					myProc.Day+"日目―<br>空腹度:"+Hunger+"%<br>"+Msg,
				];				
				if(MsgAddFlg){
					msgList = msgList.concat(myST.EventData[evenIdx]);
				}else{
					msgList[msgList.length] = [
						"FUNC",function(){
							myBT.showMessage("");
							_self.ViewBox("menu1");
						}
					];
				}
				//パンティ
				var pantyIdx = myImg.GetIndexPos("panty");
				if(pantyIdx!=0)myImg.SetIndexPos("panty",1);
				//汁
				myImg.SetIndexPos("siru",0);
				myImg.AllImageView();
				myBT.setMessage(msgList);
				//自動セーブ
				var backIndex = myProc.LoadIndex;
				myProc.LoadIndex = 3;
				myProc.saveData();
				myProc.LoadIndex = 	backIndex;			
				myBT.chgDayTime();
			});
		});
	}
	
	//見る
	lock(){
		myBT.setCommandProcessing(myBT.CommandLock,function(){
			//見る機能準備
			var fcLock = myST.Lock;
			for(var loop in fcLock){
				fcLock[loop]();
			}
		});
	}
	
	//押し倒す
	sex(){
		myBT.setCommandProcessing(myBT.CommandSex,function(){
			if(myST.SexFunc!=0x11)return;
			//立ち絵変更
			myST.Sex();
		});
		myST.SexFunc = false;
		if(myST.SexFunc==false)return;
		if(_self.product_flg)myST.SexFunc |= 0x10;
		if(_self.sample2_flg)myST.SexFunc |= 0x10;
		if(myBE.EndFlg[22]||myBE.EndFlg[23])myST.SexFunc |= 0x01;
		if(myST.SexFunc==0x11)_self.ViewBox(myBT.CommandSex);
	}
	
	//オナニー
	Onani(){
		myBT.setCommandProcessing(myBT.CommandOnani,function(){
			if(myRpg.Charctor.INRAN>=40){
				myRpg.OnaniFlg = true;
				myBE.excuteEvent(22);
			}else{
				myBT.setMessage(["淫乱度が40以上でオナニーが出来るようになります。"]);
			}
		});		
	}
	
	//タッチ・絶頂モード切替
	OrgasmModeChange(){
		myBT.setCommandProcessing(myBT.CommandOrgasm,function(){
            console.log("OrgasmModeChange");
			var elm = _self.Elm("OrgasmMode",_self.TypeID);
			if(!myProc.OrgasmModeFlg){
				//elm.innerText = "絶頂モード";
				elm.innerText = "タッチモード:ON";
				myProc.OrgasmModeFlg = true;
				myProc.TouchCount = 0;
				myProc.TouchCount2 = 0;
				myST.TouchData[myST.TouchData.length-1]();
			}else{
				//elm.innerText = "タッチモード";
				elm.innerText = "タッチモード:OFF";
				myProc.OrgasmModeFlg = false;
				_self.ViewBox("menu1");
			}
			myProc.OrgasmModeChangeAfter();
		});
	}
	
	//タッチモード切替後処理
	OrgasmModeChangeAfter(){
		//ここに何か書くか外部から上書きして使う。
		console.log("OrgasmModeChangeAfter:processing");
		return;
	}	
	
	//食事
	Eat(){
		myBT.setCommandProcessing(myBT.CommandEat,function(){
			var Hunger = (myProc.GetStatusData("空腹度"))[2];
			var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
			var evenIdx = 0;
			if(JudgeValue>85){
				evenIdx = 10;
			}else if(JudgeValue>70){
				evenIdx = 11;
			}else if(JudgeValue>55){
				evenIdx = 12;
			}else if(JudgeValue<=55){
				evenIdx = 13;
			}
			if(Hunger==0)evenIdx = 17;
			myBT.setMessage(myST.EventData[evenIdx]);
		});
	}
	
	//捲る
	makuru(){
		//捲るコマンド文字列変更
		myProc.ChangeMakuruName = function(){
			//シャツ
			var idx = myImg.GetIndexPos("shatu");
			if((idx == 3)||(idx == 4)){
				_self.Elm(myBT.CommandMakuruW,_self.TypeID).innerText = "シャツを捲る";
			}else if(idx != 0){
				var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
				if(JudgeValue>70){
					_self.Elm(myBT.CommandMakuruW,_self.TypeID).innerText = "シャツを捲る";
				}else{
					_self.Elm(myBT.CommandMakuruW,_self.TypeID).innerText = "シャツを戻す";
				}
			}
			//スカート			
			var idx = myImg.GetIndexPos("sukart");
			if(idx == 1){
				_self.Elm(myBT.CommandMakuruU,_self.TypeID).innerText = "スカートを捲る";
			}else if(idx != 0){
				_self.Elm(myBT.CommandMakuruU,_self.TypeID).innerText = "スカートを戻す";
			}
		}
		//捲るーコマンド
		myBT.setCommandProcessing(myBT.CommandMakuru,function(){
			myBT.MenuMakuru();
			myProc.ChangeMakuruName();
		});
		//シャツを捲るーコマンド
		myBT.setCommandProcessing(myBT.CommandMakuruW,function(){
			var idx = myImg.GetIndexPos("shatu");
			if((idx == 3)||(idx == 4)){
				myST.CheageImage("shatu",idx+5);
				var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
				var evenIdx = -1;
				if(JudgeValue>55){
					evenIdx = 8;
				}else if(JudgeValue<=55){
					evenIdx = 9;
				}
				//シャツのボタンを外してなければメッセージなし
				myBT.setMessage(myST.EventData[evenIdx]);
			}else if((idx == 8)||(idx == 9)){
				myST.CheageImage("shatu",idx-5);
				myBT.showMessage("女子校生<br>「...」");
			}else if(idx!=0){
				myBT.showMessage("せめてシャツのボタンを外さないとな。");
			}else{
				myBT.showMessage("シャツは脱がしてるな。");
			}
			myProc.ChangeMakuruName();			
		});
		//スカートを捲るーコマンド
		myBT.setCommandProcessing(myBT.CommandMakuruU,function(){
			var idx = myImg.GetIndexPos("sukart");
			if(idx == 1){
				myST.CheageImage("sukart",idx+1);
				var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
				var evenIdx = 0;
				if(JudgeValue>85){
					evenIdx = 4;
				}else if(JudgeValue>70){
					evenIdx = 5;
				}else if(JudgeValue>55){
					evenIdx = 6;
				}else if(JudgeValue<=55){
					evenIdx = 7;
				}
				myBT.setMessage(myST.EventData[evenIdx]);
			}else if(idx!=0){
				myST.CheageImage("sukart",idx-1);
				myBT.showMessage("女子校生<br>「...」");
			}else{
				myBT.showMessage("スカートは脱がしてるな。");
			}
			myProc.ChangeMakuruName();
		});
		//捲るコマンドから戻る
		myBT.setCommandProcessing(myBT.CommandMakuruR,function(){
			myBT.MenuHidden();
			myBT.MenuView();
			_self.ViewBox(myBT.Menu);
		});
	}
	
	//上着を脱がす
	waer(){
		myBT.setCommandProcessing(myBT.CommandWaer,function(){
			myST.WearUnder("wear");
		});
	}	
	
	//スカート/下着を脱がす
	under(){
		myBT.setCommandProcessing(myBT.CommandUnder,function(){
			myST.WearUnder("under");
		});
	}
	//着替える
	Kigaeru(){
		//脱衣メニュー表示
		myBT.setCommandProcessing(myBT.CommandKigaeru,function(){
			myBT.MenuKigae();
			//着替え1・ネグリジェ
			myBT.setCommandProcessing(myBT.CommandKigae1,function(){
				//衣服変更
				if(myImg.GetIndexPos("shatu")!=imgNegurije){
					//ネグリジェに着替える/ブラとパンティは消す。
					myProc.WearBackUp();//衣服状態のバックアップ		
					myST.AntenImageView(function(){
						myProc.changeImage(12,myProc.moveIndex,false);
					},510,1000)
					this.innerText = "魔導士の服";
				}else{
					//制服に着替える/ブラとパンティは戻す。
					/*myST.AntenImageView(function(){
						myST.CheageImage("seihuku",myProc.backupWear["seihuku"]);
						myST.CheageImage("shatu",myProc.backupWear["shatu"]);
						myST.CheageImage("sukart",myProc.backupWear["sukart"]);
						myST.CheageImage("kutu",myProc.backupWear["kutu"]);
						myST.CheageImage("inner",myProc.backupWear["inner"]);
						myST.CheageImage("burager",myProc.backupWear["burager"]);
						myST.CheageImage("panty",myProc.backupWear["panty"]);
						myRpg.WearBreak(myRpg.Charctor);
					},510,1000);*/
					myBE.excuteEvent(13);
					this.innerText = "ネグリジェ";
				}
			});
			//戻る
			myBT.setCommandProcessing(myBT.CommandMenuReturn,function(){
				myBT.MenuHidden();
				_self.ViewBox(myBT.Menu);		
				myBT.MenuView();
			});
		});
	}
	
	//脱衣機能ー自分で脱ぐ方
	Nugu(){
		//衣服状態のバックアップ
		myProc.WearBackUp = function(){
			var WUValue = 0;
			//下記すべて身に着けている状態を保持
			WUValue = myImg.GetIndexPos("seihuku");
			if(WUValue)myProc.backupWear["seihuku"] = myImg.GetIndexPos("seihuku");
			WUValue = myImg.GetIndexPos("shatu");
			if(WUValue)myProc.backupWear["shatu"] = myImg.GetIndexPos("shatu");
			WUValue = myImg.GetIndexPos("sukart");
			if(WUValue)myProc.backupWear["sukart"] = myImg.GetIndexPos("sukart");
			WUValue = myImg.GetIndexPos("inner");
			if(WUValue)myProc.backupWear["inner"] = myImg.GetIndexPos("inner");
			WUValue = myImg.GetIndexPos("burager");
			if(WUValue)myProc.backupWear["burager"] = myImg.GetIndexPos("burager");
			WUValue = myImg.GetIndexPos("panty");
			if(WUValue)myProc.backupWear["panty"] = myImg.GetIndexPos("panty");			
		}
		//脱衣メニュー表示
		myBT.setCommandProcessing(myBT.CommandNugu,function(){
			myBT.MenuNugu();
			myProc.WearBackUp();//衣服状態のバックアップ
			//ローブ/カーディガン
			myBT.setCommandProcessing(myBT.CommandWaer,function(){
				var tmp = myImg.GetIndexPos("seihuku");
				if(!tmp){
					if(myProc.WearBreakcheck("seihuku")){
						if(myProc.backupWear.seihuku===undefined)myProc.backupWear["seihuku"] = 1;
						myST.CheageImage("seihuku",myProc.backupWear["seihuku"]);
					}else{
						myBT.showMessage("女子校生<br>「...」");
						return;
					}
				}else{
					myST.CheageImage("seihuku",0);
				}
				myProc.WearUnderMsg(tmp);
			});
			//ブラウス
			myBT.setCommandProcessing(myBT.CommandWaer2,function(){
				var tmp = myImg.GetIndexPos("shatu");
				if(!tmp){
					if(myProc.WearBreakcheck("shatu")){
						//myST.CheageImage("shatu",myProc.backupWear["shatu"]);
						var shatuIndex = 3;
						if(myImg.GetIndexPos("burager")==0){
							shatuIndex = 4;
						}
						myST.CheageImage("shatu",shatuIndex);
						myBT.showMessage("女子校生<br>「...何がしたいの？」");
					}else{
						myBT.showMessage("女子校生<br>「...」");
						return;
					}
				}else{
					//myST.CheageImage("shatu",0);
					var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
					if(JudgeValue>85){
						myBT.setMessage(myST.EventData[0]);
					}else if(JudgeValue>70){
						myST.CheageImage("shatu",2);
						myBT.setMessage(myST.EventData[1]);
					}else if(JudgeValue>55){
						myST.CheageImage("shatu",3);
						myBT.setMessage(myST.EventData[2]);
					}else if(JudgeValue<=55){
						myST.CheageImage("shatu",0);
						myBT.setMessage(myST.EventData[3]);
					}
				}
				//myProc.WearUnderMsg(tmp);
			});
			//スカート
			myBT.setCommandProcessing(myBT.CommandWaer3,function(){
				var tmp = myImg.GetIndexPos("sukart");
				if(!tmp){
					if(myProc.WearBreakcheck("sukart")){
						myST.CheageImage("sukart",myProc.backupWear["sukart"]);
						myBT.showMessage("女子校生<br>「...何がしたいの？」");
					}else{
						myBT.showMessage("女子校生<br>「...」");
						return;
					}
				}else{
					//myST.CheageImage("sukart",0);
					var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
					if(JudgeValue>55){
						myBT.setMessage(myST.EventData[0]);
					}else if(JudgeValue<=55){
						myST.CheageImage("sukart",0);
						myBT.setMessage(myST.EventData[3]);
					}
				}
				//myProc.WearUnderMsg(tmp);
			});
			//タイツ
			myBT.setCommandProcessing(myBT.CommandWaer4,function(){
				var tmp = myImg.GetIndexPos("inner");
				if(!tmp){
					if(myProc.WearBreakcheck("inner")){
						myST.CheageImage("inner",myProc.backupWear["inner"]);
					}else{
						myBT.showMessage("女子校生<br>「...」");
						return;
					}
				}else{
					//myST.CheageImage("inner",0);
					myBT.setMessage(myST.EventData[0]);
				}
				//myProc.WearUnderMsg(tmp);
			});
			//ブラ
			myBT.setCommandProcessing(myBT.CommandUnder,function(){
				//体験版
				if((!_self.product_flg)&&(!_self.sample2_flg)){
					myBT.showMessage("体験版では脱がせません。");
					return;
				}
				var tmp = myImg.GetIndexPos("burager");
				if(!tmp){
					if(myProc.WearBreakcheck("burager")){
						myST.CheageImage("burager",myProc.backupWear["burager"]);
						myST.CheageImage("body",1);
						if(myImg.GetIndexPos("shatu")!=0){
							myST.CheageImage("shatu",3);						
						}
						myBT.showMessage("女子校生<br>「...何がしたいの？」");						
					}else{
						myBT.showMessage("女子校生<br>「...」");
						return;
					}
				}else{
					//myST.CheageImage("burager",0);
					var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
					if(JudgeValue>40){
						myBT.setMessage(myST.EventData[0]);
					}else if(JudgeValue<=40){
						myST.CheageImage("burager",0);
						myST.CheageImage("body",2);
						if(myImg.GetIndexPos("shatu")!=0){
							myST.CheageImage("shatu",4);						
						}						
						myBT.setMessage(myST.EventData[3]);
					}
				}
				//myProc.WearUnderMsg(tmp);
			});
			//パンティ
			myBT.setCommandProcessing(myBT.CommandUnder2,function(){
				//体験版
				var tmp = myImg.GetIndexPos("panty");
				if((!_self.product_flg)||(_self.sample2_flg)){
					if(!_self.sample2_flg)myBT.showMessage("体験版では脱がせません。");
					if(_self.sample2_flg)myBT.showMessage("限定体験版でも脱がせません。");
					return;
				}				
				if(!tmp){
					if(myProc.WearBreakcheck("panty")){
						myST.CheageImage("panty",myProc.backupWear["panty"]);
						myBT.showMessage("女子校生<br>「...何がしたいの？」");
					}else{
						myBT.showMessage("女子校生<br>「...」");
						return;
					}
				}else{
					//myST.CheageImage("panty",0);
					var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
					if(JudgeValue>40){
						myBT.setMessage(myST.EventData[0]);
					}else if(JudgeValue<=40){
						myST.CheageImage("panty",0);
						myBT.setMessage(myST.EventData[3]);
					}
				}
				//myProc.WearUnderMsg(tmp);
			});
			//戻る
			myBT.setCommandProcessing(myBT.CommandMenuReturn,function(){
				myBT.MenuHidden();
				_self.ViewBox(myBT.Menu);		
				myBT.MenuView();
			});
			/*//脱いだ時のメッセージ
			myProc.WearUnderMsg = function(flg){
				if(flg){
					myBT.showMessage("女子校生<br>「くっ...」");
				}else{
					myBT.showMessage("女子校生<br>「...」");
				}
				myRpg.WearBreak(myRpg.Charctor);
			}*/
		});
	}
	
	//脱衣機能
	nugasu(){
		myBT.setCommandProcessing(myBT.CommandNugasu,function(){
			if(!_self.GetBoxStatus(myBT.CommandWaer)){
				_self.Elm(myBT.CommandNugasu,_self.TypeID).innerText = "やめる";
				myBT.MenuNugasu();
			}else if(_self.GetBoxStatus(myBT.CommandWaer)){
				_self.Elm(myBT.CommandNugasu,_self.TypeID).innerText = "脱がす";
				myBT.MenuHidden();				
				myBT.MenuView();				
			}
		});
	}
	
	//挿入
	sounyuu(){
		myBT.setCommandProcessing(myBT.CommandSounyuu,function(){
			if(myProc.sounyuuFlg==undefined)return;
			var JudgeValue = (myProc.GetStatusData("抵抗力"))[2];
			if(JudgeValue>70){
				myBT.setMessage(["俺<br>「さすがにまだ早いな...」"]);
				return;
			}
			//挿入判定
			if(!myST.SexSounyuu){
				myST.SexSounyuu = true;
				myST.SexFlg = true;
				_self.Elm(myBT.CommandSounyuu,_self.TypeID).innerText = "抜く";
				myBT.MenuSounyuu2();
				myImg.SetIndexPos("seieki",0);
				myST.TouchData[myST.TouchData.length-1]();				
				if(_self.CheckTouchEvent()) {
					//タッチ対応
					_self.doc.ontouchdown = myST.Sounyuu;
				} else {
					//タッチ非対応
					_self.doc.onmousedown = myST.Sounyuu;
				}
			}else{
				myST.SexSounyuu = false;				
				myST.SexFlg = false;
				myST.ShaseiFlg = false;
				_self.Elm(myBT.CommandSounyuu,_self.TypeID).innerText = "挿入";
				_self.ViewBox(myBT.Menu);
				myST.Sounyuu();
				myBT.MenuView();
				_self.HiddenBox(myBT.CommandShasei);				
			}
		});
		myProc.sounyuuFlg = true;
	}
	
	//射精
	shasei(){
		myBT.setCommandProcessing(myBT.CommandShasei,function(){
			if(!myST.ShaseiFlg)return;
			myST.Shasei();
			_self.HiddenBox(myBT.CommandShasei);
			myST.ShaseiCount = 0;
		});
		myProc.sounyuuFlg = true;
	}
	
	//ジャンケン
	janken(){
		myBT.setCommandProcessing(myBT.Commandjanken,function(){
			myBT.setMessage(myST.EventData[0]);
		});
	}
	
	//視姦
	Lock2(){
		myBT.setCommandProcessing(myBT.CommandLock2,function(){
			var index = Math.floor(Math.random()*3)+18;
			myBT.setMessage(myST.Story[index]);
		});
	}
	
	//枠消す
	boxnone(){
		myBT.setCommandProcessing(myBT.CommandBoxnone,function(){
			if(_self.GetBoxStatus("msgBox")){
				_self.HiddenBox("msgBox");
				return;
			}
			if(!_self.GetBoxStatus("msgBox")){
				_self.ViewBox("msgBox");
				return;
			}
		});
		myProc.sounyuuFlg = true;
	}

	//枠消す
	Test(){
		myBT.setCommandProcessing(myBT.CommandBattle,function(){
			myRpg.EventBattleCount = false;
			myRpg.BattleProcessing();
		});
	}
	
	Option(){
		myBT.setCommandProcessing(myBT.CommandOption,function(){
			var parent = _self.Elm("operation",_self.TypeID);
			//var Xpos = parseInt(_self.width_hi*0.05)+"px";
			var Xpos = parseInt(_self.width_hi*0.05)+"px";
			var Ypos = "10px";
			var res = _self.Elm("Option1",_self.TypeID);
			if((res==undefined)||(res==null)){
				//オプション画面本体生成
				myBT.setCommonBox(parent,"Option1",Xpos,Ypos);
				var data = _self.GetBoxData("Option1");
				//data.width = parseInt(_self.width_hi*0.9)+"px";
				data.width = parseInt(_self.width_hi*0.9)+"px";
				data.height = parseInt(window.innerHeight*0.9)+"px";
				
				_self.ChangeBox("Option1");
				//オプションメニュー領域生成
				var elm = _self.Elm("Option1",_self.TypeID);
				elm.innerHTML = "";
				myBT.setCommonBox(elm,"OptionMenu","-1px","-1px");
				var data2 = _self.GetBoxData("OptionMenu");
				data2.height = parseInt(_self.width_hi*0.9)+"px";
				_self.ChangeBox("OptionMenu");
				_self.Elm("Option1",_self.TypeID).style.backgroundColor = "rgba(0,0,0,0.8)";				
				_self.Elm("OptionMenu",_self.TypeID).style.backgroundColor = "rgba(0,0,0,0.8)";				
				//オプションメニューを閉じる
				myProc.OptionMenuBoxClose = function(){
					var flg = _self.Elm("Setting",_self.TypeID);
					if(flg!=undefined)_self.HiddenBox("Setting");
					flg = _self.Elm("DataSave",_self.TypeID);
					if(flg!=undefined)_self.HiddenBox("DataSave");
					flg = _self.Elm("DataLoad",_self.TypeID);
					if(flg!=undefined)_self.HiddenBox("DataLoad");
				}				
				//オプションメニュー生成/閉じる
				_self.AddCommand("OptionMenu","opClose","閉じる");
				myBT.setCommandProcessing("opClose",function(){
					myProc.OptionMenuBoxClose();
					_self.HiddenBox("Option1");
					_self.HiddenBox("OptionMenu");
					myBT.MenuView();
					_self.ViewBox(myBT.Menu);					
				});
				//設定メニュー
				_self.AddCommand("OptionMenu","opSet","設定");
				myBT.setCommandProcessing("opSet",function(){
					myProc.OptionMenuBoxClose();
					Xpos = (parseInt(_self.width_hi*0.05)+99)+"px";
					//音楽ON/OFF設定
					var setElm = _self.Elm("Setting",_self.TypeID);
					if((setElm==undefined)||(setElm==null)){
						//音楽設定画面生成
						myBT.setCommonBox(parent,"Setting",Xpos,Ypos);
						var data = _self.GetBoxData("Setting");
						data.width = (parseInt(_self.width_hi*0.9)-100)+"px";
						data.height = parseInt(window.innerHeight*0.9)+"px";
						_self.ChangeBox("Setting");
						_self.Elm("Setting",_self.TypeID).style.backgroundColor = "rgba(0,0,0,0.8)";							
						//音楽On設定＆処理
						_self.AddCommand("Setting","musicOn","音楽ON");
						myBT.setCommandProcessing("musicOn",function(){
							var mustsElm = _self.Elm("musicStatus",_self.TypeID);
							myProc.music(myProc.musIndex,0);
							mustsElm.innerText = "現在の状態：再生";
						});
						//音楽Off設定＆処理
						_self.AddCommand("Setting","musicOff","音楽OFF");
						myBT.setCommandProcessing("musicOff",function(){
							var mustsElm = _self.Elm("musicStatus",_self.TypeID);
							myProc.music(myProc.musIndex,1);
							mustsElm.innerText = "現在の状態：停止";
						});
						var sts = myProc.music_flg?"再生":"停止";						
						_self.AddCommand("Setting","musicStatus","現在の状態："+sts);
						/*if(!_self.sample_flg){
							//絶対勝利フラグ
							_self.AddCommand("Setting","victory","絶対勝利フラグ");
							myBT.setCommandProcessing("victory",function(){
								var mustsElm = _self.Elm("VictoryStatus",_self.TypeID);
								myProc.victoryFlg = !myProc.victoryFlg;
								mustsElm.innerText = "現在の状態："+(myProc.victoryFlg?"オン":"オフ");
							});
							var sts = myProc.victoryFlg?"オン":"オフ";	
							_self.AddCommand("Setting","VictoryStatus","現在の状態："+sts);
						}*/
						//応援プラン用機能解放コード
						_self.AddCommand("Setting","special_code","");
						_self.Elm("special_code",_self.TypeID).innerHTML = '機能解放コード入力<br><input type="text" id="sp_code" /><br><button id="sp_func_on">機能解放</button><br><p id="sp_code_msg"></p>';
						myProc.SpFunction = function(){
							mySpCode.SetDataName(title_str+"_SpCode");
							mySpCode.SetSaveData("SpCodeValue",_self.Elm("sp_code",_self.TypeID).value);
							mySpCode.Save();
							var res = mySpCode.CheckCode();
							var msg = "機能コードが間違っています。";
							if(res)msg = "機能解放します。<br>※一度再起動してください。";
							myBT.optionMessage(parent,"機能コードが入力されました。<br>"+msg);
						}					
						myBT.setCommandProcessing("sp_func_on",myProc.SpFunction);
						//コード入力フォーカスイベント-IN
						_self.Elm("sp_code",_self.TypeID).addEventListener("focus",function(){
							//制御解除
							document.oncontextmenu = function () {
								var userAgent = window.navigator.userAgent.toLowerCase();
								var res = userAgent.indexOf("windows");
								if(res==-1){
									return true;
								}else{
									return false;
								}
							}
						});
						//コード入力フォーカスイベント=OUT
						_self.Elm("sp_code",_self.TypeID).addEventListener("blur",function(){
							document.oncontextmenu = function(){return false;}
						});
					}else{
						_self.ViewBox("Setting");	
					}				
				});
				/*セーブ/ロードなし*/
				//return;
				//保存生成
				_self.AddCommand_org("OptionMenu","opSave","セーブ");
				myBT.setCommandProcessing("opSave",function(){
					myProc.OptionMenuBoxClose();					
					Xpos = (parseInt(_self.width_hi*0.05)+99)+"px";
					//保存設定
					var setElm = _self.Elm("DataSave",_self.TypeID);
					if((setElm==undefined)||(setElm==null)){
						//保存設定画面生成
						myBT.setCommonBox(parent,"DataSave",Xpos,Ypos);
						var data = _self.GetBoxData("DataSave");
						data.width = (parseInt(_self.width_hi*0.9)-100)+"px";
						data.height = parseInt(window.innerHeight*0.9)+"px";
						_self.ChangeBox("DataSave");
						_self.AddCommand_org("DataSave","SaveMenu","セーブ");
						_self.Elm("SaveMenu",_self.TypeID).innerHTML += "<hr>";
						_self.Elm("DataSave",_self.TypeID).style.backgroundColor = "rgba(0,0,0,0.8)";
						_self.Elm("SaveMenu",_self.TypeID).style.backgroundColor = "rgba(0,0,0,0.8)";
						//データ設定ループ
						for(var loop=0;loop<myProc.LoadIndexMax;loop++){
							//保存設定＆処理
							var ld_data = myProc.loadData(true);
							var mvPosData = myProc.movedata[0];
							//保存データチェック
							var msg = "";
							//保存データメッセージ
							myProc.SaveMsg = function(index){
								var msg = "\nデータはありません。\n\n";
								if(ld_data["saveFlg"+index]){
									var mvIdx = ld_data["moveIndex"+index];
									msg = 'データ'+parseInt(index+1)+'\n';
									var funcIdx = mvPosData.length-1;
									msg += "場所："+mvPosData[funcIdx](mvIdx)+"\n";
									//msg += "イベントNo："+ld_data["LastEventNo"+index]+"\n";
									//msg += "LV："+ld_data["RpgData"+index].LV+",EXE："+ld_data["RpgData"+index].EXE+"\n";
									msg += "幼なじみ奴隷"+myProc.Day+"日目\n";

								}
								return msg;
							}
							//保存処理
							msg = myProc.SaveMsg(loop);
							_self.AddCommand_org("DataSave","saveNo"+loop,msg);
							_self.Elm("saveNo"+loop,_self.TypeID).innerHTML += "<hr>";
							myBT.setCommandProcessing("saveNo"+loop,function(){
								var stratPos = String("saveNo").length;
								var endPos = this.id.length - stratPos;
								var idx = parseInt(this.id.substr(stratPos,endPos));
								myProc.LoadIndex = idx;
								myProc.saveData();
								msg = myProc.SaveMsg(idx);
								_self.Elm(this.id,_self.TypeID).innerText = msg;
								_self.Elm(this.id,_self.TypeID).innerHTML += "<hr>";
								myBT.optionMessage(parent,"保存しました。");
							});
						}
					}else{
						_self.ViewBox("DataSave");	
					}
				});
				//読込生成				
				_self.AddCommand_org("OptionMenu","opLoad","ロード");
				myBT.setCommandProcessing("opLoad",function(){
					myProc.OptionMenuBoxClose();
					Xpos = (parseInt(_self.width_hi*0.05)+99)+"px";
					//読込設定
					var setElm = _self.Elm("DataLoad",_self.TypeID);
					if((setElm==undefined)||(setElm==null)){
						//読込設定画面生成
						myBT.setCommonBox(parent,"DataLoad",Xpos,Ypos);
						var data = _self.GetBoxData("DataLoad");
						data.width = (parseInt(_self.width_hi*0.9)-100)+"px";
						data.height = parseInt(window.innerHeight*0.9)+"px";
						_self.ChangeBox("DataLoad");
						_self.AddCommand_org("DataLoad","LoadMenu","ロード");
						_self.Elm("LoadMenu",_self.TypeID).innerHTML += "<hr>";
						_self.Elm("DataLoad",_self.TypeID).style.backgroundColor = "rgba(0,0,0,0.8)";
						_self.Elm("LoadMenu",_self.TypeID).style.backgroundColor = "rgba(0,0,0,0.8)";
						//データ設定ループ
						for(var loop=0;loop<myProc.LoadIndexMax;loop++){
							//読込設定＆処理
							var ld_data = myProc.loadData(true);
							var mvPosData = myProc.movedata[0];
							//読込データチェック
							var msg = "";
							//読込データメッセージ
							myProc.SaveMsg = function(index){
								var msg = "\nデータはありません。\n\n";
								if(ld_data["saveFlg"+index]){
									var mvIdx = ld_data["moveIndex"+index];
									msg = 'データ'+parseInt(index+1)+'\n';
									var funcIdx = mvPosData.length-1;
									msg += "場所："+mvPosData[funcIdx](mvIdx)+"\n";
									//msg += "イベントNo："+ld_data["LastEventNo"+index]+"\n";
									//msg += "LV："+ld_data["RpgData"+index].LV+",EXE："+ld_data["RpgData"+index].EXE+"\n";
									msg += "幼なじみ奴隷"+myProc.Day+"日目\n";
								}
								return msg;
							}
							//読込処理
							msg = myProc.SaveMsg(loop);
							_self.AddCommand_org("DataLoad","LoadNo"+loop,msg);
							_self.Elm("LoadNo"+loop,_self.TypeID).innerHTML += "<hr>";
							myBT.setCommandProcessing("LoadNo"+loop,function(){
								var stratPos = String("LoadNo").length;
								var endPos = this.id.length - stratPos;
								var idx = parseInt(this.id.substr(stratPos,endPos));
								myProc.LoadIndex = idx;
								if(MapFlg){
									//----ダンジョン解除----
									myProc.MapMoveFlg = false;
									myProc.MapExitFlg = false;
									myMap.MapViewFlg = false;
									myMap.MapHidden();
									myMap.chgArea();
									//----ダンジョン解除----
								}
								myProc.OptionMenuBoxClose();
								_self.HiddenBox("Option1");
								_self.HiddenBox("OptionMenu");
								_self.ViewBox(myBT.Menu);
								_self.Processing(false);
								/*//RPG用
								if(MapFlg){
									var tmp = myRpg.Charctor;
									if(tmp.MAPINDEX!==undefined)gl_map_index　= tmp.MAPINDEX;
									if(tmp.ADVPOS!==undefined)gl_now_adv_pos = tmp.ADVPOS;
									if(tmp.MAPX!==undefined)gl_now_pos_x = tmp.MAPX;
									if(tmp.MAPY!==undefined)gl_now_pos_y = tmp.MAPY;
								}
								myProc.moveBefore(myProc.moveIndex);*/								
								myBT.optionMessage(parent,"読み込みました。");
							});
						}
					}else{
						_self.ViewBox("DataLoad");	
					}
				});
			}else{
				_self.ViewBox("Option1");
				_self.ViewBox("OptionMenu");
			}
			myBT.MenuHidden();
			_self.HiddenBox(myBT.Menu);
		});
	}	
	//音楽
	musicData(){
		var data = [
			'./music/tmbach_piano03.mp3',
			'./music/tmbach_piano09.mp3',
		];
		return data;
	}

	//効果音
	SEArray(){
		var data = [];
		return data;
	}
	
	//効果音
	VoiceArray(){
		var data = [];
		return data;
	}	
	
	//音楽
	music(trakNo=-1,cmd=0){
		//初期化
		if(trakNo==-1){
			var musData = this.musicData();
			for(var loop in musData){
				myProc.musData[loop] = new Audio;
				myProc.musData[loop].musNo = loop;
				myProc.musData[loop].src = musData[loop];
				myProc.musData[loop].music_flg = false;
				//ロード開始
				myProc.musData[loop].load();
				//ロード完了イベント
				myProc.musData[loop].addEventListener("loadedmetadata",function(){
					//音量設定/次音声ロード
					this.volume = 0.10;
				},
				false);
				//音楽再生
				myProc.musData[loop].musStart = function(){
					if(!this.music_flg){
						this.music_flg = true;
						myProc.musIndex = this.musNo;
						myProc.musStatus = true;
						this.play();
						this.addEventListener("ended", function() {
							this.currentTime = 0;
							this.play();
						}, false);		
					}
				}
				//停止
				myProc.musData[loop].musStop = function(){
					if(this.music_flg){
						this.pause();
						this.currentTime = 0;
						this.music_flg = false;
						myProc.musStatus = false;
					}
				}				
			}
			return;
		}
		//再生
		if(cmd==0)myProc.musData[trakNo].musStart();
		//停止
		if(cmd==1)myProc.musData[trakNo].musStop();
		//全停止
		if(cmd==2){
			for(var loop in myProc.musData){
				myProc.music(loop,myST.BGM_OFF);					
			}
		}
		//再生中かチェック
		if(cmd==3)return myProc.musData[trakNo].music_flg;
	}
	//効果音
	SESound(trakNo=-1,cmd=0){
		//初期化
		if(trakNo==-1){
			var musSEData = this.SEArray();
			for(var loop in musSEData){
				myProc.musSEData[loop] = new Audio;
				myProc.musSEData[loop].musNo = loop;
				myProc.musSEData[loop].src = musSEData[loop];
				myProc.musSEData[loop].music_flg = false;
				//ロード開始
				myProc.musSEData[loop].load();
				//ロード完了イベント
				myProc.musSEData[loop].addEventListener("loadedmetadata",function(){
					//音量設定/次音声ロード
					this.volume = 0.35;
				},
				false);
				//音楽再生
				myProc.musSEData[loop].musStart = function(){
					var debugView = _self.Elm(".debug");
					if(!this.music_flg){
						this.music_flg = true;
						this.musSEIndex = loop;
						myProc.musSEStatus = true;
						myBT.debugMessage("SE発生:"+this.musNo+"\n");
						this.play();
						if(!_self.Windows_flg){
							this.addEventListener("ended", function() {
								this.currentTime = 0;
								this.music_flg = false;
							}, false);
						}
					}
				}
				//停止
				myProc.musSEData[loop].musStop = function(){
					if(this.music_flg){
						this.pause();
						this.currentTime = 0;
						this.music_flg = false;
						myProc.musSEStatus = false;
						var debugView = _self.Elm(".debug");
						myBT.debugMessage("SE消音:"+this.musNo+"\n");
					}
				}				
			}
			return;
		}
		//再生
		if(cmd==0){
			myProc.musSEData[trakNo].musStart();
		}
		//停止
		if(cmd==1)myProc.musSEData[trakNo].musStop();
	}
	
	//効果音
	Voice(trakNo=-1,cmd=0){
		//初期化
		if(trakNo==-1){
			var musVoiceData = this.VoiceArray();
			for(var loop in musVoiceData){
				myProc.musVoiceData[loop] = new Audio;
				myProc.musVoiceData[loop].musNo = loop;
				myProc.musVoiceData[loop].src = musVoiceData[loop];
				myProc.musVoiceData[loop].music_flg = false;
				//ロード開始
				myProc.musVoiceData[loop].load();
				//ロード完了イベント
				myProc.musVoiceData[loop].addEventListener("loadedmetadata",function(){
					//音量設定/次音声ロード
					this.volume = 1;
					this.loop = false;
				},
				false);
				//音楽再生
				myProc.musVoiceData[loop].musStart = function(){
					var debugView = _self.Elm(".debug");
					if(!this.music_flg){
						this.music_flg = true;
						this.musVoiceIndex = loop;
						myProc.musVoiceStatus = true;
						myBT.debugMessage("SE発生:"+this.musNo+"\n");
						this.play();
						if(!_self.Windows_flg){
							this.addEventListener("ended", function() {
								this.pause();
								this.currentTime = 0;
								this.music_flg = false;
							}, false);
						}
					}
				}
				//停止
				myProc.musVoiceData[loop].musStop = function(){
					if(!this.paused){
						this.pause();
						this.currentTime = 0;
						this.music_flg = false;
						myProc.musVoiceStatus = false;
						var debugView = _self.Elm(".debug");
						myBT.debugMessage("Voice消音:"+this.musNo+"\n");
					}
				}				
			}
			return;
		}
		//再生
		if(cmd==0){
			myProc.musVoiceData[trakNo].musStart();
		}else
		//停止
		if(cmd==1){
			myProc.musVoiceData[trakNo].musStop();
		}
	}
	
}
myProc = new MyProcessing();