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 )