ShowMessage("天下第一擂 $Rev: 1$")

--[[
[author]
class=2
]]--


function OnMove(fX, fY, nScene, fSpace)

	local nCurScene = GetActiveDataSceneID()
	if nCurScene ~= nScene then
		return false
	end

	local nServerID = LockNearestTarget("", CHA_RELATION_ENEMY|CHA_RELATION_ENEMY|CHA_TYPE_PLAYEROTHER|CHA_OWNER_ANY|CHA_OCCUPANT_ANY|CHA_STATE_ALIVE,"")

	if INVALID_ID ~= nServerID then
		return false
	end

	return true
end

function OnDiYiLei()
	
	local strSceneName = ""

	while true do

		strSceneName = GetActiveSceneName()
		
		if string.find(strSceneName, "预备室") then

			local nHPPercent = Player:GetData("HP_PERCENT")
			local nMPPercent = Player:GetData("MP_PERCENT")

			if (nHPPercent > 100 or nMPPercent > 100) then 

				MoveToNPC(32, 14, -1, "擂台指引使", false)
				QuestFrameOptionClicked("角色满怒治疗", CMP_FULL_MATCH)
				QuestFrameOptionClicked("是", CMP_FULL_MATCH)
				
				System:Sleep(500)

				MoveToNPC(32, 14, -1, "擂台指引使",false)
				QuestFrameOptionClicked("给珍兽恢复气血", CMP_FULL_MATCH)
				QuestFrameOptionClicked("好", CMP_FULL_MATCH)

			else

				local buff_index = Player_GetBuff("战斗休整")
				if buff_index ~= -1 then
					Player_DispelBuffByIndex(buff_index)
				else
					DbgPrintf("等待进入！")
				end

			end

		elseif strSceneName == "天下第一擂" then

			local nHP = Player:GetData("HP")

			if Player_GetBuff("战斗准备") ~= -1 then
			
			else
				if UI:IsWindowShow("NewMatch_ResultShow") == true then
					DbgPrintf("比赛结束！")
					MoveToNPC(107, 110, -1, "比赛指引人", false)
					QuestFrameOptionClicked("离开副本", CMP_FULL_MATCH)
					DoLuaString("MessageBox_Self_Env", "MessageBox_Self_OK_Clicked()")
					System:Sleep(3000)
				else

					DbgPrintf("比赛中！")
					if nHP > 0 then
						
						local nServerID = LockNearestTarget("", CHA_RELATION_ENEMY|CHA_RELATION_ENEMY|CHA_TYPE_PLAYEROTHER|CHA_OWNER_ANY|CHA_OCCUPANT_ANY|CHA_STATE_ALIVE,"")

						if INVALID_ID ~= nServerID then
							Attack_Target(nServerID)
							System:Sleep(1000)
						else
							MoveTo(96, 94, GetActiveDataSceneID(), "", 1, false, OnMove)
						end
					else
						DbgPrintf("角色挂了！")
					end
				end

			end

		else
			ShowMessage("请进入【预备室】后开始脚本！")
			break

		end

		System:Sleep(200)
	end
end

function _SMain(...)
	OnDiYiLei()
end


_SMain()