quest subquest_20  begin
   	state start begin
		when login or levelup with pc.level >= 30  and pc.level <= 32  begin
			set_state(information)
		end
	end

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


		when __TARGET__.target.click or	20003.chat.gameforge.subquest_20._20_npcChat  begin
			target.delete("__TARGET__")
			say_title(gameforge.npc_talk._580_sayTitle)
			say(gameforge.subquest_20._30_say)
			wait()
			say_pc_name()
			say(gameforge.subquest_20._40_say)
			wait()
			say_title(gameforge.npc_talk._580_sayTitle)
			say(gameforge.subquest_20._50_say)
			wait()
			say_title(gameforge.npc_talk._580_sayTitle)
			say(gameforge.subquest_20._60_say)
			say_item_vnum(30161)
			say(gameforge.subquest_20._70_say)
			local b= select(gameforge.subquest_20._80_select, gameforge.subquest_20._90_select)
			if 2==b then
				say(gameforge.subquest_20._100_say)
				local q= select(gameforge.locale.guild.yes, gameforge.locale.guild.no)
				if 2==q  then
					say_title(gameforge.npc_talk._580_sayTitle)
					say(gameforge.subquest_20._110_say)
					return
				end
				say_title(gameforge.npc_talk._580_sayTitle)
				say(gameforge.subquest_20._120_say)
				set_state(__GIVEUP__)
				return
			end
			say_title(gameforge.npc_talk._580_sayTitle)
			say(gameforge.subquest_20._130_say)
			set_state(for_husband_product)
		end
    end
    state for_husband_product begin
		when letter begin
			send_letter(gameforge.subquest_20._140_sendLetter)
			if pc.count_item(30161) >= 3 then
				local v=find_npc_by_vnum(20003)
				if 0==v then
				else
					target.vid("__TARGET__",v, gameforge.subquest_20._150_targetVid)
				end
			end
		end

		when button or info begin
			if pc.count_item(30161) >= 3 then
				say_title(gameforge.subquest_20._160_sayTitle)
				say(gameforge.subquest_20._170_say)
				return
			end
			say_title(gameforge.subquest_20._180_sayTitle)
			say(gameforge.subquest_20._190_say)
			say_reward(string.format(gameforge.subquest_20._200_sayReward, pc.count_item(30161)))
			
		end

		when 501.kill or 502.kill or  503.kill or 504.kill  begin
			local s = number(1, 100)
			if s <= 5 and pc.count_item("30161")<3  then
				pc.give_item2("30161", 1)
				local v=find_npc_by_vnum(20003)
				if 0==v then
				else
					target.vid("__TARGET__",v, gameforge.subquest_20._150_targetVid)
				end
			end
		end

		when 20003.chat.gameforge.subquest_20._210_npcChat with pc.count_item(30161)==0 begin
			say_title(gameforge.npc_talk._580_sayTitle)
			say(gameforge.subquest_20._220_say)
			local s= select(gameforge.subquest_20._230_select, gameforge.find_brother_article._170_select)
			if 2==s then
				say_title(gameforge.npc_talk._580_sayTitle)
				say(gameforge.subquest_20._240_say)
				local r= select(gameforge.subquest_20._250_select, gameforge.locale.guild.no)
				if 2==r then
					say(gameforge.subquest_20._260_say)
					return
				end
				say(gameforge.subquest_20._270_say)
				set_state(__GIVEUP__)
				return
			end
			say(gameforge.subquest_20._280_say)
		end
		when __TARGET__.target.click or	20003.chat.gameforge.subquest_20._290_npcChat with pc.count_item(30161)>0 begin
			target.delete("__TARGET__")
			if pc.count_item(30161)<3 then
				say_title(gameforge.subquest_20._300_sayTitle)
				say(gameforge.subquest_20._310_say)
				local z= select(gameforge.subquest_20._320_select, gameforge.subquest_20._330_select)
				if 2==z then
					say(gameforge.subquest_20._340_say)
					set_state(__GIVEUP__)
					return
				end
				say(gameforge.subquest_20._350_say)

			else
				say_title(gameforge.subquest_20._300_sayTitle)
				say(gameforge.subquest_20._360_say)
				say_reward(gameforge.subquest_20._370_sayReward)
				pc.change_money(20000)
				pc.give_exp2(300000)

				pc.remove_item(30161, 3)
				clear_letter()
				set_state(__COMPLETE__)
			end
		end
    end
    state __GIVEUP__ begin
    end
	state __COMPLETE__ begin
		when enter begin
		q.done()
		end
    end
end

