--2012.08 김용욱
--명시진 재건
--퀘스트 진행 npc
define GUARD 20378 -- 경비대장 악무르
define ICHUNG 20369 -- 이충
define TELEPORT 9012 -- 공간이동술사
define YACKHWAN 20377 -- 약령도장 약환
define SCHOLAR 20380 -- 학자
define OCKGU 20008 -- 옥구
define ALCHEMIST 20001 -- 연금술사
define UNDERLING 20379 -- 악무르의 부하

-- 명시진 재건1-1 --
define ITEM1_1 31026 --갑각종의 껍질
define ITEM1_1_NEEDED 100 -- 필요한 갯수
define ITEM1_1_PCT_GET 50 -- 획득 확률 (1/n)
define MOB1_1 3601
define MOB1_2 3602
define MOB1_3 3603
define MOB1_4 3604
define MOB1_5 3605
define MOB1_6 3690
define MOB1_7 3691
define MAP_INDEX1 1 -- 몬스터가 나오는 맵 번호
define MAP_POS1_1_X 500 -- 맵에 반짝이도록 보이는 좌표.
define MAP_POS1_1_Y 500
define MAP_POS1_2_X 600
define MAP_POS1_2_Y 500
define MAP_POS1_3_X 700
define MAP_POS1_3_Y 300
define REWARD1_EXP 40898550 -- 보상 : 경험치
define REWARD1_GOLD 346000 -- 보상 : 골드
define REWARD1_ITEM1 72308 -- 보상 : 만년한철
define REWARD1_ITEM1_COUNT 1 -- 보상 갯수
define REWARD1_ITEM2 76011 -- 보상 : 육도
define REWARD1_ITEM2_COUNT 1 -- 보상 갯수

-- 명시진 재건1-2 --
define ITEM2_1 31042 --날카로운 작살
define ITEM2_1_NEEDED 100 -- 필요한 갯수
define ITEM2_1_PCT_GET 50 -- 획득 확률 (1/n)
define MOB2_1 3401
define MOB2_2 3402
define MOB2_3 3403
define MOB2_4 3404
define MOB2_5 3405
define MOB2_6 3490
define MOB2_7 3491
define MAP_INDEX2 1 -- 몬스터가 나오는 맵 번호
define MAP_POS2_1_X 500 -- 맵에 반짝이도록 보이는 좌표.
define MAP_POS2_1_Y 500
define MAP_POS2_2_X 600
define MAP_POS2_2_Y 500
define MAP_POS2_3_X 700
define MAP_POS2_3_Y 300
define REWARD2_EXP 42646751 -- 보상 : 경험치
define REWARD2_GOLD 357000 -- 보상 : 골드
define REWARD2_ITEM1 71026 -- 보상 : 현철
define REWARD2_ITEM1_COUNT 1 -- 보상 갯수
define REWARD2_ITEM2 71025 -- 보상 : 야공석
define REWARD2_ITEM2_COUNT 2 -- 보상 갯수
define REWARD2_ITEM3 70102 -- 보상 : 선두
define REWARD2_ITEM3_COUNT 5 -- 보상 갯수

-- 생활 안정 --
define MOB3_1 3805
define MOB3_1_COUNT 50
define MOB3_2 3890
define MOB3_2_COUNT 1
define MAP_INDEX3 1 -- 몬스터가 나오는 맵 번호
define MAP_POS3_1_X 500 -- 맵에 반짝이도록 보이는 좌표.
define MAP_POS3_1_Y 500
define MAP_POS3_2_X 600
define MAP_POS3_2_Y 500
define MAP_POS3_3_X 700
define MAP_POS3_3_Y 300
define REWARD3_EXP 48584941 -- 보상 : 경험치
define REWARD3_GOLD 0 -- 보상 : 골드
define REWARD3_ITEM1 30021 -- 보상 : 깨진 보석조각
define REWARD3_ITEM1_COUNT 1 -- 보상 갯수

-- 마지막 인사 --
define NPC4_1 20381 -- 촌장
define NPC4_2 9002 -- 방어구 상인
define NPC4_3 9003 -- 잡화 상인
define NPC4_4 9001 -- 무기 상인
define REWARD4_EXP 32033398 -- 보상 : 경험치
define REWARD4_GOLD 379000 -- 보상 : 골드
define REWARD4_ITEM1 30015 -- 보상 : 사귀의 유품
define REWARD4_ITEM1_COUNT 2 -- 보상 갯수
define REWARD4_ITEM2 70043 -- 보상 : 도둑의 장갑
define REWARD4_ITEM2_COUNT 1 -- 보상 갯수

--다시 대륙으로 --
define REWARD5_EXP 38739560 -- 보상 : 경험치
define REWARD5_GOLD 390000 -- 보상 : 골드
define REWARD5_ITEM1 30006 -- 보상 : 웅귀의 어금니
define REWARD5_ITEM1_COUNT 1 -- 보상 갯수

quest main_quest_lv98 begin
	state start begin
	end
	state state0 begin
		when login or levelup or enter with pc.level >= 98 begin
			set_state (state1_1)
		end
	end
	----------------------------------명시진 재건 1-1----------------------------------
	state state1_1 begin
	
		when letter begin
			send_letter(gameforge.main_quest_lv98._010_sendLetter)
			
			local v = find_npc_by_vnum(GUARD)
			if 0 != v then
				target.vid("__TARGET__", v, mob_name(GUARD))
			end
		end
		
		when button or info begin
			say_title(gameforge.main_quest_lv98._010_sendLetter)
			say(gameforge.main_quest_lv98._020_say)
			say("")
			say_reward(gameforge.main_quest_lv98._570_sayReward)
			say("")
		end
		
		when GUARD.chat.gameforge.main_quest_lv98._010_sendLetter begin
			target.delete("__TARGET__")
			
			say_title(mob_name(GUARD))
			say(gameforge.main_quest_lv98._030_say)
			say("")
			wait()
			
			say_title(mob_name(GUARD))
			say(gameforge.main_quest_lv98._040_say)
			say("")
			wait()
			
			say_title(pc.getname())
			say(gameforge.main_quest_lv98._050_say)
			say("")
			wait()
			
			say_title(mob_name(GUARD))
			say(gameforge.main_quest_lv98._060_say)
			say("")
			
			set_state (state1_2)
		end
	end
	--껍질 모으기 퀘스트 수행--
	state state1_2 begin
		when letter begin
			send_letter(gameforge.main_quest_lv98._010_sendLetter)
			q.set_counter_name(gameforge.main_quest_lv98._660_counterName)
		end
		when button or info begin
			-- if pc.get_map_index() == MAP_INDEX1 then
				-- addmapsignal(MAP_POS1_1_X * 100, MAP_POS1_1_Y * 100)
				-- addmapsignal(MAP_POS1_2_X * 100, MAP_POS1_2_Y * 100)
				-- addmapsignal(MAP_POS1_3_X * 100, MAP_POS1_3_Y * 100)
			-- end
			say_title(gameforge.main_quest_lv98._540_sayTitle)
			say(gameforge.main_quest_lv98._550_say)
			say("")
			say_item_vnum(ITEM1_1)
			say_title(gameforge.main_quest_lv98._660_counterName)
			local remain = ITEM1_1_NEEDED - pc.count_item(ITEM1_1)
			if remain < 0 then
				remain = 0
			end
			q.set_counter_value(remain)
			say_reward(string.format(gameforge.main_quest_lv98._670_sayReward,item_name(ITEM1_1),remain))
			-- say()
			-- say_reward(locale.main_quest_lv98.pos_info)
			-- select(gameforge.main_quest_lv90._950_say)
			-- setskin(NOWINDOW)
			-- clearmapsignal()
		end
		
		--클리어 전에 돌아왔다.--
		when GUARD.chat.gameforge.main_quest_lv98._010_sendLetter begin
			say_title(mob_name(GUARD))
			say(gameforge.main_quest_lv98._070_say)
			say("")
		end
		
		when MOB1_1.kill or MOB1_2.kill or MOB1_3.kill or MOB1_4.kill or MOB1_5.kill or MOB1_6.kill or MOB1_7.kill begin
			if	number (1,ITEM1_1_PCT_GET) == 1 then	
				if pc.count_item(ITEM1_1) < ITEM1_1_NEEDED then				
					pc.give_item2 ( ITEM1_1, 1 )
					
					local remain = ITEM1_1_NEEDED - pc.count_item(ITEM1_1)
					if remain < 0 then
						remain = 0
					end
					q.set_counter_value(remain)
					
					if pc.count_item(ITEM1_1) >= ITEM1_1_NEEDED then
						notice_multiline(gameforge.main_quest_lv98._080_1_notice, notice)
						notice_multiline(gameforge.main_quest_lv98._080_2_notice,notice)
						
						set_state (state1_3)
					end
				end
			end
		end
	end
	state state1_3 begin
		when letter begin
			send_letter(gameforge.main_quest_lv98._010_sendLetter)
			
			local v = find_npc_by_vnum(GUARD)
			if 0 != v then
				target.vid("__TARGET__", v, mob_name(GUARD))
			end
			q.set_counter_name("")
		end
		when button or info begin
			say_title(gameforge.main_quest_lv98._010_sendLetter)
			say(gameforge.main_quest_lv98._560_say)
			say("")
			say_reward(gameforge.main_quest_lv98._570_sayReward)
			say("")
		end
		
		-- 중간에 퀘스트 아이템을 버릴 경우를 대비한 부분.
		when MOB1_1.kill or MOB1_2.kill or MOB1_3.kill or MOB1_4.kill or MOB1_5.kill or MOB1_6.kill or MOB1_7.kill begin
			if	number (1,ITEM1_1_PCT_GET) == 1 then	
				if pc.count_item(ITEM1_1) < ITEM1_1_NEEDED then
					pc.give_item2 ( ITEM1_1, 1 )
					
					if pc.count_item(ITEM1_1) >= ITEM1_1_NEEDED then
						notice_multiline(gameforge.main_quest_lv98._080_1_notice,notice)
						notice_multiline(gameforge.main_quest_lv98._080_2_notice,notice)
					end
				end
			end
		end
		
		when GUARD.chat.gameforge.main_quest_lv98._010_sendLetter begin
			target.delete("__TARGET__")
			
			if pc.count_item(ITEM1_1) >= ITEM1_1_NEEDED then
				pc.remove_item ( ITEM1_1, pc.count_item(ITEM1_1))	
				
				say_title(mob_name(GUARD))
				say(gameforge.main_quest_lv98._090_say)
				say("")
				wait()
				
				--보상
				say_title(locale.reward)
				
				say_reward(string.format (gameforge.main_quest_lv60._190_sayReward, REWARD1_EXP))
				say_reward(string.format (gameforge.main_quest_lv60._200_sayReward, REWARD1_GOLD))
				say_reward(string.format (gameforge.main_quest_lv60._210_sayReward, item_name(REWARD1_ITEM1),REWARD1_ITEM1_COUNT,locale.count_postfix))
				say_reward(string.format (gameforge.main_quest_lv60._210_sayReward, item_name(REWARD1_ITEM2),REWARD1_ITEM2_COUNT,locale.count_postfix))
				say("")
				
				pc.give_exp2(REWARD1_EXP)
				pc.change_money(REWARD1_GOLD)
				pc.give_item2(REWARD1_ITEM1, REWARD1_ITEM1_COUNT)
				pc.give_item2_select(REWARD1_ITEM2)
				item.set_socket(2, 120)
				
				set_state (state2_1)
			else --중간에 아이템을 빼놓고 왔다.
				say_title(mob_name(GUARD))
				say(gameforge.main_quest_lv98._070_say)
				say("")
				
				set_state (state1_2)
			end
		end
	end
	
	---------------------------------- 명시진 재건 1-2 ----------------------------------
	state state2_1 begin
		when letter begin
			send_letter(gameforge.main_quest_lv98._130_sendLetter)
			
			local v = find_npc_by_vnum(GUARD)
			if 0 != v then
				target.vid("__TARGET__", v, mob_name(GUARD))
			end
		end
		when button or info begin
			say_title(gameforge.main_quest_lv98._130_sendLetter)
			say(gameforge.main_quest_lv98._140_say)
			say("")
			say_reward(gameforge.main_quest_lv98._570_sayReward)
			say("")
		end
		
		when GUARD.chat.gameforge.main_quest_lv98._130_sendLetter begin
			target.delete("__TARGET__")
			
			say_title(mob_name(GUARD))
			say(gameforge.main_quest_lv98._150_say)
			say("")
			wait()
			
			say_title(pc.getname())
			say(gameforge.main_quest_lv98._160_say)
			say("")
			
			set_state (state2_2)
		end
	end
	state state2_2 begin
		when letter begin
			send_letter(gameforge.main_quest_lv98._130_sendLetter)
			q.set_counter_name(gameforge.main_quest_lv98._660_counterName)
		end
		when button or info begin
			-- if pc.get_map_index() == MAP_INDEX2 then
				-- addmapsignal(MAP_POS2_1_X * 100, MAP_POS2_1_Y * 100)
				-- addmapsignal(MAP_POS2_2_X * 100, MAP_POS2_2_Y * 100)
				-- addmapsignal(MAP_POS2_3_X * 100, MAP_POS2_3_Y * 100)
			-- end
			say_title(gameforge.main_quest_lv98._130_sendLetter)
			say(gameforge.main_quest_lv98._590_say)
			say("")
			say_item_vnum(ITEM2_1)
			say_title(gameforge.main_quest_lv98._660_counterName)
			local remain = ITEM2_1_NEEDED - pc.count_item(ITEM2_1)
			if remain < 0 then
				remain = 0
			end
			q.set_counter_value(remain)
			say_reward(string.format(gameforge.main_quest_lv98._670_sayReward,item_name(ITEM2_1),remain))
			-- say()
			-- say_reward(locale.main_quest_lv98.pos_info)
			-- select(gameforge.main_quest_lv90._950_say)
			-- setskin(NOWINDOW)
			-- clearmapsignal()
		end
		--클리어 전--
		when GUARD.chat.gameforge.main_quest_lv98._130_sendLetter begin
			say_title(mob_name(GUARD))
			say(gameforge.main_quest_lv98._170_say)
			say("")
		end
		
		when MOB2_1.kill or MOB2_2.kill or MOB2_3.kill or MOB2_4.kill or MOB2_5.kill or MOB2_6.kill or MOB2_7.kill begin
			if	number (1,ITEM2_1_PCT_GET) == 1 then	
				if pc.count_item(ITEM2_1) < ITEM2_1_NEEDED then
					pc.give_item2 ( ITEM2_1, 1 )
					local remain = ITEM2_1_NEEDED - pc.count_item(ITEM2_1)
					if remain < 0 then
						remain = 0
					end
					q.set_counter_value(remain)
					
					if pc.count_item(ITEM2_1) >= ITEM2_1_NEEDED then
						notice_multiline(gameforge.main_quest_lv98._180_1_notice,notice)
						notice_multiline(gameforge.main_quest_lv98._180_2_notice,notice)
						set_state (state2_3)
					end
				end
			end
		end
		
	end
	state state2_3 begin
		when letter begin
			send_letter(gameforge.main_quest_lv98._130_sendLetter)
			
			local v = find_npc_by_vnum(GUARD)
			if 0 != v then
				target.vid("__TARGET__", v, mob_name(GUARD))
			end
			q.set_counter_name("")
		end
		when button or info begin
			say_title(gameforge.main_quest_lv98._130_sendLetter)
			say(gameforge.main_quest_lv98._600_say)
			say("")
			say_reward(gameforge.main_quest_lv98._570_sayReward)
			say("")
		end
		
		-- 중간에 퀘스트 아이템을 버릴 경우를 대비한 부분.
		when MOB2_1.kill or MOB2_2.kill or MOB2_3.kill or MOB2_4.kill or MOB2_5.kill or MOB2_6.kill or MOB2_7.kill begin
			if	number (1,ITEM2_1_PCT_GET) == 1 then	
				if pc.count_item(ITEM2_1) < ITEM2_1_NEEDED then
					pc.give_item2 ( ITEM2_1, 1 )
					
					if pc.count_item(ITEM2_1) >= ITEM2_1_NEEDED then
						notice_multiline(gameforge.main_quest_lv98._180_1_notice,notice)
						notice_multiline(gameforge.main_quest_lv98._180_2_notice,notice)
					end
				end
			end
		end
		
		when GUARD.chat.gameforge.main_quest_lv98._130_sendLetter begin
			target.delete("__TARGET__")
			
			if pc.count_item(ITEM2_1) >= ITEM2_1_NEEDED then
				pc.remove_item ( ITEM2_1, pc.count_item(ITEM2_1))	
				say_title(mob_name(GUARD))
				say(gameforge.main_quest_lv98._190_say)
				say("")
				wait()
				--보상
				say_title(locale.reward)
				say_reward(string.format (gameforge.main_quest_lv60._190_sayReward, REWARD2_EXP))
				say_reward(string.format (gameforge.main_quest_lv60._200_sayReward, REWARD2_GOLD))
				say_reward(string.format (gameforge.main_quest_lv60._210_sayReward, item_name(REWARD2_ITEM1),REWARD2_ITEM1_COUNT,locale.count_postfix))
				say_reward(string.format (gameforge.main_quest_lv60._210_sayReward, item_name(REWARD2_ITEM2),REWARD2_ITEM2_COUNT,locale.count_postfix))
				say_reward(string.format (gameforge.main_quest_lv60._210_sayReward, item_name(REWARD2_ITEM3),REWARD2_ITEM3_COUNT,locale.count_postfix))
				say("")
				
				pc.give_exp2(REWARD2_EXP)
				pc.change_money(REWARD2_GOLD)
				pc.give_item2(REWARD2_ITEM1, REWARD2_ITEM1_COUNT)
				pc.give_item2(REWARD2_ITEM2, 1)
				pc.give_item2(REWARD2_ITEM2, 1)
				
				pc.give_item2(REWARD2_ITEM3, 1)
				pc.give_item2(REWARD2_ITEM3, 1)
				pc.give_item2(REWARD2_ITEM3, 1)
				pc.give_item2(REWARD2_ITEM3, 1)
				pc.give_item2(REWARD2_ITEM3, 1)
				
				set_state (state3_1)
			else -- 중간에 아이템을 빠뜨렸다.
				say_title(mob_name(GUARD))
				say(gameforge.main_quest_lv98._170_say)
				say("")
				
				set_state (state2_2)
			
			end
		end
	end
	
	---------------------------------- 생활 안정----------------------------------
	state state3_1 begin
		when letter begin
			send_letter(gameforge.main_quest_lv98._200_sendLetter)
			
			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_lv98._200_sendLetter)
			say(gameforge.main_quest_lv98._210_say)
			say("")
			say_reward(gameforge.main_quest_lv98._570_sayReward)
			say("")
		end
		when YACKHWAN.chat.gameforge.main_quest_lv98._200_sendLetter begin
			target.delete("__TARGET__")
			
			say_title(mob_name(YACKHWAN ))
			say(gameforge.main_quest_lv98._220_say)
			say("")
			wait()
			say_title(mob_name(YACKHWAN ))
			say(gameforge.main_quest_lv98._260_say)
			say("")
			wait()
			say_title(mob_name(YACKHWAN ))
			say(gameforge.main_quest_lv98._280_say)
			say("")
			set_state (state3_2)
		end
	end
	state state3_2 begin
		when letter begin
			send_letter(gameforge.main_quest_lv98._200_sendLetter)
			q.set_counter_name(gameforge.main_quest_lv98._680_counterName)
		end
		when button or info begin
			-- if pc.get_map_index() == MAP_INDEX3 then
				-- addmapsignal(MAP_POS3_1_X * 100, MAP_POS3_1_Y * 100)
				-- addmapsignal(MAP_POS3_2_X * 100, MAP_POS3_2_Y * 100)
				-- addmapsignal(MAP_POS3_3_X * 100, MAP_POS3_3_Y * 100)
			-- end
			say_title(gameforge.main_quest_lv98._610_sayTitle)
			say(gameforge.main_quest_lv98._620_say)
			say("")
			say(gameforge.main_quest_lv98._680_counterName)
			local remain1 = MOB3_1_COUNT - pc.getqf("mob3_1_kill")
			if remain1 < 0 then
				remain1 = 0
			end
			local remain2 = MOB3_2_COUNT - pc.getqf("mob3_2_kill")
			if remain2 < 0 then
				remain2 = 0
			end
			q.set_counter_value(remain1 + remain2)
			say_reward(string.format(gameforge.main_quest_lv98._690_sayReward,mob_name(MOB3_1),remain1,mob_name(MOB3_2),remain2))
			-- say()
			-- say_reward(locale.main_quest_lv98.pos_info)
			-- select(gameforge.main_quest_lv90._950_say)
			-- setskin(NOWINDOW)
			-- clearmapsignal()
		end
		
		when YACKHWAN.chat.gameforge.main_quest_lv98._200_sendLetter begin
			say_title(mob_name(YACKHWAN ))
			say(gameforge.main_quest_lv98._300_say)
			say("")
		end
		
		when MOB3_1.kill begin
			local mob3_1_kill = pc.getqf("mob3_1_kill")
			if mob3_1_kill < MOB3_1_COUNT then
				pc.setqf("mob3_1_kill",mob3_1_kill +1)
				
				local remain1 = MOB3_1_COUNT - pc.getqf("mob3_1_kill")
				if remain1 < 0 then
					remain1 = 0
				end
				local remain2 = MOB3_2_COUNT - pc.getqf("mob3_2_kill")
				if remain2 < 0 then
					remain2 = 0
				end
				q.set_counter_value(remain1 + remain2)
			end
			
			if pc.getqf("mob3_1_kill") >= MOB3_1_COUNT and pc.getqf("mob3_2_kill") >= MOB3_2_COUNT then
				notice_multiline(gameforge.main_quest_lv98._310_1_notice,notice)
				notice_multiline(gameforge.main_quest_lv98._310_2_notice,notice)
				
				set_state (state3_3)
			end
		end
		when MOB3_2.kill begin
			local mob3_2_kill = pc.getqf("mob3_2_kill")
			if mob3_2_kill < MOB3_2_COUNT then
				pc.setqf("mob3_2_kill",1)
				
				local remain1 = MOB3_1_COUNT - pc.getqf("mob3_1_kill")
				if remain1 < 0 then
					remain1 = 0
				end
				local remain2 = MOB3_2_COUNT - pc.getqf("mob3_2_kill")
				if remain2 < 0 then
					remain2 = 0
				end
				q.set_counter_value(remain1 + remain2)
			end
			
			if pc.getqf("mob3_1_kill") >= MOB3_1_COUNT and pc.getqf("mob3_2_kill") >= MOB3_2_COUNT then
				notice_multiline(gameforge.main_quest_lv98._310_1_notice,notice)
				notice_multiline(gameforge.main_quest_lv98._310_2_notice,notice)
				
				set_state (state3_3)
			end
		end
	end
	state state3_3 begin
		when letter begin
			send_letter(gameforge.main_quest_lv98._200_sendLetter)
			
			local v = find_npc_by_vnum(YACKHWAN)
			if 0 != v then
				target.vid("__TARGET__", v, mob_name(YACKHWAN))
			end
			q.set_counter_name("")
		end
		when button or info begin
			say_title(gameforge.main_quest_lv98._200_sendLetter)
			say(gameforge.main_quest_lv98._630_say)
			say("")
			say_reward(gameforge.main_quest_lv98._570_sayReward)
			say("")
		end
		
		when YACKHWAN.chat.gameforge.main_quest_lv98._200_sendLetter begin
			target.delete("__TARGET__")
			
			say_title(mob_name(YACKHWAN ))
			say(gameforge.main_quest_lv98._320_say)
			say("")
			wait()
			
			--보상
			say_title(locale.reward)
			say_reward(string.format(gameforge.main_quest_lv60._190_sayReward, REWARD3_EXP))
			--say_reward(string.format(gameforge.main_quest_lv60._200_sayReward, REWARD3_GOLD))
			say_reward(string.format (gameforge.main_quest_lv60._210_sayReward, item_name(REWARD3_ITEM1),REWARD3_ITEM1_COUNT,locale.count_postfix))
			say("")
			
			pc.give_exp2(REWARD3_EXP)
			--pc.change_money(REWARD3_GOLD)
			pc.give_item2(REWARD3_ITEM1, REWARD3_ITEM1_COUNT)
				
			set_state (state4_1)
		end
	end
	---------------------------------- 마지막 인사----------------------------------
	state state4_1 begin
		when letter begin
			send_letter(gameforge.main_quest_lv98._330_sendLetter)
			
			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_lv98._330_sendLetter)
			say(gameforge.main_quest_lv98._340_say)
			say("")
			say_reward(gameforge.main_quest_lv98._570_sayReward)
			say("")
		end
		
		when YACKHWAN.chat.gameforge.main_quest_lv98._330_sendLetter begin
			target.delete("__TARGET__")
			
			say_title(mob_name(YACKHWAN ))
			say(gameforge.main_quest_lv98._350_say)
			say("")
			wait()
			
			say_title(mob_name(YACKHWAN ))
			say(gameforge.main_quest_lv98._360_say)
			say("")
			wait()
			say_title(pc.getname())
			say(gameforge.main_quest_lv98._380_say)
			say("")
		
			set_state (state4_2)
		end
	end
	-- 인사 퀘스트 진행 --
	state state4_2 begin
		when letter begin
			send_letter(gameforge.main_quest_lv98._330_sendLetter)
			q.set_counter_name(gameforge.main_quest_lv98._700_counterName)
			
			local v_npc1 = find_npc_by_vnum(NPC4_1)
			local v_npc2 = find_npc_by_vnum(NPC4_2)
			local v_npc3 = find_npc_by_vnum(NPC4_3)
			local v_npc4 = find_npc_by_vnum(NPC4_4)
			if 0 != v_npc1 and pc.getqf("click_npc1") ~= 1 then
				target.vid("__target_npc1__", v_npc1, mob_name(NPC4_1))
			end
			if 0 != v_npc2 and pc.getqf("click_npc2") ~= 1 then
				target.vid("__target_npc2__", v_npc2, mob_name(NPC4_2))
			end
			if 0 != v_npc3 and pc.getqf("click_npc3") ~= 1 then
				target.vid("__target_npc3__", v_npc3, mob_name(NPC4_3))
			end
			if 0 != v_npc4 and pc.getqf("click_npc4") ~= 1 then
				target.vid("__target_npc4__", v_npc4, mob_name(NPC4_4))
			end
			
		end
		when button or info begin
			say_title(gameforge.main_quest_lv98._640_sayTitle)
			say(gameforge.main_quest_lv98._650_say)
			say("")
			say_title(gameforge.main_quest_lv98._700_counterName)
			local npc1 = " "
			if pc.getqf("click_npc1") == 1 then
				npc1 = "O"
			end
			local npc2 = " "
			if pc.getqf("click_npc2") == 1 then
				npc2 = "O"
			end
			local npc3 = " "
			if pc.getqf("click_npc3") == 1 then
				npc3 = "O"
			end
			local npc4 = " "
			if pc.getqf("click_npc4") == 1 then
				npc4 = "O"
			end
			local remain = 4 - pc.getqf("click_npc1") - pc.getqf("click_npc2") - pc.getqf("click_npc3") - pc.getqf("click_npc4")
			q.set_counter_value(remain)
			say(string.format(gameforge.main_quest_lv98._710_say,npc1,npc2))
			say(string.format(gameforge.main_quest_lv98._720_say,npc3,npc4))
			say("")
			say_reward(gameforge.main_quest_lv98._570_sayReward)
			say("")
			
		end
		
		-- 클리어 전에 클릭 --
		when YACKHWAN.chat.gameforge.main_quest_lv98._330_sendLetter begin
			say_title(mob_name(YACKHWAN ))
			say(gameforge.main_quest_lv98._390_say)
			say("")
			wait()
		end
		
		when __target_npc1__.target.click or NPC4_1.click with pc.getqf("click_npc1") ~= 1 begin -- 촌장
			target.delete("__target_npc1__")
			pc.setqf("click_npc1",1)
		
			say_title(mob_name(NPC4_1))
			say(gameforge.main_quest_lv98._400_say)
			say("")
			
			local remain = 4 - pc.getqf("click_npc1") - pc.getqf("click_npc2") - pc.getqf("click_npc3") - pc.getqf("click_npc4")
			q.set_counter_value(remain)
			
			if pc.getqf("click_npc1") == 1 and pc.getqf("click_npc2") == 1 and pc.getqf("click_npc3") == 1 and pc.getqf("click_npc4") == 1 then
				
				notice_multiline(gameforge.main_quest_lv98._440_1_notice,notice)
				notice_multiline(gameforge.main_quest_lv98._440_2_notice,notice)
				
				set_state (state4_3)
			end
		end
		when __target_npc2__.target.click or NPC4_2.click with pc.getqf("click_npc2") ~= 1 begin -- 방어구
			target.delete("__target_npc2__")
			pc.setqf("click_npc2",1)
		
			say_title(mob_name(NPC4_2))
			say(gameforge.main_quest_lv98._410_say)
			say("")
			
			local remain = 4 - pc.getqf("click_npc1") - pc.getqf("click_npc2") - pc.getqf("click_npc3") - pc.getqf("click_npc4")
			q.set_counter_value(remain)
			
			if pc.getqf("click_npc1") == 1 and pc.getqf("click_npc2") == 1 and pc.getqf("click_npc3") == 1 and pc.getqf("click_npc4") == 1 then
				
				notice_multiline(gameforge.main_quest_lv98._440_1_notice,notice)
				notice_multiline(gameforge.main_quest_lv98._440_2_notice,notice)
				
				set_state (state4_3)
			end
			
		end
		when __target_npc3__.target.click or NPC4_3.click with pc.getqf("click_npc3") ~= 1 begin -- 잡화상점
			target.delete("__target_npc3__")
			pc.setqf("click_npc3",1)
		
			say_title(mob_name(NPC4_3))
			say(gameforge.main_quest_lv98._430_say)
			say("")
			
			local remain = 4 - pc.getqf("click_npc1") - pc.getqf("click_npc2") - pc.getqf("click_npc3") - pc.getqf("click_npc4")
			q.set_counter_value(remain)
			
			
			if pc.getqf("click_npc1") == 1 and pc.getqf("click_npc2") == 1 and pc.getqf("click_npc3") == 1 and pc.getqf("click_npc4") == 1 then
				
				notice_multiline(gameforge.main_quest_lv98._440_1_notice,notice)
				notice_multiline(gameforge.main_quest_lv98._440_2_notice,notice)
				
				set_state (state4_3)
			end
		end
		when __target_npc4__.target.click or NPC4_4.click with pc.getqf("click_npc4") ~= 1 begin -- 무기상점
			target.delete("__target_npc4__")
			pc.setqf("click_npc4",1)
		
			say_title(mob_name(NPC4_4))
			say(gameforge.main_quest_lv98._420_say)
			say("")
			
			local remain = 4 - pc.getqf("click_npc1") - pc.getqf("click_npc2") - pc.getqf("click_npc3") - pc.getqf("click_npc4")
			q.set_counter_value(remain)
			
			if pc.getqf("click_npc1") == 1 and pc.getqf("click_npc2") == 1 and pc.getqf("click_npc3") == 1 and pc.getqf("click_npc4") == 1 then
				
				notice_multiline(gameforge.main_quest_lv98._440_1_notice,notice)
				notice_multiline(gameforge.main_quest_lv98._440_2_notice,notice)
				
				set_state (state4_3)
			end
		end
	end
	state state4_3 begin
		when letter begin
			send_letter(gameforge.main_quest_lv98._330_sendLetter)
			
			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_lv98._330_sendLetter)
			say(gameforge.main_quest_lv98._630_say)
			say("")
			say_reward(gameforge.main_quest_lv98._570_sayReward)
			say("")
		end
		
		when YACKHWAN.chat.gameforge.main_quest_lv98._330_sendLetter begin
			target.delete("__TARGET__")
			
			say_title(mob_name(YACKHWAN ))
			say(gameforge.main_quest_lv98._450_say)
			say("")
			wait()
			--보상
			say_title(locale.reward)
			say_reward(string.format (gameforge.main_quest_lv60._190_sayReward, REWARD4_EXP))
			say_reward(string.format (gameforge.main_quest_lv60._200_sayReward, REWARD4_GOLD))
			say_reward(string.format (gameforge.main_quest_lv60._210_sayReward, item_name(REWARD4_ITEM1),REWARD4_ITEM1_COUNT,locale.count_postfix))
			say_reward(string.format (gameforge.main_quest_lv60._210_sayReward, item_name(REWARD4_ITEM2),REWARD4_ITEM2_COUNT,locale.count_postfix))
			say("")
			
			pc.give_exp2(REWARD4_EXP)
			pc.change_money(REWARD4_GOLD)
			pc.give_item2(REWARD4_ITEM1, REWARD4_ITEM1_COUNT)
			pc.give_item2_select(REWARD4_ITEM2)
			item.set_socket(2, 60)
				
			set_state (state5_1)
		end
	end
	----------------------------------다시 대륙으로----------------------------------
	state state5_1 begin
		when letter begin
			send_letter(gameforge.main_quest_lv98._480_sendLetter)
			
			local v = find_npc_by_vnum(GUARD)
			if 0 != v then
				target.vid("__TARGET__", v, mob_name(GUARD))
			end
		end
		when button or info begin
			say_title(gameforge.main_quest_lv98._480_sendLetter)
			say(gameforge.main_quest_lv98._490_say)
			say("")
			say_reward(gameforge.main_quest_lv98._570_sayReward)
			say("")
		end
		
		when GUARD.chat.gameforge.main_quest_lv98._480_sendLetter begin
			target.delete("__TARGET__")
			
			say_title(mob_name(GUARD))
			say(gameforge.main_quest_lv98._500_say)
			say("")
			wait()
			
			say_title(mob_name(GUARD))
			say(gameforge.main_quest_lv98._520_say)
			say("")
			wait()
			
			--보상
			say_title(locale.reward)
			say_reward(string.format (gameforge.main_quest_lv60._190_sayReward, REWARD5_EXP))
			say_reward(string.format (gameforge.main_quest_lv60._200_sayReward, REWARD5_GOLD))
			say_reward(string.format (gameforge.main_quest_lv60._210_sayReward, item_name(REWARD5_ITEM1),REWARD5_ITEM1_COUNT,locale.count_postfix))
			say("")
			
			pc.give_exp2(REWARD5_EXP)
			pc.change_money(REWARD5_GOLD)
			pc.give_item2(REWARD5_ITEM1, REWARD5_ITEM1_COUNT)
			
			clear_letter()
			set_state (__COMPLETE__)
		end
	end
	
	state __COMPLETE__ begin
		when enter begin
			q.done()
		end
	end
end
