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

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


script_name="սƮ"
local g_MissionMap = 261
local g_VirtualBoss = "ǷĿ"
local pre_state = "" 

local fuben_process_do = 0
local fuben_process_chk = 0 

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

local g_boss = {
	[""] = 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 ,
	["׿NPC"] = INVALID_ID ,
	["ƽNPC"] = INVALID_ID ,
	["ˮNPC"] = INVALID_ID ,
	["NPC"] = INVALID_ID , 
	["׽ʬ"] = INVALID_ID , 
	["ǷĿ"] = INVALID_ID 
}

local g_Process =
{
	[0] = { npc="" , x=124 , y=86 , fight_boss="" } ,
	[1] = { npc="ɣ" , x=41 , y=105 , fight_boss="ɣ" } ,
	[2] = { npc="ϴ" , x=116 , y=49 , fight_boss="ϴ"} ,
	[3] = { npc="" , x=158 , y=54 , fight_boss="ƽ"} ,
	[4] = { npc="ϴ" , x=96 , y=40  , fight_boss ="ˮ"} ,
	[5] = { npc="ϴ" , x=96 , y=40  , fight_boss =""}
--սƽ˺׿
-- 125,33 ƽ ׿ ƽ
-- 98,38 Ի ϴ  ѡ սˮ
-- 120 41 Ըˮ
-- Իϴ 뿪Ʈ ȷ뿪
}


function UpdateBossInfo()

	g_boss[""] = INVALID_ID 
	g_boss["ɣ"] = INVALID_ID 
	g_boss["ϴ"] = INVALID_ID 
	g_boss["ƽ"] = INVALID_ID 
	g_boss["׿"] = INVALID_ID 
	g_boss["ƽ"] = INVALID_ID 
	g_boss["ˮ"] = INVALID_ID 
	g_boss["NPC"] = INVALID_ID 
	g_boss["ɣNPC"] = INVALID_ID 
	g_boss["ϴNPC"] = INVALID_ID 
	g_boss["ƽNPC"] = INVALID_ID 
	g_boss["׿NPC"] = INVALID_ID 
	g_boss["ƽNPC"] = INVALID_ID 
	g_boss["ˮNPC"] = INVALID_ID 
	g_boss["NPC"] = INVALID_ID 
	g_boss["׽ʬ"] = INVALID_ID 
	g_boss["ǷĿ"] = INVALID_ID 

	
	local n = EnumObject(true)
	local pre_do = fuben_process_do

	for i=0, n - 1 do
		local idObj, classObj, nameObj, xObj, yObj = EnumObject(false, i)
		if idObj ~= INVALID_ID then
			if nameObj == "" then
				if classObj == "MON" then
					if Character:GetData(idObj, "DIE") == false then
						g_boss[""] = idObj
						fuben_process_do = 0 
					else
						fuben_process_do = 1
					end
				elseif classObj == "NPC" then
					g_boss["NPC"] = idObj
					fuben_process_do = 0
				end
			elseif nameObj == "ɣ" then 
				if classObj == "MON" then
					if Character:GetData(idObj, "DIE") == false then
						g_boss["ɣ"] = idObj
						fuben_process_do = 1
					else
						fuben_process_do = 2
					end
				elseif classObj == "NPC" then
					g_boss["ɣNPC"] = idObj

					if fuben_process_do > 1 then
						fuben_process_do = 0
					end
				end
			elseif nameObj == "ϴ" then 
				if classObj == "MON" then
					if Character:GetData(idObj, "DIE") == false then
						g_boss["ϴ"] = idObj
						fuben_process_do = 2
					else
						fuben_process_do = 3 
					end
				elseif classObj == "NPC" then
					g_boss["ϴNPC"] = idObj
				end
			elseif nameObj == "ƽ" then
				if classObj == "MON" then
					if Character:GetData(idObj, "DIE") == false then
						g_boss["ƽ"] = idObj
						fuben_process_do = 3 
					else
						if fuben_process_do < 3 then
							fuben_process_do = 3 
						end
					end
				elseif classObj == "NPC" then
					g_boss["ƽNPC"] = idObj
				end
			elseif nameObj == "׿" then
				if classObj == "MON" then
					if Character:GetData(idObj, "DIE") == false then
						g_boss["׿"] = idObj
						fuben_process_do = 3
					else
						if fuben_process_do < 3 then
							fuben_process_do = 3 
						end
					end
				elseif classObj == "NPC" then
					g_boss["׿"] = idObj
				end
			elseif nameObj == "ƽ" then
				if classObj == "MON" then
					if Character:GetData(idObj, "DIE") == false then
						g_boss["ƽ"] = idObj
						fuben_process_do = 3
					else
						fuben_process_do = 4
					end
				elseif classObj == "NPC" then
					g_boss["ƽNPC"] = idObj
				end
			elseif nameObj == "ˮ" then
				if classObj == "MON" then
					if Character:GetData(idObj, "DIE") == false then
						g_boss["ˮ"] = idObj
						fuben_process_do = 4
					else
						fuben_process_do = 5 
					end
				elseif classObj == "NPC" then
					g_boss["ˮNPC"] = idObj
				end
			elseif nameObj == "׽ʬ" and Character:GetData(idObj, "DIE") == false then
				g_boss["׽ʬ"] = idObj
				fuben_process_do = 1
				--AI:SetAdv("в" , idObj , 4 )
			elseif nameObj == "" and classObj == "NPC" then
				g_boss["NPC"] = idObj
			end
		end
	end

	--öԱǰ׼
	if IsMsgCold("Quest_PM_VirtualBoss" , 10000) == false then
		if g_VirtualBoss ~= "ǷĿ" and g_boss[g_VirtualBoss] == INVALID_ID then
			g_boss[g_VirtualBoss] = INVALID_ID -1 
			DbgPrintf("boss %s" , tostring(g_VirtualBoss))
		end
	else
		g_VirtualBoss = "ǷĿ"
	end

	if pre_do ~= fuben_process_do then
		fuben_process_chk = fuben_process_do
	end
end

-- 0,  1,ս  2,
function CheckProcess()

	UpdateBossInfo()
	
	if g_boss[""] ~= INVALID_ID then
		return 1,0
	elseif g_boss["ɣ"] ~= INVALID_ID or g_boss["׽ʬ"] ~= INVALID_ID then
		return 1,1
	elseif g_boss["ϴ"] ~= INVALID_ID then
		return 1,2
	elseif g_boss["׿"] ~= INVALID_ID or g_boss["ƽ"] ~= INVALID_ID or g_boss["ƽ"] ~= INVALID_ID then
		return 1,3
	elseif g_boss["ˮ"] ~= INVALID_ID then
		return 1,4
	end

	if fuben_process_do > 4 then
		return 3,5
	end

	if g_boss["NPC"] ~= INVALID_ID then
		return 2,0
	elseif g_boss["ɣNPC"] ~= INVALID_ID then
		return 2,1
	elseif g_boss["ϴNPC"] ~= INVALID_ID then
		local npc_id , npc_x , npc_y = FindObjectByID( g_boss["ϴNPC"], "NPC" )
		if GetDist( npc_x , npc_y , 95 , 39 ) < 3 then
			return 2,4
		end
		return 2,2
	elseif g_boss["NPC"] ~= INVALID_ID then
		return 2,3
	end
	
	return 0,0
end

function OnProcessBoss( nProcess_do )

	local pos , menpai = GetTeamStandPos()
	AI:SetAI("߼ս") 
	AI:SetParameter("ͼ" , g_MissionMap)

	local main_x , main_y = Player:GetPos()
	local main_r = 5
	local bRangeAttack = Player:IsRangeAttack()

	if nProcess_do == 0 then
		if pos ~= 1 then
			main_x = 114
			main_y = 94
			main_r = 5
		else
			main_x = 122
			main_y = 94
			main_r = 9
		end
	elseif nProcess_do == 1 then
		main_x = 47
		main_y = 115
		main_r = 8
	elseif nProcess_do == 2 then
		if pos == 1 then 
			main_x = 111
			main_y = 49
			main_r = 6
		else
			main_x = 110
			main_y = 54
			main_r = 6
		end
	elseif nProcess_do == 3 then
		main_x = 127
		main_y = 35
		main_r = 6
	elseif nProcess_do == 4 then
		main_x = 125
		main_y = 40
		main_r = 3
	end

	AI:SetAdv("Ȧ" , main_x , main_y , main_r )
	AI:Start()
	Dismount()
	local nPos = 0 

	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

		System:Sleep(300)

		-- Ѫ  ﵱǰ 70% ʱٻ
		-- ˹  ﵱǰѪ 70% ʱٻ
		local nHPPercent = Player:GetData("HP_PERCENT")
		local nMPPercent = Player:GetData("MP_PERCENT")
		if nHPPercent < 70 then
			if IsSkillSetUse(686) or IsSkillSetUse(687) then
				bCallPet = 1
			end
		end

		if nMPPercent < 70 then
			if IsSkillSetUse(696) or IsSkillSetUse(697) then
				bCallPet = 1
			end
		end	

		local nType , nStep = CheckProcess()

		UpdateBossInfo()

		if IsMsgCold("Quest_PM_lqs" , 15000 ) == false 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_PM_Complete")

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

			local nHpPercent = Player:GetData("HP_PERCENT")
			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

			-- սص
			local main_x , main_y = Player:GetPos()
			local main_r = 5

			if nProcess_do == 0 then
				if pos ~= 1 then
					main_x = 114
					main_y = 94
					main_r = 5
				else
					main_x = 122
					main_y = 94
					main_r = 9
				end
			elseif nProcess_do == 1 then
				main_x = 47
				main_y = 115
				main_r = 8
			elseif nProcess_do == 2 then
				if pos == 1 then 
					main_x = 111
					main_y = 49
					main_r = 6
				else
					main_x = 110
					main_y = 54
					main_r = 6
				end
			elseif nProcess_do == 3 then
				main_x = 127
				main_y = 35
				main_r = 6
			elseif nProcess_do == 4 then
				main_x = 125
				main_y = 40
				main_r = 3
			end

			AI:SetAdv("Ȧ" , main_x , main_y , main_r )

			--ݲͬbossвͬĲ

			if g_boss[""] ~= INVALID_ID then

				if pos ~= 1 then
					bYinshen = 1				
				end

				local iPos,_,_ = CheckBufferByName( g_boss[""] , "֮ʹ")
				if INVALID_ID ~= iPos then
					AI:SetAdv("Ȧ" , 122 , 94 , 9 )
					AI:SetAdv("в" , g_boss[""] , 5 , "" )
					if bRangeAttack == false then
						bKillMonster = 0
					end
				else
					AI:SetAdv("ɾв" , "" )
					local iPos,_,_ = CheckBufferByName( g_boss[""] , "˿֮ʹ")
					if INVALID_ID ~= iPos then
						if INVALID_ID ~= Player:GetBuffByName("") then 
							bKillMonster = 0
						end
					end
				end

				if pos ~= 1 and Player:GetData("HP_PERCENT") < 60 then
					bKillMonster = 0
				end

				if menpai == MENPAI_GAIBANG then
					if INVALID_ID == Player:GetBuffByName("սҰ") then
						AI:SetParameter("в" , "ʹü" , "սҰ" , "" )
					else
						AI:SetAdv("ɾв" , "" )
						bKillMonster = 1
					end
				end

				if pos == 0 and menpai == 4 then
					bYinshen = 1
					bKillMonster = 0
				end

				UpdateMsg("Quest_PM_Complete")

			elseif g_boss["ɣ"] ~= INVALID_ID or g_boss["׽ʬ"] ~= INVALID_ID then

				if pos ~= 2 then 
					bYinshen = 1
				end

				if g_boss["ɣ"] == INVALID_ID then
					--
					bKillMonster = 0 
					bCallPet = 0

					if pos == 2 then
						-- ɣ Ȧ 48,108  38,111  44,121   52,114
						if nPos == 0 then
							MoveTo( 48 , 108 , g_MissionMap )
							AI:Start()
						elseif nPos == 1 then
							MoveTo( 38 , 111 , g_MissionMap )
							AI:Start()
						elseif nPos == 2 then
							MoveTo( 44 , 121 , g_MissionMap )
							AI:Start()
						elseif nPos == 3 then
							MoveTo( 52 , 114 , g_MissionMap )
							AI:Start()
						else
							nPos = -1
						end

						nPos = nPos + 1
					end
				else
					FingerAttack = g_boss["ɣ"]
					FingerAttackName = "ɣ"
				end

				UpdateMsg("Quest_PM_Complete")

			elseif g_boss["ϴ"] ~= INVALID_ID then

				if pos ~= 1 then 
					local nDefencePoison = Player:GetData("DEFENCEPOISON")
					local nHpPercent = Player:GetData("HP_PERCENT")
					if nDefencePoison < 60 then
						bYinshen = 1
						if nHpPercent < 65 then
							bKillMonster = 0 
						end
					end

					if pos == 0 and menpai == 4 then
						bKillMonster = 0
					end
				end

				UpdateMsg("Quest_PM_Complete")

			elseif g_boss["ƽ"] ~= INVALID_ID or g_boss["׿"] ~= INVALID_ID or g_boss["ƽ"] ~= INVALID_ID then

				if g_boss["ƽ"] ~= INVALID_ID then
					FingerAttack = g_boss["ƽ"]
					FingerAttackName = "ƽ"
				end

				UpdateMsg("Quest_PM_Complete")			
		
			elseif g_boss["ˮ"] ~= INVALID_ID then

				if INVALID_ID ~= Player:GetBuffByName("޷ʹκι") then
					bKillMonster = 0
				end

				bFixPlace = 1

				UpdateMsg("Quest_PM_Complete")
			
			else
				--Ҳboss
				local self_x , self_y = Player:GetPos()
				if GetDist( self_x , self_y , main_x , main_y ) > 3 then
					UpdateMsg("Quest_PM_Complete")
				else
					--ûصȫ
					if IsMsgCold("Quest_PM_Complete" , 5000 ) then
						break
					else
						PushDebugMessage("׼ǰһboss !" , 1)
					end
				end
			end
		end

		if GetActiveDataSceneID() ~= g_MissionMap then
			break 
		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

		--жԼǷ
--[[		local nPetID = Player:GetFightingPetID()
		if nPetID ~= INVALID_ID then
			local iPos,_,_ = CheckBufferByName( nPetID, "")
			if INVALID_ID ~= iPos then
				bCallPet = 0
			end
		end
]]--		


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

			if nHPPercent < 60 or nMPPercent < 15 then
				bKillMonster = 0
			end
		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("в" , "üټ" , bSpeedUp )
		AI:SetParameter("в" , "ֹͣ⹥" , bStopSpecialAttack )
		AI:SetParameter("в" , "ٻ" , bCallPet )

		AI:SetAdv("" , FollowTarget , 3 )
		--AI:SetAdv("Ȧ뾶" , mainguard_r )
		AI:SetAdv("" , bYinshen )
		AI:SetAdv("Ȧ" , bFixPlace )

		if pre_FingerAttack ~= FingerAttack then
			AI:SetAdv("ָɱ" , -1 , "" )
			pre_FingerAttack = INVALID_ID
		end
		
		if FingerAttack ~= INVALID_ID then
			AI:SetAdv("ָɱ" , FingerAttack , FingerAttackName )
			pre_FingerAttack = FingerAttack
		end
	end

	AI:Stop()
end
			

function OnNpcEvent( nProcess_chk )

	MoveToNPC( g_Process[nProcess_chk].x , g_Process[nProcess_chk].y , g_MissionMap , g_Process[nProcess_chk].npc )

	DbgPrintf("on npc %d" , tonumber(nProcess_chk))

	if nProcess_chk < 3 then
		QuestFrameOptionClicked("ս", CMP_FULL_MATCH)
	elseif 3 == nProcess_chk then
		QuestFrameOptionClicked("սƽ˺׿", CMP_FULL_MATCH)
	elseif 4 == nProcess_chk then
		QuestFrameOptionClicked("սˮ", CMP_PART_MATCH)
	else
		QuestFrameOptionClicked("뿪翷", CMP_PART_MATCH)
		QuestFrameOptionClicked("ȷ뿪", CMP_PART_MATCH)
	end

	if nProcess_chk > 4 then
		return
	end

	local sWait = 1 

	while true do

		System:Sleep(1000)

		local sWaitBoss = false
		local isNext,szMsg = GetDebugMessage()
		while isNext == 1 do
			DbgPrintf("dbg msg %s" , tostring(szMsg))
			if szMsg ~= nil then
				if string.find(szMsg ,"Ӻʼ") or string.find(szMsg,"׿") then
					g_VirtualBoss = g_Process[nProcess_chk].fight_boss
					sWaitBoss = true 
					UpdateMsg("Quest_PM_VirtualBoss")						
				end
			end
			isNext,szMsg = GetDebugMessage()
		end
		
		if sWait > 3 then 
			break
		end

		if sWaitBoss == false then
			local list_count = DataPool:GetNPCEventList_Num()
			local strType,_,_,_,szText = DataPool:GetNPCEventList_Item(0);

			if strType == "text" then
				if string.find(szText, "ȥҹ") then
					ShowMessage("ȥҹ!")
					fuben_process_chk = 0 
					break
				elseif string.find(szText, "ϴ") then

					fuben_process_chk = 2
					strType,_,_,_,szText = DataPool:GetNPCEventList_Item(1)
					if strType == "id" then
						if string.find(szText , "սƽ˺׿") then
							fuben_process_chk = 3
						end
					end

					if fuben_process_chk == 2 then 
						ShowMessage("ȥϴ!")
					end
					
					break
				elseif string.find(szText, "Ҷ") then
					ShowMessage("ȥɣ!")
					fuben_process_chk = 1
					break
				elseif string.find(szText, "Ȼ") then

					fuben_process_chk = 3
					strType,_,_,_,szText = DataPool:GetNPCEventList_Item(1)
					if strType == "id" then

						if string.find(szText , "սˮ") then
							fuben_process_chk = 4
						elseif string.find(szText , "뿪翷") then
							fuben_process_chk = 5
						end
					end

					if fuben_process_chk == 3 then 
						ShowMessage("ȥҷ!")
					end
					
					break
				end
			end
		end
	
		UpdateBossInfo()

		if g_boss[g_Process[nProcess_chk].npc] ~= INVALID_ID then
			ShowMessage("boss")
			break
		end

		sWait = sWait + 1

	end
		
end


function OnSearch_Member()

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

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

		System:Sleep(1000)
		if DataPool:IsTeamLeader() == true then
			break
		end

		if GetActiveDataSceneID() ~= g_MissionMap then
			break 
		end

		local isNext,szMsg = GetDebugMessage()
		while isNext == 1 do
			DbgPrintf("dbg msg %s" , tostring(szMsg))
			if szMsg ~= nil then
				if string.find(szMsg ,"Ӻʼ") then
					-- g_VirtualBoss = check_npc
					-- ӳĸboss
					local _,_,_,leader_mapid,leader_x,leader_y = DataPool:GetTeamMemInfo(-1)
					local vDistance = 999999
					local vBoss = "ǷĿ"

					for i,v in pairs(g_Process) do
						local this_distance = GetDist( leader_x , leader_y , v.x , v.y )
						if this_distance < vDistance then
							vDistance = this_distance
							vBoss = v.fight_boss
						end							 
					end

					if vBoss ~= "ǷĿ" then
						g_VirtualBoss = vBoss
						UpdateMsg("Quest_PM_VirtualBoss")
					end					
				end
			end
			isNext,szMsg = GetDebugMessage()
		end

		local nType , nStep = CheckProcess()
		if nType == 1 or nType == 3 then
			-- npc  npc , Ӹ
			break
		end

	end

end

local first_process = true

function _SMain(...)

	LogChatMsg(0)
	LogChatMsg(1)

	--սʼ
	AI:SetAdv( "" )

	local nWaitBoss = 0 

	while true do
		
		if GetActiveDataSceneID() == g_MissionMap then

			if first_process == true and DataPool:IsTeamLeader() == true then
				first_process = false 
				local vDistance = 999999
				local self_x , self_y = Player:GetPos()

				for i,v in pairs(g_Process) do
					local this_distance = GetDist( self_x , self_y , v.x , v.y )
					DbgPrintf("%d ľ %d" , tonumber(i) , tonumber(this_distance))
					if this_distance < vDistance then
						vDistance = this_distance
						fuben_process_chk = i
					end							 
				end
			end

			local nType , nStep = CheckProcess()
			local nPre_chk = fuben_process_chk

			DbgPrintf("check process %d %d, chk = %d" , nType , nStep , fuben_process_chk )

			if nType == 1 then
				nWaitBoss = 0 
				OnProcessBoss( nStep )
			else
				if DataPool:IsTeamLeader() == false then
					OnSearch_Member()
				else
					if nType == 0 then 
						if nWaitBoss > 4 then
							--λÿѾûboss 
							if fuben_process_chk == 4 or fuben_process_chk == 5 then
								fuben_process_chk = 3
							elseif fuben_process_chk == 2 then
								fuben_process_chk = 4
							elseif fuben_process_chk == 1 then
								fuben_process_chk = 2
							elseif fuben_process_chk == 0 then
								fuben_process_chk = 1
							else
								fuben_process_chk = 5
							end
							nWaitBoss = 0 
						else
							nWaitBoss = nWaitBoss + 1 
						end
					else
						nWaitBoss = 0 
					
						if nType == 3 then
							ShowMessage("")
							OnNpcEvent( 5 )
						elseif nType == 2 and DataPool:IsTeamLeader() then
							OnNpcEvent( fuben_process_chk )
						end
					end
				end
			end

			if fuben_process_chk < fuben_process_do then
				fuben_process_chk = fuben_process_do 
			end				

			if DataPool:IsTeamLeader() == true then
				MoveTo( g_Process[fuben_process_chk].x , g_Process[fuben_process_chk].y , g_MissionMap )
			end			
		else
			first_process = false
			fuben_process_do = 0 
			fuben_process_chk = 0 

			LuoYangRestore()

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

			MoveToNPC(191, 223, 246, "˪")
			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(500)
	end


	LogChatMsg(-1)
end

_SMain()
