ShowMessage("Ѱַű $Rev: 100 $")


--[[
[author]
class=3
perday_max=1
descript="ⱳո񣬱֤㹻λÿýű˳ִС"
]]--
script_name="Ѱַ"

local g_NpcName = "С"			-- NPC
local g_Npc_X = 289
local g_Npc_Y = 222
local g_Npc_Map = 1


function _SMain(...)

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

	while true do

		nIndex, idMission, idScript = DataPool:GetPlayerMission( script_name )

		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_Npc_X, g_Npc_Y, g_Npc_Map , g_NpcName )
				QuestFrameOptionClicked(script_name, CMP_FULL_MATCH)	-- ѡѡ
				QuestFrameMissionContinue()	-- 
				QuestFrameMissionComplete()	-- 
				
			else
				local nParam 
				-- ȡ
				for i=0,7 do
					nParam[i] = DataPool:GetPlayerMission_Variable(nIndex, i)
					DbgPrintf("[%d]%d", i, nParam[i])
				end

				Dismount()
				UseItem("Ѱɾ")
				System:Sleep(1000)
				local isNext,szMsg = GetDebugMessage()

				local tX = 0 
				local tY = 0 
				local tMap = -1
				while isNext == 1 do
					DbgPrintf("  =>%s" , tostring(szMsg))
					local _,_,sX,sY = string.find( szMsg , "%*.(%d+)%*.(%d+)" )
					if sX ~= nil and sY ~= nil then 
						tX = tonumber(sX)
						tY = tonumber(sY)
					end

					isNext,szMsg = GetDebugMessage()
				end

				if tX > 0 and tY > 0  then
					if nParam[1] == 0 then 
						tMap = 1
					elseif nParam[2] == 0 then 
						tMap = 0
					elseif nParam[0] == 0 then						
						tMap = 2
					end
				else
					ShowMessage("ٴλȡ!")
					System:Sleep(1000)
					continue				
				end

				if tMap ~= -1 and tX > 0 and tY > 0 then
					MoveTo( tX , tY , tMap )
					Dismount()
					UseItem("Ѱɾ")
				end
			end
		else
			-------------------------------------------------------------------------------------
			-- ȡ

			local nLevel = Player:GetData("LEVEL")

			if nLevel < 30 then 
				ShowMessage("ȼ30ܽѰַ")
				return
			end

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

			MoveToNPC( g_Npc_X, g_Npc_Y, g_Npc_Map , g_NpcName )
			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

		System:Sleep(500)
	end

end

_SMain()