ShowMessage(" $Rev: 100 $")


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

local g_NpcInfo = {
	[0] = {szNpcName="" , mapId = 1 , fX=221 , fY=205 , CheckID1=0x013bdb8c , CheckID2=0x2626c2c },
}

function _SMain(...)

	local nIndex = 0
	local idMission = -1 
	local idScript = 0 
	local nParam = {}

	while true do

		nIndex, idMission, idScript = DataPool:GetPlayerMission( script_name )
		-- ȡ
		for i=0,7 do
			nParam[i] = DataPool:GetPlayerMission_Variable(nIndex, i)
			DbgPrintf("[%d]%d", i, nParam[i])
		end

		if nIndex ~= -1 then

			--DbgPrintf("%s Index:%d MissionID:%d ScriptID:%d", script_name, nIndex, idMission, idScript)

			if DataPool:IsMissionCanCommit(idMission) then

				-- 
				DbgPrintf("")
				MoveToNPC(  g_NpcInfo[0].fX, g_NpcInfo[0].fY , g_NpcInfo[0].mapId , g_NpcInfo[0].szNpcName )
				QuestFrameOptionClicked(script_name, CMP_FULL_MATCH)	-- ѡѡ
				QuestFrameMissionContinue()	-- 
				QuestFrameMissionComplete()	-- 
				
			else
				local nCheck1 = DataPool:UserBag_CountItemByIDTable( g_NpcInfo[0].CheckID1 ) 
				local nCheck2 = DataPool:UserBag_CountItemByIDTable( g_NpcInfo[0].CheckID2 ) 

				if nParam[1] < 1 then
 
					if nCheck1 < 5 then

						AI:SetAI("ɼ")
						AI:SetParameter("ʼ")
						AI:SetParameter("Ŀ", "", "")
						AI:SetParameter("ͼ", 4 )
						AI:SetParameter("", "",272, 187)

						AI:Start(false)

						while true do
							nCheck1 = DataPool:UserBag_CountItemByIDTable( g_NpcInfo[0].CheckID1 ) 
							if nCheck1 > 4 then
								break
							end
	
							System:Sleep(500)
						end
		
						AI:Stop()
					else

						--Ҷ
						MoveToNPC(  g_NpcInfo[0].fX, g_NpcInfo[0].fY , g_NpcInfo[0].mapId , g_NpcInfo[0].szNpcName )
						QuestFrameOptionClicked("", CMP_FULL_MATCH)	-- ѡѡ
						System:Sleep(3000)
					end

				else

					if nCheck2 < 1 then
						ShowMessage("δֵ ")
						MissionBlockProcess(idScript)
					else
						math.randomseed(os.time())
						local nX = math.random(221, 231)
						local nY = math.random(188, 212)
						MoveTo(  nX, nY , g_NpcInfo[0].mapId )
						Dismount()
						UseItem("", "")
						System:Sleep(2000)
					end

				end

			end

		else
			-- ȡ

			local nEmptySlot = PlayerPackage:GetEmptySlot(1)
			if  nEmptySlot < 2 then 
				ShowMessage("Ҫ2ոܽȡ")
				return 
			end

			MoveToNPC(  g_NpcInfo[0].fX, g_NpcInfo[0].fY , g_NpcInfo[0].mapId , g_NpcInfo[0].szNpcName )
			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

_SMain()