var gl_MapDataVersion = "2023040103";
//画像読み出し先
var gl_map_part_image_path = [
	"./js/MapTool/MapChip/map_0.png",
	"./js/MapTool/MapChip/map_1.png",
	"./js/MapTool/MapChip/map_2.png",
	"./js/MapTool/MapChip/map_3.png",
	"./js/MapTool/MapChip/map_4.png",
	"./js/MapTool/MapChip/map_5.png",
	"./js/MapTool/MapChip/map_6.png",
	"./js/MapTool/MapChip/map_7.png",
	"./js/MapTool/MapChip/map_8.png",
	"./js/MapTool/MapChip/map_9.png",
	"./js/MapTool/MapChip/map_a.png",
	"./js/MapTool/MapChip/map_b.png",
	"./js/MapTool/MapChip/map_c.png",
	"./js/MapTool/MapChip/map_d.png",
	"./js/MapTool/MapChip/map_b1.png",
];
//宝箱表示箇所設定用
var gl_Const_Points = [
	[//第1階層・宝箱配置候補
		{"x":0,"y":0,"flg":1},
		{"x":7,"y":0,"flg":0},
		{"x":13,"y":0,"flg":0},
		{"x":17,"y":0,"flg":0},
		{"x":19,"y":0,"flg":0},
		{"x":2,"y":1,"flg":0},
		{"x":8,"y":1,"flg":0},
		{"x":0,"y":2,"flg":0},
		{"x":6,"y":2,"flg":0},
		{"x":16,"y":3,"flg":0},
		{"x":2,"y":4,"flg":0},
		{"x":8,"y":4,"flg":0},
		{"x":6,"y":5,"flg":0},
		{"x":14,"y":5,"flg":0},
		{"x":1,"y":6,"flg":0},
		{"x":8,"y":6,"flg":0},
		{"x":12,"y":6,"flg":0},
		{"x":2,"y":7,"flg":0},
		{"x":16,"y":7,"flg":0},
		{"x":0,"y":8,"flg":0},
		{"x":3,"y":8,"flg":0},
		{"x":12,"y":8,"flg":0},
		{"x":19,"y":9,"flg":0},
		{"x":10,"y":10,"flg":0},
		{"x":13,"y":10,"flg":0},
		{"x":16,"y":10,"flg":0},
		{"x":6,"y":11,"flg":0},
		{"x":15,"y":11,"flg":0},
		{"x":18,"y":11,"flg":0},
		{"x":13,"y":12,"flg":0},
		{"x":19,"y":12,"flg":0},
		{"x":5,"y":13,"flg":0},
		{"x":7,"y":13,"flg":0},
		{"x":0,"y":14,"flg":0},
		{"x":6,"y":14,"flg":0},
		{"x":8,"y":14,"flg":0},
		{"x":11,"y":14,"flg":0},
		{"x":13,"y":14,"flg":0},
		{"x":16,"y":15,"flg":0},
		{"x":15,"y":16,"flg":0},
		{"x":0,"y":17,"flg":0},
		{"x":18,"y":17,"flg":0},
		{"x":4,"y":18,"flg":0},
		{"x":6,"y":18,"flg":1},
		{"x":15,"y":18,"flg":0},
		{"x":17,"y":18,"flg":0},
		{"x":0,"y":19,"flg":0},
		{"x":3,"y":19,"flg":0}
	],
	[//第2階層・宝箱配置候補
		{"x":0,"y":0,"flg":0},
		{"x":6,"y":0,"flg":0},
		{"x":12,"y":0,"flg":0},
		{"x":8,"y":1,"flg":0},
		{"x":15,"y":1,"flg":0},
		{"x":0,"y":2,"flg":0},
		{"x":18,"y":2,"flg":0},
		{"x":9,"y":3,"flg":0},
		{"x":12,"y":3,"flg":0},
		{"x":8,"y":4,"flg":0},
		{"x":18,"y":4,"flg":0},
		{"x":3,"y":5,"flg":0},
		{"x":9,"y":5,"flg":0},
		{"x":12,"y":5,"flg":0},
		{"x":14,"y":5,"flg":0},
		{"x":4,"y":6,"flg":0},
		{"x":16,"y":6,"flg":0},
		{"x":2,"y":7,"flg":0},
		{"x":12,"y":7,"flg":0},
		{"x":0,"y":8,"flg":0},
		{"x":4,"y":9,"flg":1},
		{"x":8,"y":10,"flg":0},
		{"x":16,"y":10,"flg":0},
		{"x":3,"y":11,"flg":0},
		{"x":5,"y":11,"flg":0},
		{"x":14,"y":11,"flg":0},
		{"x":4,"y":12,"flg":0},
		{"x":17,"y":12,"flg":0},
		{"x":18,"y":13,"flg":0},
		{"x":4,"y":14,"flg":0},
		{"x":10,"y":14,"flg":0},
		{"x":13,"y":14,"flg":0},
		{"x":0,"y":15,"flg":0},
		{"x":12,"y":15,"flg":0},
		{"x":4,"y":17,"flg":0},
		{"x":8,"y":17,"flg":0},
		{"x":12,"y":17,"flg":0},
		{"x":16,"y":17,"flg":0},
		{"x":0,"y":18,"flg":0},
		{"x":9,"y":18,"flg":0},
		{"x":5,"y":19,"flg":0},
		{"x":8,"y":19,"flg":0},
		{"x":10,"y":19,"flg":0},
		{"x":12,"y":19,"flg":0},
		{"x":18,"y":19,"flg":1}
	],
	[//第3階層・宝箱配置候補
		{"x":8,"y":0,"flg":0},
		{"x":11,"y":0,"flg":0},
		{"x":19,"y":0,"flg":0},
		{"x":5,"y":1,"flg":0},
		{"x":13,"y":1,"flg":0},
		{"x":16,"y":1,"flg":0},
		{"x":14,"y":2,"flg":0},
		{"x":17,"y":2,"flg":0},
		{"x":0,"y":4,"flg":0},
		{"x":6,"y":5,"flg":0},
		{"x":18,"y":5,"flg":0},
		{"x":9,"y":6,"flg":0},
		{"x":12,"y":6,"flg":0},
		{"x":2,"y":7,"flg":0},
		{"x":7,"y":7,"flg":0},
		{"x":10,"y":7,"flg":0},
		{"x":14,"y":7,"flg":0},
		{"x":17,"y":7,"flg":0},
		{"x":13,"y":8,"flg":0},
		{"x":5,"y":9,"flg":0},
		{"x":15,"y":9,"flg":0},
		{"x":13,"y":10,"flg":0},
		{"x":16,"y":10,"flg":0},
		{"x":1,"y":11,"flg":0},
		{"x":3,"y":12,"flg":0},
		{"x":15,"y":12,"flg":0},
		{"x":4,"y":13,"flg":0},
		{"x":17,"y":13,"flg":0},
		{"x":0,"y":14,"flg":0},
		{"x":12,"y":14,"flg":1},
		{"x":5,"y":15,"flg":0},
		{"x":10,"y":15,"flg":0},
		{"x":17,"y":15,"flg":0},
		{"x":7,"y":16,"flg":0},
		{"x":11,"y":16,"flg":0},
		{"x":15,"y":16,"flg":0},
		{"x":18,"y":16,"flg":0},
		{"x":4,"y":17,"flg":0},
		{"x":16,"y":17,"flg":0},
		{"x":1,"y":19,"flg":1},
		{"x":8,"y":19,"flg":0},
		{"x":10,"y":19,"flg":0},
		{"x":12,"y":19,"flg":0},
		{"x":14,"y":19,"flg":0},
		{"x":18,"y":19,"flg":0}
	],
	[//第4階層・宝箱配置候補
		{"x":4,"y":0,"flg":0},
		{"x":11,"y":0,"flg":0},
		{"x":16,"y":0,"flg":0},
		{"x":19,"y":0,"flg":0},
		{"x":8,"y":1,"flg":0},
		{"x":4,"y":2,"flg":0},
		{"x":10,"y":2,"flg":1},
		{"x":9,"y":4,"flg":0},
		{"x":16,"y":4,"flg":0},
		{"x":7,"y":5,"flg":0},
		{"x":14,"y":5,"flg":1},
		{"x":17,"y":5,"flg":0},
		{"x":10,"y":6,"flg":0},
		{"x":13,"y":6,"flg":0},
		{"x":4,"y":7,"flg":0},
		{"x":0,"y":8,"flg":0},
		{"x":11,"y":8,"flg":0},
		{"x":3,"y":9,"flg":0},
		{"x":5,"y":10,"flg":0},
		{"x":10,"y":10,"flg":0},
		{"x":12,"y":11,"flg":0},
		{"x":17,"y":11,"flg":0},
		{"x":6,"y":12,"flg":0},
		{"x":0,"y":13,"flg":0},
		{"x":8,"y":13,"flg":0},
		{"x":17,"y":13,"flg":0},
		{"x":18,"y":14,"flg":0},
		{"x":12,"y":15,"flg":0},
		{"x":6,"y":16,"flg":0},
		{"x":10,"y":16,"flg":0},
		{"x":14,"y":16,"flg":0},
		{"x":4,"y":17,"flg":0},
		{"x":17,"y":17,"flg":0},
		{"x":13,"y":19,"flg":0}
	],
	[//第5階層・宝箱配置候補
		{"x":0,"y":0,"flg":0},
		{"x":6,"y":0,"flg":0},
		{"x":11,"y":0,"flg":0},
		{"x":7,"y":2,"flg":0},
		{"x":17,"y":2,"flg":0},
		{"x":13,"y":3,"flg":0},
		{"x":16,"y":3,"flg":0},
		{"x":0,"y":5,"flg":0},
		{"x":4,"y":5,"flg":0},
		{"x":6,"y":5,"flg":0},
		{"x":14,"y":5,"flg":1},
		{"x":16,"y":5,"flg":0},
		{"x":9,"y":6,"flg":0},
		{"x":11,"y":6,"flg":0},
		{"x":10,"y":9,"flg":0},
		{"x":16,"y":9,"flg":0},
		{"x":7,"y":10,"flg":0},
		{"x":13,"y":10,"flg":0},
		{"x":4,"y":11,"flg":0},
		{"x":12,"y":11,"flg":0},
		{"x":18,"y":11,"flg":0},
		{"x":0,"y":12,"flg":0},
		{"x":6,"y":12,"flg":0},
		{"x":8,"y":13,"flg":0},
		{"x":11,"y":13,"flg":0},
		{"x":7,"y":14,"flg":0},
		{"x":14,"y":14,"flg":0},
		{"x":18,"y":14,"flg":0},
		{"x":13,"y":16,"flg":0},
		{"x":6,"y":17,"flg":0},
		{"x":12,"y":18,"flg":0},
		{"x":4,"y":19,"flg":0},
		{"x":6,"y":19,"flg":0},
		{"x":13,"y":19,"flg":0}
	]
];
//罠設定用
var gl_Const_Points2 = [
	[//1階・十字
		{"x":15,"y":1,"flg":0},
		{"x":2,"y":2,"flg":0},
		{"x":13,"y":2,"flg":0},
		{"x":13,"y":3,"flg":0},
		{"x":14,"y":3,"flg":0},
		{"x":10,"y":5,"flg":0},
		{"x":9,"y":6,"flg":0},
		{"x":7,"y":7,"flg":0},
		{"x":6,"y":8,"flg":0},
		{"x":5,"y":9,"flg":0},
		{"x":6,"y":9,"flg":0},
		{"x":9,"y":9,"flg":0},
		{"x":11,"y":9,"flg":0},
		{"x":12,"y":9,"flg":0},
		{"x":15,"y":9,"flg":0},
		{"x":4,"y":10,"flg":0},
		{"x":17,"y":10,"flg":0},
		{"x":2,"y":12,"flg":0},
		{"x":11,"y":12,"flg":0},
		{"x":18,"y":12,"flg":0},
		{"x":9,"y":13,"flg":0},
		{"x":4,"y":14,"flg":0},
		{"x":7,"y":16,"flg":0},
		{"x":15,"y":17,"flg":0},
		{"x":2,"y":18,"flg":0},
		{"x":12,"y":18,"flg":0}
	],
	[//2階・十字
		{"x":6,"y":2,"flg":0},
		{"x":10,"y":4,"flg":0},
		{"x":16,"y":4,"flg":0},
		{"x":10,"y":5,"flg":0},
		{"x":9,"y":7,"flg":0},
		{"x":16,"y":8,"flg":0},
		{"x":17,"y":8,"flg":0},
		{"x":12,"y":9,"flg":0},
		{"x":17,"y":9,"flg":0},
		{"x":2,"y":11,"flg":0},
		{"x":7,"y":12,"flg":0},
		{"x":2,"y":13,"flg":0},
		{"x":8,"y":13,"flg":0},
		{"x":9,"y":13,"flg":0},
		{"x":15,"y":14,"flg":0},
		{"x":4,"y":15,"flg":0},
		{"x":10,"y":15,"flg":0},
		{"x":2,"y":16,"flg":0},
		{"x":4,"y":18,"flg":0}
	],
	[//3階・十字
		{"x":2,"y":2,"flg":0},
		{"x":15,"y":2,"flg":0},
		{"x":14,"y":3,"flg":0},
		{"x":15,"y":3,"flg":0},
		{"x":17,"y":3,"flg":0},
		{"x":7,"y":4,"flg":0},
		{"x":13,"y":4,"flg":0},
		{"x":14,"y":4,"flg":0},
		{"x":15,"y":4,"flg":0},
		{"x":17,"y":4,"flg":0},
		{"x":5,"y":6,"flg":0},
		{"x":12,"y":7,"flg":0},
		{"x":12,"y":9,"flg":0},
		{"x":16,"y":11,"flg":0},
		{"x":8,"y":13,"flg":0},
		{"x":14,"y":14,"flg":0},
		{"x":12,"y":17,"flg":0},
		{"x":17,"y":17,"flg":0},
		{"x":9,"y":18,"flg":0},
		{"x":12,"y":18,"flg":0}
	],
	//4階・十字
	[
		{"x":9,"y":1,"flg":0},
		{"x":8,"y":2,"flg":0},
		{"x":13,"y":2,"flg":0},
		{"x":4,"y":4,"flg":0},
		{"x":16,"y":6,"flg":0},
		{"x":13,"y":7,"flg":0},
		{"x":11,"y":13,"flg":0},
		{"x":13,"y":15,"flg":0},
		{"x":7,"y":16,"flg":0},
		{"x":15,"y":17,"flg":0},
		{"x":18,"y":17,"flg":0}
	],
	[//5階・十字
		{"x":9,"y":3,"flg":0},
		{"x":13,"y":4,"flg":0},
		{"x":18,"y":5,"flg":0},
		{"x":3,"y":7,"flg":0},
		{"x":14,"y":8,"flg":0},
		{"x":3,"y":10,"flg":0},
		{"x":8,"y":11,"flg":0},
		{"x":10,"y":12,"flg":0},
		{"x":8,"y":14,"flg":0},
		{"x":18,"y":15,"flg":0},
		{"x":18,"y":17,"flg":0},
		{"x":5,"y":18,"flg":0}
	]
];
//安全地帯
var gl_safe_squear = [
	[
		{"x":13,"y":5,"flg":0},
		{"x":4,"y":9,"flg":0},
		{"x":8,"y":18,"flg":0}
	],
	[
		{"x":18,"y":1,"flg":0},
		{"x":3,"y":2,"flg":0},
		{"x":1,"y":11,"flg":0},
		{"x":11,"y":12,"flg":0}
	],
	[
		{"x":0,"y":1,"flg":0},
		{"x":12,"y":13,"flg":0},
		{"x":11,"y":18,"flg":0}
	],
	[
		{"x":0,"y":0,"flg":0},
		{"x":15,"y":19,"flg":0}
	],
	[
		{"x":8,"y":8,"flg":0},
		{"x":16,"y":16,"flg":0},
		{"x":3,"y":17,"flg":0}
	]
];
//マップ操作クラス
var MapLib = function(){
	MapLib.prototype.FunctionFlg = true;
	MapLib.prototype.ImageMagn = null;
	MapLib.prototype.ImageXY = null;
	MapLib.prototype.MapViewFlg = false;
	MapLib.prototype.AfterBattle = 0;
	MapLib.prototype.AffterFlg = false;
	MapLib.prototype.CharctorBack = {
		"body":0,
		"body_face_bk":0,
		"body_fr_hair":0,
		"body_bk_hair":0
	};
	MapLib.prototype.TreasureIdx = -1;
	MapLib.prototype.TreasureLoop = -1;
    MapLib.prototype.MapData = {};
}
//立ち絵サイズ・位置補正
MapLib.prototype.SetImageCorrect = function(){
	myMap.ImageMagn = myImg.GetImageMagn("body");
	myMap.ImageXY = myImg.GetImgPos("body");		
}
//初期化
MapLib.prototype.Initialize = function(Option=null){	
	//マップ有効かつライブラリ読込完了時
	if(myMap.FunctionFlg&&MapFlg){
		//初期化前設定
		if(Option!=null){
			//親要素設定
			if(Option["parent"]!=undefined)parentElm = Option["parent"];
		}
		MapInitialize();
		_self.HiddenBox("Danjon");
		_self.HiddenBox("canvas3");
		//初期化後設定
		if(Option!=null){
			//マップ用キャンパス移動先
			if(Option["move_canvas"]!=undefined){
				var parent_elm = _self.Elm(parentElm,_self.TypeID);
				var elm = _self.Elm(Option["move_canvas"],_self.TypeID);
				var elm1 = _self.Elm("canvas3",_self.TypeID);
				_self.ClassOpr(elm1,elm.classList.value,_self.ClassAdd);
				parent_elm.insertBefore(elm1,elm);
			}
		}
	}
}
//MAP表示
MapLib.prototype.MapView = function(){
	myST.AntenImageView(function(){
		var elm1= _self.Elm("Danjon",_self.TypeID);
		elm1.style.left = _self.width_hi-115+"px";
		_self.ViewBox("Danjon");
		_self.ViewBox("canvas1");
		_self.ViewBox("canvas2");
		_self.ViewBox("canvas3");
		if(!myMap.MapViewFlg){
			pos_change();
			myImg.AllClearImage();
			var Magn = 0.4;
			myImg.SetImageMagn("body",Magn);
			myImg.SetImageMagn("body_face_bk",Magn);
			myImg.SetImageMagn("body_fr_hair",Magn);
			myImg.SetImageMagn("body_bk_hair",Magn);
			var Ypos = 40;
			var Xpos = 50;
			myImg.SetImgPos("body",[Xpos,Ypos]);
			myImg.SetImgPos("body_face_bk",[Xpos,Ypos]);
			myImg.SetImgPos("body_fr_hair",[Xpos,Ypos]);
			myImg.SetImgPos("body_bk_hair",[Xpos,Ypos]);
			myImg.AllImageView(true,false,false);
			myMap.MapViewFlg = true;
			myMap.chgArea();
		}else{
			_self.ViewBox(myMap.ViewMapArea);
		}
	},900,500);

}

//MAP非表示
MapLib.prototype.MapHidden = function(){
	_self.HiddenBox("Danjon");
	_self.HiddenBox("canvas1");
	_self.HiddenBox("canvas2");
	_self.HiddenBox("canvas3");
	//一度ダンジョンに入っていたら
	if(!myMap.MapViewFlg){
		myImg.AllClearImage();
		myImg.SetImageMagn("body",myMap.ImageMagn);
		myImg.SetImageMagn("body_face_bk",myMap.ImageMagn);
		myImg.SetImageMagn("body_fr_hair",myMap.ImageMagn);
		myImg.SetImageMagn("body_bk_hair",myMap.ImageMagn);
		myImg.SetImgPos("body",[myMap.ImageXY[0],myMap.ImageXY[1]]);
		myImg.SetImgPos("body_face_bk",[myMap.ImageXY[0],myMap.ImageXY[1]]);
		myImg.SetImgPos("body_fr_hair",[myMap.ImageXY[0],myMap.ImageXY[1]]);
		myImg.SetImgPos("body_bk_hair",[myMap.ImageXY[0],myMap.ImageXY[1]]);
		myImg.AllImageView(true,false,false);
		myMap.MapViewFlg = false;
	}
}

//ダンジョン脱出
MapLib.prototype.MapExit = function(){
	var res = false;
	if(!myMap.MapViewFlg)return res;
	if(gl_map_index != 0)return res;
	var data = gl_exit_points[gl_map_index];
	if(data === undefined)return res;
	if(gl_now_adv_pos == data.lc_adv_pos){
		if((data.x_pos==gl_now_pos_x)&&(data.y_pos==gl_now_pos_y)){
			res = true;
		}
	}
	return res;
}

//Mapポイント
MapLib.prototype.MapPoint = function(points,mapFlg=false){
	var res = false;
	if(!myMap.MapViewFlg)return res;
	if(points === undefined)return res;
	var data = points;
	if((gl_now_adv_pos == data.lc_adv_pos)||(mapFlg)){
		if((data.x_pos==gl_now_pos_x)&&(data.y_pos==gl_now_pos_y)){
			res = true;
		}
	}
	return res;
}

//エリアチェック
MapLib.prototype.ChangeAreaCheck = function(){
	var res = false;
	
	//エリア変更フラグをOFF
	myBT.NextAreaFlg = false;
	myBT.BeforeAreaFlg = false;
	
	//次のエリア
	res = myMap.MapPoint(gl_next_points[gl_map_index]);
	if(res){
		myBT.NextAreaFlg = true;
		_self.ViewBox(myBT.CommandNextArea);
	}
	//前のエリア
	else{
		_self.HiddenBox(myBT.CommandNextArea);
		res = myMap.MapPoint(gl_before_points[gl_map_index]);
		if(res){
			myBT.BeforeAreaFlg = true;
			_self.ViewBox(myBT.CommandBeforeArea);
		}else{
			_self.HiddenBox(myBT.CommandBeforeArea);
		}
	}
	
	//RPG用
	myRpg.Charctor.MAPINDEX = gl_map_index;
	myRpg.Charctor.ADVPOS = gl_now_adv_pos;
	myRpg.Charctor.MAPX = gl_now_pos_x;
	myRpg.Charctor.MAPY = gl_now_pos_y;

	return res;
}

//エリア変更・次の階
MapLib.prototype.NextArea = function(){
	myBT.setCommandProcessing(myBT.CommandNextArea,function(){
		gl_map_index++;
		_self.HiddenBox(myBT.CommandNextArea);
		gl_now_adv_pos = gl_before_points[gl_map_index].lc_adv_pos;
		gl_now_pos_x = gl_before_points[gl_map_index].x_pos;
		gl_now_pos_y = gl_before_points[gl_map_index].y_pos;
		pos_change();
		myMap.chgArea();
	});
}

//エリア変更・前の階
MapLib.prototype.BeforeArea = function(){
	myBT.setCommandProcessing(myBT.CommandBeforeArea,function(){
		gl_map_index--;
		_self.HiddenBox(myBT.CommandBeforeArea);
		gl_now_adv_pos = gl_next_points[gl_map_index].lc_adv_pos;
		gl_now_pos_x = gl_next_points[gl_map_index].x_pos;
		gl_now_pos_y = gl_next_points[gl_map_index].y_pos;
		pos_change();
		myMap.chgArea();
	});
}

//脱出イベント
MapLib.prototype.EcapeDungeon = function(){
	gl_map_index = 0;
	gl_now_pos_x = 0;
	gl_now_pos_y = 0;
	gl_now_adv_pos = 0;
	myST.AntenImageView(pos_change,1000);
}

//宝箱配置
MapLib.prototype.SetTreasure = function(){
    var lc_Treasure_points = [];
	var lc_Treasure_Contents = [];
	var lc_TreasureChange_flg = false;
	lc_Treasure_Contents[0] = [
	//1階層目
		[{id:0,type:"money",value:500},{id:0,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:1,type:"item",value:0,count:5},{id:1,output:50,count:-1,viewFlg:true,eventFlg:false}],//薬草
		[{id:2,type:"money",value:250},{id:2,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:3,type:"item",value:13,count:3},{id:3,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:4,type:"item",value:14,count:1},{id:4,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:5,type:"item",value:15,count:1},{id:4,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:6,type:"money",value:300},{id:6,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:7,type:"item",value:14,count:1},{id:7,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:8,type:"item",value:13,count:5},{id:8,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:9,type:"item",value:1,count:5},{id:9,output:50,count:-1,viewFlg:true,eventFlg:false}],//薬草
		[{id:10,type:"item",value:1,count:5},{id:10,output:50,count:-1,viewFlg:true,eventFlg:false}],//薬草

	];
	lc_Treasure_Contents[lc_Treasure_Contents.length] = [
		//2階層目
		[{id:0,type:"item",value:1,count:5},{id:0,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:1,type:"item",value:10,count:2},{id:1,output:50,count:-1,viewFlg:true,eventFlg:false}],//薬草
		[{id:2,type:"money",value:1000},{id:2,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:3,type:"item",value:13,count:3},{id:3,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:4,type:"item",value:14,count:1},{id:4,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:5,type:"item",value:15,count:1},{id:5,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:6,type:"item",value:2,count:1},{id:6,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:7,type:"item",value:2,count:1},{id:7,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
	];
	lc_Treasure_Contents[lc_Treasure_Contents.length] = [
		//3階層目
		[{id:0,type:"item",value:1,count:5},{id:0,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:1,type:"item",value:10,count:2},{id:1,output:50,count:-1,viewFlg:true,eventFlg:false}],//薬草
		[{id:2,type:"money",value:1000},{id:2,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:3,type:"money",value:1500},{id:3,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:4,type:"money",value:2000},{id:4,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:5,type:"money",value:500},{id:5,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:6,type:"item",value:13,count:3},{id:6,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:7,type:"item",value:14,count:1},{id:7,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:8,type:"item",value:15,count:1},{id:8,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:9,type:"item",value:2,count:1},{id:9,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:10,type:"item",value:3,count:1},{id:10,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:11,type:"item",value:11,count:1},{id:11,output:50,count:-1,viewFlg:true,eventFlg:false}],//薬草
	];
	lc_Treasure_Contents[lc_Treasure_Contents.length] = [
		//4階層目
		[{id:0,type:"item",value:2,count:5},{id:0,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:1,type:"item",value:10,count:2},{id:1,output:50,count:-1,viewFlg:true,eventFlg:false}],//薬草
		[{id:2,type:"money",value:1000},{id:2,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:3,type:"money",value:1500},{id:3,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:4,type:"money",value:2000},{id:4,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:5,type:"money",value:500},{id:5,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:6,type:"item",value:13,count:3},{id:6,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:7,type:"item",value:14,count:1},{id:7,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:8,type:"item",value:15,count:1},{id:8,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:9,type:"item",value:3,count:3},{id:9,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:10,type:"item",value:3,count:2},{id:10,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:11,type:"item",value:11,count:2},{id:11,output:50,count:-1,viewFlg:true,eventFlg:false}],//薬草
	];
	lc_Treasure_Contents[lc_Treasure_Contents.length] = [
		//5階層目
		[{id:0,type:"item",value:2,count:5},{id:0,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:1,type:"item",value:10,count:2},{id:1,output:50,count:-1,viewFlg:true,eventFlg:false}],//薬草
		[{id:2,type:"money",value:1000},{id:2,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:3,type:"money",value:1500},{id:3,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:4,type:"money",value:2000},{id:4,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:5,type:"money",value:500},{id:5,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:6,type:"item",value:13,count:3},{id:6,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:7,type:"item",value:14,count:1},{id:7,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:8,type:"item",value:15,count:1},{id:8,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:9,type:"item",value:3,count:3},{id:9,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:10,type:"item",value:3,count:2},{id:10,output:50,count:-1,viewFlg:true,eventFlg:false}],//お金
		[{id:11,type:"item",value:11,count:5},{id:11,output:50,count:-1,viewFlg:true,eventFlg:false}],//薬草
		[{id:12,type:"item",value:12,count:1},{id:12,output:50,count:-1,viewFlg:true,eventFlg:false}],//薬草
	];
	
	//更新判定
	if((myMap.MapData["TreasureUpdate"]!=undefined)&&(myMap.MapData["TreasureUpdate"]!=gl_MapDataVersion)){
		myMap.MapData["TreasureChange"] = true;
		lc_TreasureChange_flg = true;
	}
	
	//初期宝箱コンテンツセット
	if(myMap.MapData.TreasureContents0==undefined){
		//宝箱データ更新フラグ
		myMap.MapData["TreasureChange"] = false;
		myMap.MapData["TreasureUpdate"] = gl_MapDataVersion;
		//宝箱データ
		for(var loop=0;loop<lc_Treasure_Contents.length;loop++){
			var ContentsData = lc_Treasure_Contents[loop];
			myMap.MapData["TreasureContents"+loop] = [];
			for(var loop2 = 0;loop2<ContentsData.length;loop2++){
				myMap.MapData["TreasureContents"+loop].push(ContentsData[loop2]);
			}
		}
	}
	//更新宝箱コンテンツ
	else if(myMap.MapData["TreasureChange"]){
		//宝箱データ更新
		myMap.MapData["TreasureUpdate"] = gl_MapDataVersion;
		//宝箱データ
		for(var loop=0;loop<lc_Treasure_Contents.length;loop++){
			var ContentsData = lc_Treasure_Contents[loop];
			myMap.MapData["TreasureContents"+loop] = [];
			for(var loop2 = 0;loop2<ContentsData.length;loop2++){
				var saveData = myMap.MapData["TreasureContents"+loop][loop2];
				var LocalData = ContentsData[loop2];
				if((saveData!=undefined)&&(saveData[0].id == LocalData[0].id)){
					myMap.MapData["TreasureContents"+loop][loop2] = LocalData;
					myMap.MapData["TreasureContents"+loop][loop2][1] = saveData[1].eventFlg;
				}else{
					myMap.MapData["TreasureContents"+loop].push(LocalData);
				}
			}
		}
	}
	
	//宝箱配置設定
	gl_Treasure_points = [];
	for(var loop=0;loop<gl_Const_Points.length;loop++){
		lc_Treasure_points[loop] = [];
		if((myMap.MapData["TreasurePoints"+loop]==undefined)||(myMap.MapData["TreasurePoints"+loop]==null||lc_TreasureChange_flg)){
			for(var loop2=0;loop2<10;loop2++){
				var errorCount = 0;
				var posData = gl_Const_Points[loop];
				var index = Math.round(Math.random()*(posData.length-1));
				var index2 = Math.round(Math.random()*lc_Treasure_Contents.length-1);
				//出入口の場合設定しなおし
				console.log(JSON.stringify(posData[index]));
				while(posData[index].flg){
					index = Math.round(Math.random()*(posData.length-1));
				}
				//方向取得
				var map_idx = GetMapDataIndex(posData[index].x,posData[index].y);
				var adv_pos = undefined;
				var adv_pos_array = [];
				console.log("loop:"+loop+",loop2:"+loop2);
				//方向設定
				while(adv_pos==undefined){
					var gl_set_adv_pos = Math.round(Math.random()*3);
					var flgCount = 0;
					for(var advLoop=0;advLoop<4;advLoop++){
						console.log("advLoop:"+advLoop);
						console.log("gl_set_adv_pos:"+gl_set_adv_pos);
						console.log(JSON.stringify(gl_map_part[map_idx][gl_set_adv_pos]));
						console.log(JSON.stringify(gl_pass_data[gl_map_part[map_idx][gl_set_adv_pos]]));
						var flg = gl_pass_data[gl_map_part[map_idx][gl_set_adv_pos]][advLoop];
						flgCount += parseInt(flg);
						if(flg)adv_pos_array[adv_pos_array.length] = gl_set_adv_pos;
					}

					adv_pos = adv_pos_array[Math.round(Math.random()*(adv_pos_array.length-1))];
					//移動先が無い場合はエラー扱い
					if(!flgCount){
						console.log("エラー回避");
						if(loop2!=0)loop2--;
						errorCount++;
						if(errorCount>=100){
							console.log("エラー上限");
							break;
						}
						continue;
					}
				}
				//配置箇所詳細
				lc_Treasure_points[loop].push(new gl_check_point(
					posData[index].x,
					posData[index].y,
					-1,
					adv_pos,
					lc_Treasure_Contents[loop][index2]
				));//お金
			}
		}
		//配置データ設定
		if((myMap.MapData["TreasurePoints"+loop]==undefined)||(myMap.MapData["TreasurePoints"+loop]==null||lc_TreasureChange_flg)){
			gl_Treasure_points.push(lc_Treasure_points[loop]);
			myMap.MapData["TreasurePoints"+loop] = gl_Treasure_points[loop];
		}else{
			gl_Treasure_points[loop] = myMap.MapData["TreasurePoints"+loop];
			var setCount = 0;
			for(var setloop=0;setloop<gl_Treasure_points[loop].length;setloop++){
				if(gl_Treasure_points[loop][setloop].treasure!=null){
					var res = gl_Treasure_points[loop][setloop].treasure[0].hasOwnProperty("id");
					if(!res){
						gl_Treasure_points[loop][setloop].treasure[0] = gl_Treasure_points[loop][setloop].treasure[0][setCount];
						setCount++;
					}
				}
			}
		}
	}
}

//宝箱チェック/表示
MapLib.prototype.ChecnkTreasure = function(mapFlg=false,point=[0,0]){
	var TreasureSet = !mapFlg;
    for(var loop=0;loop<gl_Treasure_points[gl_map_index].length;loop++){
		//---Map印表示用---
		if(mapFlg)backPoint = [gl_now_pos_x,gl_now_pos_y];
		if(mapFlg)gl_now_pos_x = point[0];
		if(mapFlg)gl_now_pos_y = point[1];
		//---Map印表示用---
		if(TreasureSet)mapFlg = true;
        var flg = myMap.MapPoint(gl_Treasure_points[gl_map_index][loop],mapFlg);
		if(TreasureSet)mapFlg = false;
		//---Map印表示用---
		if(mapFlg)gl_now_pos_x = backPoint[0];
		if(mapFlg)gl_now_pos_y = backPoint[1];
		//---Map印表示用---
        //表示位置
        if(flg){
            //宝箱の表示フラグチェック
			if(gl_Treasure_points[gl_map_index][loop].treasure==undefined)continue;
			var idx = gl_Treasure_points[gl_map_index][loop].treasure[0].id;
            if(myMap.MapData["TreasureContents"+gl_map_index][idx][1].viewFlg){
                //未開の場合
				var lc_eventFlg = gl_Treasure_points[gl_map_index][loop].treasure[1].eventFlg;
                var save_eventFlg = myMap.MapData["TreasureContents"+gl_map_index][idx][1].eventFlg;
				if((!save_eventFlg)&&(!lc_eventFlg)){
					if(mapFlg)return true;
                    myMap.image.src = myMap.ViewMapItem(myMap.CloseBox,true);
                    myMap.image.onload = function(){
                        ctxback.drawImage(myMap.image, -130,100,800*0.8,600*0.8);
                    }
					myMap.TreasureIdx = idx;
					myMap.TreasureLoop = loop;
					var exc = myBE.serchExecuteEvent();
					myBE.excuteEvent(exc);
					break;
                }
                //既開の場合
                else{
					if(mapFlg)return false;
                    myMap.image.src = myMap.ViewMapItem(myMap.OpenBox,true);
                    myMap.image.onload = function(){
                        ctxback.drawImage(myMap.image, -130,100,800*0.8,600*0.8);
                    }
					break;
                }
            }
        }
    }
	if(mapFlg)return false;
}

//宝箱イベント
MapLib.prototype.OpenTreasure = function(index){
	//開く確認
	if(index==0){
		//選択
		var func = function(id){
			if(id==0){//開ける
				myBE.Flg[myBE.eventIndex] = 1;
			}else{//開けない
				myBE.Flg[myBE.eventIndex] = 2;
			}
		}		
		var selectData = [
			["開ける",func],
			["開けない",func],
		];
		myST.selectEvent(selectData);		
	}
	//開けた場合
	if(index==1){
		var idx = myMap.TreasureIdx;
		var data = myMap.MapData["TreasureContents"+gl_map_index][idx];
		//お金
		if(data[0].type=="money"){
			myBT.showMessage(data[0].value+"Gが入っていた！");
			myRpg.Charctor.GOLD += data[0].value;
			if(data[1].count>=1){
				data[1].count--;
				if(data[1].count==0)data[1].eventFlg = true;
			}
			var setData = gl_Treasure_points[gl_map_index][myMap.TreasureLoop];
			setData.treasure[1].eventFlg = true;			
		}
		//アイテム
		else if(data[0].type=="item"){
			var itemIdx = data[0].value;
			myBT.showMessage(myRpg.Items[itemIdx].Name+"が"+(data[0].count>=2?data[0].count+"個、":"")+"入っていた！");
			if(!myRpg.ItemFind(myRpg.Items[itemIdx].Name,"buy")){
				var Item = [];
				if(myRpg.Charctor.Item==undefined)myRpg.Charctor.Item = Item;
				var itemIdx2 = myRpg.Charctor.Item.length;
				myRpg.Charctor.Item[itemIdx2] = JSON.parse(JSON.stringify(myRpg.Items[itemIdx]));
				myRpg.Charctor.Item[itemIdx2].count = 1;
			}
			//---メッセージを設定するアイテムを検索---
			var ItemData = myRpg.Items[itemIdx];
			var SetIndex = 0;
			for(var idxloop in myRpg.Charctor.Item){
				if(myRpg.Charctor.Item[idxloop].ItemId == ItemData.ItemId){
					SetIndex = idxloop;
					myRpg.Charctor.Item[idxloop].count+=data[0].count;
					break;
				}
			}
			if(ItemData.Type==4)myRpg.Charctor.Item[SetIndex].Msg = ItemData.Msg(ItemData.Limit);
			//---メッセージを設定するアイテムを検索---			
			if(data[1].count>=1){
				data[1].count--;
				if(data[1].count==0)data[1].eventFlg = true;
			}
			var setData = gl_Treasure_points[gl_map_index][myMap.TreasureLoop];
			setData.treasure[1].eventFlg = true;
		}
		myMap.TreasureIdx = -1;
		//画像変更：宝箱・開
		myMap.image.src = myMap.ViewMapItem(myMap.OpenBox,true);
		myMap.image.onload = function(){
			ctxback.drawImage(myMap.image, -130,100,800*0.8,600*0.8);
		}
	}else if(index==2){
		myMap.TreasureIdx = -1;
	}
}

//エロイベント配置
MapLib.prototype.SetEroEvent = function(){
	//エロトラップイベント初期化
	if((myMap.MapData['EroEventChange']==undefined)||myMap.MapData['EroEventChange']){
		for(var loop=0;loop<gl_Const_Points2.length;loop++){
			myMap.MapData['EroEvent'+loop] = [];
		}
		myMap.MapData['EroEventChange'] = true;
	}
	
	//エロトラップ設定
	if(myMap.MapData['EroEventChange']){
		for(var loop=0;loop<gl_Const_Points2.length;loop++){
			for(var loop2=0;loop2<5;loop2++){
				var len = myMap.MapData['EroEvent'+loop].length;
				myMap.MapData['EroEvent'+loop][len] = gl_Const_Points2[gl_map_index][Math.round(Math.random()*(gl_Const_Points2[gl_map_index].length-1))];
			}
		}
		myMap.MapData['EroEventChange']	= false;
	}
	
	//イベント用関数
	if(myMap.EroEventFunc==undefined){
		myMap.EroEventFunc = function(){
			for(var loop=0;loop<myMap.MapData['EroEvent'+gl_map_index].length;loop++){
				var temp = myMap.MapData['EroEvent'+gl_map_index][loop];
				var data = new gl_check_point(temp.x,temp.y,null,gl_now_adv_pos);
				var flg = myMap.MapPoint(data);
				if(flg){
					myBT.setMessage(myST.EventData[(myST.EventData.length-2)]);
				}
			}
		}
	}
}

//安全地帯
MapLib.prototype.SafeSpaceFunc = function(){
	//チェック
	for(var loop=0;loop<gl_safe_squear[gl_map_index].length;loop++){
		var temp = gl_safe_squear[gl_map_index][loop];
		var data = new gl_check_point(temp.x,temp.y,null,gl_now_adv_pos);
		var flg = myMap.MapPoint(data);
		if(flg){
			myBT.setMessage([
				"サーシャ<br>「ここは……。魔力が溢れてるの？」",
				"サーシャ<br>「魔力がわたしにも流れ込んでくる……」",
				"魔力が少し回復した。",
			]);
			myRpg.Charctor.MP+=(myRpg.Charctor.MAXMP*0.2);
			if(myRpg.Charctor.MP>=myRpg.Charctor.MAXMP)myRpg.Charctor.MP = myRpg.Charctor.MAXMP;
			myRpg.Charctor.MP = parseInt(myRpg.Charctor.MP);
			return true;
		}
	}
}

//小物表示
MapLib.prototype.UpStep = 0;
MapLib.prototype.DownStep = 1;
MapLib.prototype.CloseBox = 2;
MapLib.prototype.OpenBox = 3;
MapLib.prototype.SafeSpace = 4;
MapLib.prototype.image = new Image();
MapLib.prototype.ViewMapItem = function(index,viewFlg){
	var res = false;
	var lcImgIndex = [2/*上り階段*/,3/*下り階段*/,4/*宝箱・閉*/,5/*宝箱・開*/,6/*安全地帯*/];
	myImg.SetImgPos("Other",50,100);
	if(viewFlg){
		myImg.SetIndexPos("Other",lcImgIndex[index]);
		var idx = parseInt(myImg.GetIndexPos("Other"));	
		myImg.ImageLoad("Other",idx);
		var Data = _self.GetImage("Other"+idx);
		res = Data.Value;
		myImg.SetIndexPos("Other",0);
	}
	
	return res;
}

//階層表示
MapLib.prototype.ViewMapArea = "MapArea";
MapLib.prototype.ViewMapAreaPos = function(){
	var parent = _self.Elm("operation",_self.TypeID);
	var xpos = "250px";
	if(_self.width_hi<400)xpos = "200px";
	myBT.setCommonBox(parent,myMap.ViewMapArea,xpos);
	myMap.chgArea = function(){
		_self.Elm(myMap.ViewMapArea,_self.TypeID).innerHTML = "B"+(parseInt(gl_map_index)+1)+"F";
		_self.Elm(myMap.ViewMapArea,_self.TypeID).style.backgroundColor = "rgba(0,0,0,0.8)";
		_self.ViewBox(myMap.ViewMapArea);
		if(!myMap.MapViewFlg)_self.HiddenBox(myMap.ViewMapArea);
	}
}

//戦闘
MapLib.prototype.Battle = function(){
	console.log("myMap.AfterBattle:"+myMap.AfterBattle);
	if(myMap.AfterBattle>=1){
		myMap.AfterBattle--;
		return;
	}
	var encount = (100-(Math.random()*100))>=80;
	if(encount){
		_self.HiddenBox("Danjon");
		_self.HiddenBox("canvas1");
		_self.HiddenBox("canvas2");
		_self.HiddenBox(myMap.ViewMapArea);
		for(var loop in myMap.CharctorBack){
			myMap.CharctorBack[loop] = myImg.GetIndexPos(loop);
		}
		myRpg.ClearBattleMargn = myImg.GetImageMagn("body");
		myImg.AllClearImage();		
		myMap.AfterBattle = 3;
		myMap.AffterFlg = false;
		myRpg.EventBattleCount = false;
		myRpg.BattleProcessing();	
	}
}
//戦闘後
MapLib.prototype.BattleEnd = function(){
	//_self.setTimer(function(){
		//var ImageIndex = myImg.GetIndexPos("body");
		//if(!myMap.AffterFlg)return;
		//if(!myMap.MapViewFlg)return;//地上なら抜ける
		//if(myMap.AfterBattle==3||ImageIndex!=0)myMap.BattleEnd();
		myImg.AllClearImage();
		for(var loop in myMap.CharctorBack){
			//myImg.SetIndexPos(loop,myMap.CharctorBack[loop]);
			var Magn = 0.4;
			var Ypos = 40;
			var Xpos = 50;
			//ダンジョン用サイズへ変換
			myImg.SetImageMagn(loop,Magn);
			myImg.SetImgPos(loop,[Xpos,Ypos]);
		}
		//表示
		myImg.AllImageView(true,false,false);
	//},500);
	myMap.AffterFlg = true;
}

myMap = new MapLib();