ShowMessage("Ͷ´ս $Rev: 100 $")


--[[
[author]
class=3
perday_max=1
descript="뱣ֲϱո1߽űԶ"
]]--
script_name="Ͷ´ս"

local g_NpcInfo = {
	[0] = {szNpcName="͢" , fX=255 , fY=250 , CheckID=0x962 },
	[1] = {szNpcName="׺" , fX=352 , fY=279 , CheckID=0x02626c46 },
	[2] = {szNpcName="ʤ" , fX=252 , fY=379 , CheckID=0x02626c45 },
	[3] = {szNpcName="" , fX=160 , fY=270 , CheckID=0x02626c44 }
}

function GetMissionNPC()
	local nResult = 0
	for i=1,3 do
		if DataPool:UserBag_CountItemByIDTable( g_NpcInfo[i].CheckID ) > 0 then 
			nResult = i
		end
	end
	return nResult
end

function _SMain(...)

	local nIndex = 0
	local idMission = -1 
	local idScript = 0 

	while true do

		local nNpcIndex = GetMissionNPC()

		if nNpcIndex > 0 then 
			MoveToNPC( g_NpcInfo[nNpcIndex].fX, g_NpcInfo[nNpcIndex].fY, 0 , g_NpcInfo[nNpcIndex].szNpcName )
			QuestFrameOptionClicked( "ϽǷ" , CMP_FULL_MATCH)	-- ѡѡ
			System:Sleep(1000)
		else
			MoveToNPC( g_NpcInfo[0].fX, g_NpcInfo[0].fY, 0 , g_NpcInfo[0].szNpcName )
			Dismount()
			nIndex, idMission, idScript = DataPool:GetPlayerMission( script_name )
			if Player:IsHaveBuff( g_NpcInfo[0].CheckID ) and nIndex ~= -1 then
				--ӵ
				QuestFrameOptionClicked( "ȡǷ" , CMP_FULL_MATCH)	-- ѡѡ
				System:Sleep(1000)

				local isNext,szMsg = GetDebugMessage()
				while isNext == 1 do
					if string.find(szMsg, "޷ȡ") then
						ShowMessage("ȡͶ½ű") 
						return
					end
					isNext,szMsg = GetDebugMessage()
				end
			else
				if nIndex ~= -1 then
					QuestFrameOptionClicked( script_name , CMP_FULL_MATCH)	-- ѡѡ
					QuestFrameMissionComplete()	-- 
					System:Sleep(1000)
				else
					if PlayerPackage:GetEmptySlot(1) < 1 then 
						ShowMessage("޷ȡ,Զ")
						return 
					end

					QuestFrameOptionClicked(script_name, CMP_FULL_MATCH)	-- ѡѡ
					QuestFrameAcceptClicked()
					System:Sleep(1000)

					local isNext,szMsg = GetDebugMessage()
					while isNext == 1 do
						if string.find(szMsg, "ȡ") then
							ShowMessage("Ͷ½ű") 
							System:UpdateRecord( script_name )
							return
						end
					isNext,szMsg = GetDebugMessage()
					end
				end
			end
		end
	end
end

_SMain()