----------------------------------------------------
--COLLECT QUEST_lv94
--METIN2 수집 퀘스트  
----------------------------------------------------
quest collect_quest_lv94  begin
	state start begin
	end

	state run begin
		when login or levelup with pc.level >= 94 begin
			set_state(information)
		end	
	end

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

		when button or info begin
			say_title(gameforge.collect_quest_lv94._020_send_letter)
			say(gameforge.collect_quest_lv94._030_say)
			say("")
		end
		
		when __TARGET__.target.click or	20091.chat.gameforge.collect_quest_lv94._040_npcChat begin
			target.delete("__TARGET__")
			---                                                   l
			say_title(gameforge.collect_quest_lv94._050_say_title)
			say(gameforge.collect_quest_lv94._060_say)
			say("")
			wait()
			say_title(gameforge.collect_quest_lv94._050_say_title)
			say(gameforge.collect_quest_lv94._070_say)
			say("")
			set_state(go_to_disciple)
			pc.setqf("duration", 0)  -- 시도 할수 있는 시간
			pc.setqf("collect_count", 0)--이제껏 모은 아이템 수
			pc.setqf("drink_drug", 0) --현혹의 물약을 먹으면 1
		end
	end

	state go_to_disciple begin
		when letter begin
			send_letter(gameforge.collect_quest_lv94._080_say_title)
		end

		when button or info begin
			say_title(gameforge.collect_quest_lv94._080_say_title)
			---                                                   l
			say(gameforge.collect_quest_lv94._090_say)
			say_item_vnum(30252) 
			say_reward(string.format(gameforge.collect_quest_lv94._100_sayReward, pc.getqf("collect_count")))
			say("")
		end
		
		when 71035.use begin --현혹의 물약
			if get_time() < pc.getqf("duration") then
				say(gameforge.collect_quest_lv94._110_say)
				return
			end

			if pc.getqf("drink_drug") == 1 then
				say(gameforge.collect_quest_lv94._120_say)
				return
			end

			if pc.count_item(30252) == 0 then
				---                                                   l
				say(gameforge.collect_quest_lv94._130_say)
				say("")
				return
			end

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

		when 2414.kill or 2412.kill begin
			local s = number(1, 400)
			if s <= 1 then
				pc.give_item2(30252, 1)
				send_letter(gameforge.collect_quest_lv94._140_send_letter)
			end	
		end
		
    	when 20091.chat.gameforge.collect_quest_lv94._150_npcChat with pc.count_item(30252) > 0 begin
			if get_time() < pc.getqf("duration") then
				say_title(gameforge.collect_quest_lv94._050_say_title)
				say(gameforge.collect_quest_lv94._160_say)
				return
			end

			if pc.count_item(30252) <= 0 then
				say_title(gameforge.collect_quest_lv94._050_say_title)
				say(gameforge.collect_quest_lv94._170_say)
				return
			end

			say_title(gameforge.collect_quest_lv94._050_say_title)
			say(gameforge.collect_quest_lv94._180_say)
			pc.remove_item(30252, 1)

			if is_test_server() then 
				pc.setqf("duration", get_time() + 2) 
			else
				pc.setqf("duration", get_time()+60*60*24) -----------------------------------24 stunden nun
			end

			wait()
		
			local pass_percent

			if pc.getqf("drink_drug") == 0 then
				pass_percent = 10
			else		
				pass_percent = 60
			end
		
			local s = number(1, 100)
			if s <= pass_percent then
				if pc.getqf("collect_count") < 19 then     --10개미만 
					local index = pc.getqf("collect_count") + 1
					pc.setqf("collect_count", index) --하나 구했으니 +1 해준다
					say_title(gameforge.collect_quest_lv94._050_say_title)
					say(gameforge.collect_quest_lv94._190_say)
					say(string.format(gameforge.collect_quest_lv94._200_say, 20-pc.getqf("collect_count")))
					say(gameforge.collect_quest_lv94._210_say)
					pc.setqf("drink_drug", 0)	 --물약 초기화
					return
				end
				say_title(gameforge.collect_quest_lv94._050_say_title)
				say(gameforge.collect_quest_lv94._250_say)
				pc.setqf("collect_count",0)
				set_state(key_item)
			else
				pc.setqf("drink_drug", 0)	 --물약 초기화
				say_title(gameforge.collect_quest_lv94._050_say_title)
				say(gameforge.collect_quest_lv94._240_say)
				return
			end
		end -- end of when
	end -- end of state

	state key_item begin
		
		when letter begin
			send_letter(gameforge.collect_quest_lv94._260_send_letter)
			
			if pc.count_item(30228)>0 then	
				local v = find_npc_by_vnum(20091)
				if v != 0 then
					target.vid("__TARGET__", v, "")
				end
			end
		end

		when button or info begin
			if pc.count_item(30228) >0 then
				say_title(gameforge.collect_quest_lv94._270_say_title)
				say(gameforge.collect_quest_lv94._280_say)
				return
			end
			say_title(gameforge.collect_quest_lv94._290_say_title)
			say(gameforge.collect_quest_lv94._300_say)
			say_item_vnum(30228)
			say(gameforge.collect_quest_lv94._310_say)
		end
		
	
		when  2493.kill begin
			if pc.count_item(30228)==0 then
				pc.give_item2(30228, 1)
				send_letter(gameforge.collect_quest_lv94._320_send_letter)		
			end	
		end
		
		when 2495.kill begin
			local s = number(1, 20)
				if s == 1  then
					if pc.count_item(30228)==0 then
						pc.give_item2(30228, 1)
						send_letter(gameforge.collect_quest_lv94._320_send_letter)
					end
				end	
		end
	
		when __TARGET__.target.click  or 20091.chat.gameforge.collect_quest_lv94._330_npcChat with pc.count_item(30228) > 0  begin
		    target.delete("__TARGET__")
			if pc.count_item(30228) > 0 then 
				say_title(gameforge.collect_quest_lv94._050_say_title)
				say(gameforge.collect_quest_lv94._340_say)
				
				local s = select(gameforge.collect_quest_lv94._230_1_select, gameforge.collect_quest_lv94._230_2_select, gameforge.collect_quest_lv94._230_3_select)
				if 1 == s then
					affect.add_collect(1, 1100, 60*60*24*365*60) -- hp apply index == 1
					pc.setqf("reward", 1)
				elseif 2 == s then
					affect.add_collect(apply.DEF_GRADE_BONUS, 140, 60*60*24*365*60) 
					pc.setqf("reward", 2)
				elseif 3 == s then 
					affect.add_collect(apply.ATT_GRADE_BONUS, 60, 60*60*24*365*60) 
					pc.setqf("reward", 3)
				end
			    pc.remove_item(30228, 1)
				pc.setqf("collect_count", 0)
				pc.setqf("drink_drug", 0)
				pc.setqf("duration", 0) 
				clear_letter()
				set_quest_state("collect_quest_lv96", "run")
				set_state(__complete)
				return
			else
				say_title(gameforge.collect_quest_lv94._050_say_title)
				say(gameforge.collect_quest_lv94._350_say)
				return
			end
		end -- end of when
	end -- end of state

	state __complete begin
	end
end
