ShowMessage("þű $Rev: 1 $")

--[[
[author]
class=1
]]--


local script_name="þħ"

local g_MissionMap = 300
local g_nIndex, g_idMission, g_idScript = DataPool:GetPlayerMission(script_name)

local StepKill = {{x=63,y=39,kc=30},{x=88,y=40,kc=60},{x=100,y=64,kc=90},{x=88,y=88,kc=120},{x=64,y=100,kc=150},{x=40,y=88,kc=180},{x=30,y=64,kc=210},{x=40,y=40,kc=239}, {x=56,y=56,kc=240}}

function GetMissionComplete()

	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
		
		return tonumber(g_nParam[0])
	end

	return -1
end

function OnFighting()

	AI:SetAI("ɱ")
	AI:SetParameter("ʼ")
	AI:SetParameter("ͼ", g_MissionMap )
	AI:SetParameter("ʰȡ" , 1)
	if Player:IsRangeAttack() == true then
		AI:SetParameter("в" ,"", 1)
	end
	--AI:SetParameter("в" ,"Ӹ", 1)
	AI:SetParameter("в" ,"", 1)

	for i, v in pairs( StepKill ) do
		AI:SetParameter("", "", v.x, v.y , 25 , v.kc )
	end

	AI:Start(false)

	while true do 

		System:Sleep(1000)

		if GetActiveDataSceneID() ~= g_MissionMap then
			break 
		end

		local nComplete = GetMissionComplete()
		if 0 ~= nComplete then
			if nComplete == 1 then
				--ͣһʱ
				if IsMsgCold("Quest_TLHJ_Complete" , 5000) == true then
					break
				end
			else
				break
			end
		else
			UpdateMsg("Quest_TLHJ_Complete")
		end
	end

	AI:Stop()
end

function _SMain(...)

	while true do

		local nComplete = GetMissionComplete() 

		if GetActiveDataSceneID() ~= g_MissionMap then
			--
			if nComplete == INVALID_ID then

				if GetQuestTimesInfo("þ") == 0 then
					ShowMessage("þ!")
					return
				end

				if DataPool:IsTeamLeader() and DataPool:UserBag_CountItemByName("") <= 0 then
					ShowMessage("Ѿû  !")
					return
				end

				MoveToNPC( 171 , 119 , 246 , "" )


				-- ж϶
				if DataPool:GetTeamMemCount() < 3 then 
					ShowMessage(" 3 ˣ")
					return
				end

				QuestFrameOptionClicked( script_name , CMP_PART_MATCH)	-- ѡѡ

				local strType,_,_,_,szText = DataPool:GetNPCEventList_Item(0)
				if strType == "text" then
					if string.find(szText, "þ6") then
						ShowMessage("þѾɣ")
						break	-- ˳ѭű
					end
				end

				QuestFrameAcceptClicked()
				System:Sleep(2000)

			elseif nComplete == 0 then

				if DataPool:GetTeamMemCount() < 3 then 
					ShowMessage(" 3 ˣ")
					return
				end

				--ӳԻnpc
				MoveToNPC( 171 , 119 , 246 , "" )
				QuestFrameOptionClicked( "þ" , CMP_PART_MATCH)	-- ѡѡ
				System:Sleep(2000)

			elseif nComplete == 1 then

				--
				--ShowMessage("ִн")
				MoveToNPC( 171 , 119 , 246 , "" )
				QuestFrameOptionClicked( script_name , CMP_PART_MATCH)	-- ѡѡ
				QuestFrameMissionContinue()
				QuestFrameMissionComplete()

			else
				--
				QuestFrameMissionAbnegate(g_idScript)

			end
		else
			--ڸ
			if nComplete == 0 then
				local LockId = LockNearestTarget("",CHA_TYPE_NPC|CHA_RELATION_ENEMY )
				if INVALID_ID == LockId and DataPool:IsTeamLeader() == true then
					MoveToNPC(66,58,g_MissionMap,"")
					local sSelect = GetQuestFrameOption(1)
					if sSelect == "뿪þ" then
						OnFighting()
					elseif sSelect == "ٻ˲" then
						QuestFrameOptionClicked( "ٻ˲" , CMP_PART_MATCH)	-- ѡѡ
						QuestFrameOptionClicked( "ȷٻ" , CMP_PART_MATCH)	-- ѡѡ
						System:Sleep(1000)
					else
						System:Sleep(500)	
					end
				else
					OnFighting()
				end
			else
				--
				MoveToNPC(66,58,g_MissionMap,"")
				QuestFrameOptionClicked( "뿪þ" , CMP_PART_MATCH)	-- ѡѡ
				QuestFrameOptionClicked( "ȷ" , CMP_PART_MATCH)	-- ѡѡ
				System:Sleep(2000)
			end			
		end			

		System:Sleep(500)
	end

end

_SMain()
