//=============================================================================
// O_MenuQuest.js
//=============================================================================
/*:ja
 * @plugindesc クエストリスト
 * @author 
 *
 * @help
 */



function Scene_MenuQuest() {
    this.initialize.apply(this, arguments);
}

(function(){
	var $dataQuest = null;
	var $popupQuestVarID = "";
	
		
	var advanceGame = function() {
		var update = false;
		
		//------------------------スライムボス討伐後---------------------------
		
		//気弱なマシュー
        if($gameVariables.value(102) >= 99 && $gameVariables.value(110) <= 0){
			$gameVariables._data[110] = 1;
			update = true;
		}
		//見える男
        if($gameVariables.value(102) >= 99 && $gameVariables.value(111) <= 0){
			$gameVariables._data[111] = 1;
			update = true;
		}else if($gameVariables._data[111] == 2){
			$gameVariables._data[111]=999;
		}
		
		//井戸の中には
        if($gameVariables.value(102) >= 99 && $gameVariables.value(138) <= 0){
			$gameVariables._data[138] = 1;
			update = true;
		}
		//穴に落ちたら
        if($gameVariables.value(102) >= 99 && $gameVariables.value(139) <= 0){
			$gameVariables._data[139] = 1;
			update = true;
		}
		//村娘の困り事
        if($gameVariables.value(102) >= 99 && $gameVariables.value(140) <= 0){
			$gameVariables._data[140] = 1;
			update = true;
		}	
			
			
		//いたずらっ子
        if($gameVariables.value(104) == 1 || $gameVariables.value(104) == 3){
			$gameVariables._data[104] ++;
			update = true;
		}else if($gameVariables.value(104) == 5 && $gameSwitches.value(11)){//性におおらかになった状態
			$gameVariables._data[104] ++;
			update = true;
		}else if($gameVariables.value(104) == 7 && $gameVariables.value(1) >= 40){//ヒャコル攻略済み
			$gameVariables._data[104] ++;
			update = true;
		}
		
		//気弱なマシュー
		if($gameVariables.value(110) == 3){
			$gameVariables._data[110] ++;
			update = true;
		}
		
		//マジックショー
        if($gameVariables.value(117) == 1 && $gameVariables._data[118] == 3){// 壁穴ファック済み
			$gameVariables._data[117] ++;
			update = true;
		}
		
		//壁穴
        if($gameVariables.value(118) == 1){
			$gameVariables._data[118] ++;
			update = true;
		}
		
		//酒場開放状態
        if($gameVariables.value(119) >= 99 && $gameVariables.value(121) <= 0){
			$gameVariables._data[121] = 1;//酒場エロイベの開始
			update = true;
		}
		
		//------------------------ヒャコル攻略後------------------------
		//落とし穴２ 穴の底には
		if($gameVariables.value(109) == 1 && $gameVariables.value(1) >= 40 && $gameSwitches.value(11)){//性に大らか
			$gameVariables._data[109]++;
			update = true;
		}
		//病気の妹２
        if($gameVariables.value(116) == 1 && $gameVariables.value(1) >= 40 && $gameSwitches.value(11)){//性に大らか
			$gameVariables._data[116] ++;
			update = true;
		}
		//泥酔２
        if($gameVariables.value(121) == 2 && $gameVariables.value(1) >= 40 && $gameSwitches.value(11)){//性に大らか
			$gameVariables._data[121] ++;
			update = true;
		}
		
		//ナンダーラの教え・秘
        if($gameVariables.value(124) <= 0 && $gameVariables.value(1) >= 40 && $gameVariables.value(114) >= 99){
			$gameVariables._data[124] = 1;
			update = true;
		}
		
		//M男
		if($gameVariables.value(123) <= 0 && $gameVariables.value(1) >= 40){//ヒャコル攻略済み
			$gameVariables._data[123] = 1;
			update = true;
		}else if($gameVariables.value(123) == 2){
			$gameVariables._data[123] = 999;
		}
		
		//----壁穴２------------------------------------------
		if($gameVariables.value(118) == 3 && $gameVariables.value(35) == 4){
			$gameVariables._data[118] ++;
			update = true;
		}
		
		//----スケベ--------------------------------------------
		
		//脱童貞集会 マジックショー
        if($gameVariables.value(117) == 6 && $gameVariables.value(125) <= 0 && $gameSwitches.value(12)){//すけべ
			$gameVariables._data[125] = 1;
			update = true;
		}
		
		//温泉ヘルス
        if($gameVariables.value(122) == 3 && $gameSwitches.value(12)){//すけべ
			$gameVariables._data[122] ++;
			update = true;
		}
		
		//娼館ホルン  =1 という事はドラゴンワプスを倒したという事
		if($gameVariables.value(126) == 1 && $gameSwitches.value(12)){//すけべ
			$gameVariables._data[126] ++;
			$gameVariables._data[150] = 1;
			update = true;
		}
		
		
		//---娼婦---------------------------------------------
		//売春:神父
		if($gameVariables.value(130) <= 0 && $gameSwitches.value(13)){//娼婦
			$gameVariables._data[130] =1;
			update = true;
		}
		
		//売春：鎧マニア
		if($gameVariables.value(128) <= 0 && $gameSwitches.value(13)){//娼婦
			$gameVariables._data[128] =1;
			update = true;
		}
		
		//売春：マサオとヨシコ
		if($gameVariables.value(129) <= 0 && $gameSwitches.value(13)){//娼婦
			$gameVariables._data[129] =1;
			update = true;
		}
		
		//縄縛りハード
		if(($gameVariables.value(115) == 4 || $gameVariables.value(115) == 5) && $gameSwitches.value(13)){//娼婦
			$gameVariables._data[115] = 6;
			update = true;
		}
		
		//売春：賢者ペネロ
		if($gameVariables.value(131) <= 0 && $gameVariables.value(1) >= 60 && $gameSwitches.value(13)){//娼婦 進行度60以上
			$gameVariables._data[131] =1;
			update = true;
		}
		
		//温泉ソープ
        if($gameVariables.value(122) == 5 && $gameSwitches.value(13)){//娼婦
			$gameVariables._data[122] ++;
			update = true;
		}
		
		//多忙な酒場店主
		if($gameVariables.value(132) <= 0 && $gameVariables.value(119) >= 99 && $gameSwitches.value(13)){//娼婦
			$gameVariables._data[132] = 1;
			update = true;
		}
		
		//イッたら負け
		if($gameVariables.value(133) <= 0 && $gameVariables.value(125) >= 2 && $gameSwitches.value(13)){//娼婦
			$gameVariables._data[133] = 1;
			update = true;
		}
		
		//売春：下着マニア
		if($gameVariables.value(113) == 1 && $gameSwitches.value(13)){//娼婦
			$gameVariables._data[113] = 2;
			update = true;
		}

		//売春：パパタ
		if($gameVariables.value(108) >= 99 && $gameVariables.value(134) <= 0 && $gameSwitches.value(13)){//娼婦
			$gameVariables._data[134] = 1;
			update = true;
		}
		
		//売春：困り顔の男
        if($gameVariables.value(116) >= 3 && $gameVariables.value(135) <= 0 && $gameSwitches.value(13)){//娼婦
			$gameVariables._data[135] = 1;
			update = true;
		}
		
		//売春：農民
        if($gameVariables.value(109) >= 4 && $gameVariables.value(127) <= 0 && $gameSwitches.value(13)){//娼婦
			$gameVariables._data[127] = 1;
			update = true;
		}
		
		//売春：不良たち
		if($gameVariables.value(110) == 5 && $gameSwitches.value(13)){//娼婦
			$gameVariables._data[110] = 6;
			$gameVariables._data[136] = 1;
			update = true;
		}
		
		if(update){
			$gameMap.requestRefresh();
			$popupQuestVarID = 9999;//ヒント更新表示
			
		}else if($gameVariables.value(16) >= 70 && $gameVariables.value(17) >= 196 &&　!$gameSwitches.value(14)){
			$gameSwitches._data[14] = true;
			$gameMap.requestRefresh();
			$popupQuestVarID = 9998;//コンプリート表示
		}
    };
//***** マップ切り替え時の処理
	/*var _Scene_Map_prototype_initialize = Scene_Map.prototype.initialize;
	Scene_Map.prototype.initialize = function(){
		_Scene_Map_prototype_initialize.call(this);
		
		if($gamePlayer.newMapId() == 1){
			advanceGame();
		}
	};*/
	var _Scene_Map_prototype_onMapLoaded = Scene_Map.prototype.onMapLoaded;
	Scene_Map.prototype.onMapLoaded = function(){
		_Scene_Map_prototype_onMapLoaded.call(this);
		
		//全体マップ移動でイベント更新 イベント実行中なら更新しない
		if($gameMap.mapId() == 1 && !$gameSwitches.value(3)){
			advanceGame();
		}
	};
	//Scene_Map.prototype.onMapLoaded
	
//***** クエストメニュー定義
	Scene_MenuQuest.prototype = Object.create(Scene_MenuBase.prototype);
	Scene_MenuQuest.prototype.constructor = Scene_Menu;
	
	Scene_MenuQuest.prototype.initialize = function() {
		Scene_MenuBase.prototype.initialize.call(this);
	};
	
	Scene_MenuQuest.prototype.create = function() {
		$dataQuest = new DataQuest;
		
		Scene_MenuBase.prototype.create.call(this);
		this.createTitleWindow();
		this.createListWindow();
		
	};
	
	Scene_MenuQuest.prototype.start = function() {
		Scene_MenuBase.prototype.start.call(this);
		this._contentsWindow.refresh();
	};
	
	
	Scene_MenuQuest.prototype.createTitleWindow = function() {
		this._titleWindow = new Window_MenuTitle('Journey Hints');
		this.addWindow(this._titleWindow);
	};
	
	
	Scene_MenuQuest.prototype.createListWindow = function() {
		this._listWindow = new Window_MenuQuestList(0, this._titleWindow.height);
		this._listWindow.setHandler('cancel', this.popScene.bind(this));
		
		this.createContentsWindow();
		
		this._listWindow.setContentsWindow(this._contentsWindow);
		this._listWindow.select(0);
		this._listWindow.refresh();
		this.addWindow(this._listWindow);
	};
	
	Scene_MenuQuest.prototype.createContentsWindow = function() {
		this._contentsWindow = new Window_MenuQuestContents(this._listWindow.width, this._titleWindow.height);
		this.addWindow(this._contentsWindow);
	};
	
	

//**** クエストリストウィンドウ  Window_MenuCommand を参考にする
	function Window_MenuQuestList() {
   	 this.initialize.apply(this, arguments);
	}
	
	Window_MenuQuestList.prototype = Object.create(Window_Command.prototype);
	Window_MenuQuestList.prototype.constructor = Window_MenuQuestList;
	Window_MenuQuestList.prototype.initialize = function(x, y) {
		this._offsetY = y;
		Window_Command.prototype.initialize.call(this, x, y);
		//this.selectLast();
	};
	
	Window_MenuQuestList.prototype.setContentsWindow = function(contentsWindow) {
		this._contentsWindow = contentsWindow;
		this._contentsWindow.refresh();
	};
	
	Window_MenuQuestList.prototype.windowWidth = function() {
		return 360;
	};
	Window_MenuQuestList.prototype.windowHeight = function() {
		return Graphics.boxHeight - this._offsetY;
	};

	Window_MenuQuestList.prototype.makeCommandList = function() {
		//ここでリスト作成
		var enabled = true;
		var list = $dataQuest.getCommandList();
		for(var i = 0; i < list.length ;i++){
			this.addCommand(list[i], 'quest', enabled);
		}
	};

	Window_MenuQuestList.prototype.callUpdateHelp = function() {
		if(this._contentsWindow){
			this._contentsWindow.setIndex(this._index);
		}
	};
	
	Window_MenuQuestList.prototype.processOk = function(){
		
	};
	
	Window_MenuQuestList.prototype.drawItem = function(index) {
		var rect = this.itemRectForText(index);
		var align = this.itemTextAlign();
		this.resetTextColor();
		this.changePaintOpacity(this.isCommandEnabled(index));
		this.drawTextEx(this.commandName(index), rect.x, rect.y-1, rect.width, align);
	};

	Window_MenuQuestList.prototype.drawIcon = function(iconIndex, x, y) {
		var bitmap = ImageManager.loadSystem('IconSet');
		var pw = Window_Base._iconWidth;
		var ph = Window_Base._iconHeight;
		var sx = iconIndex % 16 * pw;
		var sy = Math.floor(iconIndex / 16) * ph;
		this.contents.blt(bitmap, sx, sy, pw, ph, x, y+2, pw*0.8, ph*0.8);//アイコンサイズを小さく
	};

	
//**** コンテンツウィンドウ   Window_MenuStatus を参考にする select_window　なので注意
	function Window_MenuQuestContents() {
		this.initialize.apply(this, arguments);
	}
	
	Window_MenuQuestContents.prototype = Object.create(Window_Base.prototype);
	Window_MenuQuestContents.prototype.constructor = Window_MenuQuestContents;
	
	Window_MenuQuestContents.prototype.initialize = function(x, y) {
		var width = Graphics.boxWidth - x;
		var height = Graphics.boxHeight - y;
		Window_Base.prototype.initialize.call(this, x, y, width, height);
		this._index = 0;
	};
	Window_MenuQuestContents.prototype.setIndex = function(index) {
		if (this._index !== index) {
			this._index = index;
			this.refresh();
		}
	};

	Window_MenuQuestContents.prototype.refresh = function() {
		if (this.contents) {
			this.contents.clear();
			this.drawAllItems();
		}
	};
	Window_MenuQuestContents.prototype.drawAllItems = function() {
		var line_y = -5;
		var title = $dataQuest.getTitle(this._index).replace(/\\I\[\d+\]/g, '');//タイトルのアイコンは除去
		var text  = $dataQuest.getDetail(this._index);
		
		if(title){
			this.drawTextEx('\\C[4]'+title+'\\C[0]',0,line_y);
			line_y += this.horzLinePadding();
			//this.drawHorzLine(line_y);
			line_y += this.horzLinePadding();
		}
		
		for (var i = 0; i < text.length; i++) {
			if(text[i] == '<hr>'){
				line_y -= this.horzLinePadding();
				this.drawHorzLine(line_y);
				line_y += this.horzLinePadding();
			}else{
				if(text[i][1] == undefined){
					text[i][1] = true;
				}
				this.changePaintOpacity(text[i][1]);
				this.drawTextEx(text[i][0],0,line_y);
				line_y += this.lineHeight();
			}
		}
		this.changePaintOpacity(true);
	};

	Window_MenuQuestContents.prototype.drawIcon = function(iconIndex, x, y) {
		var bitmap = ImageManager.loadSystem('IconSet');
		var pw = Window_Base._iconWidth;
		var ph = Window_Base._iconHeight;
		var sx = iconIndex % 16 * pw;
		var sy = Math.floor(iconIndex / 16) * ph;
		this.contents.blt(bitmap, sx, sy, pw, ph, x, y+2, pw*0.8, ph*0.8);//アイコンサイズを小さく
	};
	
	Window_MenuQuestContents.prototype.drawHorzLine = function(y) {
		var lineY = y + this.lineHeight() / 2 - 1;
		this.contents.paintOpacity = 48;
		this.contents.fillRect(0, lineY, this.contentsWidth(), 2, this.lineColor());
		this.contents.paintOpacity = 255;
	};
	Window_MenuQuestContents.prototype.lineColor = function() {
		return this.normalColor();
	};
	Window_MenuQuestContents.prototype.horzLinePadding = function(){
		return this.lineHeight() / 2;
	};


//***** クエストデータ
	function DataQuest(){
		this.initialize.apply(this,arguments);
	};
	
	DataQuest.prototype.initialize = function(){
		this._idList = [];
		this._textList = [];
		
		
		for(var i = 200; i >= 101; i--){
			this.setActiveData(i);//段階系イベント
		}
		this.setActiveData(1);//メインクエスト
	}
	
	//進行中クエストをリスト化
	//@param id 変数ID
	DataQuest.prototype.setActiveData = function (id){
		var step = Number($gameVariables._data[id]);
		if(step > 0 && step < 999){
			var text = this.createQuestDetail(id,step);
			if(text != null){
				this._idList.push(id);
				this._textList.push(text);
			}
		}
	};
	
	DataQuest.prototype.createQuestDetail = function(id,step){
		var text = [];
		var active = true;
		switch(id){
		case 1:
			if(step < 60){
				text.push(['A ritual held in Ambell Kingdom every 66 years.']);
				text.push(['Purify the magic crystals of the "Four Pillars", in the ']);
				text.push(['order of: West, North, East, and South.']);
				
				if(step < 51){
				text.push('<hr>');
					if(step >= 10){
						active = step > 10 ? false :true;	
						text.push(['> The first pillar: Defeat Undine at Siren Lake, in the',active]);	
						text.push(['  West.',active]);
					}
					if(step >= 20){
						active = step > 20 ? false :true;	
						text.push(['> The second pillar: Defeat Gnome at Gengan Cave, in the',active]);	
						text.push(['  North.',active]);	
					}
					if(step >= 30){
						active = step > 30 ? false :true;	
						text.push(['> The third pillar: Defeat Sylph at Hierkoll Tower, in ',active]);	
						text.push(['  the East.',active]);	
					}
					if(step >= 40){
						active = step > 40 ? false :true;	
						text.push(['> The fourth pillar: Defeat Salamander at Mount Unjak,',active]);
						text.push(['  in the South.',active]);	
					}
				}
				text.push('<hr>');
				if(step >= 50){
					active = step > 50 ? false :true;	
					text.push('<hr>');
					text.push(['The Four Pillars have been purified. Try returning to ',active]);
					text.push(['the castle.',active]);
				}
				if(step >= 51){
					text.push('<hr>');
					active = step > 51 ? false :true;	
					text.push(['Cannot gain access to the castle.',active]);
					text.push(['Try talking to Penerro the Sage, who lives in a house',active]);
					text.push(['west of the castle.',active]);
				}
			}else{
				text.push(['Hans\' goal is the demon god Elygorl, who is sealed inside']);	
				text.push(['the castle basement, and his magical core.']);	
				text.push(['Check your equipment, then make your way to the Sealed ']);
				text.push(['Altar, via the tunnel from Bedrock Cave, and stop the ']);
				text.push(['evil mage Hans.']);
			}
			
			break;
		case 102:
			text.push(['The Super Slime bars your passage.']);
			text.push('<hr>');
			if(step >= 1){
				active = step > 1 ? false :true;
				text.push(['>Try talking to the Village Chief who can be found in',active]);
				text.push([' Kaltaka Forest Central.',active]);
			}
			
			if(step >= 2){
				active = step > 2 ? false :true;
				text.push(['>Try using the salt that you received from the Village',active]);
				text.push([' Chief on the Super Slime.',active]);
			}
			
			if(step >= 3){
				active = step > 3 ? false :true;
				text.push(['>Throwing salt on it made it smaller.',active]);
				text.push([' Try defeating it now.',active]);
			}
			break;
		case 103:
			switch(step){
			case 1:
				text.push(['Kengo has closed the bridge.']);
				text.push(['You will need to defeat him to proceed further.']);
				break;
			}
			break;
		case 104://いたずらっ子
			switch(step){
			case 2:
				text.push(['Try talking to the Naughty Kid in the North-East part ']);
				text.push(['of Weys Village']);
				break;
			case 4:
			case 6:
			case 8:
				text.push(['Try stepping on the heart symbol in the North-East part ']);
				text.push(['of Weys Village']);
				break;
			}
			break;
		case 105:
			text.push(['Penerro the Sage is encased in ice.',active]);
			text.push('<hr>');
			if(step >= 1){
				active = step > 1 ? false :true;
				text.push(['>Try retrieving the Purgatory Stone from Mount Unjak.',active]);
			}
			
			if(step >= 2){
				active = step > 2 ? false :true;
				text.push(['>Obtained the Purgatory Stone.'],active);
				text.push(['Give the stone to Catherine, in Penerro\'s house west ',active]);
				text.push(['of the castle.',active]);
			}
				
		case 106:
			switch(step){
			case 1:
				text.push(['A Giant Squid has appeared inside the Underwater Tunnel,']);
				text.push(['and is blocking the path.']);
				text.push(['You will need to defeat it to proceed further.']);
				break;
			}
			break;
		case 107:
			switch(step){
			case 1:
				text.push(['A Dragon Wasp has appeared and is blocking the path.']);
				text.push(['You will need to defeat it to proceed further.']);
				break;
				
				
			
			}
			break;
		case 108:
			if(step >= 1){
				text.push(['Papata, the father of the small girl in Weys Village,']);
				text.push(['went out to collect herbs, but hasn\'t come back.']);
				text.push('<hr>');
			
				active = step > 1 ? false :true;
				text.push(['Look for Papata at Siren Lake.',active]);
				
				if(step >= 2){
					active = step > 2 ? false :true;
					text.push(['You saved Papata. Try talking to his daughter next time ',active]);
					text.push(['you go to Weys village.',active]);
					break;
				}
			}
			
			break;			
								
		case 109://穴の底には
			if(step == 2){
				text.push(['Try talking to the fortuneteller in Arlima village.']);
			}else if(step == 3){
				text.push(['It seems there is something glowing at the bottom of ']);
				text.push(['a hole near the vegetable patch in Weys village.']);
			}
			
			break;				
		case 110://気弱なマシュー
			switch(step){
			case 1:
				text.push(['A boy is getting picked on by misfits in the North-East ']);
				text.push(['of Weys village.']);
				break;
			case 4:
				text.push(['Mathias is facing harassment by the misfits in the ']);
				text.push(['North-East of Weys village, again.']);
				break;
			}
			break;
			
		case 111://見える男
			if(step == 1){
				text.push(['In the South-Eastern part of Weys village, try talking ']);
				text.push(['to a man stuck wedged between two buildings.']);
			}
			
			break;
	
		case 112://猫のコテツ探し
			text.push(['The Wandering Chef wants you to bring his cat, Kotetsu, ',active]);
			text.push(['back to him.',active]);
			text.push('<hr>');
			
			if(step >= 1){
				active = step > 1 ? false :true;
				text.push(['>Find Kotetsu somewhere in Nourwess village.',active]);
			}
			
			if(step >= 2){
				active = step > 2 ? false :true;
				text.push(['>Found Kotetsu. Bring him back to the Wandering Chef,',active]);
				text.push([' somewhere in Nourwess village.',active]);
			}
			break;
	
		case 113://下着マニア
			if(step == 2){
				text.push(['Try talking to the Underwear Expert, in the Northern part']);
				text.push(['of Nourwess village.']);
			}
			break;

		case 114://ナンダーラの教え
			text.push(['Was told to bring two items to the Monk in Nourwess ',active]);
			text.push(['village.',active]);
			text.push('<hr>');
			
			active = $gameParty.hasItem($dataItems[59]) ? false :true;
			text.push(['>Get the Siren mineral water from Siren Lake.',active]);
			
			active = $gameParty.hasItem($dataItems[63]) ? false :true;
			text.push(['>Get the Gengan rock from Gengan Cave.',active]);
			
			if(step >= 2){
				active = step > 2 ? false :true;
				text.push(['>You retrieved the items.',active]);
				text.push([' Take them back to the Monk in Nourwess village.',active]);
			}
			break;
		case 115://縄使い
			if(step == 6){
				text.push(['Try talking to the Rope User in Nourwess village.']);
			}
			
			break;
		case 116://病気の妹
			
			if(step == 2){
				text.push(['Try talking to the Worried Man in the South-Eastern part ']);
				text.push(['of Easton.']);
			}
			
			break;
			
		case 117://マジックショー
			if(step == 2){
				text.push(['Try talking to the red clown at Easton theatre.']);
			}
			break;
			
		case 118://壁穴
			
			if(step == 2){
				text.push(['Have you seen the hole in the wall in the front of ']);
				text.push(['Easton tavern?']);
			}else if(step == 4){
				text.push(['Try investigating the hole in the wall in the front ']);
				text.push(['of Easton tavern.']);
			}
			
			break;
			
		case 119://酒場店主の悩み
				
			if(step >= 1){
				active = step > 1 ? false :true;
				text.push(['>The Barkeep of Easton tavern is having trouble preparing',active]);
				text.push([' a food menu. Try talking to the Wandering Chef in ',active]);
				text.push([' Nourwess village.',active]);
			}
			if(step >= 2){
				active = step > 2 ? false :true;
				text.push(['>Kotetsu the cat wants to eat fish.',active]);
				text.push([' Try talking to the Angler near the water in Easton.',active]);
			}
			if(step >= 3){
				active = step > 3 ? false :true;
				text.push(['>Received an Easton trout.',active]);
				text.push([' Try talking to the Wandering Chef, in Nourwess village.',active]);
			}
			if(step >= 4){
				active = step > 4 ? false :true;
				text.push(['>Obtained the Special Recipe.',active]);
				text.push([' Try giving it to the Barkeep at the Easton tavern.',active]);
			}
			
			
			break;
			
		case 120://赤いピエロに制裁を
			if(step >= 1){
				active = step > 1 ? false :true;
				text.push(['>Go to the Easton theatre in order to punish',active]);
				text.push([' the lawless red clown.',active]);
			}
			if(step >= 2){
				active = step > 2 ? false :true;
				text.push(['>The clown has returned to his home.',active]);
				text.push([' Try talking to his father (the Rope User) in Nourwess \r\n village.',active]);
			}
			if(step >= 3){
				active = step > 3 ? false :true;
				text.push(['>The red clown is nowhere to be found.',active]);
				text.push([' Try visiting Easton theatre again.',active]);
			}
			
			break;
			
		case 121://お酒はほどほどに
			
			if(step == 1){
				text.push(['Try talking to the Playboys at Easton theatre.']);
			}else if(step == 3){
				text.push(['Try talking to the Playboys at Easton theatre.']);
			}
			
			break;
		case 122://温泉
			
			if(step == 1){
				text.push(['Try entering the hot springs in Arlima village.']);
			}else if(step == 4){
				text.push(['Try entering the hot springs in Arlima village.']);
			}else if(step == 6){
				text.push(['Try entering the hot springs in Arlima village.']);
			}
			
			break;
			
		case 123://Ｍ男
			if(step == 1){
				text.push(['Try talking to the man behind the general store in ']);
				text.push(['Arlima village.']);
			}
			
			break;
			
		case 124://ナンダーラの教え・秘			
			if(step == 1){
				text.push(['Try talking to Monk in the water, North of Arlima']);
				
			}else if(step > 1 && step < 99){
				text.push(['Was told to bring the Elixir of Nandala to the Monk',active]);
				text.push(['in Arlima village.',active]);
				text.push('<hr>');
								
				active = $gameParty.hasItem($dataItems[66]) ? false :true;
				text.push(['>Get the Elixir of Nandala from Hierkoll Tower.',active]);
				if(!active){
					text.push(['>Obtained the elixir. Bring it to the Monk in Arlima ']);
					text.push([' village.']);
				}
			}
			
			break;
		case 125://脱童貞集会
			
			if(step == 1){
				text.push(['Try talking to the red clown at Easton theatre.']);
			}
			
			break;
			
		case 126://娼館ホルン
			if(step == 2){
				text.push(['Try talking to Horn the peddler, in the North-Eastern ']);
				text.push(['part of Sas-Emerlin.']);
			}else if(step == 3){
				text.push(['Try talking to the Brothel manager in the North-Eastern ']);
				text.push(['part of Sas-Emerlin.']);
			}else if(step == 4){
				text.push(['Try talking to the Brothel manager in the North-Eastern ']);
				text.push(['part of Sas-Emerlin (again).']);
			}else if(step == 5){
				text.push(['Try talking to the Brothel manager in the North-Eastern ']);
				text.push(['part of Sas-Emerlin (one last time).']);
			}
			break;
		
		case 128://売春 鎧マニア
			if(step == 1){
				text.push(['Try investigating the armor outside the inn in the ']);
				text.push(['Sas-Emerlin.']);
			}
			break;
			
		case 129://売春 ヨシオとマサコ
			if(step == 1){
				text.push(['Try talking to the couple in the Northern part of ']);
				text.push(['Sas-Emerlin.']);
			}
			
			break;
		case 130://売春 神父
			if(step == 1){
				text.push(['Try talking to the priest in the South-Western part of']);
				text.push(['Sas-Emerlin.']);
			}
			break;
		case 131://売春 賢者ペネロ
			if(step == 1){
				text.push(['Try talking to Penerro the sage.']);
			}
			break;
		
		case 132://多忙な酒場店主
			if(step == 1){
				text.push(['Try talking to the barkeep in Easton.']);
			}
			break;
		
		case 133://イッたら負け			
			if(step == 1){
				text.push(['Try talking to the clown at the entrance of Easton ']);
				text.push(['theatre.']);
			}
			if(step == 2){
				text.push(['Try talking to the angler near the Easton theatre.']);
			}
			break;
			
		case 134://売春：パパタ
			if(step == 1){
				text.push(['Try talking to Papata in Weys village.']);
			}
			break;
			
		case 135://売春：困り顔の男
			if(step == 1){
				text.push(['Try talking to the worried looking man in the']);
				text.push(['South-Eastern part of Easton.']);
			}
			break;
			
		case 127://売春：農民
			if(step == 1){
				text.push(['Try talking to the farmer at the vegetable patch in Weys ']);
				text.push(['village.']);
			}
			
			break;
		
		case 136://売春：不良
			switch(step){
			case 1:
				text.push(['Try talking to the misfits in the North-Western part of ']);
				text.push(['Weys village.']);
				break;
			}
			break;
			
		case 137://売春：マシュー
			switch(step){
			case 1:
				text.push(['Try talking to Mathias in the North-Western part of Weys ']);
				text.push(['village.']);
				break;
			}
			break;
				
		case 138://井戸の中には
			if(step == 1){
				text.push(['Try talking to the boy in the middle of Weys village.']);
			}
			
			break;
		case 139://穴に落ちたら 起点
			if(step == 1){
				text.push(['Try dropping down the hole near the vegetable patch in ']);
				text.push(['Weys village.']);
			}
			
			break;
		case 140://村娘の困り事
			if(step == 1){
				text.push(['Try talking to the girl near the middle of Weys village.']);
			}
			break;	
		
		case 140://村娘の困り事 起点
			if(step == 1){
				text.push(['Try talking to the girl near the middle of Weys village.']);
			}
			break;	
		case 141://弾ける胸
			if(step == 1){
				text.push(['Try stepping on the heart symbol in the Eastern part of ']);
				text.push(['Nourwess village.']);
			}
			break;	
		case 142://消えた子猫 起点
			if(step == 1){
				text.push(['Try talking to the chef in the South-Western part of ']);
				text.push(['Nourwess village.']);
			}
			break;	
		case 143://縄使い 起点
			if(step == 1){
				text.push(['Try talking to the rope user by the tent in Nourwess ']);
				text.push(['village.']);
			}
			break;	
		case 144://下着交換
			if(step == 1){
				text.push(['Try talking to the underwear expert in the Northern ']);
				text.push(['part of Nourwess village.']);
			}
			break;
		case 145://路傍の首
			if(step == 1){
				text.push(['Try talking to the head in the North-Eastern part of']);
				text.push(['Nourwess village.']);
			}
			break;
		case 146://マジックショー 起点			
			if(step == 2){
				text.push(['Try talking to the bunny girl in the North-Western part ']);
				text.push(['of Easton.']);
			}
			break;
		case 147://酒場店主 酒場店主
			if(step == 2){
				text.push(['Try talking to the owner inside the bar in the ']);
				text.push(['TNorth-Eastern part of Easton.']);
			}
			break;
		case 148://謎の穴 起点
			if(step == 1){
				text.push(['Try checking the back of the building by the bar in ']);
				text.push(['Easton.']);
			}
			break;
		case 149://病気の妹
			if(step == 1){
				text.push(['Try talking to the Worried Man in the South-Eastern ']);
				text.push(['part of Easton.']);
			}
			break;
		case 150://下級兵士の尋問
			if(step == 1){
				text.push(['Try checking the entrance to the barracks in the ']);
				text.push(['North-Western part of Sas-Emerlin.']);
			}
			break;
		}	
			
		
		if(text.length == 0){
			text = null;	
		}
		
		
		return text;
	};
	
	
	DataQuest.prototype.getTitle = function(index){
		if(index == this._idList.length - 1){
			//メインクエ
			var step = $gameVariables._data[1];
			if(step < 60){
				return "\\I[82]Four Pillars"	
			}else{
				return "\\I[76]Hans the Mage"	
			}
		}
		return $gameVariables.name(this._idList[index]);
	};
	
	
		
	DataQuest.prototype.getCommandList = function (index){
		var list = [];
		for(var i = 0; i < this._idList.length; i++){
			list.push(this.getTitle(i));
		}
		return list;
	};
	
	DataQuest.prototype.getDetail = function(index){
		return this._textList[index] || '';
	};

//----------------------------------------------------------------------
//*****クエストメッセージポップアップウインドウの定義
	//****Scene_Map にメッセージウィンドウを組み込み
	var _Scene_Map_prototype_createDisplayObjects = Scene_Map.prototype.createDisplayObjects;
	Scene_Map.prototype.createDisplayObjects = function() {
		_Scene_Map_prototype_createDisplayObjects.call(this);
		this.createQuestMessageWindow();
	};
	Scene_Map.prototype.createQuestMessageWindow = function() {
		this._questMessageWindow = new Window_QuestMessage();
		this.addChild(this._questMessageWindow);
		
	};
	
	var _Scene_Map_prototype_terminate = Scene_Map.prototype.terminate;
	Scene_Map.prototype.terminate = function() {
		_Scene_Map_prototype_terminate.call(this);
		if (!SceneManager.isNextScene(Scene_Battle)) {
			this._questMessageWindow.hide();
		}
		this.removeChild(this._questMessageWindow);
	};
	
	var _Scene_Map_prototype_callMenu = Scene_Map.prototype.callMenu;
	Scene_Map.prototype.callMenu = function() {
		_Scene_Map_prototype_callMenu.call(this);
		this._questMessageWindow.hide();
	};
	
	var _Scene_Map_prototype_launchBattle = Scene_Map.prototype.launchBattle;
	Scene_Map.prototype.launchBattle = function() {
		_Scene_Map_prototype_launchBattle.call(this);
		this._questMessageWindow.hide();
	};
	
	
	var _Scene_Map_update = Scene_Map.prototype.update;
	Scene_Map.prototype.update = function() {
		
		if($popupQuestVarID > 0){
			this._questMessageWindow.setVariableId($popupQuestVarID);
			$popupQuestVarID = 0;
		}
		
		_Scene_Map_update.call(this);
	};

	
//***** MessageWindowの定義
	function Window_QuestMessage() {
		this.initialize.apply(this, arguments);
	}
	
	Window_QuestMessage.prototype = Object.create(Window_MapName.prototype);
	Window_QuestMessage.prototype.constructor = Window_QuestMessage;
	
	Window_QuestMessage.prototype.initialize = function() {
		var wight = this.windowWidth();
		var height = this.windowHeight();
		var y = Graphics.boxHeight - height - 10;
		Window_Base.prototype.initialize.call(this, 0, y, wight, height);
		this.opacity = 0;
		this.contentsOpacity = 0;
		this._showCount = 0;
		
		this.setVariableId();
		
		this.refresh();
	};
	
	Window_QuestMessage.prototype.windowWidth = function() {
		return Graphics.boxWidth;
	};

	Window_QuestMessage.prototype.standardFontSize = function() {
		return 22;
	};
	Window_QuestMessage.prototype.standardPadding = function() {
		return 0;
	};


	Window_QuestMessage.prototype.setVariableId = function (id){
		if(id == undefined){
			id = 0;
		}
		if(this._id != id){
			this._id = id;
			this.refresh();

			if(id > 0){
				this._showCount = 150;
			}
		}
	};
	
	Window_QuestMessage.prototype.update = function() {
		Window_Base.prototype.update.call(this);

		//if (this._showCount > 0 && this._id > 0 && $gameVariables._data[this._id] > 0) {
		if (this._showCount > 0 && this._id > 0) {
			this.updateFadeIn();
			this._showCount--;
		} else {
			this.updateFadeOut();
			if(this.contentsOpacity <= 0){
				this._id = 0;
			}
		}
	};

	Window_QuestMessage.prototype.refresh = function() {
		this.contents.clear();

		if (this._id > 0){
			var seName = '';
			var text = '';
				
			if(this._id == 9999){
				text = "Updated the Journey Hints!";	
				seName = 'Bell3';
			}else if($gameVariables._data[this._id] > 0) {
				
				text = this.getQuestTitle();
				
				switch($gameVariables._data[this._id]){
				case 1:
					text = 'Started Quest:'+text+'!';
					seName = 'Flash2';
					break;
				case 999:
					text = 'Completed Quest:'+text+'!';
					seName = 'Flash2';
					break;
				default:
					text = 'Updated Quest:'+text+'!';
					break;
				}
			}else if(this._id == 9998){
				text = "\\I[87]Completed all events!";	
				seName = 'Flash2';	
			}
						
			var width = this.textWidth(text);
			this.drawBackground(this.windowWidth() - width, 0, width, this.lineHeight());
			this.drawTextEx(text,this.width - width, +1);
			//this.drawText(text, this.standardPadding(), 0, width);
			
			if(seName != ""){
				AudioManager.playSe({'name':seName,'volume':90,'pitch':100,'pan':0});
			}
		}
	};
	
	Window_QuestMessage.prototype.getQuestTitle = function(){
		var res ="";
		if(this._id > 1){//基本クエストは進行度で名前が変わるのでここでは省略
			res = $gameVariables.name(this._id);
			if(res != ""){
				res = '【'+res+'】';	
			}
		}
		return res;
	};
	Window_QuestMessage.prototype.drawBackground = function(x, y, width, height) {
		var color1 = this.dimColor1();
		var color2 = this.dimColor2();
		
		var gradient_width = 80;
		this.contents.gradientFillRect(x - gradient_width , y, gradient_width, height, color2,color1);
		this.contents.fillRect(x, y, width, height, color1);
	};
	
	Window_QuestMessage.prototype.drawIcon = function(iconIndex, x, y) {
		var bitmap = ImageManager.loadSystem('IconSet');
		var pw = Window_Base._iconWidth;
		var ph = Window_Base._iconHeight;
		var sx = iconIndex % 16 * pw;
		var sy = Math.floor(iconIndex / 16) * ph;
		this.contents.blt(bitmap, sx, sy, pw, ph, x + 2, y, pw*0.75, ph*0.75);//アイコンサイズを小さく
	};
	
	
//*****プラグインコマンドの定義
	var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
	Game_Interpreter.prototype.pluginCommand = function(command, args) {
		_Game_Interpreter_pluginCommand.call(this, command, args);
		switch (command) {
		case 'PopupHint':
			var varID = args[0];
			if(isNaN(varID) && varID.indexOf('V[') != -1){
				varID=$gameVariables.value(varID.replace(/[^0-9^\.]/g,""));
			}
			
			$popupQuestVarID = Number(varID);
			break;
		
		case 'AdvanceGame':
			advanceGame();
			break;
		}
		
		
	};

})();