ShowMessage("Ʈű $Rev: 212 $")

--[[
[author]
class=1
attr=1
chk0str=Խ
]]--


script_name="սƮ"
local nFubenMapId = 261
local pre_state = "" 
local pre_talk_boss = "" 
local nIgoneLqs = 0

local nSetNoFight = 0

--ڵ㣺 Դ-0 ɣ-1 ϴ-2 ƽ-3 ˮ-4

local l_boss = {
	[""] = INVALID_ID ,
	["ɣ"] = INVALID_ID ,
	["ϴ"] = INVALID_ID ,
	["ƽ"] = INVALID_ID ,
	["׿"] = INVALID_ID ,
	["ƽ"] = INVALID_ID ,
	["ˮ"] = INVALID_ID ,
	[""] = INVALID_ID ,
	["׽ʬ"] = INVALID_ID , 
	["NPC"] = INVALID_ID , 
	["ɣNPC"] = INVALID_ID , 
	["ϴNPC"] = INVALID_ID , 
	["NPC"] = INVALID_ID , 
	["ϴ2NPC"] = INVALID_ID 
}

local l_npc = {
	[""] = {x=124,y=86,qs="ս",name="",next="ɣ",fx=114,fy=94,fight_step=1} ,
	["ɣ"] = {x=41,y=105,qs="ս",name="ɣ",next="ϴ",fx=41,fy=105,fight_step=2} ,
	["ϴ"] = {x=116,y=49,qs="ս",name="ϴ",next="",fx=116,fy=49,fight_step=3} ,
	[""] = {x=158,y=54,qs="սƽ˺׿",name="",next="ϴ2",fx=127,fy=35,fight_step=4} ,
	["ϴ2"] = {x=96,y=40,qs="սˮ",name="ϴ",next="",fx=127,fy=35,fight_step=5}
}

local BOSS_RECORD_INIT = 0
local BOSS_RECORD_MET = 1
local BOSS_RECORD_DEAD = 2

function reset_pmf()
	g_state_pmf = {}
	g_state_pmf[""] = BOSS_RECORD_INIT
	g_state_pmf["ɣ"] = BOSS_RECORD_INIT
	g_state_pmf["ϴ"] = BOSS_RECORD_INIT
	g_state_pmf["ƽ"] = BOSS_RECORD_INIT
	g_state_pmf["ˮ"] = BOSS_RECORD_INIT
end

function can_leave_teamfollow( p_step , param )

	if l_boss[""] ~= INVALID_ID then
		return true
	elseif l_boss["ɣ"] ~= INVALID_ID then
		return true
	elseif l_boss["ϴ"] ~= INVALID_ID then
		return true
	elseif l_boss["ƽ"] ~= INVALID_ID or l_boss["׿"] ~= INVALID_ID or l_boss["ƽ"] ~= INVALID_ID then
		return true
	elseif l_boss["ˮ"] ~= INVALID_ID then
		return true
	end

	if p_step == 1 then
		if IsDestination( 114 , 94 , nFubenMapId  , 3 ) == true or IsDestination( 122 , 94 , nFubenMapId  , 3 ) then
			return true
		end
	elseif p_step == 2 then
		if param == 1 then
			if IsDestination( 72 , 65 , nFubenMapId  , 3 ) == true then
				return true 
			end
		else
			if IsDestination( 41 , 105 , nFubenMapId  , 3 ) == true then
				return true 
			end
		end
	elseif p_step == 3 then
		if IsDestination( 116 , 49 , nFubenMapId  , 3 ) == true then
			return true 
		end
	elseif p_step == 4 then
		if IsDestination( 127 , 35 , nFubenMapId  , 3 ) == true then
			return true 
		end
	elseif p_step == 5 then
		if IsDestination( 125 , 40 , nFubenMapId  , 3 ) == true then
			return true 
		end
	end
	return false 
end

function set_boss_record( name , npc , die )

	if name == "" then
		g_state_pmf["ɣ"] = BOSS_RECORD_INIT
		g_state_pmf["ϴ"] = BOSS_RECORD_INIT
		g_state_pmf["ƽ"] = BOSS_RECORD_INIT
		g_state_pmf["ˮ"] = BOSS_RECORD_INIT
		if npc == true then
			g_state_pmf[""] = BOSS_RECORD_INIT
		else
			if die == true then
				g_state_pmf[""] = BOSS_RECORD_DEAD
			else
				g_state_pmf[""] = BOSS_RECORD_MET
			end
		end
	elseif name == "ɣ" then

		g_state_pmf["ƽ"] = BOSS_RECORD_INIT
		g_state_pmf["ˮ"] = BOSS_RECORD_INIT

		if npc == true then
			g_state_pmf["ɣ"] = BOSS_RECORD_INIT
		else
			g_state_pmf[""] = BOSS_RECORD_DEAD

			if die == true then
				g_state_pmf["ɣ"] = BOSS_RECORD_DEAD
			else
				g_state_pmf["ɣ"] = BOSS_RECORD_MET
			end
		end

	elseif name == "׽ʬ" then
		g_state_pmf[""] = BOSS_RECORD_DEAD
		g_state_pmf["ɣ"] = BOSS_RECORD_MET
		g_state_pmf["ϴ"] = BOSS_RECORD_INIT
		g_state_pmf["ƽ"] = BOSS_RECORD_INIT
		g_state_pmf["ˮ"] = BOSS_RECORD_INIT	
	elseif name == "ϴ" then
		if npc == false then
			g_state_pmf[""] = BOSS_RECORD_DEAD
			g_state_pmf["ɣ"] = BOSS_RECORD_DEAD
			g_state_pmf["ƽ"] = BOSS_RECORD_INIT
			g_state_pmf["ˮ"] = BOSS_RECORD_INIT
			if die == true then
				g_state_pmf["ϴ"] = BOSS_RECORD_DEAD
			else
				g_state_pmf["ϴ"] = BOSS_RECORD_MET
			end
		else
			if die == true then
				-- ϴ2
				g_state_pmf[""] = BOSS_RECORD_DEAD
				g_state_pmf["ɣ"] = BOSS_RECORD_DEAD
				g_state_pmf["ϴ"] = BOSS_RECORD_DEAD
				g_state_pmf["ƽ"] = BOSS_RECORD_DEAD
			end
		end
	elseif name == "ƽ" or name == "׿" or name == "ƽ" then
		g_state_pmf[""] = BOSS_RECORD_DEAD
		g_state_pmf["ɣ"] = BOSS_RECORD_DEAD
		g_state_pmf["ϴ"] = BOSS_RECORD_DEAD
		g_state_pmf["ˮ"] = BOSS_RECORD_INIT
		if die == true then
			g_state_pmf["ƽ"] = BOSS_RECORD_DEAD
		else
			g_state_pmf["ƽ"] = BOSS_RECORD_MET
		end
	elseif name == "ˮ" then
		g_state_pmf[""] = BOSS_RECORD_DEAD
		g_state_pmf["ɣ"] = BOSS_RECORD_DEAD
		g_state_pmf["ϴ"] = BOSS_RECORD_DEAD
		g_state_pmf["ƽ"] = BOSS_RECORD_DEAD	
		if die == true then
			g_state_pmf["ˮ"] = BOSS_RECORD_DEAD
		else
			g_state_pmf["ˮ"] = BOSS_RECORD_MET
		end
	end
end

function get_boss_step()

	if g_state_pmf["ˮ"] == BOSS_RECORD_DEAD then
		return 6 , "ϴ2"
	elseif g_state_pmf["ƽ"] == BOSS_RECORD_DEAD then
		return 5 , "ϴ2"
	elseif g_state_pmf["ϴ"] == BOSS_RECORD_DEAD then
		return 4 , ""
	elseif g_state_pmf["ɣ"] == BOSS_RECORD_DEAD then
		return 3 , "ϴ"
	elseif g_state_pmf[""] == BOSS_RECORD_DEAD then
		return 2 , "ɣ"
	elseif g_state_pmf[""] ~= BOSS_RECORD_DEAD then
		return 1 , ""
	elseif g_state_pmf[""] == BOSS_RECORD_INIT then
		return 1 , ""
	end
		
	return 0 , ""
end


if g_state_pmf == nil then
	reset_pmf()
end

function ResetBoss()
	l_boss[""] = INVALID_ID 
	l_boss["ɣ"] = INVALID_ID 
	l_boss["ϴ"] = INVALID_ID 
	l_boss["ƽ"] = INVALID_ID 
	l_boss["׿"] = INVALID_ID 
	l_boss["ƽ"] = INVALID_ID 
	l_boss["ˮ"] = INVALID_ID 
	l_boss[""] = INVALID_ID
	l_boss["׽ʬ"] = INVALID_ID  
	l_boss["NPC"] = INVALID_ID 
	l_boss["ɣNPC"] = INVALID_ID
	l_boss["ϴNPC"] = INVALID_ID
	l_boss["NPC"] = INVALID_ID
	l_boss["ϴ2NPC"] = INVALID_ID 
end

function IsFuben()
	if GetActiveDataSceneID() ~= nFubenMapId then
		return false 
	end
	return true 
end

function do_except( msg )
	ShowMessage("ű %s" , tostring(msg))
end

function UpdateData()

	if IsFuben() == false then
		return nil , 0
	end

	ResetBoss()

	local n = EnumObject(true)

	for i=0 , n - 1 do
		local idObj, classObj, nameObj, xObj, yObj = EnumObject(false, i)
		if idObj == INVALID_ID then
			continue
		end

		if classObj == "MON" then
			if l_boss[nameObj] ~= nil then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				end
			end
			set_boss_record( nameObj , false , Character:GetData(idObj, "DIE") )
		elseif classObj == "NPC" then
			local s_npc = nameObj.."NPC"

			if nameObj == "ϴ" then
				if IsDestination( 96 , 40 , nFubenMapId  , 3 ) == true  then
					s_npc = "ϴ2NPC"
					set_boss_record( nameObj , true , true )
				else
					set_boss_record( nameObj , true , false )
				end
			else
				set_boss_record( nameObj , true , false )
			end

			if l_boss[s_npc] ~= nil then
				l_boss[s_npc] = idObj
			end
		elseif classObj == "SPECIAL" then
			if nameObj == "" then
				l_boss[""] = idObj
			end
		end
	end

	--öԱǰ׼
	if l_boss[""] ~= INVALID_ID then
		return process_boss_kill , 1
	elseif l_boss["׽ʬ"] ~= INVALID_ID or l_boss["ɣ"] ~= INVALID_ID then
		return process_boss_kill , 2
	elseif l_boss["ϴ"] ~= INVALID_ID then
		return process_boss_kill , 3
	elseif l_boss["ƽ"] ~= INVALID_ID or l_boss["׿"] ~= INVALID_ID or l_boss["ƽ"] ~= INVALID_ID then
		return process_boss_kill , 4
	elseif l_boss["ˮ"] ~= INVALID_ID then
		return process_boss_kill , 5
	elseif l_boss[""] ~= INVALID_ID then
		if g_state_pmf["ˮ"] ~= BOSS_RECORD_DEAD then
			return process_boss_kill , 5
		end
	end

	local isNext,szMsg = GetDebugMessage()
	while isNext == 1 do
		DbgPrintf("dbg msg %s" , tostring(szMsg))
		if szMsg ~= nil then
			if string.find(szMsg,"׿") then
				return process_boss_kill , 4 
			elseif string.find(szMsg,"ˮ") then
				return process_boss_kill , 5
			elseif string.find(szMsg ,"Ӻʼ") then
				if DataPool:IsTeamLeader() == true then
					local vBoss = get_boss_step()

					if IsMsgCold("PMF_CHOOSE_NPCITEM" , 15000) == false then
						if l_npc[pre_talk_boss] ~= nil then
							vBoss = l_npc[pre_talk_boss].fight_step
						end
					end
					if vBoss > 0 and vBoss < 6 then
						return process_boss_kill , vBoss
					else
						PushDebugMessage( "޷λǰboss..." , 1 )
					end
				end
			end
		end
		isNext,szMsg = GetDebugMessage()
	end

	return nil , 0
end

function process_exit()
	MoveToNPC( 96 , 40 , nFubenMapId ,"ϴ" )
	Dismount()

	System:Sleep(500)
	if FindQuestFrameOption( "뿪翷" , CMP_PART_MATCH) == true then
		QuestFrameOptionClicked("뿪翷", CMP_PART_MATCH)
		QuestFrameOptionClicked("ȷ뿪", CMP_PART_MATCH)
	end
end

function process_boss_kill( p_step )

	g_step_sss = p_step
	SetEvent( "EVENT_PICKUP" , 0 )
	UpdateMsg("Quest_PMF_Begin")

	local bRangeAttack = Player:IsRangeAttack()
	local pos , menpai = GetTeamStandPos()
	if pos < 0 then
		pos = 0
	end

	AI:SetAdv( "" )

	local step2_pos = 0 
	local stg_pre = INVALID_ID

	if p_step == 1 then
		if pos == 1 then
			AI:SetAdv( "Ȧ" , 114 , 94 , 5 )
		else
			AI:SetAdv( "Ȧ" , 122 , 94 , 9 )
		end
	elseif p_step == 2 then
		AI:SetAdv( "Ȧ" , 41 , 105 , 8 )
	elseif p_step == 3 then
		AI:SetAdv( "Ȧ" , 116 , 49 , 6 )
	elseif p_step == 4 then
		AI:SetAdv( "Ȧ" , 127 , 35 , 6 )
	elseif p_step == 5 then
		AI:SetAdv( "Ȧ" , 125 ,  40 , 3 )
	end

	AI:SetAI("߼ս") 
	AI:SetParameter("ͼ" , nFubenMapId ) 
	AI:Start()

	local result = nil
	local r_param

	while true do

		local bPickUp = 1
		local bKillMonster = 1
		local bYinGuai = 0
		local bTeamFollow = 0 
		local bTeamAttack = 0 
		local bStopAssistSelf = 0 
		local bStopAssist = 0
		local bStopSpecialAttack = 0 
		local bCallPet = 1
		local bYinshen = 0 
		local bFixPlace = 0
		local bSpeedUp = 0

		local FingerAttack = -1
		local FingerAttackName = ""
		local FollowTarget = -1

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

		System:Sleep(500)

		if AI:IsStop() == true then
			break
		end

		local isNext,szMsg = GetDebugMessage()
		while isNext == 1 do
			if szMsg ~= nil then
				if string.find(szMsg,"׿") or string.find(szMsg,"Ӻʼ") then
					UpdateMsg("Quest_PMF_Begin")
				end
				isNext,szMsg = GetDebugMessage()
			end
		end

		result , r_param = UpdateData()

		if result ~= process_boss_kill or r_param ~= p_step then
			local nWait = 5000
			if p_step == 2 then
				if step2_pos == 1 then
					nWait = 32000
				else
					nWait = 8000
				end
			end

			if IsMsgCold("Quest_PMF_Begin" , nWait ) then
				break
			elseif p_step == 1 and g_state_pmf[""] == BOSS_RECORD_DEAD then
				break 
			elseif p_step == 2 and g_state_pmf["ɣ"] == BOSS_RECORD_DEAD then
				break 
			elseif p_step == 3 and g_state_pmf["ϴ"] == BOSS_RECORD_DEAD then
				break 
			elseif p_step == 4 and g_state_pmf["ƽ"] == BOSS_RECORD_DEAD then
				break 
			elseif p_step == 5 then
				if g_state_pmf["ˮ"] == BOSS_RECORD_DEAD and GetEvent("EVENT_PICKUP" , 0) == 1 then
					break 
				else
					--ߵһ
					if IsDestination( 125 , 40 , nFubenMapId , 3 ) == false then
						UpdateMsg("Quest_PMF_Begin")
					end
				end
			end
		else
			UpdateMsg("Quest_PMF_Begin")
		end

		if p_step == 2 then
			if l_boss["ɣ"] == INVALID_ID and stg_pre ~= INVALID_ID then
				step2_pos = step2_pos + 1 
				bTeamFollow = 1
				if step2_pos == 1 then
					Player:EnableTeamFollow(true)
					AI:SetAdv( "Ȧ" , 72 , 65 , 8 )
				end
			end 
			stg_pre = l_boss["ɣ"]
		end

		if l_boss["ɣ"] ~= INVALID_ID or l_boss["׽ʬ"] ~= INVALID_ID then
			AI:SetAdv("ָɱ" , 0 , "ɣ" )
		elseif l_boss["ƽ"] ~= INVALID_ID then
			AI:SetAdv("ָɱ" , 0 , "ƽ" )
		else
			AI:SetAdv("ָɱ" , -1 , "" )
		end

		if l_boss[""] ~= INVALID_ID then
			if CheckBufferByName( l_boss[""] , "֮ʹ") ~= INVALID_ID then
				AI:SetAdv("в" , l_boss[""] , 5 , "" )
				if bRangeAttack == false then
					bKillMonster = 0 
					PushDebugMessage("սְҵͣ" , 1)
				end
			else
				AI:SetAdv("ɾв" , "" )
			end

			--CheckBufferByName( l_boss[""] , "˿֮ʹ")

			if INVALID_ID ~= Player:GetBuffByName("") then 
				bKillMonster = 0
			end

			if menpai == 4 then
				bYinshen = 1
			end
		else
			AI:SetAdv("ɾв" , "" )
		end

		if l_boss["ϴ"] ~= INVALID_ID then
			if pos ~= 1 then 
				local nDefencePoison = Player:GetData("DEFENCEPOISON")
				if nDefencePoison < 60 then
					bYinshen = 1
					if nHPPercent < 65 then
						bKillMonster = 0 
						PushDebugMessage("60,Ϊⱻֹͣ" , 1)
					end
				end
			end
		end


		if IsMsgCold("Quest_PM_lqs" , 15000 ) == false  and nIgoneLqs == 0 then

			local main_x = 125
			local main_y = 40
			if pre_state == "" then
				main_x = 114
				main_y = 28
			elseif pre_state == "̹ǵĺ" then
				main_x = 136
				main_y = 28
			elseif pre_state == "֮" then
				main_x = 147
				main_y = 48
			elseif pre_state == "" then
				main_x = 135
				main_y = 66
			elseif pre_state == "   " then
				main_x = 114
				main_y = 66
			else
				--""
				main_x = 102
				main_y = 47
			end

			AI:SetAdv( "Ȧ" , tonumber(main_x) , tonumber(main_y) , 2 )
			UpdateMsg("Quest_PMF_Begin")

			bPickUp = 0
			bKillMonster = 0 
			bCallPet = 0
			bFixPlace = 1
			bSpeedUp = 1

			if INVALID_ID == Player:GetBuffByName("") then
				bStopAssist = 1
				bStopAssistSelf = 1

				if menpai == MENPAI_EMEI and nHPPercent < 60 then
					if INVALID_ID == Player:GetBuffByName("ľ") then
						AI:SetParameter("в" , "ʹü" , "ľ" , "" )
					end
				end
			end
		else
			if p_step == 5 then
				AI:SetAdv( "Ȧ" , 125 , 40 , 2 )
			end
		end

		local nMsgChannel = -1
		while true do 
			local channel, time, name, data = GetChatMsg()
	
			if channel == INVALID_ID then 
				break 
			end

			local now = System:timeGetTime()
			--channel == 0 and
			if now < time + 5 then

				if string.find(data, "") then
					pre_state = ""
					UpdateMsg("Quest_PM_lqs")
					nMsgChannel = channel 
				end

				if string.find(data, "̹ǵĺ") then
					pre_state = "̹ǵĺ"
					UpdateMsg("Quest_PM_lqs")
					nMsgChannel = channel
				end

				if string.find(data, "֮") then
					pre_state = "֮"
					UpdateMsg("Quest_PM_lqs")
					nMsgChannel = channel
				end

				if string.find(data, "") then
					pre_state = ""
					UpdateMsg("Quest_PM_lqs")
					nMsgChannel = channel
				end

				if string.find(data, "׺䶥") then
					pre_state = "   "
					UpdateMsg("Quest_PM_lqs")
					nMsgChannel = channel
				end

				if string.find(data, "") then
					pre_state = ""
					UpdateMsg("Quest_PM_lqs")
					nMsgChannel = channel
				end
			end
		end

		if nMsgChannel == 0 then
			local sMsg = "ǰ => "..pre_state
			Shout( "team" , sMsg )
		end


		--ԼѪ,ұʱ,ֹͣ
		if pos == 0 and menpai == 4 then
			bYinshen = 1

			if nHPPercent < 60 or nMPPercent < 15 then
				bKillMonster = 0
				PushDebugMessage(",ͣ" , 1)
			end
		end

		if p_step == 2 then
			bTeamFollow = 1
			local _,LeaderId,_,Leader_mapid,Leader_x,Leader_y = DataPool:GetTeamMemInfo(-1)
			local t_followleader = false
			if LeaderId ~= Player:GetData("ID") then
				t_followleader = Player:CompareLocalArea( Leader_mapid , Leader_x , Leader_y )
				if t_followleader == true then
					FollowTarget = LeaderId
				else
					FollowTarget = -1
				end
			else
				FollowTarget = -1
			end
		else
			FollowTarget = -1
		end

		if Player:GetBuffByName("ʧ" , 1) ~= INVALID_ID then
			bKillMonster = 0
			bTeamFollow = 0
			bTeamAttack = 0
			bStopAssist = 1
		end

		if nSetNoFight > 0 then
			bKillMonster = 0 
			bYinGuai = 0 
			bTeamAttack = 0 
			bYinshen = 1
			bStopAssist = 1
		end

		if p_step == 5 then
			if INVALID_ID ~= Player:GetBuffByName("޷ʹκι") then
				bFixPlace = 1
			end
		end

		if can_leave_teamfollow( p_step , step2_pos ) == true then
			Player:EnableTeamFollow(false)
		end

		AI:SetParameter("в" , "" , 1 )
		AI:SetParameter("ʰȡ" , bPickUp )
		AI:SetParameter("в" , "ɱ" , bKillMonster )
		AI:SetParameter("в" , "" , bYinGuai )
		AI:SetParameter("в" , "Ӹ" , bTeamFollow )
		AI:SetParameter("в" , "" , bTeamAttack )
		AI:SetParameter("в" , "ֹܸͣ" , bStopAssistSelf )
		AI:SetParameter("в" , "ֹͣ" , bStopAssist )
		AI:SetParameter("в" , "ֹͣ⹥" , bStopSpecialAttack )
		AI:SetParameter("в" , "ٻ" , bCallPet )

		AI:SetAdv("" , FollowTarget , 3 )
		AI:SetAdv("" , bYinshen )
		AI:SetAdv("Ȧ" , bFixPlace )
	end

	AI:Stop()

	OnSweepBattleField()

	-- nil,""
	return nil , nil
end

function _callback(fX, fY, nScene)

	--¸npc жԻ
	local result , param = UpdateData()
	if result == nil or result == process_npc_t then
		if DataPool:IsTeamLeader() == true and GetMount() ~= INVALID_ID then
			Player:EnableTeamFollow(true)
		end
		return true 
	end

	return false
end

function _breakmove_infuben(fX , fY , nScene )

	if IsFuben() == false then
		return true
	end

	return false
end

function is_process_npc()

	if UI:IsWindowShow("Quest") == false then 
		return false , ""
	end
	
	if l_boss["NPC"] ~= INVALID_ID then
		return  true , ""
	elseif l_boss["ɣNPC"] ~= INVALID_ID then
		return true , "ɣ"
	elseif l_boss["ϴNPC"] ~= INVALID_ID then
		return true , "ϴ"
	elseif l_boss["NPC"] ~= INVALID_ID then
		return true , ""
	elseif l_boss["ϴ2NPC"] ~= INVALID_ID then
		return true , "ϴ2"
	end

	return false , ""
end

function move_npc( p_npc )

	local s_npc = p_npc.."NPC"

	if IsDestination( l_npc[p_npc].x , l_npc[p_npc].y , nFubenMapId  , 3 ) == true  then

		UpdateData()
		if l_boss[s_npc] == INVALID_ID then
			--npc
			return move_npc , l_npc[p_npc].next
		end
	end

	if p_npc ~= "ϴ2" then
		MoveToNPC( l_npc[p_npc].x , l_npc[p_npc].y , nFubenMapId , l_npc[p_npc].name , true , false , _callback )
	else
		MoveToNPC( l_npc[p_npc].x , l_npc[p_npc].y , nFubenMapId , l_npc[p_npc].name )
	end

	return move_npc , p_npc
end
		
function process_npc_t( p_npc )

	--ֻnpcԻ
	local s_npc = p_npc.."NPC" 

	--Dismount()

	while true do 

		System:Sleep(500)

		local result , v_npc = UpdateData()
		if result ~= nil then
			--Ҫ
			QuestFrameMissionClose()
			return result , v_npc
		end

		if l_boss[s_npc] == INVALID_ID then
			return nil , nil
		end

		local list_count , npc_id = DataPool:GetNPCEventList_Num()
		if npc_id ~= l_boss[s_npc] then
			return nil , nil 
		end

		if list_count < 1 then
			-- ѡ
		else
			local t_click = ""
			for i=0, list_count - 1 do
				local strType,_,_,_,szText = DataPool:GetNPCEventList_Item(i)
				if strType == "text" then
					if string.find(szText, "ȥҹ") then
						QuestFrameMissionClose()
						return move_npc , ""
					elseif string.find(szText, "ϴ") then
						--ûսѡ,
						--[8180]     =>    ɽҪͷˣǸϴ֪λǺܶãɷʩԮ־Ⱦɽأ
					elseif string.find(szText, "Ҷ") then
						QuestFrameMissionClose()
						return move_npc , "ɣ"
					elseif string.find(szText, "Ȼ") then
					end
				elseif strType == "id" then
					if string.find(szText , "սƽ˺׿") then
						set_boss_record( "ƽ" , false , false )
						t_click = "սƽ˺׿"
					elseif string.find(szText , "սˮ") then
						set_boss_record( "ˮ" , false , false )
						t_click = "սˮ"
					elseif string.find(szText , "ս") then
						if p_npc == "" then
							set_boss_record( "" , true , false )
						elseif p_npc == "ɣ" then
							set_boss_record( "ɣ" , true , false )
						elseif p_npc == "ϴ" then
							set_boss_record( "ϴ" , true , false )
						end

						t_click = "ս"
					elseif string.find(szText , "뿪翷") then
						if t_click == "" then
							t_click = "뿪翷"	
						end
					elseif string.find(szText , "ȷ뿪") then
						t_click = "ȷ뿪"	
					end
				end
			end
			
			if t_click == "" then
				--ûкѡ
				QuestFrameMissionClose()
				return move_npc , l_npc[p_npc].next 
			else
				UpdateMsg("PMF_CHOOSE_NPCITEM")
				pre_talk_boss = p_npc
				QuestFrameOptionClicked( t_click , CMP_PART_MATCH)
				System:Sleep(500)
			end	
		end
	end

end


function FindProcess()

	local step , npc = get_boss_step()
	if step == 6 then
		return process_exit, ""
	elseif step > 0 then
		return move_npc, npc
	else
		return move_npc, npc
	end
end

function OnSearch_Member()

	AI:SetAI("ɱ")	
	AI:SetParameter("ʼ")
	AI:SetParameter("ʰȡ", 0)
	AI:SetParameter("ͼ", nFubenMapId )

	AI:Start()
	AI:SetParameter("в" ,"Ӹ", 1)
	AI:SetParameter("в" ,"ɱ", 0)
		
	while true do

		System:Sleep(1000)

		if IsFuben() == false then
			break 
		end

		local process , param = UpdateData()

		local l_follow = false
		if DataPool:IsTeamLeader() == false then
			if process == nil or process == process_npc_t then
				l_follow = true 
			end
		end

		if l_follow == false then
			break 
		end
	end

	AI:Stop()

end

function _SMain()

	nSetNoFight = GetScriptParam( script_name , "attr" , SCRIPT_ATTR_NOFIGHT )
	nIgoneLqs = gscript_check( 0 , 0 , 1 )

	LogChatMsg(0)
	LogChatMsg(1)

	local task = nil 
	local task_param = nil
	local check_quest = false

	while true do

		System:Sleep(500) 

		if IsFuben() == true then

			check_quest = false
			
			local process , param = UpdateData()

			local l_follow = false
			if DataPool:IsTeamLeader() == false and FindProcess() ~= process_exit then
				if process == nil or process == process_npc_t then
					l_follow = true 
				end
			end

			if l_follow == true then
				task = nil 
				task_param = nil
				OnSearch_Member()
			else
				if process~= nil then
					task , task_param = process(param)
				else
					local is_talk , npc_name = is_process_npc()
					if is_talk == true then
						task , task_param = process_npc_t( npc_name )
					else
						if task ~= nil then
							task , task_param = task( task_param )
						else
							task , task_param = FindProcess()
						end
					end
				end
			end

		else
			--Ұ
			reset_pmf()

			if check_quest == false then
				if GetQuestTimesInfo("¥") == 0 and IsFuben()== false then
					ShowMessage("Ѿɴ翸!")
					break 
				end
			end
	
			check_quest = true 

			MoveToNPC(191, 223, 246, "˪" , true , true , _breakmove_infuben )
			if DataPool:IsTeamLeader() == true or DataPool:GetTeamMemCount() == 0 then
				if DataPool:GetTeamMemCount() < 3 and IsFuben()== false then
					ShowMessage("С 3 ,ִ 翷帱")
					return
				end
			end

			if DataPool:IsTeamLeader() == true then
				QuestFrameOptionClicked("ս翷", CMP_FULL_MATCH)

				local strType,_,_,_,szText = DataPool:GetNPCEventList_Item(0)

				if strType == "text" then
					if string.find(szText, "") then
						ShowMessage(",ֹű!")
						break	-- ˳ѭű
					end
				end
			end

			System:Sleep(2000)
		end

	end

	LogChatMsg(-1)

end

AI:SetMode("ͣͼ" , nFubenMapId )
_SMain()
AI:SetMode("ͣͼ" , -1 )