
quest subquest_38 begin
	state start begin
		when login or levelup with pc.level >= 45 and pc.level <= 47 begin
			set_state(information)
		end

	end

	state information begin
		when letter begin
					
			local v = find_npc_by_vnum(20019)

			if v != 0 then
				target.vid("__TARGET__", v, gameforge.subquest_38._10_targetVid)
			end
		end

		
		when __TARGET__.target.click or 20019.chat.gameforge.subquest_38._10_targetVid with pc.level >= 16 begin
			target.delete("__TARGET__")

			say_title(gameforge.main_quest_lv32._510_sayTitle)
			say(gameforge.subquest_38._20_say)
			wait()
			say_title(gameforge.main_quest_lv32._510_sayTitle)
			say(gameforge.subquest_38._30_say)
			wait()
			say_title(gameforge.main_quest_lv32._510_sayTitle)

			say(gameforge.subquest_38._40_say)
			local s= select(gameforge.find_brother_article._90_select, gameforge.subquest_01._60_select)
			if 2==s then
				say(gameforge.subquest_31._190_say)
				local a= select(gameforge.locale.guild.yes, gameforge.locale.guild.no)
				if  2==a then
					say_title(gameforge.subquest_38._50_sayTitle)
					say(gameforge.subquest_38._60_say)
					return
				end
				say_title(gameforge.main_quest_lv32._510_sayTitle)
				say(gameforge.subquest_38._70_say)
				set_state(__GIVEUP__)
				return
			end
			
			say_title(gameforge.main_quest_lv32._510_sayTitle)
			say(gameforge.subquest_38._80_say)
			set_state(hunt_monkey)
		
		end
	end

	state hunt_monkey begin
		when enter or login or letter begin
			if pc.count_item("30136") == 0then
				send_letter(gameforge.subquest_38._10_targetVid)
			else
				send_letter(gameforge.subquest_38._110_sendLetter)
			end
		end
		when info or button begin
			if pc.count_item("30136") == 0then
				say_title(gameforge.subquest_38._90_sayTitle)
				say(gameforge.subquest_38._100_say)
			else
				say_title(gameforge.subquest_38._120_targetVid)
				say(gameforge.subquest_38._125_say)
			end
		end

		when 5121.kill or 5122.kill or 5123.kill or 5124.kill or 5125.kill begin
			local s = number(1, 100) 
			if s <= 5 and pc.count_item("30136")== 0  then
				pc.give_item2("30136", 1)
				send_letter(gameforge.subquest_38._110_sendLetter)
				local v=find_npc_by_vnum(20019)
				if 0== v then
				else
					target.vid("__TARGET__",v, gameforge.subquest_38._120_targetVid)
				end
			end

		end	

		when 20019.chat.gameforge.subquest_38._130_npcChat begin
			target.delete("__TARGET__")
		
			if pc.count_item("30136") >= 1 then
				say_title(gameforge.main_quest_lv32._510_sayTitle)
				say(gameforge.subquest_38._140_say)
				pc.remove_item("30136", 1)
				
				say_reward(gameforge.subquest_38._150_sayReward)
				pc.give_exp2(1500000)
				
				say_reward(gameforge.subquest_38._160_sayReward)
				pc.give_item2(70038)
				
				say_reward(gameforge.subquest_38._170_sayReward)
				pc.change_money(35000)
				set_state(COMPLETE)
				clear_letter()
				return
			else
				say_title(gameforge.main_quest_lv32._510_sayTitle)
				say(gameforge.subquest_38._180_say)
				local s= select(gameforge.subquest_38._190_select, gameforge.subquest_24._200_select)
				if 2==s then
					say(gameforge.subquest_37._50_say)
					local a= select(gameforge.locale.guild.yes, gameforge.locale.guild.no)
					if  1==a then
						say_title(gameforge.main_quest_lv32._510_sayTitle)
						say(gameforge.subquest_38._200_say)
						set_state(__GIVEUP__)
						return
					end
					say_title(gameforge.main_quest_lv32._510_sayTitle)
					say(gameforge.subquest_38._210_say)
				end	
			end
		end
	end

	state __GIVEUP__ begin
	end
		
	state COMPLETE begin
		when enter begin
			q.done()
		end
	end
end
