ShowMessage("¥ $Rev: 206 $")

--[[
[author]
]]--
script_name="¥"

function _SMain(...)


	while true do

		local szMapName = GetActiveSceneName()
		local nMapID = GetActiveDataSceneID()
		
		local g_nIndex, g_idMission, g_idScript = DataPool:GetPlayerMission(script_name)
			
		if g_nIndex ~= -1 then

			if string.find(szMapName , "¥")  then
				DbgPrintf("%s Index:%d MissionID:%d ScriptID:%d", script_name, g_nIndex, g_idMission, g_idScript)

				-- ȡ
				for i=0,7 do
					g_nParam[i] = DataPool:GetPlayerMission_Variable(g_nIndex, i)
					DbgPrintf("[%d]%d", i, g_nParam[i])
				end

				if DataPool:IsMissionCanCommit(g_idMission) then

					-- 
					DbgPrintf("")

					MoveToNPC(74, 77, nMapID , "")
					QuestFrameOptionClicked("¥", CMP_FULL_MATCH)	-- ѡѡ
					QuestFrameMissionComplete()
					QuestFrameOptionClicked("һ", CMP_FULL_MATCH)
				else

					AI:SetAI("ɱ")
					AI:SetParameter("ͼ", nMapID)
					AI:SetParameter("", "", 80, 66)
					AI:SetParameter("", "", 81, 53)
					AI:Start(false)

					while DataPool:IsMissionCanCommit(g_idMission) == false do
						if nMapID ~= GetActiveDataSceneID() then
							break
						end
						System:Sleep(1000)
					end
					
					AI:Stop()
				end
			else
				MoveToNPC(93, 202, 2 , "")
				QuestFrameOptionClicked("ǰ¥", CMP_FULL_MATCH)	-- ѡѡ
				System:Sleep(1500)
			end
		else
			if string.find(szMapName , "¥")  then
				MoveToNPC(74, 77, nMapID , "")
				QuestFrameOptionClicked("¥", CMP_FULL_MATCH)	-- ѡѡ

				System:Sleep(1000)
				local strType,_,_,_,szText = DataPool:GetNPCEventList_Item(0);

				DbgPrintf("%s" , szText)

				if strType == "text" then
					if string.find(szText, "Ȼ˵") then
						MoveTo(84,80,-1)
						break	-- ˳ѭű
					end
				end
				QuestFrameAcceptClicked()
			else
				if GetQuestTimesInfo("¥") == 0 then
					ShowMessage("¥Ѿ!")
					break
				end

				MoveToNPC(93, 202, 2 , "")
				QuestFrameOptionClicked("ǰ¥", CMP_FULL_MATCH)	-- ѡѡ
				System:Sleep(1500)
			end
		end

		System:Sleep(500)
	end
end

_SMain()