//メイン処理
var title_str = 'GirlPrison2';
var ver_str = "ver.1.0.0-220105";
var ver_str_option = "";
ver_str = ver_str+ver_str_option;
var dateDay = "20"+ver_str.split("-")[1];
var proc_buff = ["",dateDay.slice(0,4),dateDay.substr(4,2),dateDay.substr(6,2)];
var time_obj = new Date(proc_buff[1],(parseInt(proc_buff[2])-1),proc_buff[3],23,59);
time_obj.setMonth(time_obj.getMonth() + 1);
var timelimit = "timelimit,"+time_obj.getFullYear()+","+(time_obj.getMonth()+1)+","+time_obj.getDate();
var myRpg = null;
var imageSetting = null;
var myImg = null;
var myBT = null;
var myBE = null;
var myProc = null;
var myST = null;
var mySpCode;
Main = new StartProcess();
Main.title_str = title_str+"\n地下室に監禁された女子校生";
//処理開始
Main.ProcStart = function(){
	if(window.parent.caches!=undefined)window.parent.caches.delete("call");
	var _this = null;
	_this = new BaseJs();
	_self = _this;
	_self.doc = document;
	//タイトル
	_self.doc.title = this.title_str;
	_self.debug = true;
	//起動時機能解放コード取得
	mySpCode = new DataSave;
	mySpCode.constructor();
	mySpCode.SetDataName(title_str+"_SpCode");
	mySpCode.Load();		
	var sData = mySpCode.AppSaveData;
	_self.Spcode = 0;
	mySpCode.CheckCode = function(){
		var res = false;
		if(sData!=null){
			var code = sData["SpCodeValue"];
			var codeConvert = {
				free:["apos@qi",false],
				code100:["kis@h9e",false],
				code300:["lois@fh",false],
				code500:["youwr12",false],
				codeProduct:["oisuf@q",false],
				codeWebReLimit:["yissf@r",false],
			};
			_self.Spcode = 0;
			if(codeConvert.free[0]==code){_self.Spcode += 1;codeConvert.free[1]=true;res = true;}//1
			if(codeConvert.code100[0]==code){_self.Spcode += 2;codeConvert.code100[1]=true;res = true;}//2
			if(codeConvert.code300[0]==code){_self.Spcode += 4;codeConvert.code300[1]=true;res = true;}//4
			if(codeConvert.codeProduct[0]==code){_self.Spcode += 8;codeConvert.codeProduct[1]=true;res = true;}//8
			if(codeConvert.code500[0]==code){_self.Spcode = 31;codeConvert.code500[1]=true;res = true;}//16
			if(codeConvert.codeWebReLimit[0]==code){_self.Spcode = 0;codeConvert.codeWebReLimit[1]=true;res = true;}//16
			_self.codeData = codeConvert;
		}else{
			mySpCode.SetDataName(title_str+"_SpCode");
			mySpCode.SetSaveData("SpCodeValue","");
			mySpCode.Save();		
		}
		return res;
	}
	mySpCode.CheckCode();
	//製品フラグ
	var webSw = location.origin.indexOf("http");
	var input_option = location.search.substr(1,location.search.length);
	_self.Windows_flg = (input_option.indexOf("windows")!=-1);
	_self.product_flg = (input_option.indexOf("true")==-1)||(_self.Spcode&4);
	_self.sample_flg = (input_option.indexOf("true")!=-1);
	_self.sample2_flg = (input_option.indexOf("true2")!=-1)||(_self.Spcode==1);
	_self.special_flg = (input_option.indexOf("special")!=-1)||(_self.Spcode&16);
	_self.clear_flg = (input_option.indexOf("clear")!=-1);
	_self.test_flg = (input_option.indexOf("test")!=-1);
	if(_self.sample2_flg)_self.product_flg = true;
	_self.timelimit = ((input_option.indexOf("timelimit")!=-1)?true:false)||(_self.Spcode&2);
	console.log("製品モード:"+_self.product_flg);
	//製品時のコード設定
	if(_self.product_flg){
		if(_self.Spcode>=4 && _self.Spcode<=15){
			mySpCode.SetDataName(title_str+"_SpCode");
			mySpCode.SetSaveData("SpCodeValue",_self.codeData.codeProduct[0]);
			mySpCode.Save();
		}else if(input_option.indexOf("true")==-1 && _self.Spcode<=15){
			mySpCode.SetDataName(title_str+"_SpCode");
			mySpCode.SetSaveData("SpCodeValue",_self.codeData.codeProduct[0]);
			mySpCode.Save();
		}
	}
	//Web専用製品モード
	if(_self.codeData.codeWebReLimit[1]){
		_self.product_flg = true;
	}
	//設定コードから解除
	if(_self.Spcode>=4){
		_self.sample_flg = false;
		_self.sample2_flg = false;
		_self.timelimit = false;
	}
	if(_self.Spcode&2){
		_self.sample_flg = false;
		_self.sample2_flg = false;
		_self.product_flg = true;
	}
	//データ初期化
	if(_self.clear_flg){
		localStorage.removeItem(title_str+"_SpCode");
		localStorage.removeItem("title_str");
		_self.Elm("operation",_self.TypeID).innerHTML = '<center><p style="color:white">データを初期化致しました。<br>アプリを再起動してください。</p></center>';
		return;
	}
	var buffWidth = window.innerWidth<=800?window.innerWidth:800;
	var buffheight = window.innerHeight<=600?window.innerHeight:600;
	var bodyElm = _self.doc.body;
	var zoom_value = 0;
	var zoom_value_x = 1;
	var zoom_value_y = 1;
	if((buffWidth-10)>=_self.width_hi)zoom_value_x = (buffWidth-10)/_self.width_hi;
	if((buffheight-10)>=_self.width_hi)zoom_value_y = (buffheight-10)/_self.height_hi;
	if(buffWidth <= 800)zoom_value = zoom_value_x;
	if((buffheight <= 600)&&(zoom_value==0))zoom_value = zoom_value_y;
	_self.zoom_value = zoom_value;
	bodyElm.style.transformOrigin='top left';
	bodyElm.style.transform='scale(' + zoom_value + ')';
	bodyElm.style.width=Math.round(1000/zoom_value)/10 + '%';
	bodyElm.style.height=Math.round(1000/zoom_value)/10 + '%';
	var width = Main.DisplayWidth(_self.width_hi);
	var height = Main.DisplayHeight(_self.height_hi);
	_this.setWidthHi(width);
	_this.setHeightHi(height);
	//暗幕
	Main.Loading(_this,width+"px",height+"px",false);
	//メイン処理
	Main.MainProc = function(){
		document.oncontextmenu = function () {return false;}
		//データ名設定
		//画像表示用カスタムクラス読み込み
		Main.oneload = false;
		Main.ScriptLoad("./js/MyRPGSystem.js?202201052158");
		Main.ScriptLoad("./js/ImageSetting.js?202201052158");
		Main.ScriptLoad("./js/MyBoxTouch.js?202201052158");
		Main.ScriptLoad("./js/MyImage.js?202201052158");	
		Main.ScriptLoad("./js/MySetting.js?202201052158");	
		Main.ScriptLoad("./js/MyBaseEvent.js?202201052158");	
		Main.ScriptLoad("./js/MyProcessing.js?202201052158");	
		Main.WaitLoad = function(){
			if(myRpg==null){
				_this.setTimer(Main.WaitLoad,100);
				return;
			}else if(imageSetting==null){
				_this.setTimer(Main.WaitLoad,100);
				return;
			}else if(myBT==null){
				_this.setTimer(Main.WaitLoad,100);
				return;
			}
			else if(myImg==null){
				_this.setTimer(Main.WaitLoad,100);
				return;
			}
			else if(myST==null){
				_this.setTimer(Main.WaitLoad,100);
				return;
			}			
			else if(myBE==null){
				_this.setTimer(Main.WaitLoad,100);
				return;
			}
			else if(myProc==null){
				_this.setTimer(Main.WaitLoad,100);
				return;
			}
			//画像データ設定
			myST.Img = imageSetting.Img;
			//音楽/効果音読込
			myProc.music();
			myProc.SESound();
			myProc.Voice();
			//キャンバス生成
			myImg.CreateCanvas();		
			//初期読み込み処理
			_this.InitProgeress = function(_this){
				//画像読み込み
				_this.Elm(".Progress").innerText = parseInt(myImg.InitializeProgress*100)+"%";
				if(parseInt(myImg.InitializeProgress*100)<100){
					_this.setTimer(_this.InitProgeress,100,_this);
				}else{
					/*_this.setTimer(function(_this){
						if((_this.Elm(".Progress").innerText!="")||(!_self.StartOn)){
							_this.Elm(".Progress").innerText = "まもなく起動します...";
						}else{
							
						}
						_self.WarningView();
					},500,_this);*/
					//期間限定か否かチェック
					_this.setTimer(function(){
						//現在時刻を取得
						var now_obj = new Date();	
						var now_time = now_obj.getTime();					
						//期限設定
						if(_self.timelimit){
							var split_data = timelimit.split(",");
							//入力された日付から期間を取得
							var after_obj = new Date(split_data[1],(parseInt(split_data[2])-1),split_data[3],23,59);
							var now_time = now_obj.getTime();
							var after_time = after_obj.getTime();
							if(after_time>=now_time){
								_this.Elm(".Progress").innerHTML = "この製品はプレイ期間限定版モードです。<br>"+split_data[1]+"年"+split_data[2]+"月"+split_data[3]+"日までプレイが出来ます。";
								_self.product_flg = true;
							}else{
								sample_flg = "true";
								_this.Elm(".Progress").innerHTML = "プレイ期間が過ぎています。<br>限定体験版で動作させます。";
								_self.sample2_flg = true;
							}
						}else if(_self.sample2_flg){
							_this.Elm(".Progress").innerHTML = "この製品は限定体験版モードです。";
						}else if(_self.codeData.codeWebReLimit[1]&&(webSw!=-1)){
							_this.Elm(".Progress").innerHTML = "この製品はWeb制限解除版モードです。";
						}
						myImg.SetIndexPos('back',0);
						myImg.SetIndexPos('Other',1);
						myImg.AllImageView(true);
						_this.setTimer(function(){
						var elm = _this.Elm("anmaku",_this.TypeID);
							elm.style.opacity = "0.5";
						},200);
					},550);
				}
			}
			_this.InitProgeress(_this);
			myImg.InitImageView();
		}	
		Main.WaitLoad();
		//枠描画
		_this.ViewInitializeBox = function(){
			var elm = _this.Elm("anmaku",_this.TypeID);
			if(elm.innerHTML!=""){
				_this.setTimer(_this.ViewInitializeBox,1000);
				return;
			}
			var touch = _self.Elm("body");
			if(!_self.CheckTouchEvent()){
				touch[0].onmousedown = myST.BodyTouch;
			}else{
				touch[0].ontouchdown = myST.BodyTouch;
			}
			//枠を生成
			var parent = _self.Elm("operation",_self.TypeID);
			parent.style.width = _self.width_hi;
			parent.style.height = _self.height_hi;
			var imgElm = _self.Elm(".image");
			//画像消去
			myImg.AllClearImage();
			//イベント設定
			myProc.move(true);
			myProc.event(myST.GetEvent);
			var data = myProc.loadData(true);
			var dataCount = myProc.LoadIndexMax;
			//保存データ枠生成
			for(var loop=0;loop<myProc.LoadIndexMax;loop++){
				var boxId = myBT.saveLoadBox(parent,loop);
				var elm = _self.Elm(boxId,_self.TypeID);
				elm.style.textAlign = "center";
				if(data["saveFlg"+loop]==false){
					dataCount--;
					elm.innerHTML = "<br>";
					elm.innerHTML += "データなし";
					_this.DataLoadFunc = function(input_id){
						var stratPos = String("saveLoad").length;
						var endPos = input_id.length - stratPos;
						var idx = parseInt(input_id.substr(stratPos,endPos));
						myProc.LoadIndex = idx;
						myBT.yesNoBox(parent,"データNo"+parseInt(idx+1)+"でゲームを始めますか？",function(){
							//枠描画
							myBT.setBoxTouch(parent);
							//処理設定
							_this.Processing();							
						});
					}
					elm.onmousedown = function(){
						if(!_self.CheckTouchEvent()){
							_this.DataLoadFunc(this.id);
						}
					}
					elm.ontouchdown = function(){
						_this.DataLoadFunc(this.id);
					}
				}else{
					var mvPosData = myProc.movedata[0];
					var mvIdx = data["moveIndex"+loop];
					elm.innerHTML += '<div id="load'+loop+'"></div>';
					elm.innerHTML += '<div id="del'+loop+'">消去</div>';
					var loadelm = _self.Elm("load"+loop,_self.TypeID);
					loadelm.innerHTML += 'データ'+parseInt(loop+1)+'<br>';
					var funcIdx = mvPosData.length-1;
					loadelm.innerHTML += "場所："+mvPosData[funcIdx](mvIdx)+"<br>";
					//loadelm.innerHTML += "LV："+data["RpgData"+loop].LV+",EXE："+data["RpgData"+loop].EXE+"<br>";
					loadelm.innerHTML += "監禁"+data["Day"+loop]+"日目<br>";
					loadelm.onmousedown = function(){
						var stratPos = String("load").length;
						var endPos = this.id.length - stratPos;
						var idx = parseInt(this.id.substr(stratPos,endPos));
						myProc.LoadIndex = idx;
						myBT.yesNoBox(parent,"データNo"+parseInt(idx+1)+"の続きを始めますか？",function(){
							//枠描画
							myBT.setBoxTouch(parent);
							//処理設定
							_this.Processing();
						});	
					}
					loadelm.ontouchdown = function(){
						elm.onmousedown();
					}					
					var delelm = _self.Elm("del"+loop,_self.TypeID);
					delelm.onmousedown = function(){
						var stratPos = String("del").length;
						var endPos = this.id.length - stratPos;
						var idx = parseInt(this.id.substr(stratPos,endPos));
						myProc.LoadIndex = idx;
						myBT.yesNoBox(parent,"データNo"+parseInt(idx+1)+"を消しますか？",function(){
							//枠描画
							myBT.setBoxTouch(parent);
							//処理設定
							myProc.deleteData();
							parent.innerHTML = "";
							_this.ViewInitializeBox();
						});						
					}
					delelm.ontouchdown = function(){
						delelm.onmousedown();
					}
				}
			}
			/*ロードデータあり/なしの場合はいきなりゲームスタート*/
			if(!dataCount){
				if(dataCount==0)myProc.LoadIndex = 4;
				myBT.setBoxTouch(parent);
				_this.Processing();
			}
		}
		//各種処理
		_this.Processing = function(firstFlg=true){
			_self.Elm("anmaku",_self.TypeID).style.opacity = 0;
			_self.ViewBox("anmaku");
			//セーブ枠を消す
			for(var loop=0;loop<myProc.LoadIndexMax;loop++){
				_self.HiddenBox("saveLoad"+loop);
			}
			/*画像位置初期変更*/
			var imgYpos = -90;
			//横位置画面幅毎変更
			var imgXpos = -50;
			if(_self.width_hi!=400)imgXpos = -70;			
			myImg.SetImgPos("back",[imgXpos,imgYpos]);
			myImg.SetImgPos("Other",[imgXpos,imgYpos]);		
			myImg.SetImgPos("body",[imgXpos,imgYpos]);		
			myImg.SetImgPos("body_bk_hair",[imgXpos,imgYpos]);		
			myImg.SetImgPos("body_face_bk",[imgXpos,imgYpos]);		
			myImg.SetImgPos("body_fr_hair",[imgXpos,imgYpos]);		
			myImg.SetImgPos("body_face_fk",[imgXpos,imgYpos]);		
			myImg.SetImgPos("kutusita",[imgXpos,imgYpos]);		
			myImg.SetImgPos("kutu",[imgXpos,imgYpos]);		
			myImg.SetImgPos("burager",[imgXpos,imgYpos]);		
			myImg.SetImgPos("siru",[imgXpos,imgYpos]);		
			myImg.SetImgPos("manko",[imgXpos,imgYpos]);		
			myImg.SetImgPos("panty",[imgXpos,imgYpos]);		
			myImg.SetImgPos("inner",[imgXpos,imgYpos]);		
			myImg.SetImgPos("shatu",[imgXpos,imgYpos]);		
			myImg.SetImgPos("sukart",[imgXpos,imgYpos]);		
			myImg.SetImgPos("seihuku",[imgXpos,imgYpos]);		
			myImg.SetImgPos("penis",[imgXpos,imgYpos]);		
			myImg.SetImgPos("shokushu",[imgXpos,imgYpos]);		
			myImg.SetImgPos("seieki",[imgXpos,imgYpos]);		
			myImg.SetImgPos("sitem",[imgXpos,imgYpos]);		
			myImg.SetImgPos("monster1",[imgXpos,imgYpos]);		
			myImg.SetImgPos("monster2",[imgXpos,imgYpos]);		
			myImg.SetImgPos("monster3",[imgXpos,imgYpos]);		
			myImg.SetImgPos("MagicEffect",[imgXpos,imgYpos]);		
			myImg.SetImgPos("BattleEffect",[imgXpos,imgYpos]);		
			myImg.SetImgPos("Other2Back",[imgXpos,imgYpos]);		
			myImg.SetImgPos("Other2",[imgXpos,imgYpos]);
			/*-------------------------*/						
			//各種コマンド処理宣言
			myBT.DayTime();
			myBT.OrgasmFunc();
			myProc.Initialize();
			myRpg.SetCharactors();
			myRpg.SetMagicItemData();
			myRpg.StoreFunction();
			myRpg.StatusFunction();
			myRpg.SleepFunction();
			myRpg.ItemFunction();
			myRpg.Attack();
			myRpg.Guard();
			myRpg.BattleItem();
			myRpg.Escape();			
			
			//データロード
			myProc.loadData();
			//シナリオデータログ出力
			myProc.OutPutSinario();			
			console.log(_self.width_hi);
			_self.setTimer(function(){
				var exc = myBE.serchExecuteEvent();
				if(exc[myBE.ID]!=0)myBT.OpeningFlg = false;
				myBE.excuteEvent(exc);
				if((!myBT.OpeningFlg)&&(!exc))myProc.moveBefore(myProc.moveIndex);
				//固定音楽再生
				myProc.music(0,0);
				if((!myBT.OpeningFlg))_self.HiddenBox("anmaku");				
			},500);
		}
		_this.ViewInitializeBox();
	}	
	Main.MainProc();
}
Main.ClassLoad();
Main.Start(Main.ProcStart);
