ShowMessage("¥ $Rev: 206 $")

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

local g_nIndex = -1
local g_idMission = -1
local g_idScript = -1

function _SMain(...)


	while true do

		local szMapName = GetActiveSceneName()
		local nMapID = GetActiveDataSceneID()
		
		if string.find(szMapName , "¥")  then

			g_nIndex, g_idMission, g_idScript = DataPool:GetPlayerMission(script_name)
			
			if g_nIndex ~= -1 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(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
						ShowMessage("¸ĸģ5")
						System:UpdateRecord( script_name )
						MoveTo(84,80,-1)
						break	-- ˳ѭű
					end
				end
				QuestFrameAcceptClicked()

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

		System:Sleep(500)
	end
end

_SMain()