quest new_quest_lv17 begin
    state start begin
	-- When level 17 target Wonda Rim for new Quest-------------------------------------------------------------
		when login or levelup with pc.get_level() >= 17 begin
			local v=find_npc_by_vnum(20087)
			if 0==v then
			else
				target.vid("__TARGET__", v, gameforge.new_quest_lv17._010_target)
			end
		end
		when 20087.chat.gameforge.new_quest_lv17._020_say_title begin
			target.delete("__TARGET__")
			say_title(gameforge.new_quest_lv17._012_say_title) -- yellow text headline
			say(gameforge.new_quest_lv17._021_say) -- white font text
			wait() -- next button 
			say_title(gameforge.new_quest_lv17._012_say_title);
           	say(gameforge.new_quest_lv17._030_say) -- yellow text headline
			say(gameforge.new_quest_lv17._031_say) -- white font text
			local doquest = select(gameforge.subquest_06._40_select, gameforge.subquest_12._50_select, gameforge.new_quest_lv75._290_2_select)
			if doquest == 1 then
				set_state(ask_uriel)
			elseif doquest == 3 then
				say(gameforge.subquest_06._60_say)
				local abortquest = select(gameforge.subquest_06._70_select, gameforge.subquest_06._80_select)
				if abortquest == 1 then
					set_state(__GIVEUP__)
				else
					say_title(gameforge.new_quest_lv17._012_say_title) -- yellow text headline
					say(gameforge.subquest_11._80_say)
					return
				end
			else
				say_title(gameforge.new_quest_lv17._012_say_title) -- yellow text headline
				say(gameforge.subquest_11._80_say)
				return
			end
		end
	end
	---- ask uriel what to do --------------------------------------------------------------------------------
	state ask_uriel begin
		--BEGIN EDIT by Arne 18Sept09 according to mantis0026065, Reason: letter, quest
		when enter or login begin
			send_letter(gameforge.new_quest_lv17._020_say_title)
			q.start()
			q.set_title(gameforge.new_quest_lv17._020_say_title)
			local v=find_npc_by_vnum(20011)
			if 0==v then
			else
				target.vid("__TARGET2__", v, gameforge.new_quest_lv17._040_target)
			end
		end
		
		when button or info begin
		say_title(gameforge.new_quest_lv17._040_say_title)
		say(gameforge.new_quest_lv17._041_say)
		say("")
		say(string.format(gameforge.new_quest_lv17._042_say, get_map_name_by_number(1)))
		end
		--END EDIT
		
		when 20011.chat.gameforge.new_quest_lv17._020_say_title begin
			target.delete("__TARGET2__")
			say_title(gameforge.new_quest_lv17._039_say_title) -- yellow text headline
			say(gameforge.new_quest_lv17._051_say)
			say_item_vnum(30173) -- icon of item by vnum
			say(gameforge.new_quest_lv17._052_say)
			local s = select(gameforge.new_quest_lv17._060_select)
			if s == 1 then
				clear_letter()
				q.done() -- EDIT added by Arne 18Sept09, see above for Reason
				set_state(back_to_wondarim)
			end
		end
	end
	--- tell wonda rim what to do---------------------------------------------------------------------------------------------------
	state back_to_wondarim begin

		--BEGIN EDIT by Arne 18Sept09 according to mantis0026065, Reason: letter, quest
		when enter or login begin
			send_letter(gameforge.new_quest_lv17._020_say_title)
			q.start()
			q.set_title(gameforge.new_quest_lv17._020_say_title)
			local v=find_npc_by_vnum(20087)
			if 0!=v then
				target.vid("__TARGET__", v, gameforge.new_quest_lv17._010_target)
			end
		end
		
		when button or info begin
		say_title(gameforge.new_quest_lv17._065_say_title)
		say(gameforge.new_quest_lv17._066_say)
		say("")
		say(string.format(gameforge.new_quest_lv17._067_say, get_map_name_by_number(1)))
		end
		--END EDIT
		
		when 20087.chat.gameforge.new_quest_lv17._020_say_title begin
			pc.setqf("collect_count",5) --Current number of items
			target.delete("__TARGET__")
			say_title(gameforge.new_quest_lv17._012_say_title)  -- yellow text headline
			say(gameforge.new_quest_lv17._070_say) -- red font text
			wait() -- next button 
			say(gameforge.new_quest_lv17._071_say) -- white font text
			say_item_vnum(30173) -- icon of item by vnum
			say(gameforge.new_quest_lv17._072_say) 
			say(gameforge.new_quest_lv17._073_say)
			q.done() -- EDIT added by Arne 18Sept09, see above for Reason
			set_state(findmurang)
		end
	end
	----- kill mu rang to gather wolfskin -------------------------------------------------------------------------------------------------
	state findmurang begin
	
		--BEGIN EDIT by Arne 18Sept09 according to mantis0026065, Reason: letter, quest
		when enter or login begin
			send_letter(gameforge.new_quest_lv17._020_say_title)
			q.start()
			q.set_title(gameforge.new_quest_lv17._020_say_title)
			-- ticket id: 0076498
			if pc.getqf("collect_count") == 0 then
				pc.setqf("collect_count", 5)
			end
		end
		--END EDIT 
		
		-- kill a mu rang wolf
		when 152.kill begin
			if pc.getqf("collect_count") >= 1 and math.random(1,5) < 4 then -- probability if s.th. drops
				local index =pc.getqf("collect_count") - 1
				pc.setqf("collect_count",index) --you got one, so you have one less to kill
				pc.give_item2(30173) -- spawn item by vnum in inventory
				notice_multiline(gameforge.new_quest_lv17._074_notice, notice)
				--BEGIN EDIT by Arne 18Sept09 according to mantis0026065, Reason: , new state for quest	
				if pc.getqf("collect_count") <= 0 then
					q.done()
					set_state(skins_to_wonda)
				end
				--END EDIT
			else
				return
			end
		end
		
		when button or info begin
			-------------- info if a wolfskin dropped
			-- hier fehlt questjournal eintrag und es wird keine info angezeigt wo man hin muss
			say_title(gameforge.new_quest_lv17._020_say_title) -- yellow text headline
			say(gameforge.new_quest_lv17._075_say)
			say_reward(string.format(gameforge.new_quest_lv17._076_say_reward, 5 - pc.getqf("collect_count")))
		end
	end
		-------------- try to give wonda rim the wolfskins		
		--BEGIN EDIT by Arne 18Sept09 according to mantis0026065, Reason: new state for quest	
	state skins_to_wonda begin
		when enter or login begin
			send_letter(gameforge.new_quest_lv17._020_say_title)
			q.start()
			q.set_title(gameforge.new_quest_lv17._020_say_title)
			local v=find_npc_by_vnum(20087)
			if 0==v then
			else
				target.vid("__TARGET__", v, gameforge.new_quest_lv17._010_target)
			end
		end
		
		when button or info begin
		say_title(gameforge.new_quest_lv17._081_say_title)
		say(gameforge.new_quest_lv17._082_say)
		say("")
		say(string.format(gameforge.new_quest_lv17._067_say, get_map_name_by_number(1)))
		end
		--END EDIT
	
		when 20087.chat.gameforge.new_quest_lv17._020_say_title begin  
		target.delete("__TARGET__")
			say_title(gameforge.new_quest_lv17._012_say_title)
			if pc.getqf("collect_count") > 0 then
				say_reward(string.format(gameforge.new_quest_lv17._092_say_reward, 5 - pc.getqf("collect_count")))
			else
				say(gameforge.new_quest_lv17._110_say)
				q.done() -- EDIT added by Arne 18Sept09, see above for Reason
				set_state(gotochaegirab)
			end
		end
	end
	------  talk with uncle chaegirab about the wolfskins and wonda rim ------------------------------------------------------------------------------------------------------
	state gotochaegirab begin
		
		--BEGIN EDIT by Arne 18Sept09 according to mantis0026065, Reason: letter, quest
		when enter or login begin
			send_letter(gameforge.new_quest_lv17._020_say_title)
			q.start()
			q.set_title(gameforge.new_quest_lv17._020_say_title)
			local v=find_npc_by_vnum(20084)
			if 0==v then
			else
				target.vid("__TARGET3__", v, gameforge.new_quest_lv17._120_target)
			end
		end
		
		when button or info begin
		say_title(gameforge.new_quest_lv17._020_say_title)
		say(gameforge.new_quest_lv17._121_say)
		say("")
		say(string.format(gameforge.new_quest_lv17._122_say, get_map_name_by_number(1)))
		end
		--END EDIT
	
		when 20084.chat.gameforge.new_quest_lv17._020_say_title begin  
			target.delete("__TARGET3__")
			say_title(gameforge.new_quest_lv17._020_say_title)
			say(gameforge.new_quest_lv17._130_say)
			say(gameforge.new_quest_lv17._131_say)
			say(gameforge.new_quest_lv17._132_say_reward)
			-- Questjournal eintrag fehlt
			q.done() -- EDIT added by Arne 18Sept09, see above for Reason
			set_state(back_to_wondarim_final)
		end
	end
	------  tell wonda rim what uncle chaegirab told ------------------------------------------------------------------------------------------------------
	state back_to_wondarim_final begin
	
		--BEGIN EDIT by Arne 18Sept09 according to mantis0026065, Reason: letter, quest
		when enter or login begin
		send_letter(gameforge.new_quest_lv17._020_say_title)
		q.start()
		q.set_title(gameforge.new_quest_lv17._020_say_title)
					local v=find_npc_by_vnum(20087)
			if 0==v then
			else
				target.vid("__TARGET__", v, gameforge.new_quest_lv17._010_target)
			end
		end
		
		when button or info begin
		say_title(gameforge.new_quest_lv17._020_say_title)
		say(gameforge.new_quest_lv17._140_say)
		say("")
		say(string.format(gameforge.new_quest_lv17._067_say, get_map_name_by_number(1)))		
		end
		--END EDIT
		
		when 20087.chat.gameforge.new_quest_lv17._020_say_title begin  
			target.delete("__TARGET__")
			say_title(gameforge.new_quest_lv17._020_say_title)
			say(gameforge.new_quest_lv17._141_say)
			local s = select(gameforge.new_quest_lv17._142_1_select, gameforge.new_quest_lv17._142_2_select)
			-- when player chooses option 1 (lying) -> 
			if s == 1 then
				say(gameforge.new_quest_lv17._143_say)
				say_reward(gameforge.new_quest_lv17._144_say_reward_a)
				pc.remove_item(30173, pc.count_item(30173))
				pc.give_item2(80008) -- gold
				pc.change_money(20000)
				pc.give_exp2(20000)
				q.done() -- EDIT added by Arne 18Sept09, see above for Reason
				set_state(__COMPLETE__)
				return
			end
			-- when player chooses option 2 (telling the truth) -> 
			if s == 2 then
                say_title(gameforge.new_quest_lv17._012_say_title)
				say(gameforge.new_quest_lv17._145_say)
				say(gameforge.new_quest_lv17._146_say_reward)
				q.done() -- EDIT added by Arne 18Sept09, see above for Reason
				set_state(goto_yangshin)
			end
		end
	end
	------  sell wolfskin to yangshin (optional) ------------------------------------------------------------------------------------------------------
	state goto_yangshin begin
		--BEGIN EDIT by Arne 18Sept09 according to mantis0026065, Reason: letter, quest
		when login or enter begin
				local empire = pc.get_empire()
				if is_destination_village(2)  then
				local v=find_npc_by_vnum(20019)
				if 0!=v then
					target.vid("__TARGET4__", v, gameforge.new_quest_lv17._160_target)
				end
			end
			if empire == 1 then -- = Shinsoo
				send_letter(gameforge.new_quest_lv17._020_say_title)
			end
			if empire == 2 then -- = Chunjo
				send_letter(gameforge.new_quest_lv17._020_say_title)
			end
			if empire == 3 then -- = Jinno
				send_letter(gameforge.new_quest_lv17._020_say_title)
			end
			q.start()
			q.set_title(gameforge.new_quest_lv17._020_say_title)		
		end
		
		when button or info begin
			say_title(gameforge.new_quest_lv17._020_say_title)
			local empire = pc.get_empire()
			if empire == 1 then -- = Shinsoo
				say(gameforge.new_quest_lv17._147_say)
			end
			if empire == 2 then -- = Chunjo
				say(gameforge.new_quest_lv17._148_say)
			end
			if empire == 3 then -- = Jinno
				say(gameforge.new_quest_lv17._149_say)
			end	
		end
		--END EDIT
		when 20019.chat.gameforge.new_quest_lv17._020_say_title begin  
			target.delete("__TARGET4__")
			say_title(gameforge.new_quest_lv17._161_say_title)
			say(gameforge.new_quest_lv17._151_say )
            say_title(gameforge.blacksmith._40_sayTitle)
			say_reward(gameforge.new_quest_lv17._152_say_reward)
			pc.remove_item(30173, pc.count_item(30173))
			pc.give_item_from_special_item_group(50300)
			pc.change_money(10000)
			pc.give_exp2(40000)
			q.done() -- EDIT added by Arne 18Sept09, see above for Reason
			set_state(__COMPLETE__)
			return
		end
	end
	------  give up ------------------------------------------------------------------------------------------------------
	state __GIVEUP__ begin
	end
	------  complete ------------------------------------------------------------------------------------------------------
	state __COMPLETE__ begin
	end
end


