ShowMessage("ű $Rev: 209 $")

--[[
[author]
class=3
]]--

local NEED_ACTIVEPOINT = 50

local g_szMission = ""
local g_nParam = {}
local g_nIndex = 0
local g_idMission = 0
local g_idScript = 0
local g_dwNextTime = 0

local g_NpcInfo = {
	[0] = {szNpcName="", fX=66, fY=135},
	[1] = {szNpcName="", fX=44, fY=46},
	[2] = {szNpcName="Ӧ", fX=65, fY=55},
	[3] = {szNpcName="", fX=134, fY=49},
	[4] = {szNpcName="ر", fX=149, fY=44},
	[5] = {szNpcName="ǮΪһ", fX=149, fY=56},
	[6] = {szNpcName="١ܽ", fX=147, fY=95},
	[7] = {szNpcName="", fX=129, fY=98},
	[8] = {szNpcName="д", fX=73, fY=93},
	[9] = {szNpcName="¬", fX=50, fY=97},
	[10] = {szNpcName="", fX=46, fY=90},
	[11] = {szNpcName="", fX=45, fY=73},
	[12] = {szNpcName="", fX=44, fY=58},
	[13] = {szNpcName="ǿʢ", fX=131, fY=126}
}

function LJ_OnMission_600061()
	
	local index = g_nParam[5]

	if g_NpcInfo[index] == nil then
		ShowMessage("δ֪NPC")
		return
	end

	if Player_GetBuff("") ~= -1 then
		MoveToNPC(g_NpcInfo[0].fX, g_NpcInfo[0].fY, -1, g_NpcInfo[0].szNpcName)
	else
		MoveToNPC(g_NpcInfo[index].fX, g_NpcInfo[index].fY, -1, g_NpcInfo[index].szNpcName)
		Dismount()
		QuestFrameOptionClicked("ʼ˽", CMP_PART_MATCH)
	end

end

function LJ_OnMission_600062()
	if Player_GetBuff("") == -1 then
		MoveToNPC(g_NpcInfo[0].fX, g_NpcInfo[0].fY, -1, g_NpcInfo[0].szNpcName)
		Dismount()
		QuestFrameOptionClicked("ȡ", CMP_FULL_MATCH)
	else
		if Get_XParam_INT(600055, 0) == 0 then
			UseSkill("Դ")
		else
			local x = Get_XParam_INT(600055, 1)
			local y = Get_XParam_INT(600055, 2)

			MoveTo(x, y, -1, "")
			UseSkill("ɼԴ")
		end
	end
end

function LJ_OnMission_600063()

	if Player_GetBuff("") == -1 then
		MoveToNPC(g_NpcInfo[0].fX, g_NpcInfo[0].fY, -1, g_NpcInfo[0].szNpcName)
		Dismount()
		QuestFrameOptionClicked("ȡ", CMP_FULL_MATCH)
	else
		if Get_XParam_INT(600055, 0) == 0 then
			UseSkill("Դ")
		else
			local x = Get_XParam_INT(600055, 1)
			local y = Get_XParam_INT(600055, 2)

			MoveTo(x, y, -1, "")
			UseSkill("ռԴ")
		end
	end
end

function LJ_OnMission_600064()

	if Player_GetBuff("") == -1 then
		MoveToNPC(g_NpcInfo[0].fX, g_NpcInfo[0].fY, -1, g_NpcInfo[0].szNpcName)
		Dismount()
		QuestFrameOptionClicked("ȡ", CMP_FULL_MATCH)
	else
	--[[
		while TripperObj_Active("") do
			System:Sleep(1000)
		end
		]]--
		
		OnPickup()
		
		if Get_XParam_INT(600055, 0) == 0 then
			UseSkill("Դ")
		else
			local x = Get_XParam_INT(600055, 1)
			local y = Get_XParam_INT(600055, 2)

			MoveTo(x, y, -1, "")
			UseSkill("ھԴ")
		end
	end

end



------------------------------------------------------------------------------------------------
function _SMain(...)

	local nQuestTimes = 0 
	local nWaitTimes = 0 

	while true do

		g_nIndex, g_idMission, g_idScript = DataPool:GetPlayerMission("")
		if g_nIndex == -1 then
			g_szMission = ""
			g_nIndex, g_idMission, g_idScript = DataPool:GetPlayerMission(g_szMission)
		else
			g_szMission = ""
		end

		if g_nIndex ~= -1 then

			DbgPrintf("%s Index:%d MissionID:%d ScriptID:%d", g_szMission, 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

			CityToGuild()	-- ɳ

			if DataPool:IsMissionCanCommit(g_idMission) then

				-- 
				DbgPrintf("")
				MoveToNPC(g_NpcInfo[0].fX, g_NpcInfo[0].fY, -1, g_NpcInfo[0].szNpcName)
				QuestFrameOptionClicked(g_szMission, CMP_FULL_MATCH)	-- ѡѡ
				QuestFrameMissionContinue()	-- 
				QuestFrameMissionComplete()	-- 
				QuestFrameMissionClose()
				
			else
				-- ѽδ
				DbgPrintf("")

				if g_idScript == 600061 or g_idScript == 891013 then		-- ָNPC
					LJ_OnMission_600061()
				elseif g_idScript == 600062 or g_idScript == 891014 then	-- һɼԴֱӽ뱳
					LJ_OnMission_600062()
				elseif g_idScript == 600063 or g_idScript == 891015 then	-- һռԴֱӽ뱳
					LJ_OnMission_600063()
				elseif g_idScript == 600064 or g_idScript == 891016 then	-- һھԴӵڵ
					LJ_OnMission_600064()
				else
					ShowMessage("δ֪ű")
					DbgPrintf("δ֪ %d" , tonumber(g_idScript))
					break
				end

				local bUseSkill = false 

				local isNext,szMsg = GetDebugMessage()
				while isNext == 1 do
					if string.find(szMsg, "ûзֺʵĵطռƷ") then
						bUseSkill = true 
					end
					isNext,szMsg = GetDebugMessage()
				end

				if bUseSkill == true then 
					UseSkill("Դ")
				end
			end
		else
			-------------------------------------------------------------------------------------
			-- ȡ

			-- жϻԾֵ
			local nActivePoint = Player:GetData("ACTIVEPOINT")

			if nActivePoint < 50 then
				if nQuestTimes == 0 then
					ShowMessage("񣺻Ծֵ㣡")
					break
				else
					if nWaitTimes > 3 then 
						ShowMessage("񣺻Ծֵ㣡")
						break
					else
						nWaitTimes = nWaitTimes + 1
						System:Sleep(1000)
						continue
					end
				end 
			end

			if nActivePoint >= 250 then
				g_szMission = ""
			else
				g_szMission = ""
			end

			-- ɳ
			if CityToGuild() == false then
				ShowMessage("ûаɳУ")
				break 
			end

			MoveToNPC(g_NpcInfo[0].fX, g_NpcInfo[0].fY, -1, g_NpcInfo[0].szNpcName)
			--Dismount()
			QuestFrameOptionClicked(g_szMission, CMP_FULL_MATCH)	-- ѡѡ
			QuestFrameAcceptClicked()

			nWaitTimes = 0
			nQuestTimes = nQuestTimes + 1

		end

		System:Sleep(500)
	end

	GuildToCity(0)
end

_SMain()