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