quest subquest_6 begin
	state start begin
		when login or levelup with pc.level >= 11 and pc.level <= 16 begin
			set_state(information)
		end
	end

	state information begin
		when letter begin
			local v = find_npc_by_vnum(9002)
			if v != 0 then
				target.vid("__TARGET__", v, gameforge.subquest_06._10_targetVid)
			end
		end

		when __TARGET__.target.click or	9002.chat.gameforge.subquest_06._20_npcChat with pc.level >= 11 begin
			target.delete("__TARGET__")

			say_title(gameforge.main_quest_lv3._160_sayTitle)
			say(gameforge.subquest_06._30_say)
			local s= select(gameforge.subquest_06._40_select, gameforge.subquest_06._50_select)
			if 2==s then
				say(gameforge.subquest_06._60_say)
				local a= select(gameforge.subquest_06._70_select, gameforge.subquest_06._80_select)
				if  2==a then
				say_title(gameforge.main_quest_lv3._160_sayTitle)
				say(gameforge.subquest_06._90_say)
					return
				end
				say_title(gameforge.main_quest_lv3._160_sayTitle)
                                say(gameforge.subquest_06._100_say)
				set_state(__GIVEUP__)
				return
			end
			say_title(gameforge.main_quest_lv3._160_sayTitle)
			say(gameforge.subquest_06._110_say)
			set_state(ask_blacksmith)
		end
	end
	state ask_blacksmith begin
		when info or button begin
			say_title(gameforge.subquest_06._20_npcChat)
			say_reward(gameforge.subquest_06._120_sayReward)
		end

		when letter begin
			send_letter(gameforge.subquest_06._10_targetVid)
		end

		when __TARGET__.target.click or	20016.chat.gameforge.subquest_06._130_npcChat begin
			target.delete("__TARGET__")
			say_title(gameforge.blacksmith._20_sayTitle)
			say(gameforge.subquest_06._140_say)

			local s= select(gameforge.subquest_06._150_select, gameforge.subquest_06._160_select)
			if 2==s then
				say(gameforge.subquest_06._170_say)
				local a= select(gameforge.locale.guild.yes, gameforge.subquest_05._320_select)
				if  2==a then
					say_title(gameforge.blacksmith._20_sayTitle)
                                        say(gameforge.subquest_06._180_say)
					return
				end
				say_title(gameforge.blacksmith._20_sayTitle)
                                say(gameforge.subquest_06._190_say)
				set_state(__GIVEUP__)
				return
			end
			say_title(gameforge.blacksmith._20_sayTitle)
			say(gameforge.subquest_06._200_say)
			set_state(to_get_material)
		end

	end
	state to_get_material begin
		when button or info begin
			say_title(gameforge.subquest_06._20_npcChat)
			say(gameforge.subquest_06._220_sayReward)
			if pc.getqf("asked_20011") == 1 then
				say(gameforge.subquest_06._285_say)
			elseif pc.getqf("ironore_done") == 1 then
				say_reward(gameforge.subquest_06._224_sayReward)
			else 
				say(gameforge.subquest_06._221_say)
			end
			
			if pc.getqf("asked_20008") == 1 then
				say(gameforge.subquest_06._345_say)
			elseif pc.getqf("leather_done") == 1 then
				say_reward(gameforge.subquest_06._225_sayReward)
			else 
				say(gameforge.subquest_06._222_say)
			end
			
			if pc.getqf("asked_20005") == 1 then
				say(gameforge.subquest_06._395_say)
			elseif pc.getqf("coal_done") == 1 then
				say_reward(gameforge.subquest_06._226_sayReward)
			else
				say(gameforge.subquest_06._223_say)
			end
		end

		when letter begin
			send_letter(gameforge.subquest_06._210_sendLetter)
			if pc.getqf("leather_done")!=1 then
				local v=find_npc_by_vnum(20008)
				if 0!=v then
					target.vid("__TARGET1__",v, gameforge.subquest_06._230_targetVid)
				end
			end

			if pc.getqf("ironore_done")!=1 then
				local v=find_npc_by_vnum(20011)
				if 0!=v then
					target.vid("__TARGET2__",v, gameforge.subquest_06._240_targetVid)
				end
			end

			if pc.getqf("coal_done")!=1 then
				local v=find_npc_by_vnum(20005)
				if 0!=v then
					target.vid("__TARGET3__",v, gameforge.subquest_06._250_targetVid)
				end
			end
		end

		when 20011.chat.gameforge.subquest_06._260_npcChat with pc.getf("subquest_6","ironore_done") == 0 begin
			target.delete("__TARGET2__")
			if pc.count_item(30132) >= 1 then
				pc.setqf("ironore_done", 1)
				pc.setqf("asked_20011", 0)
				pc.remove_item("30132", 1)

				say_title(gameforge.main_quest_lv30._40_sayTitle)
				say(gameforge.subquest_06._270_say)
				if  pc.getqf("ironore_done") == 1 and pc.getqf("leather_done") == 1 and pc.getqf("coal_done") == 1 then
					set_state(back_to_blacksmith)
				end
				return
			end
			say_title(gameforge.main_quest_lv30._40_sayTitle)
			say(gameforge.subquest_06._280_say)
			say_item_vnum("30132")
			pc.setqf("asked_20011", 1)

		end
		when 20011.chat.gameforge.subquest_06._290_npcChat with pc.getf("subquest_6","ironore_done")==1 begin
				target.delete("__TARGET2__")
				say_title(gameforge.main_quest_lv30._40_sayTitle)
				say(gameforge.subquest_06._300_say)
		end
		when 20008.chat.gameforge.subquest_06._310_npcChat with pc.getf("subquest_6","leather_done") == 0 begin
			target.delete("__TARGET1__")
			if pc.count_item(60001) >= 1 then
				pc.setqf("leather_done", 1)
				pc.setqf("asked_20008", 0)
				pc.remove_item("60001", 1)

				say_title(gameforge.subquest_06._320_sayTitle)
				say(gameforge.subquest_06._330_say)
				if pc.getqf("ironore_done") == 1 and pc.getqf("leather_done") == 1 and pc.getqf("coal_done") == 1 then

					set_state(back_to_blacksmith)
				end
				return
			end
			say_title(gameforge.subquest_06._320_sayTitle)
			say(gameforge.subquest_06._340_say)
			say_item_vnum("60001")
			pc.setqf("asked_20008", 1)

		end
		when 20008.chat.gameforge.subquest_06._350_npcChat with pc.getqf("leather_done")==1 begin
				target.delete("__TARGET1__")
				say_title(gameforge.subquest_06._320_sayTitle)
				say(gameforge.subquest_06._360_say)
		end


		when 20005.chat.gameforge.subquest_06._370_npcChat with pc.getf("subquest_6","coal_done") == 0 begin
			target.delete("__TARGET3__")
			if pc.count_item(30044) >= 1 then
				pc.setqf("coal_done", 1)
				pc.setqf("asked_20005", 0)
				pc.remove_item("30044", 1)

				say_title(gameforge.subquest_01._140_sayTitle)
				say(gameforge.subquest_06._380_say)
				if  pc.getqf("ironore_done") == 1 and pc.getqf("leather_done") == 1 and pc.getqf("coal_done") == 1 then
					set_state(back_to_blacksmith)

				end
				return
			end
			say_title(gameforge.subquest_01._140_sayTitle)
			say(gameforge.subquest_06._390_say)
			wait()

			say_title(gameforge.subquest_01._140_sayTitle)
			say(gameforge.subquest_06._400_say)
			say_item_vnum("30044")
			pc.setqf("asked_20005", 1)
		end
		when 20005.chat.gameforge.subquest_06._410_npcChat with pc.getf("subquest_6","coal_done")==1 begin
				target.delete("__TARGET3__")
				say_title(gameforge.subquest_01._140_sayTitle)
				say(gameforge.subquest_06._420_say)
		end

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


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

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

		when 20016.chat.gameforge.subquest_06._430_npcChat begin
			target.delete("__TARGET__")
			if pc.getqf("ironore_done") != 1 then
				say_title(gameforge.blacksmith._20_sayTitle)
				say(gameforge.subquest_06._440_say)
				return
			end

			if pc.getqf("leather_done") != 1 then
				say_title(gameforge.blacksmith._20_sayTitle)
				say(gameforge.subquest_06._450_say)
				return
			end
			if pc.getqf("coal_done") != 1 then
				say_title(gameforge.blacksmith._20_sayTitle)
				say(gameforge.subquest_06._460_say)
				return
			end
		end
	end
	state back_to_blacksmith begin
		when letter begin
			setskin(NOWINDOW)
			makequestbutton(gameforge.subquest_06._470_makequestbutton)
			q.set_title(gameforge.subquest_06._480_qSetTitle)
			q.start()

			local v=find_npc_by_vnum(20016)
			if 0==v then
			else
				target.vid("__TARGET__",v, gameforge.subquest_06._490_targetVid)
			end
		end
		when info or button begin
			say_title(gameforge.subquest_06._500_sayTitle)
						say(gameforge.subquest_06._510_sayReward)
					end

		when __TARGET__.target.click or	20016.chat.gameforge.subquest_06._520_npcChat with pc.getf("subquest_6","ironore_done") == 1 and pc.getf("subquest_6","leather_done") == 1 and pc.getf("subquest_6","coal_done") == 1 begin
				say_title(gameforge.blacksmith._20_sayTitle)
				say(gameforge.subquest_06._530_say)
				set_state(resource_complete)
		end
	end
	state resource_complete begin
		when info or button begin
			say_title(gameforge.subquest_06._20_npcChat)
            say(gameforge.subquest_06._540_sayReward)
		end

		when letter begin
			send_letter(gameforge.subquest_06._10_targetVid)

		    local v=find_npc_by_vnum(9002)
			if 0==v then
			else
				target.vid("__TARGET__", v, gameforge.subquest_06._550_targetVid)
			end
		end


		when __TARGET__.target.click or	9002.chat.gameforge.subquest_06._560_npcChat begin
			target.delete("__TARGET__")
			say_title(gameforge.main_quest_lv3._160_sayTitle)
			say(gameforge.subquest_06._570_say)

			pc.give_exp2(26000)
			set_quest_state("levelup","run")
			pc.change_money(15000)

			pc.give_item2("30003", 1)

			say_title(gameforge.collect_herb_lv4._130_sayTitle)
						say_reward(gameforge.subquest_06._580_sayReward)
             clear_letter()
			set_state(__COMPLETE__)

			if pc.job == 0 then
				pc.give_item2("11223", 1)
				say_reward(gameforge.subquest_06._590_sayReward)
			elseif pc.job == 1 then
				pc.give_item2("11423", 1)
				say_reward(gameforge.subquest_06._600_sayReward)
			elseif pc.job == 2 then
				pc.give_item2("11623", 1)
				say_reward(gameforge.subquest_06._610_sayReward)
			elseif pc.job==3 then
				pc.give_item2("11823", 1)
				say_reward(gameforge.subquest_06._620_sayReward)
			end
			pc.setqf("ironore_done",0)
			pc.setqf("leather_done" ,0)
			pc.setqf("coal_done",0)
		end
	end

	state __GIVEUP__ begin
	end
	state __COMPLETE__ begin
	end
end
