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