--2013.01.29 김용욱

--퀘스트 진행 npc
define YACKHWAN 20377 -- 약령도장 약환
define SCHOLAR 20380 -- 학자

-- 다시 시작되는 추적 정찰 좌표값 --
define RECON1_X 127
define RECON1_Y 928
define RECON1_MAPINDEX 62 -- 도염화지 맵

define ITEM3_1 31076 -- 태양초
define NPC3_1 20391 -- 태양초 주는 NPC

--다시 시작되는 추적--
quest main_quest_flame_lv99 begin
	state start begin
		when login or levelup or enter with pc.get_level() >= 99 begin
			if pc.getf("main_quest_lv98", "__status")==main_quest_lv98.__COMPLETE__ then
				set_state ( state0 )
			end
		end
	end
	state state0 begin
		when login or levelup or enter with pc.level >= 99 begin
			set_state (state1_1)
		end
	end

	-- 다시 시작되는 추적 : 임무받기
	state state1_1 begin 

		when letter begin 
			send_letter(gameforge.main_quest_flame_lv99._010_sendLetter) 
 			--npc 타겟 
			local v = find_npc_by_vnum(YACKHWAN) 
			if 0 != v then
				target.vid("__TARGET__", v, mob_name(YACKHWAN))
			end
		end

		when button or info begin 
			say_title(gameforge.main_quest_flame_lv99._010_sendLetter) 
			say(gameforge.main_quest_flame_lv99._020_say) 
			--npc 타겟 안내문
			--say_reward(locale.target_npc_info) 
		end

		when YACKHWAN.chat.gameforge.main_quest_flame_lv99._010_sendLetter begin 
			target.delete("__TARGET__") 
			say_title(mob_name(YACKHWAN)) 
			say(gameforge.main_quest_flame_lv99._030_say) 
			wait()--추가 대화 

			say_title(mob_name(YACKHWAN)) 
			say(gameforge.main_quest_flame_lv99._050_say) 
			wait()--추가 대화 

			say_title(mob_name(YACKHWAN)) 
			say(gameforge.main_quest_flame_lv99._060_say) 
			wait()--추가 대화 

			say_title(pc.getname()) 
			say(gameforge.main_quest_flame_lv99._070_say) 
			wait()--추가 대화 
			
			say_title(mob_name(YACKHWAN)) 
			say(gameforge.main_quest_flame_lv99._080_say) 
			--다음 스테이트로
			set_state (state1_2)
		end

		when leave begin 
			--q.done()
		end
	end
	state state1_2 begin 	-- 다시 시작되는 추적 : 정찰하기
		when enter begin 
			-- notice 설정
			notice_multiline(string.format(gameforge.main_quest_flame_lv99._090_notice, RECON1_X, RECON1_Y),notice)
		end

		when letter begin 
			target.pos ("__TARGET__",RECON1_X,RECON1_Y,RECON1_MAPINDEX,"")
			send_letter (gameforge.main_quest_flame_lv99._010_sendLetter)
		end

		when button or info begin 
			say_title(gameforge.main_quest_flame_lv99._100_sayTitle) 
			say(gameforge.main_quest_flame_lv99._110_say) 
			--npc 타겟 안내문
			--say_reward(locale.target_info) 
		end

		when YACKHWAN.chat.gameforge.main_quest_flame_lv99._010_sendLetter begin 
			say_title(mob_name(YACKHWAN)) 
			say(gameforge.main_quest_flame_lv99._120_say) 
		end
		
		-- 도착 --
		when __TARGET__.target.arrive begin
			target.delete("__TARGET__")
			set_state (state1_3)
		end

		when leave begin 
			--q.done()
		end
	end
	state state1_3 begin 	-- 다시 시작되는 추적 : 완료 & 보상받기
		when enter begin 
			-- notice 설정
			notice_multiline(gameforge.main_quest_flame_lv99._130_notice,notice)
		end

		when letter begin 
			send_letter(gameforge.main_quest_flame_lv99._010_sendLetter) 
 			--npc 타겟 
			local v = find_npc_by_vnum(YACKHWAN) 
			if 0 != v then
				target.vid("__TARGET__", v, mob_name(YACKHWAN))
			end
		end

		when button or info begin 
			say_title(gameforge.main_quest_flame_lv99._010_sendLetter) 
			say(gameforge.main_quest_flame_lv99._140_say) 
			--npc 타겟 안내문
			--say_reward(locale.target_npc_info) 
		end

		when YACKHWAN.chat.gameforge.main_quest_flame_lv99._010_sendLetter begin 
			target.delete("__TARGET__") 
			say_title(mob_name(YACKHWAN)) 
			say(gameforge.main_quest_flame_lv99._150_say) 
			wait()--추가 대화 

			say_title(pc.getname()) 
			say(gameforge.main_quest_flame_lv99._160_say) 
			wait()--추가 대화 

			say_title(mob_name(YACKHWAN)) 
			say(gameforge.main_quest_flame_lv99._170_say) 
			--보상
			wait()--reward

			say_reward(string.format (gameforge.main_quest_lv60._190_sayReward, 33003000))
			pc.give_exp2( 33003000)
			say_reward(string.format (gameforge.main_quest_lv60._200_sayReward, 145000))
			pc.change_money( 145000)
			say_reward(string.format(gameforge.main_quest_lv60._210_sayReward, item_name(50705),10))
			pc.give_item2(50705, 10)
			say()

			--다음 스테이트로
			set_state (state2_1)
		end

		when leave begin 
			--q.done()
		end
	end

	-- 조사1-1 : 임무받기
	state state2_1 begin 
		when letter begin 
			send_letter(gameforge.main_quest_flame_lv99._180_sendLetter) 
 			--npc 타겟 
			local v = find_npc_by_vnum(YACKHWAN) 
			if 0 != v then
				target.vid("__TARGET__", v, mob_name(YACKHWAN))
			end
		end

		when button or info begin 
			say_title(gameforge.main_quest_flame_lv99._180_sendLetter) 
			say(gameforge.main_quest_flame_lv99._020_say) 
			--npc 타겟 안내문
			--say_reward(locale.target_npc_info) 
		end

		when YACKHWAN.chat.gameforge.main_quest_flame_lv99._180_sendLetter begin 
			target.delete("__TARGET__") 
			say_title(mob_name(YACKHWAN)) 
			say(gameforge.main_quest_flame_lv99._190_say) 
			wait()--추가 대화 

			say_title(pc.getname()) 
			say(gameforge.main_quest_flame_lv99._070_say) 
			--다음 스테이트로
			set_state (state2_2)
		end

		when leave begin 
			--q.done()
		end
	end
	state state2_2 begin 	-- 조사1-1 : 학자에게 찾아가는 내용..
		when letter begin 
			send_letter(gameforge.main_quest_flame_lv99._180_sendLetter) 
 			--npc 타겟 
			local v = find_npc_by_vnum(SCHOLAR) 
			if 0 != v then
				target.vid("__TARGET__", v, mob_name(SCHOLAR))
			end
		end

		when button or info begin 
			say_title(gameforge.main_quest_flame_lv99._180_sendLetter) 
			say(gameforge.main_quest_flame_lv99._200_say) 
			--npc 타겟 안내문
			--say_reward(locale.target_npc_info) 
		end

		when SCHOLAR.chat.gameforge.main_quest_flame_lv99._180_sendLetter begin 
			target.delete("__TARGET__") 
			say_title(mob_name(SCHOLAR)) 
			say(gameforge.main_quest_flame_lv99._210_say) 
			wait()--추가 대화 

			say_title(mob_name(SCHOLAR)) 
			say(gameforge.main_quest_flame_lv99._240_say) 
			--다음 스테이트로
			set_state (state2_3)
		end

		when leave begin 
			--q.done()
		end
	end
	state state2_3 begin 	-- 조사1-1 : 몬스터 잡기
		when enter begin 
			notice_multiline(gameforge.main_quest_flame_lv99._250_notice,notice)
		end

		when letter begin 
			send_letter(gameforge.main_quest_flame_lv99._180_sendLetter) 
		end

		when button or info begin 
			say_title(gameforge.main_quest_flame_lv99._260_sayTitle) 
			say(gameforge.main_quest_flame_lv99._270_say) 
		end

		when SCHOLAR.chat.gameforge.main_quest_flame_lv99._180_sendLetter begin 
			say_title(mob_name(SCHOLAR)) 
			say(gameforge.main_quest_flame_lv99._280_say) 
		end

		when 2202.kill begin
			if number(1,100) == 1 then
				set_state (state2_4)
			end
		end

		when 2203.kill begin
			if number(1,100) == 1 then
				set_state (state2_4)
			end
		end

		when 2204.kill begin
			if number(1,100) == 1 then
				set_state (state2_4)
			end
		end

		when 2205.kill begin
			if number(1,100) == 1 then
				set_state (state2_4)
			end
		end
		
		
		-- 이 아래는 보험용으로 같은 이름의 vnum이 다른 몬스터를 잡았을때도 퀘스트가 클리어 되도록 하였다.
		when 7020.kill begin
			if number(1,100) == 1 then
				set_state (state2_4)
			end
		end

		when 7021.kill begin
			if number(1,100) == 1 then
				set_state (state2_4)
			end
		end

		when 7022.kill begin
			if number(1,100) == 1 then
				set_state (state2_4)
			end
		end

		when 7023.kill begin
			if number(1,100) == 1 then
				set_state (state2_4)
			end
		end

		when leave begin 
			--q.done()
		end
	end
	-- 조사1-1 : 학자에게 돌아가기.
	state state2_4 begin 
		when enter begin 
			-- notice 설정
			notice_multiline(gameforge.main_quest_flame_lv99._290_notice,notice)
		end

		when letter begin 
			send_letter(gameforge.main_quest_flame_lv99._180_sendLetter) 
 			--npc 타겟 
			local v = find_npc_by_vnum(SCHOLAR) 
			if 0 != v then
				target.vid("__TARGET__", v, mob_name(SCHOLAR))
			end
		end

		when button or info begin 
			say_title(gameforge.main_quest_flame_lv99._180_sendLetter) 
			say(gameforge.main_quest_flame_lv99._200_say) 
			--npc 타겟 안내문
			--say_reward(locale.target_npc_info) 
		end

		when SCHOLAR.chat.gameforge.main_quest_flame_lv99._180_sendLetter begin 
			target.delete("__TARGET__") 
			say_title(mob_name(SCHOLAR)) 
			say(gameforge.main_quest_flame_lv99._300_say) 
			--보상
			wait()--reward

			say_reward(string.format (gameforge.main_quest_lv60._190_sayReward, 37003000))
			pc.give_exp2(37003000)
			say_reward(string.format (gameforge.main_quest_lv60._200_sayReward, 146000))
			pc.change_money(146000)
			say_reward(string.format(gameforge.main_quest_lv60._210_sayReward, item_name(72001),1))
			pc.give_item2_select(72001)
			item.set_socket(2, 60)
			say_reward(string.format(gameforge.main_quest_lv60._210_sayReward, item_name(30046),1))
			pc.give_item2(30046, 1)
			say()

			--다음 스테이트로
			set_state (state3_1)
		end

		when leave begin 
			--q.done()
		end
	end
	
	-- 조사1-2 : 임무받기
	state state3_1 begin 

		when letter begin 
			send_letter(gameforge.main_quest_flame_lv99._310_sendLetter) 
 			--npc 타겟 
			local v = find_npc_by_vnum(SCHOLAR) 
			if 0 != v then
				target.vid("__TARGET__", v, mob_name(SCHOLAR))
			end
		end

		when button or info begin 
			say_title(gameforge.main_quest_flame_lv99._310_sendLetter) 
			say(gameforge.main_quest_flame_lv99._320_say) 
			--npc 타겟 안내문
			--say_reward(locale.target_npc_info) 
		end

		when SCHOLAR.chat.gameforge.main_quest_flame_lv99._310_sendLetter begin 
			target.delete("__TARGET__") 
			say_title(mob_name(SCHOLAR)) 
			say(gameforge.main_quest_flame_lv99._330_say) 
			wait()--추가 대화 

			say_title(pc.getname()) 
			say(gameforge.main_quest_flame_lv99._340_say) 
			wait()--추가 대화 

			say_title(mob_name(SCHOLAR)) 
			say(gameforge.main_quest_flame_lv99._350_say) 
			wait()--추가 대화 

			say_title(pc.getname()) 
			say(gameforge.main_quest_flame_lv99._360_say) 
			--다음 스테이트로
			set_state (state3_2)
		end

		when leave begin 
			--q.done()
		end
	end
	state state3_2 begin 	-- 조사1-2
		when enter begin 
			notice_multiline(gameforge.main_quest_flame_lv99._370_notice,notice)
		end

		when letter begin 
			send_letter(gameforge.main_quest_flame_lv99._310_sendLetter) 
			q.set_counter_name(gameforge.main_quest_lv97._670_counterName)
 			--npc 타겟 
			local v = find_npc_by_vnum(NPC3_1) 
			if 0 != v then
				target.vid("__TARGET__", v, mob_name(NPC3_1))
			end
 		end

		when button or info begin 
			say_title(gameforge.main_quest_flame_lv99._380_sayTitle) 
			say(gameforge.main_quest_flame_lv99._390_say) 
			say(gameforge.main_quest_lv97._670_counterName)
			say(string.format(gameforge.main_quest_lv90._1190_say,item_name(ITEM3_1), 1 - pc.count_item(ITEM3_1)))
			--say_reward(locale.target_info)
		end

		when SCHOLAR.chat.gameforge.main_quest_flame_lv99._310_sendLetter begin 
			say_title(mob_name(SCHOLAR)) 
			say(gameforge.main_quest_flame_lv99._400_say) 
		end
		
		-- 태양초 NPC를 클릭하여 태양초 아이템을 얻는 부분.
		when NPC3_1.click begin
			target.delete("__TARGET__") 
			pc.give_item2(ITEM3_1, 1)
			set_state (state3_3)
		end

		when leave begin 
			--q.done()
		end
	end
	state state3_3 begin 	-- 조사1-2
		when enter begin 
			-- notice 설정
			notice_multiline(gameforge.main_quest_flame_lv99._410_notice,notice)
		end

		when letter begin 
			send_letter(gameforge.main_quest_flame_lv99._310_sendLetter) 
 			--npc 타겟 
			local v = find_npc_by_vnum(SCHOLAR) 
			if 0 != v then
				target.vid("__TARGET__", v, mob_name(SCHOLAR))
			end
		end

		when button or info begin 
			say_title(gameforge.main_quest_flame_lv99._310_sendLetter) 
			say(gameforge.main_quest_flame_lv99._200_say) 
			--npc 타겟 안내문
			--say_reward(locale.target_npc_info) 
		end
		
		when SCHOLAR.chat.gameforge.main_quest_flame_lv99._310_sendLetter begin 
			target.delete("__TARGET__") 
			if pc.count_item(ITEM3_1) >= 1 then
				pc.remove_item ( ITEM3_1, pc.count_item(ITEM3_1))	
				say_title(mob_name(SCHOLAR)) 
				say(gameforge.main_quest_flame_lv99._420_say) 
				--보상
				wait()--reward
                say_title(gameforge.main_quest_lv27._120_sayTitle)
				say_reward(string.format (gameforge.main_quest_lv60._190_sayReward, 35003000))
				pc.give_exp2(35003000)
				say_reward(string.format (gameforge.main_quest_lv60._200_sayReward, 147000))
				pc.change_money(147000)
				say_reward(string.format(gameforge.main_quest_lv60._210_sayReward, item_name(30021),1))
				pc.give_item2(30021, 1)
				say()
				say_title(string.format(gameforge.main_quest_flame_lv99._430_say, 100))

				--다음 스테이트로
				set_state (__COMPLETE__)
				set_quest_state ("main_quest_flame_lv100", "state0")
			else
				say_title(mob_name(SCHOLAR)) 
				say(gameforge.main_quest_flame_lv99._400_say) 
				
				set_state (state3_2)
			end
		end

		when leave begin 
			--q.done()
		end
	end
	
	state __COMPLETE__ begin
		when enter begin
			--q.done()
		end
	end

end
