quest subquest_31 begin
	state start begin
		when login or levelup or enter with pc.get_level() >=34  and pc.get_level() <= 36 begin
			set_state( information )
		end
	end

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

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

				
		when __TARGET__.target.click or	20016.chat.gameforge.subquest_31._20_npcChat with pc.level >= 34 begin
			target.delete("__TARGET__")
			say_title(gameforge.subquest_09._50_sayTitle)
			say(gameforge.subquest_31._30_say)
			wait()
			say_title(gameforge.blacksmith._20_sayTitle)
			say(gameforge.subquest_31._40_say)
			local s= select(gameforge.subquest_31._50_select, gameforge.subquest_30._50_select)
			if 2==s then
			say_title(gameforge.blacksmith._20_sayTitle)
			say(gameforge.subquest_31._60_say)
			local a= select(gameforge.locale.guild.yes, gameforge.locale.guild.no)
				if  2==a then
					say_title(gameforge.subquest_09._50_sayTitle)
					say(gameforge.subquest_31._70_say)
					return
				end
				say_title(gameforge.subquest_09._50_sayTitle)
				say(gameforge.subquest_31._80_say)
				set_state(__GIVEUP__)
				return
			end
			say_title(gameforge.subquest_09._50_sayTitle)
			say(gameforge.subquest_31._90_say)
			set_state(to_gain_material)
		end	
	end

	state to_gain_material begin

		when letter begin

			send_letter(gameforge.subquest_31._100_sendLetter)
			local copper =pc.count_item(50604)
			local pearl=pc.count_item(50609)
			local ebony=pc.count_item(50608)
			
			if	copper>100  or  pearl>100 or  ebony>100 then
				
				local v = find_npc_by_vnum(20016)

				if v != 0 then
				target.vid("__TARGET__", v, gameforge.subquest_30._110_targetVid)
				end
				return
			end
	
		end

		when info or button begin
			local copper=pc.count_item(50604)
			local pearl=pc.count_item(50609)
			local ebony=pc.count_item(50608)
			
			if	copper>=100  and   pearl>=100 and  ebony>=100 then
				say_title(gameforge.subquest_31._110_sayTitle)
				say(gameforge.subquest_31._120_sayReward)
				return
			end
			
			say_title(gameforge.subquest_31._130_sayTitle)
			say(gameforge.subquest_31._140_sayReward)
		end

		when 20016.chat.gameforge.subquest_31._150_npcChat  begin
			target.delete("__TARGET__")
			
			local copper =pc.count_item(50604)
			local pearl=pc.count_item(50609)
			local ebony=pc.count_item(50608)
			

			
			if	copper<100  or  pearl<100 or  ebony<100 then

				say_title(gameforge.blacksmith._20_sayTitle)

				say(gameforge.subquest_31._160_say)
				local s= select(gameforge.subquest_31._170_select, gameforge.subquest_31._180_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.blacksmith._20_sayTitle)
						say(gameforge.subquest_31._200_say)
						return
					end
					say_title(gameforge.subquest_09._50_sayTitle)
					say(gameforge.subquest_31._210_say)
					set_state(__GIVEUP__)
					return
				end
				say_title(gameforge.blacksmith._20_sayTitle)
				say(gameforge.subquest_31._220_say)
		end	
		if copper>=100  and pearl>=100 and ebony>=100 then
			say(gameforge.subquest_31._230_say)
			say_reward(gameforge.subquest_31._240_sayReward)
			pc.give_exp2(200000)

			
			pc.remove_item(50604,100)
			pc.remove_item(50609,100)
			pc.remove_item(50608,100)
			
			say_reward(gameforge.subquest_31._250_sayReward)
			pc.change_money(20000)

				if pc.job == 0 then
					pc.give_item2(11233, 1)
					say_reward(gameforge.subquest_31._260_sayReward)
				elseif pc.job == 1 then
					pc.give_item2(11433, 1)
					say_reward(gameforge.subquest_31._270_sayReward)
				elseif pc.job == 2 then
					pc.give_item2(11633, 1)
					say_reward(gameforge.subquest_31._280_sayReward)
				elseif pc.job == 3 then
					pc.give_item2(11833, 1)
					say_reward(gameforge.subquest_31._290_sayReward)
				end	
			
			
			clear_letter()
			set_state(__COMPLETE__)	
			end

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