----------------------------------------------------
--COLLECT QUEST_lv90
--METIN2 ?? ???  
----------------------------------------------------
quest collect_quest_lv90  begin
	state start begin
	end
	state run begin
		when login or levelup with pc.level >= 90  begin
			set_state(information)
		end	
	end

	state information begin
		when letter begin
			local v = find_npc_by_vnum(20084)
			if v != 0 then
			target.vid("__TARGET__",v,gameforge.collect_quest_lv90._010_target)
			end
			send_letter(gameforge.collect_quest_lv90._020_send_letter)
		end

		when button or info begin
			say_title(gameforge.collect_quest_lv90._030_say_title)
			say(gameforge.collect_quest_lv90._040_say)
			say("")
		end
		
		when __TARGET__.target.click or	20084.chat.gameforge.collect_quest_lv90._050_npcChat begin
			target.delete("__TARGET__")

			say_title(gameforge.collect_quest_lv90._055_say_title)
			say(gameforge.collect_quest_lv90._060_say)
			wait()
			say_title(gameforge.collect_quest_lv90._055_say_title)
			say(gameforge.collect_quest_lv90._064_say)
			say(gameforge.collect_quest_lv90._065_say)

			set_state(go_to_disciple)
			pc.setqf("duration",0)  
			pc.setqf("collect_count",0)
			pc.setqf("drink_drug",0) 
		end
	end

	state go_to_disciple begin
		when letter begin
			send_letter(gameforge.collect_quest_lv90._080_send_letter)
			
		end
		when button or info begin
			say_title (gameforge.collect_quest_lv90._090_say_title)
			say(gameforge.collect_quest_lv90._100_say)
			say("")
			say_item_vnum(30168) 
			say_reward(string.format(gameforge.collect_quest_lv90._105_say_reward, pc.getqf("collect_count")))
		end
		
		when 71035.use begin 
			if get_time() < pc.getqf("duration") then
				say (gameforge.collect_quest_lv90._110_say)
				return
			end
			if pc.getqf("drink_drug")==1 then
				say(gameforge.collect_quest_lv90._115_say)
				return
			end
			if pc.count_item(30168)==0 then
				say_title(gameforge.collect_quest_lv90._055_say_title)
				say(gameforge.collect_quest_lv90._120_say)
				say("")
				return
			end

			pc.remove_item(71035, 1)
			pc.setqf("drink_drug",1)
		end

		when 691.kill or 792.kill or 791.kill or 1093.kill or  1304.kill or 2091.kill or 2191.kill or 2206.kill or 1901.kill or
			 3090.kill or 3290.kill or 3590.kill or 6091.kill or 6191.kill  begin
			local s = number(1, 100)
			if s <= 30 and pc.count_item(30168)==0 then
				pc.give_item2(30168, 1)
				send_letter(gameforge.collect_quest_lv90._130_send_letter)
			end	
		end

		
    	when 20084.chat.gameforge.collect_quest_lv90._140_npcChat with pc.count_item(30168) >0   begin
			if get_time() > pc.getqf("duration") then
				if  pc.count_item(30168) >0 then
				say(mob_name(20084))
				
				say(gameforge.collect_quest_lv90._150_say)
				say("")
				pc.remove_item(30168, 1)
				if  is_test_server()  then 
					pc.setqf("duration",get_time()+2) 
				else
					pc.setqf("duration",get_time()+60*60*22) 
				end
				wait()
				
				local pass_percent
				if pc.getqf("drink_drug")==0 then
					pass_percent=60
				else		
					pass_percent=90
				end
				
				local s= number(1,100)
				if s<= pass_percent  then
				   if pc.getqf("collect_count")< 49 then 
						local index =pc.getqf("collect_count")+1 
						pc.setqf("collect_count",index)     
						say(mob_name(20084))
						say(gameforge.collect_quest_lv90._160_say)
						say(string.format(gameforge.collect_quest_lv90._165_say, 50-pc.getqf("collect_count")))
						say(gameforge.collect_quest_lv90._170_say)
						say("")
						pc.setqf("drink_drug",0)	 
						return
					end
					say(mob_name(20084))
					say(gameforge.collect_quest_lv90._175_say)
					say("")
					pc.setqf("collect_count",0)
					pc.setqf("drink_drug",0)	
					pc.setqf("duration",0) 
					set_state(key_item)
					return
					else
						say(mob_name(20084))
						say(gameforge.collect_quest_lv90._180_say)
						say("")				   
						pc.setqf("drink_drug",0)	 
						return
					 end
				else
					say(mob_name(20084))
					say(item_name(30168)..gameforge.collect_quest_lv90._185_say)
					return
				end
		  else
		 say(mob_name(20084) )
		  say(gameforge.collect_quest_lv90._190_say)
		  say("")
		  return
		end

		end
end


	state key_item begin
		when letter begin
			send_letter(gameforge.collect_quest_lv90._195_send_letter)
			
			if pc.count_item(30227)>0 then	
				local v = find_npc_by_vnum(20084)
				if v != 0 then
					target.vid("__TARGET__", v, "???")
				end
			end

		end
		when button or info begin
			if pc.count_item(30227) >0 then
				say_title(gameforge.collect_quest_lv90._200_say_title)
				
				say(gameforge.collect_quest_lv90._210_say)
				say("")
				return
			end

			say_title(gameforge.collect_quest_lv90._220_say_title)
			say(gameforge.collect_quest_lv90._230_say)
			say_item_vnum(30227)
			say(gameforge.collect_quest_lv90._240_say)
			say(mob_name(1304)..", "..mob_name(1093)..",")
			say(mob_name(1901)..".")
			say(""..mob_name(3090)..", "..mob_name(3290)..", "..mob_name(3590)..",")
			say(""..mob_name(6091)..", "..mob_name(6191)..".")
		end
		when 1093.kill or 1304.kill or 1901.kill or 3090.kill or 3290.kill or 3590.kill or 6091.kill or 6191.kill  begin
			local s = number(1, 100)
			if s <= 30 and pc.count_item(30227)==0 then
				pc.give_item2(30227, 1)
				send_letter(gameforge.collect_quest_lv90._250_send_letter)
			end	
		end



		
		when __TARGET__.target.click  or 20084.chat.gameforge.collect_quest_lv90._260_npcChat with pc.count_item(30227) > 0  begin
		    target.delete("__TARGET__")
			if pc.count_item(30227) > 0 then 
			say(mob_name(20084))
			say(gameforge.collect_quest_lv90._265_say)
			pc.remove_item(30227,1)
			set_state(__reward)
			else
				say(mob_name(20084))
				say(""..item_name(30227)..gameforge.collect_quest_lv90._266_say)
				say("")
				return
			end
		end
		
	end
	
	state __reward begin
		when letter begin
			send_letter(gameforge.collect_quest_lv90._270_send_letter)
			
			local v = find_npc_by_vnum(20018)
			if v != 0 then
						target.vid("__TARGET__",v,gameforge.collect_quest_lv90._280_target)
			end

		end
		when button or info begin
			say_title(gameforge.collect_quest_lv90._290_say_title)
			
			say(gameforge.collect_quest_lv90._300_say)
			say("")
		end
		
		when __TARGET__.target.click  or	20018.chat. gameforge.collect_quest_lv90._310_npcChat begin
		    target.delete("__TARGET__")
			say(mob_name(20018))
			say(gameforge.collect_quest_lv90._315_say)
			say("")
			wait()
			say(mob_name(20018))
			say(gameforge.collect_quest_lv90._316_say)
			say("")
			say_reward(gameforge.collect_quest_lv90._317_say_reward)
			say_reward(gameforge.collect_quest_lv90._318_say_reward)
			say_reward(gameforge.collect_quest_lv90._319_say_reward)
			affect.add_collect_point(POINT_ATTBONUS_WARRIOR,8,60*60*24*365*60)
			affect.add_collect_point(POINT_ATTBONUS_ASSASSIN,8,60*60*24*365*60)
			affect.add_collect_point(POINT_ATTBONUS_SURA,8,60*60*24*365*60)	
			affect.add_collect_point(POINT_ATTBONUS_SHAMAN,8,60*60*24*365*60)
			pc.give_item2(50114)
			clear_letter()
			set_quest_state("collect_quest_lv92", "run")
			set_state(__complete)
		end
			
	end

	
	state __complete begin
	end
end

