quest subquest_27 begin
	state start begin
		when login or levelup with pc.level >= 38  and pc.level <= 40  begin
			set_state(information)
		end
	end

	state information begin
		when letter begin
			local v=find_npc_by_vnum(20023)
			if 0==v then
			else
				target.vid("__TARGET__", v, gameforge.subquest_27._10_targetVid)
			end
		end

		when __TARGET__.target.click or 20023.chat.gameforge.subquest_27._20_npcChat begin
			target.delete("__TARGET__")
			say_title(gameforge.subquest_05._30_sayTitle)
			say(gameforge.subquest_27._30_say)
			wait()
		
			say_title(gameforge.subquest_05._30_sayTitle)
			say(gameforge.subquest_27._40_say)
			
			set_state(to_wife)

		end
	end
	state to_wife begin
		when letter begin
			local v=find_npc_by_vnum(20002)
			if 0==v then
			else
				target.vid("__TARGET__", v, gameforge.subquest_18._20_sayTitle)
			end
			
			setskin(NOWINDOW)
			makequestbutton(gameforge.subquest_27._50_makequestbutton)
			q.set_title(gameforge.subquest_27._50_makequestbutton)
			q.start()

		end

		when info or button begin
		
			say_title(gameforge.subquest_27._60_sayTitle)
			say(gameforge.subquest_27._70_say)


		end

		when __TARGET__.target.click or	20002.chat.gameforge.subquest_27._80_npcChat begin
			target.delete("__TARGET__")
			say_title(gameforge.npc_talk._630_sayTitle)
			say(gameforge.subquest_27._90_say)
			wait()
			say_title(gameforge.npc_talk._630_sayTitle)
			say(gameforge.subquest_27._100_say)
			set_state(to_neighbor)
		end
	end	
	
	state to_neighbor  begin
		when letter begin
			local v=find_npc_by_vnum(9003)
			if 0==v then
			else
				target.vid("__TARGET__", v, gameforge.subquest_27._110_targetVid)
			end
			
			setskin(NOWINDOW)
			makequestbutton(gameforge.subquest_27._120_makequestbutton)
			q.set_title(gameforge.subquest_27._120_makequestbutton)
			q.start()

		end

		when info or button begin
		
			say_title(gameforge.subquest_27._120_makequestbutton)
			say(gameforge.subquest_27._130_say)


		end


		when __TARGET__target.click or	9003.chat.gameforge.subquest_27._140_npcChat  begin
			target.delete("__TARGET__")
			say_title(gameforge.find_squareguard._130_sayTitle)
			say(gameforge.subquest_27._150_say)
			wait()
			say_title(gameforge.subquest_27._160_sayTitle)
			say(gameforge.subquest_27._170_say)
			set_state(back_to_soonyougil)
		end	
			
	end

	state back_to_soonyougil begin

		when letter begin

			setskin(NOWINDOW)
			makequestbutton(gameforge.subquest_27._180_makequestbutton)
			q.set_title(gameforge.subquest_27._190_qSetTitle)
			q.start()
			
			local v = find_npc_by_vnum(20023)
			if 0==v then
			else
				target.vid("__TARGET__", v, gameforge.subquest_27._200_targetVid)
			end

		end

		when info or button begin
		
			say(gameforge.subquest_27._210_say)


		end

		when __TARGET__.target.click or	20023.chat.gameforge.subquest_27._220_npcChat begin
			target.delete("__TARGET__")
			say_title(gameforge.subquest_05._30_sayTitle)
			say(gameforge.subquest_27._230_say)
			wait("")
			say_title(gameforge.subquest_05._30_sayTitle)
			say(gameforge.subquest_27._240_say)

			local s= select(gameforge.subquest_27._250_select, gameforge.subquest_27._260_select)
			if 2==s then
				say(gameforge.subquest_27._270_say)
				local a= select(gameforge.locale.guild.yes, gameforge.locale.guild.no)
				if  2==a then
					say_title(gameforge.subquest_05._30_sayTitle)
					say(gameforge.subquest_27._280_say)
					return
				end
				say_title(gameforge.subquest_05._30_sayTitle)
				say(gameforge.subquest_27._290_say)
				set_state(__GIVEUP__)
				return
			end
					
			say_title(gameforge.subquest_05._30_sayTitle)
			say(gameforge.subquest_27._300_say)
			set_state(find_book)
			
		end

	end
			

	state find_book begin

		when letter begin
					
			if pc.count_item("30156")>=1 then
				setskin(NOWINDOW)
				makequestbutton(gameforge.subquest_27._310_makequestbutton)
				q.set_title(gameforge.subquest_27._320_qSetTitle)
				q.start()

				local v=find_npc_by_vnum(20023)
				if 0!= v then
					target.vid("__TARGET__",v, gameforge.subquest_27._330_targetVid)
				end 
				return
			end
			
			setskin(NOWINDOW)
			makequestbutton(gameforge.subquest_27._340_makequestbutton)
			q.set_title(gameforge.subquest_27._340_makequestbutton)
			q.start()

		end

		when info or  button begin
			if pc.count_item("30156")>=1 then
				say_title(gameforge.subquest_27._350_sayTitle)
				say(gameforge.subquest_27._360_say)
				return
			end
			
			say_title(gameforge.subquest_27._340_makequestbutton)
			say(gameforge.subquest_27._370_say)
		end

		when 701.kill  begin
			
			local s = number(1, 100)
			if s <= 5 and pc.count_item("30156")==0  then
				pc.give_item2(30156, 1)

			end
		end

			
		when __TARGET__.target.click or	20023.chat.gameforge.subquest_27._380_npcChat   begin
			target.delete("__TARGET__")
			if pc.count_item("30156")>=1	then
				say_title(gameforge.subquest_05._30_sayTitle)
				say(gameforge.subquest_27._390_say)
				pc.remove_item("30156",1)	
				say_reward(gameforge.subquest_27._400_sayReward)
				pc.change_money(20000)
				
				say_reward(gameforge.subquest_27._410_sayReward)
				pc.give_exp2(850000)


				clear_letter()
				set_state(__COMPLETE__)


				
				
				return
			else		
				say_title(gameforge.subquest_05._30_sayTitle)
				say(gameforge.subquest_27._420_say)


				local s= select(gameforge.subquest_26._330_select, gameforge.find_brother_article._170_select)
				if 2==s then
					say(gameforge.subquest_26._80_say)
					local a= select(gameforge.locale.guild.yes, gameforge.locale.guild.no)
					if  2==a then
						say_title(gameforge.subquest_05._30_sayTitle)
						say(gameforge.subquest_27._430_say)
						return
					end
					say_title(gameforge.subquest_05._30_sayTitle)
					say(gameforge.subquest_27._440_say)

					set_state(__GIVEUP__)
					return
				end
						
				say_title(gameforge.subquest_05._30_sayTitle)
				say(gameforge.subquest_27._450_say)

				end


			end

		end



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


