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()