

--[[

[author]
class=1
attr=1
descript = 凤鸣王陵副本，每天能进2次  

]]--

script_name = "凤鸣王陵"



local g_szNameSence = {
	[1] = "凤鸣镇" ,
	[2] = "凤鸣王陵"	
}


local g_objBoss = {

	[1] = "相柳" , 
	[2] = "开明" , 
	[3] = "长右" , 

	[4] = "英招" , 
	[5] = "穷奇" , 

	[6] = "饕餮" , 
	[7] = "陆吾" , 
	[8] = "毕方" ,  

	[9] = "蛊雕" , 


	[10] = "毕方幻象" 
}



local g_objNe = {

	[1] = "SPECIAL" , 
	[2] = "SPECIAL" , 
	[7] = "SPECIAL"   


}


local g_objBossSmall = {

	[1] = "慑魂" , 
	[3] = "美味的食物" ,
	[6] = "侍魔者" , 
	[9] = "镇魔天雷"  
}



if G_nMemberExe == nil then
	G_nMemberExe = 0
end

if G_bOut == nil then
	G_bOut = 0
end


if G_bMsgFinish == nil then
	G_bMsgFinish = 0 
end

if G_idNpc8 == nil then
	G_idNpc8 = 0
end

if G_nX == nil then
	G_nX = -1
end

if G_nY == nil then
	G_nY = -1
end


if G_bRevival == nil then
	G_bRevival = 0
end


if G_idObjNpc8 == nil then
	G_idObjNpc8 = -1
end

if G_bBreakBoss10 == nil then
	G_bBreakBoss10 = 0
end

local g_nMemPai = -1
local g_nNoFight = 0

local g_bKillMonster = 0
local g_bYinGuai = 0
local g_bTeamFollow = 0
local g_bTeamAttack = 0
local g_bStopAssistSelf = 0
local g_bStopAssist = 0
local g_bStopSpecialAttack = 0
local g_bCallPet = 1
local g_bYinshen = 0
local g_FollowTarget = -1
local g_mainguard_r = 6
local g_bPickUp = 0




function getTargetPos( szNameObj )

	local n = EnumObject(true)
	if n == 0 then
		return -1 , -1 , -1
	end

	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )
		if tostring( nameObj ) == tostring( szNameObj ) then
			return idObj , xObj , yObj
		end
	end
	return -1 , -1 , -1
	
end

function setKeepOffSpecial( nR )
	local n = EnumObject(true)
	if n == 0 then
		return 0
	end

	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )

		if "SPECIAL" == tostring( classObj ) then			
			AI:SetAdv("增加威胁对象" , idObj , nR , tostring( nameObj ) )
		end
	end
	return 1
	
end


function setKeepOffOneSpecial( nR )
	local n = EnumObject(true)
	if n == 0 then
		return 0
	end

	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )
		if "SPECIAL" == tostring( classObj ) then
			AI:SetAdv("增加威胁对象" , idObj , nR , tostring( nameObj ) )
			return 1
		end
	end
	return 0	
end



function setListFightName( szNameFight )
	local n = EnumObject(true)
	if n == 0 then
		return 0
	end

	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )
		if tostring( szNameFight ) == tostring( nameObj ) and Character:GetData( idObj , "DIE" ) == false then
			AI:SetAdv( "指定击杀" , idObj , tostring( szNameFight ) )
		end
	end
	return 1
end


function isClassTarget( szClassObj )

	local n = EnumObject(true)

	if n == 0 then
		return false
	end

	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )
		if tostring( szClassObj ) == tostring( classObj ) then
			return true
		end
	end
	return false
	
end


function isMonster( szNameObj )

	local n = EnumObject(true)

	if n == 0 then
		return false
	end

	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )
		if tostring( szNameObj ) == tostring( nameObj ) then
			if classObj == "MON" then
				return true
			else
				return false
			end
		end
	end
	return false
	
end

function getTargetPosID( idTarget )

	local n = EnumObject(true)
	if n == 0 then		
		return -1 , -1 , nil
	end
	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )
		if idObj == idTarget then
			return xObj , yObj , tostring( nameObj )
		end
	end
	return -1 , -1 , nil
	
end


function getTargetID( szNameTarget )
	local id , _ , _ = getTargetPos( szNameTarget )
	if id ~= -1 then
		return id
	else
		return -1
	end

end


function isMonsterLive( szNameMonster )

	local n = EnumObject(true)
	if n == 0 then
		return false
	end
	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )

		if tostring( nameObj ) == tostring( szNameMonster ) then
			return true
		end
	end
	return false
end


function isLiveID( idTarget )

	local n = EnumObject(true)
	if n == 0 then
		return false
	end
	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )
		if idTarget == idObj then
			return true
		end
	end
	return false
end
 

function getPosMemberFollow( nR )
	if DataPool:GetTeamMemCount() <= 0 then
		return -1 , -1
	end
	local xPos, yPos = Player:GetPos()
	for i = 0 , DataPool:GetTeamMemCount() do
		local szName , idPlayer ,  _, idMap , xCurPos , yCurPos = DataPool:GetTeamMemInfo( i )
		if szName ~= Player:GetName() and  GetDist( xPos , yPos , xCurPos , yCurPos ) < nR and GetDist( xPos , yPos , xCurPos , yCurPos ) > 9 then		
			return xCurPos , yCurPos
		end
	end
	return -1 , -1

end

function onRide()
	if GetMount() == -1 then
		Player:EnableTeamFollow( false )
	end
	while true do
		if GetMount() ~= -1 then
			break
		end
		DoMount( true )
		System:Sleep( 1000 )
	end
end



function goFollowMe()

	if DataPool:GetTeamMemCount() <= 0 then
		return 2
	end

	while true do
		System:Sleep( 10 )

		if GetActiveSceneName() ~= "凤鸣王陵" then
			break
		end

		if getTargetID( g_objCurrent[ 1 ] ) ~= -1 then
			break
		end

		local x , y = getPosMemberFollow( 50 )
		if x ~= -1 and y ~= -1 then
			onRide()
			Player:EnableTeamFollow( true )
			MoveTo( x , y , -1 , "" , 0 , true , _callbackInGoSence )
			Player:EnableTeamFollow( true )
		elseif x == -1 and y == -1 then
			onRide()
			Player:EnableTeamFollow( true )
			break
		end	
	end
	onRide()
end

function isTeamLeaderLive()
	if DataPool:GetTeamMemCount() <= 0 then
		return 2
	end
	local szName , idPlayer ,  _, idMap , xCurPos , yCurPos = DataPool:GetTeamMemInfo( 0 )
	if getTargetID( szName ) ~= -1 then		
		return 1
	end
	return 0
end


function getCurrentMonsterID()
	local idResult = -1
	for i = 1 , 10 do
		local id = getTargetID( g_objBoss[ i ] )
		if id ~= -1 then
			if Character:GetData( id , "DIE" ) == false then
				idResult = id
				break
			elseif Character:GetData( id , "DIE" ) then
				if id ~= idResult then
					idResult = id
				end
			end
		end
	end
	return idResult
end


function getIdFromMsg( szMsg )

	local i , nStart = string.find( tostring( szMsg ) , "毕方幻象" )
	nStart = nStart + 2

	local nEnd = string.find( tostring( szMsg ) , ";" , nStart ) - 1
	local szID = string.sub( tostring( szMsg ) , tonumber( nStart ) , tonumber( nEnd ) )

	return tonumber( szID )

end

function getIdBoss8()

	while true do
		local channel, time, name, data , _ , idObj = GetChatMsg()


		if channel == -1 then
			return 0
		end

		if string.find( data , "各位高手已经斩杀了王陵中所有破除封印的洪荒异兽" ) then
			G_bMsgFinish = 1
		end

		if string.find( data , "没想到尔等眼力如此之强，竟能识得本尊真身" ) then
			G_bBreakBoss10 = 1
		end

		if string.find( data , "本尊真身在此，尔等看清"  ) then

			G_idObjNpc8 = getIdFromMsg( tostring( data ) )
			break
		end
	end
end

function clearMsg()
	local channel, data = GetDebugMessage()
	while channel == 1 do
		channel, data = GetDebugMessage()
	end
end

function getMsgCheck()
	local channel, data = GetDebugMessage()
	while channel == 1 do
		if string.find( data , "各位高手已经斩杀了王陵中所有破除封印的洪荒异兽" ) then
			G_bMsgFinish = 1
		end
		channel, data = GetDebugMessage()
	end
end


function isStopBuff( nMax )
	local nCount = DataPool:GetTeamMemCount()

	if nCount <= 0 then
		return 1
	end

	for i = 0 , nCount - 1 do

		local szName , idPlayer , playerMempai , idMap , xCurPos , yCurPos , nHp , nMaxHp = DataPool:GetTeamMemInfo( i )
		if szName ~= Player:GetName() and getTargetID( szName ) ~= -1 then
			if nHp < nMaxHp * ( nMax / 100 ) then
				return 0
			end

		end
	end

	return 1
end


function getMemberDieID( nMemPos )
	local nCount = DataPool:GetTeamMemCount()

	if nCount <= 0 then
		return -1 , -1 , -1
	end
	if nMemPos > nCount then
		return -1 , -1 , -1
	end

	for i = nMemPos , DataPool:GetTeamMemCount() - 1  do
		local szName , idPlayer , playerMempai , idMap , xCurPos , yCurPos , nHp , nMaxHp = DataPool:GetTeamMemInfo( i )
		if szName ~= Player:GetName() and getTargetID( szName ) ~= -1 and nHp <= 0 then
			return idPlayer , xCurPos , yCurPos , tostring( szName )
		end
	end
	
	return -1 , -1 , -1
end

function getNumMemberDie()
	local nCount = DataPool:GetTeamMemCount()
	if nCount <= 0 then
		return 0
	end
	local nCountDie = 0
	for i = 0 , DataPool:GetTeamMemCount() - 1  do
		local szName , idPlayer , playerMempai , idMap , xCurPos , yCurPos , nHp , nMaxHp = DataPool:GetTeamMemInfo( i )
		if szName ~= Player:GetName() and getTargetID( szName ) ~= -1 and nHp <= 0 then
			nCountDie = nCountDie + 1
		end
	end
	return nCountDie
end



function revivalFriend()
	AI:SetParameter( "保存" )
	AI:SetAI("杀怪") 
	AI:SetParameter( "初始化")
	AI:SetParameter( "拾取" , 0 ) 
	AI:SetParameter( "地图" , -1) 
	local xNow, yNow = Player:GetPos()
	AI:SetParameter("坐标" , "添加" , xNow , yNow , 40 )
	AI:Start(true)
		
	AI:SetParameter("运行参数" , "杀怪" , 0 ) 
	AI:SetParameter("运行参数" , "停止辅助技能" , 1 ) 
	AI:SetParameter("运行参数" , "召唤珍兽" , 0 ) 
	local nNumDie = getNumMemberDie()
	if nNumDie <= 0 then
		return 0
	else
		UpdateMsg( "revivalAll" )
	end
	while true do 
		
		if getNumMemberDie() <= 0 then
			break
		end
		if IsMsgCold( "revivalAll" , nNumDie*13000 ) == true then
			DelMsg( "revivalAll" )
			break
		end
		local idHpSlow , x , y , szName = getMemberDieID( 0 )
		if idHpSlow ~= -1 then
			MoveTo( x , y , -1 , "" , 0 , true , _callbackInSence )
			LockTarget( idHpSlow )
			System:Sleep( 500 )
			UseSkill_Target( "起死回生" , szName )
		end
		System:Sleep( 1000 )
	end
	
	AI:Stop()
	AI:SetParameter("恢复")
end


function isFullBag( nID )
	
	local nResult = PlayerPackage:GetEmptySlot( nID )

	if nResult == 0 then
		return true
	end

	return false
end



function revivalFight()

	g_bPickUp = 0
	g_bKillMonster = 0

	g_bStopAssistSelf = 1
	g_bStopAssist = 1
	g_bStopSpecialAttack = 1
	g_bCallPet = 0

	local idMemberDie , x , y , szName = getMemberDieID( 0 )
	if idMemberDie ~= -1 then
		MoveTo( x , y , -1 , "" , 0 , true , _callbackInSence )
		LockTarget( idMemberDie )
		System:Sleep( 500 )
		UseSkill_Target( "起死回生" , szName )
	end

end

function isConditionTeam()
	local nCount = DataPool:GetTeamMemCount()
	if nCount < 3 then
		return true
	end
	for i = 0 , DataPool:GetTeamMemCount() - 1  do
		local szName , idPlayer ,  _, idMap , xCurPos , yCurPos = DataPool:GetTeamMemInfo( i )
		if szName ~= Player:GetName() and getTargetID( szName ) == -1 and GetActiveSceneName() ==  "太湖" and getTargetID( "李纲" ) ~= -1 then
			if DataPool:IsTeamLeader() then
				local szWait = string.format( " %s 快来集合， 准备进入副本了 " , szName )
				Shout( "team" , szWait )
				mySleep( 5 )
			else
				if IsMsgCold( "WaitTeam" , 5000 ) == true then
					ShowMessage( " %s 没有在附近！ " , szName )
					UpdateMsg( "WaitTeam" )
				end
			end	
			nCount = nCount - 1
		end
	end

	if nCount >= DataPool:GetTeamMemCount() then
		return true
	end
	return false
end

function offRide()
	if GetMount() ~= -1 then
		Player:EnableTeamFollow( false )
		Dismount()
	end
end

function buffMySeltAndFriend( nFlag )
	Player:EnableTeamFollow( false )
	offRide()
	AI:SetAI("高级战斗") 
	AI:Start()
	local xPos , yPos = Player:GetPos()
	g_mainguard_r = 25
	AI:SetAdv( "主防御圈" , xPos , yPos , g_mainguard_r )
		
	g_bKillMonster = 0

	g_bStopAssistSelf = 0
	g_bStopAssist = 0	

	if Player:GetData( "MP" ) < Player:GetData( "MAXMP" )*0.5 then
		AI:SetParameter( "运行参数" , "召唤珍兽" , 1 ) 
	end
	while true do
		
		System:Sleep( 10 )

		getMsgCheck()

		if G_bMsgFinish == 1 then
			break
		end
		if Player:GetData( "MP" ) <= 0 then
			ShowMessage( "真气不足" )
			break
		end

		local idCurrent = getCurrentMonsterID()
		if idCurrent ~= -1 then
			if Character:GetData( idCurrent , "DIE" ) == false then
				break
			end
		end

		if isStopBuff( 80 ) == 1 then
			ShowMessage( "加血完毕" )
			break
		end
		if nFlag == 1 then
			if  GetActiveSceneName() == tostring( g_szNameSence[ 2 ] ) then
				break
			end
		else
			if GetActiveSceneName() ~= tostring( g_szNameSence[ 2 ] ) then
				break
			end

			if isClassTarget( "MON" ) == true then
				break
			end
		end

		AI:SetParameter("运行参数" , "答题" , 1 )
		AI:SetParameter("拾取" , 0 )
		AI:SetParameter("运行参数" , "杀怪" , g_bKillMonster )
		AI:SetParameter("运行参数" , "引怪" , 0 )
		AI:SetParameter("运行参数" , "组队跟随" , 0 )
		AI:SetParameter("运行参数" , "辅助攻击" , g_bTeamAttack )
		AI:SetParameter("运行参数" , "停止自身技能辅助" , g_bStopAssistSelf )
		AI:SetParameter("运行参数" , "停止辅助技能" , g_bStopAssist )
		AI:SetParameter("运行参数" , "停止特殊攻击技能" , g_bStopSpecialAttack )
		AI:SetParameter("运行参数" , "召唤珍兽" , 1 ) 
		AI:SetAdv("主防御圈半径" , g_mainguard_r ) 
		AI:SetAdv("允许隐身" , g_bYinshen ) 
	end

	AI:Stop()
end

function isStopPopular( monsterID )
	if monsterID == -1 then
		if isClassTarget( "MON" ) == false then
			return true
		end
	else
		if isLiveID( monsterID ) == false or Character:GetData( monsterID , "DIE" ) == true then
			return true
		end

	end

	if  GetActiveSceneName() ~= tostring( g_szNameSence[ 2 ] ) then
		return true
	end
	return false
end

function fightPopular( monsterID , xPos , yPos , nPickup , nCallPet )
	AI:SetParameter( "保存" )
	AI:SetAI("杀怪") 
	AI:SetParameter( "初始化")
	AI:SetParameter( "地图" , -1 ) 
	AI:SetParameter( "坐标" , "添加" , xPos , yPos , 40 )
	AI:SetParameter( "运行参数" , "召唤珍兽" , 1 ) 
	AI:Start(true)
	AI:SetParameter( "运行参数" , "杀怪" , 1 ) 

	AI:SetParameter("运行参数" , "停止自身技能辅助" , 0 )
	AI:SetParameter("运行参数" , "停止辅助技能" , 0 )

	AI:SetParameter( "运行参数" , "停止特殊攻击技能" , 0 ) 
	while true do 

		System:Sleep( 10 )

		local idBreak = getTargetID( tostring( g_objBoss[ 4 ] ) )
		if idBreak ~= -1 then
			if Character:GetData( idBreak , "DIE" ) == true then
				break
			end
		end

		idBreak = getTargetID( tostring( g_objBoss[ 5 ] ) )

		if idBreak ~= -1 then
			if Character:GetData( idBreak , "DIE" ) == true then
				break
			end
		end


		if isStopPopular( monsterID ) then
			break
		end
		AI:SetParameter( "拾取" , 0 ) 

	end
	
	AI:Stop()
	AI:SetParameter("恢复")
end


function fightPopularOnce( monsterID , xPos , yPos , nPickup , nCallPet , szNameMonster )


	AI:SetParameter( "保存" )
	AI:SetAI("杀怪") 
	AI:SetParameter( "初始化")
	AI:SetParameter( "地图" , -1 ) 
	AI:SetParameter( "坐标" , "添加" , xPos , yPos , 40 )

	AI:SetParameter( "运行参数" , "召唤珍兽" , 1 ) 

	if monsterID ~= -1 then
		AI:SetAdv("指定击杀" , monsterID , tostring( szNameMonster ) )
	else

		AI:SetParameter( "运行参数" , "辅助攻击" , 1 ) 
	end

	AI:Start(true)

	AI:SetParameter( "运行参数" , "杀怪" , 1 ) 

	AI:SetParameter( "运行参数" , "停止辅助技能" , 0 ) 
	AI:SetParameter( "运行参数" , "停止特殊攻击技能" , 0 ) 

	if g_nNoFight == 1 then
		AI:SetParameter("运行参数" ,"停止自身技能辅助", 1)
		AI:SetParameter("运行参数" ,"停止特殊攻击技能", 1)
		AI:SetParameter("运行参数" ,"停止辅助技能", 1 )
	end

	while true do 

		System:Sleep( 10 )

		getIdBoss8()

		if G_bMsgFinish == 1 then
			break
		end
		if G_bBreakBoss10 == 1 then
			break
		end
		if isStopPopular( monsterID ) == true then
			break
		end
		AI:SetParameter( "拾取" , 0 ) 

	end
	
	AI:Stop()
	AI:SetParameter( "恢复" )
end

function isStopBuff( nMax )
	local nCount = DataPool:GetTeamMemCount()

	if nCount <= 0 then
		return 1
	end

	for i = 0 , nCount - 1 do

		local szName , idPlayer , playerMempai , idMap , xCurPos , yCurPos , nHp , nMaxHp = DataPool:GetTeamMemInfo( i )
		if szName ~= Player:GetName() and getTargetID( szName ) ~= -1 then
			if nHp < nMaxHp * ( nMax / 100 ) then
				return 0
			end

		end
	end

	return 1
end

function setRevival( nHpTeam )

	local nNumDie = getNumMemberDie()
	if nNumDie <= 0 then
		if G_bRevival == 1 then
			AI:Start()
			G_bRevival = 0
		end
		return 0
	else
		if Player:GetData( "HP" ) > Player:GetData( "MAXHP" )*0.5 then
			G_bRevival = 1
			if isStopBuff( nHpTeam ) == 1 then
				revivalFight()
			end
		end
	end
end


function setFixPlace()
	AI:SetAdv( "清除界限" )
	AI:SetAdv( "战场界限" ,  6 , 5 , 89 , 6 )
	AI:SetAdv( "战场界限" ,  89 , 6 , 88 , 88 )
	AI:SetAdv( "战场界限" ,  88 , 88 , 8 , 88 )
	AI:SetAdv( "战场界限" ,  8 , 88 , 6 , 5 )
end





local g_nMaxR1 = 20



local g_nX_O = -1
local g_nY_O = -1



local g_nX_Keep = -1
local g_nY_Kepp = -1

local g_objCoordinate = { nX , nY , nAngle }

function getRadian( nAngle )
	local nResult = ( nAngle * math.pi ) / 180
	return nResult
end

function setPointCircle( x , y , nAngle , nR )
	local nCount = 360 / nAngle
	for i = 1 , nCount do
		local xResult = x + nR * math.cos( getRadian( nAngle*i ) )
		local yResult = y + nR * math.sin( getRadian( nAngle*i ) )

		

		g_objCoordinate[ i ] = { nX = xResult , nY = yResult , nAngle = nAngle*i }
	end
end

local g_objCanPoint = { nX , nY }
local g_objTempCanPoint = { nX , nY , nR }
local g_objTargetKeep = { nID , nX , nY , nR }

function setCanPoint()

	local nNumMember = table.getn( g_objCoordinate )

	if  nNumMember <= 0 then
		return -1 , -1
	end

	g_objCanPoint = { nX , nY }

	local nIndex = 1
	for i = 1 , nNumMember do
		if GetDist( g_objCoordinate[ i ].nX , g_objCoordinate[ i ].nY , g_nX_O , g_nY_O ) < tonumber( g_nMaxR1 ) then
			g_objCanPoint[ nIndex ] = { nX = g_objCoordinate[ i ].nX , nY = g_objCoordinate[ i ].nY }
			nIndex = nIndex + 1
		end
	end
end


function setTempCanPoint( rObj )

	local nNumMember = table.getn( g_objCoordinate )

	if  nNumMember <= 0 then
		return false
	end

	

	local nIndex = 1
	local nCount = table.getn( g_objTempCanPoint )

	if nCount > 0  then
		nIndex = nCount + 1
	end



	for i = 1 , nNumMember do
		if GetDist( g_objCoordinate[ i ].nX , g_objCoordinate[ i ].nY , g_nX_O , g_nY_O ) <= tonumber( g_nMaxR1 ) then

			g_objTempCanPoint[ nIndex ] = { nX = g_objCoordinate[ i ].nX , nY = g_objCoordinate[ i ].nY , nR = rObj }
			nIndex = nIndex + 1
		end
	end

	return true
end


function isOutPointKeep( nX , nY )
	local nNumMember = table.getn( g_objTargetKeep )
	if nNumMember <= 0 then
		return false
	end

	for i = 1 , nNumMember do
		if GetDist( g_objTargetKeep[ i ].nX , g_objTargetKeep[ i ].nY , nX , nY ) < g_objTargetKeep[ i ].nR then
			return false
		end
	end

	return true
end




function setManyCanPoint()
	local nNumMember = table.getn( g_objTempCanPoint )

	if  nNumMember <= 0 then
		return false
	end



	local nIndex = 1

	for i = 1 , nNumMember do		
		if isOutPointKeep( g_objTempCanPoint[ i ].nX , g_objTempCanPoint[ i ].nY ) == true then

			g_objCanPoint[ nIndex ] = { nX = g_objTempCanPoint[ i ].nX , nY = g_objTempCanPoint[ i ].nY }
			nIndex = nIndex + 1
		end

	end

	return true	
end


function getMinCanPoint( nX , nY )
	


	local nNumMember = table.getn( g_objCanPoint )
	if nNumMember <= 0 then
		return -1 , -1
	end
	printCanPoint()

	local nIndex = 1
	local nMinDist = GetDist( g_objCanPoint[ 1 ].nX , g_objCanPoint[ 1 ].nY , nX , nY )
		
	for i = 2 , nNumMember do
		local nDist = GetDist( g_objCanPoint[ i ].nX , g_objCanPoint[ i ].nY , nX , nY )

		

		if nDist < nMinDist then			
			nMinDist = nDist
			nIndex = i
		end
	end
	return g_objCanPoint[ nIndex ].nX , g_objCanPoint[ nIndex ].nY
end



function getMaxCanPoint( nX , nY )
	


	local nNumMember = table.getn( g_objCanPoint )
	if nNumMember <= 0 then
		return -1 , -1
	end
	printCanPoint()

	local nIndex = 1
	local nMinDist = GetDist( g_objCanPoint[ 1 ].nX , g_objCanPoint[ 1 ].nY , nX , nY )

	for i = 2 , nNumMember do
		local nDist = GetDist( g_objCanPoint[ i ].nX , g_objCanPoint[ i ].nY , nX , nY )

		if nDist > nMinDist then			
			nMinDist = nDist
			nIndex = i
		end
	end
	return g_objCanPoint[ nIndex ].nX , g_objCanPoint[ nIndex ].nY
end


function keepOffOneTarget( idObjKeep , nR )
	local xKeep , yKeep , _ = getTargetPosID( idObjKeep )
	if xKeep ~= -1 then
		g_objCoordinate = { nX , nY , nAngle }
		setPointCircle( xKeep , yKeep , 45 , nR )
		g_objCanPoint = { nX , nY }
		setCanPoint()
		local x , y = getMinCanPoint( xKeep , yKeep )
		if x ~= -1 and y ~= -1 then
			g_bKillMonster = 0

			g_bStopAssistSelf = 1
			g_bStopAssist = 1
			g_bStopSpecialAttack = 1
	
			g_mainguard_r = 1
			
			AI:SetAdv( "主防御圈" , x , y , g_mainguard_r )
			updateTime( "keepOffOneTarget" )
			return true
		end
	end
	return false
end


function keepOffTarget( nR )
	local nNumMember = table.getn( g_objTargetKeep )
	if nNumMember <= 0 then
		return false
	end

	g_objTempCanPoint = { nX , nY , nR }

	for i = 1 , nNumMember do

		g_objCoordinate = { nX , nY , nAngle }
		setPointCircle( g_objTargetKeep[ i ].nX , g_objTargetKeep[ i ].nY , 45 , nR )
		setTempCanPoint( nR )
	end

	g_objCanPoint = { nX , nY }
	setManyCanPoint()

	local xPos , yPos = Player:GetPos()
	local x , y = getMinCanPoint( xPos , yPos )
	if x ~= -1 and y ~= -1 then
		g_bKillMonster = 0

		g_bStopAssistSelf = 1
		g_bStopAssist = 1
		g_bStopSpecialAttack = 1

		g_mainguard_r = 1
			
		AI:SetAdv( "主防御圈" , x , y , g_mainguard_r )	

		updateTime( "KeepOffTarget" )
		return true
	end

end


function keepOffMulti()
	local nNumMember = table.getn( g_objTargetKeep )
	if nNumMember <= 0 then
		return false
	end

	local xPos ,  yPos = Player:GetPos()
	if isOutPointKeep( xPos , yPos ) == true then
		g_mainguard_r = 1
		g_nX_Keep = xPos
		g_nY_Keep = yPos
		return true	
	else
		g_objTempCanPoint = { nX , nY , nR }

		for i = 1 , nNumMember do
			g_objCoordinate = { nX , nY , nAngle }
			setPointCircle( g_objTargetKeep[ i ].nX , g_objTargetKeep[ i ].nY , 45 , g_objTargetKeep[ i ].nR + 1 )
			setTempCanPoint( g_objTargetKeep[ i ].nR )
		end

		g_objCanPoint = { nX , nY }
		setManyCanPoint()

		local xPos , yPos = Player:GetPos()
		local x , y = getMinCanPoint( xPos , yPos )
		if x ~= -1 and y ~= -1 then
			g_bKillMonster = 0

			g_bStopAssistSelf = 1
			g_bStopAssist = 1
			g_bStopSpecialAttack = 1
	
			g_mainguard_r = 1
			g_nX_Keep = x
			g_nY_Keep = y	
			AI:SetAdv( "主防御圈" , x , y , g_mainguard_r )	


			return true
		end
	end
	return false
end





function keepOffMultiMax()
	local nNumMember = table.getn( g_objTargetKeep )
	if nNumMember <= 0 then
		return false
	end
	printObj()
	local xPos ,  yPos = Player:GetPos()
	if isOutPointKeep( xPos , yPos ) == true then
		g_mainguard_r = 1
		g_nX_Keep = xPos
		g_nY_Keep = yPos
		return true	
	else
		g_objTempCanPoint = { nX , nY , nR }

		for i = 1 , nNumMember do
			g_objCoordinate = { nX , nY , nAngle }
			setPointCircle( g_objTargetKeep[ i ].nX , g_objTargetKeep[ i ].nY , 45 , g_objTargetKeep[ i ].nR + 1 )
			setTempCanPoint( g_objTargetKeep[ i ].nR )
		end

		g_objCanPoint = { nX , nY }
		setManyCanPoint()

		local xPos , yPos = Player:GetPos()
		local x , y = getMaxCanPoint( xPos , yPos )
		if x ~= -1 and y ~= -1 then

			g_bKillMonster = 0

			g_bStopAssistSelf = 1
			g_bStopAssist = 1
			g_bStopSpecialAttack = 1

			g_mainguard_r = 1
			g_nX_Keep = x
			g_nY_Keep = y			
			AI:SetAdv( "主防御圈" , x , y , g_mainguard_r )	


			return true
		end
	end
	return false
end

function addKeepOffTarget( idObj , xObj , yObj , rObj )

	local nNumMember = table.getn( g_objTargetKeep )
	local nIndex = 1
	if nNumMember > 0 then
		nIndex = nNumMember + 1
	end

	g_objTargetKeep[ nIndex ] = { nID = idObj , nX = xObj , nY = yObj , nR = rObj }
end


local g_objTarget = { nID , nX , nY }

function setListObjTarget( szNameKeep )

	g_objTarget = { nID , nX , nY }

	local n = EnumObject(true)
	if n == 0 then		
		return false
	end

	g_objTargetKeep = { nID , nX , nY , nR }

	if tostring( szNameKeep ) == "PLAYER" or tostring( szNameKeep ) == "SPECIAL" then

		local nIndex = 1
		for i = 0 , n - 1 do
			local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )
			if classObj == tostring( szNameKeep ) then
				if xObj ~= -1 and yObj ~= -1 then

					g_objTarget[ nIndex ] = { nID = idObj , nX = xObj , nY = yObj }
					nIndex = nIndex + 1
				end
			end
		end
	elseif tostring( szNameKeep ) == "FRIEND" then

		local nCount = DataPool:GetTeamMemCount()
		if nCount <= 0  then
			return false
		end
		local nIndex = 1
		for i = 0 , nCount - 1  do
			local szName , idPlayer ,  _, idMap , xCurPos , yCurPos = DataPool:GetTeamMemInfo( i )
			if szName ~= Player:GetName() and szName ~= nil then
				if xCurPos ~= -1 and yCurPos ~= -1 then
					g_objTarget[ nIndex ] = { nID = idPlayer , nX = xCurPos , nY = yCurPos }
					nIndex = nIndex + 1
				end
			end
		end

	else
		local nIndex = 1
		for i = 0 , n - 1 do
			local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )
			if nameObj == tostring( szNameKeep ) then
				if xObj ~= -1 and yObj ~= -1 then

					g_objTarget[ nIndex ] = { nID = idObj , nX = xObj , nY = yObj }
					nIndex = nIndex + 1
				end
			end
		end


	end

	return true
end

function isNearTarget( szName , rObj )

	setListObjTarget( szName )
	local nNum = table.getn( g_objTarget )
	if nNum <= 0 then
		return false
	end
	local xPos , yPos = Player:GetPos()
	for i = 1 , nNum do
		if GetDist( xPos , yPos ,  g_objTarget[ i ].nX , g_objTarget[ i ].nY ) <= rObj then
			return true

		end
	end

	return false
end

function keepOffTargetName( szNameKeep , rObj )

	if isNearTarget( szNameKeep , rObj ) == true then

		g_objTargetKeep = { nID , nX , nY , nR }

		local nNum = table.getn( g_objTarget )
		if nNum <= 0 then
			return false
		end

		for i = 1 , nNum do
			addKeepOffTarget( g_objTarget[ i ].nID , g_objTarget[ i ].nX , g_objTarget[ i ].nY , rObj )
		end
	
		return keepOffMulti()

	else
		return true
	end	
end


function keepOffTargetNameDist( szNameKeep , rObj , nDistMySelf )

	if isNearTarget( szNameKeep , rObj ) == true then

		g_objTargetKeep = { nID , nX , nY , nR }

		local nNum = table.getn( g_objTarget )
		if nNum <= 0 then
			return false
		end
		local xPos , yPos = Player:GetPos()
		if xPos ~= -1 then
			for i = 1 , nNum do
				
				if GetDist( xPos , yPos , tonumber( g_objTarget[ i ].nX ) , tonumber( g_objTarget[ i ].nY ) ) <= ( nDistMySelf + rObj ) then
					addKeepOffTarget( g_objTarget[ i ].nID , g_objTarget[ i ].nX , g_objTarget[ i ].nY , rObj )
				end
			end
	
			return keepOffMulti()
		else
			return false
		end
	end
	return true
end

function keepOffTargetNameMax( szNameKeep , rObj )

	if isNearTarget( szNameKeep , rObj ) == true then

		g_objTargetKeep = { nID , nX , nY , nR }

		local nNum = table.getn( g_objTarget )
		if nNum <= 0 then
			return false
		end

		for i = 1 , nNum do
			addKeepOffTarget( g_objTarget[ i ].nID , g_objTarget[ i ].nX , g_objTarget[ i ].nY , rObj )
		end
	
		return keepOffMultiMax()

	else
		return true
	end	

end



function printCoordinate()
	local nNum = table.getn( g_objCoordinate )

	if nNum <= 0 then
		return fasle
	end

	for i = 1 , nNum do
		
	end
end


function printCanPoint()

	local nNumMember = table.getn( g_objCanPoint )
	if nNumMember <= 0 then
		return false
	end	
	for i = 1 , nNumMember do
		
	end
end


function printObj()
	local nNum = table.getn( g_objTargetKeep )
	if nNum <= 0 then
		return false
	end
	for i = 1 , nNum do
		
	end
end

function printTempCanPoint()
	local nNumMember = table.getn( g_objTempCanPoint )

	if  nNumMember <= 0 then
		return false
	end

	for i = 1 , nNumMember do
		
	end
end


function keepOffTargetID( idTarget , rObj )

	local n = EnumObject(true)
	if n == 0 then		
		return flase
	end

	g_objTargetKeep = { nID , nX , nY , nR }

	local nIndex = 1
	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )
		if idTarget == idObj then
			if xObj ~= -1 and yObj ~= -1 then
				local xPos , yPos = Player:GetPos()
				if GetDist( xPos , yPos , xObj , yObj ) < rObj then
					addKeepOffTarget( idObj , xObj , yObj , rObj )
					break
				else
					return true
				end
			end
		end
	end

	return keepOffMulti()
	
end
function isTargetSpecial( szNameObj )

	local n = EnumObject(true)

	if n == 0 then
		return false
	end

	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )
		if tostring( classObj ) == "SPECIAL" and tostring( szNameObj ) == nameObj then

			return true
		end
	end
	return false
	
end

function exeFightSpecial1( monsterID )

	Player:EnableTeamFollow( false )
	offRide()
	AI:SetAI("高级战斗") 
	AI:SetParameter( "地图" , -1 )
	g_mainguard_r = 25
	AI:SetAdv( "主防御圈" , 48 , 48 , g_mainguard_r ) 
	AI:Start()
	AI:SetAdv( "指定击杀" , -1 , "" )
	g_bYinGuai = 0
	g_bTeamFollow = 0
	g_bTeamAttack = 0

	g_bStopAssistSelf = 0
	g_bStopAssist = 0
	g_bStopSpecialAttack = 1

	g_bYinshen = 0
	g_FollowTarget = -1

	g_bKillMonster = 1
	g_bCallPet = 1
	g_bPickUp = 0
	g_nX_O = 48
	g_nY_O = 48

	local bKeepoff = false

	while true do

		System:Sleep( 10 )

		if GetActiveSceneName() ~= tostring( g_szNameSence[ 2 ] ) then
			break
		end

		if gscript_check( 0 , 0 , 1 ) == 1 then
			if g_nMemPai == 4 then
				setRevival( 40 )
			end
		end

		if isClassTarget( "SPECIAL" ) == true then

			if isTargetSpecial( "冰冻三尺" ) == true then

				if isRecordTime( "KeepOff" , 500 ) == 1 then
					bKeepOff = false
				end

				if bKeepOff == false then

					g_bKillMonster = 0

					g_bStopAssistSelf = 1
					g_bStopSpecialAttack = 1
					g_bStopAssist = 1

					updateTime( "KeepOff" )

					keepOffTargetName( "SPECIAL" , 7 )
					bKeepOff = true

				end
			else
				g_bKillMonster = 1

				g_bStopAssistSelf = 0
				g_bStopAssist = 0
				g_bStopSpecialAttack = 0
				bKeepOff = false
				g_mainguard_r = 25

				AI:SetAdv( "主防御圈" , 48 , 48 , g_mainguard_r ) 

			end
		
		else
			g_bKillMonster = 1

			g_bStopAssistSelf = 0
			g_bStopAssist = 0
			g_bStopSpecialAttack = 0

			AI:SetAdv("清空威胁对象" )

			g_mainguard_r = 25

			AI:SetAdv( "主防御圈" , 48 , 48 , g_mainguard_r ) 

			bKeepOff = false
		end

		if Character:GetData( monsterID , "DIE" ) == true then
			clearMsg()
			break
		end

		if g_nNoFight == 1 then
			g_bKillMonster = 0
			g_bStopAssist = 1
			g_bYinshen = 1
		end



		AI:SetParameter("运行参数" , "答题" , 1 ) 
		AI:SetParameter("拾取" , g_bPickUp ) 
		AI:SetParameter("运行参数" , "杀怪" , g_bKillMonster )
		AI:SetParameter("运行参数" , "引怪" , 0 )
		AI:SetParameter("运行参数" , "组队跟随" , 0 )
		AI:SetParameter("运行参数" , "辅助攻击" , g_bTeamAttack )
		AI:SetParameter("运行参数" , "停止自身技能辅助" , g_bStopAssistSelf )
		AI:SetParameter("运行参数" , "停止辅助技能" , g_bStopAssist )
		AI:SetParameter("运行参数" , "停止特殊攻击技能" , g_bStopSpecialAttack )
		AI:SetParameter("运行参数" , "召唤珍兽" , g_bCallPet ) 
		AI:SetAdv("跟随对象" , g_FollowTarget , 6 ) 
		AI:SetAdv("主防御圈半径" , g_mainguard_r ) 
		AI:SetAdv("允许隐身" , g_bYinshen ) 


	end
	AI:Stop()
end


function isOutSpecial( nR )
	local n = EnumObject(true)
	if n == 0 then
		return false
	end
	local xPos , yPos = Player:GetPos()
	local bResult = true
	if xPos ~= -1 then
	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )

		if "SPECIAL" == tostring( classObj ) then
			if GetDist( xPos , yPos , xObj , yObj ) <= nR then
				bResult = false
			end
		end
	end
	end
	return bResult
	
end


function exeFightSpecial6( monsterID )

	Player:EnableTeamFollow( false )
	offRide()

	AI:SetAI("高级战斗") 
	AI:SetParameter( "地图" , -1 )
	g_mainguard_r = 25
	AI:SetAdv( "主防御圈" , 48 , 48 , g_mainguard_r ) 
	AI:Start()
	AI:SetAdv( "指定击杀" , -1 , "" )
	g_bYinGuai = 0
	g_bTeamFollow = 0
	g_bTeamAttack = 0

	g_bKillMonster = 1

	g_bStopAssistSelf = 0
	g_bStopAssist = 0
	g_bStopSpecialAttack = 0

	g_bYinshen = 0
	g_FollowTarget = -1

	g_nX_O = 48
	g_nY_O = 48

	g_bCallPet = 0
	g_bPickUp = 0

	local bKeepoff = false
	while true do

		System:Sleep( 10 )

		if GetActiveSceneName() ~= tostring( g_szNameSence[ 2 ] ) then
			break
		end

		if isClassTarget( "SPECIAL" ) == true then
		
			if isRecordTime( "KeepOff" , 500 ) == 1 then
				AI:SetAdv("清空威胁对象" )
				bKeepOff = false
			end

			if bKeepOff == false then

				updateTime( "KeepOff" )



				setKeepOffSpecial( 3 )

				bKeepOff = true		
			end

		else
			AI:SetAdv("清空威胁对象" )

			bKeepOff = false
		end

		if Character:GetData( monsterID , "DIE" ) == true or Character:GetData( monsterID , "HP" ) <= 0 then
				clearMsg()
				break
		end

		if g_nNoFight == 1 then
			g_bKillMonster = 0
			g_bStopAssist = 1
			g_bYinshen = 1
		end


		AI:SetParameter("运行参数" , "答题" , 1 ) 
		AI:SetParameter("拾取" , g_bPickUp ) 
		AI:SetParameter("运行参数" , "杀怪" , g_bKillMonster )
		AI:SetParameter("运行参数" , "引怪" , 0 )
		AI:SetParameter("运行参数" , "组队跟随" , 0 )
		AI:SetParameter("运行参数" , "辅助攻击" , g_bTeamAttack )
		AI:SetParameter("运行参数" , "停止自身技能辅助" , g_bStopAssistSelf )
		AI:SetParameter("运行参数" , "停止辅助技能" , g_bStopAssist )
		AI:SetParameter("运行参数" , "停止特殊攻击技能" , g_bStopSpecialAttack )
		AI:SetParameter("运行参数" , "召唤珍兽" , g_bCallPet ) 
		AI:SetAdv("跟随对象" , g_FollowTarget , 6 ) 
		AI:SetAdv("主防御圈半径" , g_mainguard_r ) 
		AI:SetAdv("允许隐身" , g_bYinshen ) 

	end
	AI:Stop()
end



function exeFightSpecial5( monsterID )

	Player:EnableTeamFollow( false )
	offRide()
	AI:SetAI("高级战斗") 
	AI:SetParameter( "地图" , -1 )
	g_mainguard_r = 25
	AI:SetAdv( "主防御圈" , 48 , 48 , g_mainguard_r ) 
	AI:Start()
	AI:SetAdv( "指定击杀" , -1 , "" )
	g_bYinGuai = 0
	g_bTeamFollow = 0
	g_bTeamAttack = 0

	g_bStopAssistSelf = 0
	g_bStopAssist = 0
	g_bStopSpecialAttack = 1

	g_bYinshen = 0
	g_FollowTarget = -1

	g_bKillMonster = 1
	g_bCallPet = 1
	g_bPickUp = 0


	local bKeepoff = false

	while true do

		System:Sleep( 10 )

		if GetActiveSceneName() ~= tostring( g_szNameSence[ 2 ] ) then
			break
		end

		if isClassTarget( "SPECIAL" ) then
			if bKeepOff == false then
				setKeepOffOneSpecial( 3 )
				bKeepOff = true
			end
		else
			AI:SetAdv("清空威胁对象" )
			bKeepOff = false
		end

		if isLiveID( monsterID ) == true then
			if Character:GetData( monsterID , "DIE" ) == true then	
				clearMsg()
				break
			end
		end

		if g_nNoFight == 1 then
			g_bKillMonster = 0
			g_bStopAssist = 1
			g_bYinshen = 1
		end

		AI:SetParameter("运行参数" , "答题" , 1 ) 
		AI:SetParameter("拾取" , g_bPickUp ) 
		AI:SetParameter("运行参数" , "杀怪" , g_bKillMonster )
		AI:SetParameter("运行参数" , "引怪" , 0 )
		AI:SetParameter("运行参数" , "组队跟随" , 0 )
		AI:SetParameter("运行参数" , "辅助攻击" , g_bTeamAttack )
		AI:SetParameter("运行参数" , "停止自身技能辅助" , g_bStopAssistSelf )
		AI:SetParameter("运行参数" , "停止辅助技能" , g_bStopAssist )
		AI:SetParameter("运行参数" , "停止特殊攻击技能" , g_bStopSpecialAttack )
		AI:SetParameter("运行参数" , "召唤珍兽" , g_bCallPet ) 
		AI:SetAdv("跟随对象" , g_FollowTarget , 6 ) 
		AI:SetAdv("主防御圈半径" , g_mainguard_r ) 
		AI:SetAdv("允许隐身" , g_bYinshen ) 


	end
	AI:Stop()
end

function isLiveName( szName )

	local n = EnumObject(true)
	if n == 0 then
		return false
	end
	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )
		if tostring( szName ) == nameObj then
			if Character:GetData( idObj , "DIE" ) == false then
				return true
			end
		end
	end
	return false
end

function setObjShortID( idDiff )
	
	g_objMonster = { nID , x , y }

	local n = EnumObject(true)

	if n == 0 then
		return false
	end

	local nIndex = 1
	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )
		if tostring( classObj ) == "MON" then
			if idObj ~= -1 then
				if idObj ~= idDiff then
					if Character:GetData( idObj , "DIE" ) == false then
						if xObj ~= -1 and yObj ~= -1 then
							g_objMonster[ nIndex ] = { nID = idObj , x = xObj , y = yObj }
							nIndex = nIndex + 1
						end
					end
				end
			end
		end
	end

	return true

end

function getNearestID( nX , nY , idBoss )

	setObjShortID( idBoss )

	local nNumMember = table.getn( g_objMonster )

	local idMonster = -1
	if  nNumMember <= 0 then
		return -1
	elseif nNumMember == 1 then

		return g_objMonster[ 1 ].nID

	else
		local nMinDist = GetDist( g_objMonster[ 1 ].x , g_objMonster[ 1 ].y , nX , nY )
		idMonster = g_objMonster[ 1 ].nID

		for i = 2 , nNumMember do

			local nDist = GetDist( g_objMonster[ i ].x , g_objMonster[ i ].y , nX , nY )

			if nDist < nMinDist then

				nMinDist = nDist
				idMonster = g_objMonster[ i ].nID
			end
		end
	end

	return idMonster
end


function fightNearestDiff( idBoss )
	local xPos , yPos = Player:GetPos()

	local idFight = getNearestID( xPos , yPos , idBoss )
	if idFight ~= -1 then
		return idFight
	end
	return -1
end


function exeFightSpecial2( monsterID )

	Player:EnableTeamFollow( false )
	offRide()
	AI:SetAI("高级战斗") 
	AI:SetParameter( "地图" , -1 )
	g_mainguard_r = 25
	AI:SetAdv( "主防御圈" , 48 , 48 , g_mainguard_r ) 
	AI:Start()

	g_bYinGuai = 0
	g_bTeamFollow = 0
	g_bTeamAttack = 0

	g_bStopAssistSelf = 0
	g_bStopAssist = 0
	g_bStopSpecialAttack = 1

	g_bYinshen = 0
	g_FollowTarget = -1

	g_bKillMonster = 1
	g_bCallPet = 1
	g_bPickUp = 0
	local bKeepOff = false

	local bFightSmall = false
	local bGetID = false

	local idOldSmall = -1


	while true do

		System:Sleep( 10 )

		if GetActiveSceneName() ~= tostring( g_szNameSence[ 2 ] ) then
			break
		end


		local idBossSmall = getTargetID( tostring( g_objBossSmall[ 6 ] ) )

		if idBossSmall  ~= -1 and isLiveName( tostring( g_objBossSmall[ 6 ] ) ) == true then 
		

			g_bKillMonster = 1

			g_bStopAssistSelf = 0
			g_bStopAssist = 0
			g_bStopSpecialAttack = 0

			if IsMsgCold( "KillSmall" , 100 ) == true then
				bFightSmall = false
			end


			if bFightSmall == false then
				if bGetID == false then
					local idObj = fightNearestDiff( monsterID )

					if idObj ~= -1 then
						if idOldSmall ~= idObj then
							if idObj ~= -1 then
								idOldSmall = idObj

								AI:SetAdv( "指定击杀" , -1 , "" )
								AI:SetAdv( "指定击杀" , idObj , tostring( g_objBossSmall[ 6 ] ) )

								bFightSmall = true
								UpdateMsg( "KillSmall" )

								bGetID = true

							end
						end
					end
				end
			end

			if idOldSmall ~= -1 then
				if isLiveID( idOldSmall ) == false or Character:GetData( idOldSmall , "DIE" ) == true then
					bGetID = false
					bFightSmall = false
				end
			end


		else
			AI:SetAdv( "指定击杀" , -1 ,"" )
			bKeepOff = false
			bFightSmall = false
		end

		if Character:GetData( monsterID , "DIE" ) == true then
			clearMsg()
			break
		end

		if g_nNoFight == 1 then
			g_bKillMonster = 0
			g_bStopAssist = 1
			g_bYinshen = 1
		end

		AI:SetParameter("运行参数" , "答题" , 1 ) 
		AI:SetParameter("拾取" , g_bPickUp ) 
		AI:SetParameter("运行参数" , "杀怪" , g_bKillMonster )
		AI:SetParameter("运行参数" , "引怪" , 0 )
		AI:SetParameter("运行参数" , "组队跟随" , 0 )
		AI:SetParameter("运行参数" , "辅助攻击" , g_bTeamAttack )
		AI:SetParameter("运行参数" , "停止自身技能辅助" , g_bStopAssistSelf )
		AI:SetParameter("运行参数" , "停止辅助技能" , g_bStopAssist )
		AI:SetParameter("运行参数" , "停止特殊攻击技能" , g_bStopSpecialAttack )
		AI:SetParameter("运行参数" , "召唤珍兽" , g_bCallPet ) 
		AI:SetAdv("跟随对象" , g_FollowTarget , 6 ) 
		AI:SetAdv("主防御圈半径" , g_mainguard_r ) 
		AI:SetAdv("允许隐身" , g_bYinshen ) 

	end
	AI:Stop()
end


function exeFightMonster( monsterID )

	AI:SetAI("高级战斗") 
	AI:SetParameter("地图" , -1 )
	AI:Start()

	g_FollowTarget = -1
	g_bKillMonster = 1
	g_bPickUp = 0
	g_bYinshen = 0

	g_bStopSpecialAttack = 1

	while true do
		System:Sleep( 10 )	
	
		if GetActiveSceneName() ~= tostring( g_szNameSence[ 2 ] ) then
			break
		end

		local idBreak = getTargetID( tostring( g_objBoss[ 10 ] ) )
		if idBreak ~= -1 then
			if Character:GetData( idBreak , "DIE" ) == true then
				break
			end
		end

		if isLiveID( monsterID ) == false or Character:GetData( monsterID , "DIE" ) == true then
			break
		end

		if isClassTarget( "MON" ) == false then
			break
		end
		AI:SetParameter("运行参数" , "答题" , 1 )
		AI:SetParameter("拾取" , g_bPickUp ) 
		AI:SetParameter("运行参数" , "杀怪" , g_bKillMonster )
		AI:SetParameter("运行参数" , "引怪" , g_bYinGuai )

		AI:SetParameter("运行参数" , "组队跟随" , g_bTeamFollow )
		AI:SetParameter("运行参数" , "辅助攻击" , g_bTeamAttack )
		AI:SetParameter("运行参数" , "停止自身技能辅助" , g_bStopAssistSelf ) 
		AI:SetParameter("运行参数" , "停止辅助技能" , g_bStopAssist ) 
		AI:SetParameter("运行参数" , "停止特殊攻击技能" , g_bStopSpecialAttack ) 
		AI:SetParameter("运行参数" , "召唤珍兽" , 1 ) 
		AI:SetAdv("跟随对象" , g_FollowTarget , 6 ) 
		AI:SetAdv("主防御圈半径" , g_mainguard_r ) 
		AI:SetAdv("允许隐身" , g_bYinshen ) 

	end
	AI:Stop()
end


local 	g_RecordTime = { { keys , nTime } }

function updateTime( szNameRecord )
	local nCount = 1
	if table.getn( g_RecordTime ) <= 1 and g_RecordTime[ 1 ].keys == nil then
		g_RecordTime[ 1 ] = { keys = szNameRecord , nTime = System:GetTickCount() }
		return 1
	else
		for i = 1 , table.getn( g_RecordTime ) do
			if g_RecordTime[ i ].keys == szNameRecord and g_RecordTime[ i ].keys ~= nil then
				g_RecordTime[ i ].nTime = System:GetTickCount()
				nResult = i
				break
			end	
				nCount = nCount + 1
		end

		if nCount >= table.getn( g_RecordTime ) then
			g_RecordTime[ nCount ] = { keys = szNameRecord , nTime = System:GetTickCount() }
			nResult = nCount
		end
		return nResult
	end

end
function isRecordTime( szNameRecord , nTimeSpan )

	for i = 1 , table.getn( g_RecordTime ) do
		if g_RecordTime[ i ].keys == szNameRecord then
			if (g_RecordTime[ i ].nTime + nTimeSpan) <= System:GetTickCount() then
				return 1
			else
				return 0
			end
		end
	end
	return -1

end

function table.removeKey( varKey )
	for i , v in pairs( g_RecordTime ) do 
		if v.keys == varKey then
			table.remove( g_RecordTime , i )
		end
	end
end

function delRecordTime( szNameRecord )
	table.removeKey( szNameRecord )
end


local g_objMonster = { nID , x , y }

function setObjShort( szNameObj )
	
	g_objMonster = { nID , x , y }

	local n = EnumObject(true)

	if n == 0 then
		return false
	end
	local nIndex = 1
	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )
		if tostring( nameObj ) == tostring( szNameObj ) and Character:GetData( idObj , "DIE" ) == false then
			g_objMonster[ nIndex ] = { nID = idObj , x = xObj , y = yObj }
			nIndex = nIndex + 1
		end
	end
	return true

end

function getNearest( nX , nY , szNameMonster )

	setObjShort( tostring( szNameMonster ) )

	local nNumMember = table.getn( g_objMonster )

	local idMonster = -1

	if  nNumMember <= 0 then
		return -1
	elseif nNumMember == 1 then

		return g_objMonster[ 1 ].nID

	else
		local nMinDist = GetDist( g_objMonster[ 1 ].x , g_objMonster[ 1 ].y , nX , nY )
		idMonster = g_objMonster[ 1 ].nID

		for i = 2 , nNumMember do

			local nDist = GetDist( g_objMonster[ i ].x , g_objMonster[ i ].y , nX , nY )

			if nDist < nMinDist then

				nMinDist = nDist
				idMonster = g_objMonster[ i ].nID
			end
		end
	end

	return idMonster
end





function exeFightTakeStep( monsterID )
	while true do

		local idBoss3 = getTargetID( tostring( g_objBoss[ 3 ] ) )
		if idBoss3 ~= -1 then
			if Character:GetData( idBoss3 , "DIE" ) == true or GetActiveSceneName() ~= tostring( g_szNameSence[ 2 ] ) then				
				break
			end
		else		
			break
		end

		local idFight = getNearest( 48 , 48 , tostring( g_objBossSmall[ 3 ] ) )
		if idFight ~= -1 then
			g_mainguard_r = 20
			AI:SetAdv( "主防御圈" , 48 , 48 , g_mainguard_r )
			AI:SetAdv("指定击杀" , idFight , tostring( g_objBossSmall[ 3 ] ) )

			exeFightMonster( idFight )
		end
	end 
end


function getIdMonsterFight( szNameBoss , szNameMonster , nR )

	local _ , x , y = getTargetPos( tostring( szNameBoss ) )

	local n = EnumObject(true)
	if n == 0 then
		return -1 , -1 , -1
	end
	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )
		if tostring( nameObj ) == tostring( szNameMonster ) then
			if x ~= -1 then
				if idObj ~= -1 then
					if GetDist( x , y , xObj , yObj ) <= nR then
							return idObj , xObj , yObj

					end
				end
			end
		end
	end
	return -1 , -1 , -1
end

local g_bFirstSetKill = false


function exeFightSpecial4( monsterID )

	Player:EnableTeamFollow( false )
	offRide()
	AI:SetAI("高级战斗") 
	AI:SetParameter( "地图" , -1 )
	g_mainguard_r = 25
	AI:SetAdv( "主防御圈" , 48 , 48 , g_mainguard_r ) 
	AI:Start()

	g_bYinGuai = 0
	g_bTeamFollow = 0
	g_bTeamAttack = 0

	g_bStopAssistSelf = 1
	g_bStopAssist = 1
	g_bStopSpecialAttack = 1

	g_bYinshen = 0
	g_FollowTarget = monsterID
	
	g_bCallPet = 1
	g_bPickUp = 0

	local nR = 3


	while true do

		System:Sleep( 10 )

		if GetActiveSceneName() ~= tostring( g_szNameSence[ 2 ] ) then
			break
		end

		if Character:GetData( monsterID , "DIE" ) == true then
			break
		end

		g_bKillMonster = 0
		g_FollowTarget = monsterID

		local x , y , _ = getTargetPosID( monsterID )

		if x ~= -1 and y~= -1 then

			local idFight , xMonster , yMonster = getIdMonsterFight( tostring( g_objBoss[ 9 ] ) , tostring( g_objBossSmall[ 9 ] ) , 4 ) 

			if xMonster ~= -1 and yMonster ~= -1 then

				if GetDist( x , y , xMonster , yMonster ) <= 4 then
						
					if idFight ~= -1 and Character:GetData( idFight , "DIE" ) == false then

						if isRecordTime( "FightKill" , 1500 ) == 1 then
							g_bFirstSetKill = false
							AI:SetAdv("指定击杀" , -1 , "" )
						end
						if g_bFirstSetKill == false then
							updateTime( "FightKill" )
							AI:SetAdv("指定击杀" , idFight , tostring( g_objBossSmall[ 9 ] ) )
							g_bFirstSetKill = true
						end

						g_bKillMonster = 1
						g_FollowTarget = -1
						AI:SetAdv( "主防御圈" , xMonster , yMonster , g_mainguard_r )
					else
						nR = 3
					end
				else
						nR = 3
				end
			else
				g_bFirstSetKill = false
			end
		else
			nR = 3
		end



--		if g_nNoFight == 1 then
--			g_bKillMonster = 0
--			g_bStopAssist = 1
--			g_bYinshen = 1
--		end

		AI:SetParameter("运行参数" , "答题" , 1 ) 
		AI:SetParameter("拾取" , g_bPickUp ) 
		AI:SetParameter("运行参数" , "杀怪" , g_bKillMonster )
		AI:SetParameter("运行参数" , "引怪" , 0 )
		AI:SetParameter("运行参数" , "组队跟随" , 0 )
		AI:SetParameter("运行参数" , "辅助攻击" , g_bTeamAttack )
		AI:SetParameter("运行参数" , "停止自身技能辅助" , g_bStopAssistSelf )
		AI:SetParameter("运行参数" , "停止辅助技能" , g_bStopAssist )
		AI:SetParameter("运行参数" , "停止特殊攻击技能" , g_bStopSpecialAttack )
		AI:SetParameter("运行参数" , "召唤珍兽" , g_bCallPet ) 
		AI:SetAdv("跟随对象" , g_FollowTarget , nR ) 
		AI:SetAdv("主防御圈半径" , g_mainguard_r ) 
		AI:SetAdv("允许隐身" , g_bYinshen ) 


	end
	AI:Stop()
end

function isTimeExeMission( subNameMember )
	for i = 1 , DataPool:GetTeamMemCount() - 1 do
		local strType,_,_,_,szText = DataPool:GetNPCEventList_Item( i )
		local szMsg = string.sub( szText , 10 , string.len( szText ) )



		if string.find( szText , subNameMember ) and string.find( szMsg , "不满足" ) then
			return false
		end
	end
	return true
end

function isMsgItem( szSub )
	local strType,_,_,_,szText = DataPool:GetNPCEventList_Item( 0 )	
	if strType == "text" then				
		if string.find(szText, szSub ) then
			return true
		end	
	end
	return false
end

function speakNpcMission()

	local NpcID , x , y = getTargetPos( "萧陵" )
	if NpcID == -1 then
		return 1
	end
	if GetActiveSceneName() == tostring( g_szNameSence[ 2 ] ) then
		return 1
	end

	Player:EnableTeamFollow( true )
	MoveToNPC( x , y , 0x244 , "萧陵" , 0 , true , _callbackOutSence )
	System:Sleep( 1000 )
	QuestFrameOptionClicked( "进入凤鸣王陵" , CMP_PART_MATCH )



	if isMsgItem( "这凤鸣王陵中诡异无比" ) then

		System:Sleep( 1000 )

		local bStopMission = false
		local nCounMember = DataPool:GetTeamMemCount() - 1
		for i = 0 , nCounMember do
			if GetActiveSceneName() == tostring( g_szNameSence[ 2 ] ) then
				return 1
			end
			local szName , idPlayer ,  _, idMap , xCurPos , yCurPos = DataPool:GetTeamMemInfo( i )
			if isTimeExeMission( szName ) == false then
				if szName == Player:GetName() then
					bStopMission = true
				end
				local szMsg = string.format( "%s 已刷两次了" , szName )
				Shout( "team" , szMsg )
				mySleep( 5 )
			end
		end

		if bStopMission then
			ShowMessage( "脚本执行完毕！" )
			Player:EnableTeamFollow( false )
			System:Sleep( 1000 )
			return 0
		end
	end
	QuestFrameMissionClose()
	return 1
	
end

function mySleep( nSleep )
	local nCount = 1
	while true do
		if nCount > nSleep then
			break
		end
		nCount = nCount + 1
		System:Sleep( 1000 )
	end
end

function getMonsterIndex( szNameCurrent )
	for i = 1 , 10 do
		if tostring( szNameCurrent ) == tostring( g_objBoss[ i ] ) then
			return i
		end
	end
	return -1
end

local g_bFirst = false
function isConditionTimes( szNameMission )

	if g_bFirst == false then
		g_bFirst = true
	end
	while true do

		DataPool:UpdateActivityList(3)
		mySleep( 1 )
		local nResult , sName,_,_, play_times, play_maxtimes = DataPool:FindActiveMission( szNameMission )
		if nResult == 1 then
			if play_times >= play_maxtimes then
				return 0
			else
				return 1
			end
		end
	end
	return -1
end

function _callbackInSence( fX , fY , nScene )

	if GetActiveSceneName() ~= tostring( g_szNameSence[ 2 ] ) then
		return false
	end
	return true
end

function _callbackOutSence( fX , fY , nScene )

	if GetActiveSceneName() == tostring( g_szNameSence[ 2 ] ) then
		return false
	end
	return true
end

function teamleaderSpeakBoss3()
	local NpcID , x , y = getTargetPos( tostring( g_objBoss[ 3 ] ) )
	if NpcID ~= -1 then
		MoveToNPC_ById( x , y , -1 , NpcID , 0 , _callbackInSence )
		System:Sleep( 1000 )
		QuestFrameOptionClicked( "开启考验" , CMP_PART_MATCH )
	end
	QuestFrameMissionClose()
end


function teamleaderSpeakBoss8()
	local NpcID , x , y = getTargetPos( tostring( g_objBoss[ 8 ] ) )
	if NpcID ~= -1 then
		MoveToNPC_ById( x , y , -1 , NpcID , 0 , _callbackInSence )
		System:Sleep( 1000 )
		QuestFrameOptionClicked( "开启考验" , CMP_PART_MATCH )
	end
	QuestFrameMissionClose()
end


function teamleaderSpeakBoss9()
	local NpcID , x , y = getTargetPos( tostring( g_objBoss[ 9 ] ) )
	if NpcID ~= -1 then

		MoveToNPC_ById( x , y , -1 , NpcID , 0 , _callbackInSence )
		System:Sleep( 1000 )
		QuestFrameOptionClicked( "开启考验" , CMP_PART_MATCH )
	end
	QuestFrameMissionClose()
end

function recordPos( idNpc )
	local xNpc , yNpc , _  = getTargetPosID( idNpc )	
	if xNpc ~= -1 and yNpc ~= -1 then
		G_nX = xNpc
		G_nY = yNpc
	end
end

function savePosNpc8( idNpc )
	while true do

		if isMonster( tostring( g_objBoss[ 10 ] ) ) then
			break
		end
		recordPos( idNpc )

		System:Sleep( 100 )

	end
end

function getIdMonsterNeed( szNameMonster )

	local n = EnumObject(true)
	if n == 0 then
		return -1
	end
	for i = 0 , n - 1 do
		local idObj , classObj , nameObj , xObj , yObj , _, modelObj = EnumObject( false, i )

		if tostring( nameObj ) == tostring( szNameMonster ) then
			if G_nX ~= -1 and G_nY ~= -1 then
				if G_nX == xObj then --and G_nY == yObj
					return idObj
				end
			end
		end
	end
	return -1
end




local g_bOnPikup = false

function _SMain(...)	


	if Player:GetData( "LEVEL" ) < 85 then
		ShowMessage( "等级>= 85 " )
		System:Sleep( 1000 )
		Player:EnableTeamFollow( false )
		System:UpdateRecord( "凤鸣王陵" )
		return
	end

	local NpcID , _ , _ = getTargetPos( "萧陵" )
	if GetActiveSceneName() ~= tostring( g_szNameSence[ 2 ] ) and DataPool:GetTeamMemCount() < 3 and NpcID == -1 then
		onRide()
		ShowMessage( "队伍人数不足 3人" )
		System:Sleep( 1000 )
		if isFullBag( 0 ) == true then
			ShowMessage( "背包已满" )
			mySleep( 2 )
		end
	end

	setFixPlace()

	LogChatMsg( 0 )
	LogChatMsg( 1 )

	g_nNoFight = GetScriptParam(script_name,"attr", SCRIPT_ATTR_NOFIGHT ) 

	if g_nNoFight == 1 then
		ShowMessage( "您已经设置不打怪！ " )
	end

	g_nMemPai = Player:GetData( "MEMPAI" )


	while true do

		System:Sleep( 10 )

		local szCurrentScene = GetActiveSceneName()
		if szCurrentScene ~= tostring( g_szNameSence[ 2 ] ) then
			clearMsg()
			G_nMemberExe = 0
			G_bOut = 0
			G_bMsgFinish = 0 
			G_idNpc8 = 0
			G_nX = -1
			G_nY = -1
			G_bRevival = 0

			G_bBreakBoss10 = 0

			g_bOnPikup = false
			G_idObjNpc8 = -1

			if GetQuestTimesInfo( "凤鸣王陵" , 10000 ) == 0 and GetActiveSceneName() ~= tostring( g_szNameSence[ 2 ] ) then 
				Player:EnableTeamFollow( false )
				ShowMessage( "今天的任务已经完成了！" )
				System:UpdateRecord( "凤鸣王陵" )
				System:Sleep( 1000 )
				return
			end

			MoveTo( 281 , 66 , 0x244 , "萧陵" , 0 , true , _callbackOutSence )

			if DataPool:GetTeamMemCount() < 3 and GetActiveSceneName() == tostring( g_szNameSence[ 1 ] ) then 
				ShowMessage("队伍人数不足 3人！")
				Player:EnableTeamFollow( false )
				return
			end
			UpdateMsg( "WaitTeam" )
			while true do

				if GetActiveSceneName() == tostring( g_szNameSence[ 2 ] ) then
					break
				else
					if isConditionTeam() == true then
						break
					end

				end
				System:Sleep( 1000 )
			end

			if DataPool:IsTeamLeader() then
				Player:EnableTeamFollow( true )
				if speakNpcMission() == 0 then
					Player:EnableTeamFollow( false )
					System:UpdateRecord( "凤鸣王陵" )
					return
				end

--				PushDebugMessage( "等待队长点击进入副本" , true )
			end	

		else
			Player:EnableTeamFollow( false )
			if GetMount() ~= -1 then				
				Dismount()
			end	

			if G_bOut == 1 then
				clearMsg()
				G_nMemberExe = G_nMemberExe + 1
				G_bOut = 0
			end

			getMsgCheck()

			local monsterID = getCurrentMonsterID()
			local indexMonster
			local xObjBoss , yObjBoss , szNameMonster

			if monsterID == -1 then
				if getTargetID( tostring( g_objBossSmall[ 1 ] ) ) ~= -1 then
					G_bMsgFinish = 0
					indexMonster = 1
				else
					if G_bMsgFinish == 0 then
						if g_nMemPai == 4 and isStopBuff( 80 ) == 0 then
							buffMySeltAndFriend( 0 )
						end
						continue						
					end
				end
				
			else
				xObjBoss , yObjBoss , szNameMonster = getTargetPosID( monsterID  )

				if szNameMonster ~= nil then
					indexMonster = getMonsterIndex( tostring( szNameMonster ) )
				else
					continue
				end

				if Character:GetData( monsterID , "DIE" ) == false then
					G_bMsgFinish = 0
				end
			end

			if G_bMsgFinish == 1 then

				OnSweepBattleField( 1 )


				MoveTo( 68 , 81 , -1 , "" , 0 , true , _callbackInSence )
				while true do

					if GetActiveSceneName() ~= tostring( g_szNameSence[ 2 ] ) then
						break
					end

					local xPos , yPos = Player:GetPos()
					if xPos ~= -1 then
						if GetDist( xPos , yPos , 48 , 48 ) <= 1 and getCurrentMonsterID() == -1 then
							G_bMsgFinish = 0
							break
						end
					end

					local idCurrent = getCurrentMonsterID()
					if idCurrent ~= -1 then
						if Character:GetData( idCurrent , "DIE" ) == false then
							break
						end
					end
					local idNpc , x , y = getTargetPos( "萧陵" )
					if idNpc ~= -1 then
						MoveToNPC_ById( x , y , -1 , idNpc , 0 , _callbackInSence )
						QuestFrameOptionClicked( "离开副本" , CMP_PART_MATCH )
						QuestFrameMissionClose()
					end
					System:Sleep( 1000 )
				end
				continue
			end

					if Character:GetData( monsterID , "DIE" ) == false then	

						g_bOnPikup = false

						Player:EnableTeamFollow( false )

						if indexMonster == 2 then

							exeFightSpecial6( monsterID )

						elseif indexMonster == 7 then					

							exeFightSpecial1( monsterID )

						elseif indexMonster == 1 then

							exeFightSpecial5( monsterID )

						elseif indexMonster == 4 or indexMonster == 5 then


							fightPopular( monsterID , 48 , 48 , 1 , 1 )

						elseif indexMonster == 6 then 


							exeFightSpecial2( monsterID )

						elseif indexMonster == 3 then 

							if isMonsterLive( tostring( g_objBossSmall[ 3 ] ) ) == false then

								if DataPool:IsTeamLeader() then
									teamleaderSpeakBoss3()								
								end
							else	
								exeFightTakeStep( monsterID )
							end

						elseif indexMonster == 8 then


							if DataPool:IsTeamLeader() then
								teamleaderSpeakBoss8()								
							end


						elseif indexMonster == 10 and G_bBreakBoss10 == 0 then

							if isMonster( tostring( g_objBoss[ 10 ] ) ) == true then

								local idFight = -1
								local nCount = 1
								while true do
									if nCount > 3 then
										break
									end
									idFight = getIdMonsterNeed( tostring( g_objBoss[ 10 ] ) )
						
									if idFight == -1 then
										System:Sleep( 1000 )
									else
										break
									end
									nCount = nCount + 1

								end

								if idFight == -1 then
									fightPopularOnce( -1 , 48 , 48 , 1 , 1 , tostring( g_objBoss[ 10 ] ) )
								else
									g_mainguard_r = 15
									AI:SetAdv( "主防御圈" , 48 , 48 , g_mainguard_r )
									AI:SetAdv("指定击杀" , idFight , tostring( g_objBoss[ 10 ] ) )		
									exeFightMonster( idFight )
								end
								
							else	
								if G_idObjNpc8 == -1 then

									getIdBoss8()
								else
									savePosNpc8( G_idObjNpc8 )
								end

							end

						elseif indexMonster == 9 then 

							if isMonsterLive( tostring( g_objBossSmall[ 9 ] ) ) == false then

								if DataPool:IsTeamLeader() then
									teamleaderSpeakBoss9()								
								end
							else
								exeFightSpecial4( monsterID )
							end

						end
					else

						if g_bOnPikup == false then

							OnSweepBattleField( 1 )

							MoveTo( 48 , 48 , -1 , "" , 0 , true , _callbackInSence )

							g_bOnPikup = true
						else
							if G_bMsgFinish == 0 then
								if g_nMemPai == 4 and isStopBuff( 80 ) == 0 then
									buffMySeltAndFriend( 0 )
								end
							end

						end
					end


		end
	end
	LogChatMsg( -1 )
end

_SMain()