--[[
[author]
class=1
attr=1
descript=杀慕容博时默认不卡位
--两个参数 1,小号 2,慕容博卡位
]]--

script_name="少室山"
local nSetNoFight = 0

local nFubenMapId = 0x236

local l_boss = {
	["吐蕃恶僧头领"] = INVALID_ID ,
	["吐蕃恶僧"] = INVALID_ID ,
	["番僧执事"] = INVALID_ID ,
	["吐蕃番僧"] = INVALID_ID ,

	["信徒"] = INVALID_ID ,
	["鸠摩智"] = INVALID_ID ,

	["庄聚贤"] = INVALID_ID ,
	["冰蚕"] = INVALID_ID ,
	["冰蚕丝"] = INVALID_ID ,
	
	["星宿弟子"] = INVALID_ID ,
	["慕容复"] = INVALID_ID ,
	["先礼后兵"] = INVALID_ID ,
	["破天式"] = INVALID_ID ,

	["丁春秋"] = INVALID_ID ,
	["血咒巫蛊"] = INVALID_ID ,
	["自爆"] = INVALID_ID ,
	["解体"] = INVALID_ID ,

	["萧远山"] = INVALID_ID ,
	["慕容博"] = 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 ,
	["萧远山NPC"] = INVALID_ID ,
	["慕容博NPC"] = INVALID_ID ,
	["扫地神僧NPC"] = INVALID_ID ,
}


function reset_sss()
	g_step_sss = 0
	g_state_sss = {}
	g_state_sss["鸠摩智"] = {met=0,die=0}
	g_state_sss["庄聚贤"] = {met=0,die=0}
	g_state_sss["慕容复"] = {met=0,die=0}
	g_state_sss["丁春秋"] = {met=0,die=0}
	g_state_sss["慕容博"] = {met=0,die=0}
end

if g_state_sss == nil then
	reset_sss()
end

if g_step_sss == nil then
	g_step_sss = 1
end

local l_dcq_zb = {
	[0] = {x=118,y=116,count=0} ,
	[1] = {x=142,y=116,count=0} , 
	[2] = {x=118,y=140,count=0} , 
	[3] = {x=142,y=140,count=0} 
}

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["星宿弟子"] = 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["慕容博"] = 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["萧远山NPC"] = INVALID_ID 
	l_boss["慕容博NPC"] = INVALID_ID 
	l_boss["扫地神僧NPC"] = INVALID_ID 
end

function DoTeamFollow( act )
	if act == true then
		if GetMount() ~= INVALID_ID then
			DoMount(true)
			System:Sleep(1000)
		end

		if DataPool:IsTeamLeader() == true then
			Player:EnableTeamFollow( true )
		end
	else
		if DataPool:IsTeamLeader() == true then
			Player:EnableTeamFollow( false )
		end
	end
end

function GetNearestPointFromList( vListPoint )
	local myX,myY = Player:GetPos()
	local tmp_dis = 9999999
	local result
	for i,v in pairs(vListPoint) do 
		local new_dis = GetDistSq(myX,myY , v.x , v.y )
		if new_dis <= tmp_dis then
			result = i
			tmp_dis = new_dis
		end
	end
	return tonumber(result)
end

function GetFarthestPointFromList( vListPoint )
	local myX,myY = Player:GetPos()
	local tmp_dis = 0
	local result
	for i,v in pairs(vListPoint) do 
		local new_dis = GetDistSq(myX,myY , v.x , v.y )
		if new_dis > tmp_dis then
			result = i
			tmp_dis = new_dis
		end
	end
	return tonumber(result)
end

function _callback_kill(fX, fY, nScene)

	--赶往下个npc 进行对话
	local result , param = UpdateData()
	if result == nil or result == process_npc_t then
		return true 
	end

	if DataPool:IsTeamLeader() == false and Player:GetData("TEAMFOLLOW") > 0 then
		--如果是组队跟随的状态,不负责引怪,让队长处理
		return false 
	end

	return false

end

function _callback(fX, fY, nScene)

	--赶往下个npc 进行对话
	local result , param = UpdateData()
	if result == nil or result == process_npc_t then
		return true 
	end

	if DataPool:IsTeamLeader() == false and Player:GetData("TEAMFOLLOW") > 0 then
		--如果是组队跟随的状态
		Player:EnableTeamFollow(false) ;
	end

	return false
end


function do_except( msg )
	ShowMessage("脚本发生了问题 %s" , tostring(msg))
end

function UpdateData()

	ResetBoss()
	local bRangeAttack = Player:IsRangeAttack()
	local tmp_mrb_zx = 9999
	local tmp_xys_zx = 9999
	local xNow, yNow = Player:GetPos()

	for i,v in pairs(l_dcq_zb) do
		v.count = 0 
	end

	if IsFuben() == false then
		local isNext,szMsg = GetDebugMessage()
		while isNext == 1 do
		isNext,szMsg = GetDebugMessage()
		end
		return do_except , "离开副本"
	end

	local n = EnumObject(true)

	local nBossCount = 0

	for i=0, n - 1 do
		local idObj, classObj, nameObj, xObj, yObj,sTitle,model,angle = EnumObject(false, i)
		if idObj == INVALID_ID then
			continue
		end
		
		if classObj == "MON" then
			if nameObj == "吐蕃恶僧头领" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				end
			elseif nameObj == "吐蕃恶僧" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				end
			elseif nameObj == "番僧执事" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				end
			elseif nameObj == "吐蕃番僧" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				end
			elseif nameObj == "信徒" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				end
			elseif nameObj == "鸠摩智" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				else
					g_state_sss[nameObj].die = 1
				end
			elseif nameObj == "庄聚贤" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				else
					g_state_sss[nameObj].die = 1
				end
			elseif nameObj == "冰蚕" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				end
			elseif nameObj == "星宿弟子" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				end
			elseif nameObj == "慕容复" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				else
					g_state_sss[nameObj].die = 1
				end
			elseif nameObj == "丁春秋" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				else
					g_state_sss[nameObj].die = 1
				end
			elseif nameObj == "血咒巫蛊" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				end
			elseif nameObj == "萧远山" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				end
			elseif nameObj == "慕容博" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				else
					g_state_sss[nameObj].die = 1
				end
			elseif nameObj == "黑色心魔" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				end
			elseif nameObj == "心魔" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				end
			elseif nameObj == "达摩正心" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				end
			elseif nameObj == "寒冰" then
				if Character:GetData(idObj, "DIE") == false then
					l_boss[nameObj] = idObj
				end
			end
		elseif classObj == "NPC" then
			if nameObj == "鸠摩智" then
				l_boss["鸠摩智NPC"] = idObj
				g_state_sss[nameObj].met = 1
			elseif nameObj == "庄聚贤" then
				l_boss["庄聚贤NPC"] = idObj
				g_state_sss[nameObj].met = 1
			elseif nameObj == "慕容复" then
				l_boss["慕容复NPC"] = idObj
				g_state_sss[nameObj].met = 1
			elseif nameObj == "丁春秋" then
				l_boss["丁春秋NPC"] = idObj
				g_state_sss[nameObj].met = 1
			elseif nameObj == "慕容博" then
				l_boss["慕容博NPC"] = idObj
				g_state_sss[nameObj].met = 1
			elseif nameObj == "萧远山" then
				l_boss["萧远山NPC"] = idObj
				g_state_sss["慕容博"].met = 1
			elseif nameObj == "扫地神僧" then
				l_boss["扫地神僧NPC"] = idObj
				g_state_sss["慕容博"].met = 1
			elseif nameObj == "达摩正心" then
				if string.find(sTitle,"慕容博") then
					local new_dis = GetDistSq( xNow,yNow ,xObj ,yObj )
					if new_dis < tmp_mrb_zx or l_boss["达摩正心_慕容博"] == INVALID_ID then
						l_boss["达摩正心_慕容博"] = idObj 
						tmp_mrb_zx = new_dis
					end						
				elseif string.find(sTitle,"萧远山") then
					local new_dis = GetDistSq( xNow,yNow ,xObj ,yObj )
					if new_dis < tmp_xys_zx or l_boss["达摩正心_萧远山"] == INVALID_ID then
						l_boss["达摩正心_萧远山"] = idObj 
						tmp_xys_zx = new_dis
					end
				end
			end
		elseif classObj == "SPECIAL" then
			if string.find( nameObj , "冰蚕丝" ) then
				if bRangeAttack then
					if model >= 0x411 and model <= 0x415 then
						--boss_冰蚕_爆炸
						l_boss["冰蚕丝"] = idObj
						AI:SetAdv("增加威胁对象" , idObj , 4 , "冰蚕丝")
					elseif model >= 0x41b and model <= 0x41f then
						--boss_火蚕_爆炸
						l_boss["冰蚕丝"] = idObj
						AI:SetAdv("增加威胁对象" , idObj , 4 , "冰蚕丝")
					end
				end
			elseif nameObj == "破天式" then
				if bRangeAttack then
					AI:SetAdv("增加威胁对象" , idObj , 4 , "破天式")
				end
			elseif string.find( nameObj , "焚天灭地" ) then
				l_boss["焚天灭地"] = idObj
				AI:SetAdv("增加威胁对象" , idObj , 15 , "焚天灭地")
			elseif string.find( nameObj , "烈焰焚身" ) then
				l_boss["焚天灭地"] = idObj
				AI:SetAdv("增加威胁对象" , idObj , 15 , "焚天灭地")
			elseif string.find( nameObj , "谁入地狱" ) then
				l_boss["焚天灭地"] = idObj
				AI:SetAdv("增加威胁对象" , idObj , 15 , "焚天灭地")
			elseif nameObj == "萧远山和慕容博复活特效" then
				g_state_sss["慕容博"].die = 1
			end
		elseif classObj == "PLAYER" then
			if CheckBufferByName( idObj , "先礼后兵") ~= INVALID_ID then
				l_boss["先礼后兵"] = idObj
			elseif CheckBufferByName( idObj , "自爆") ~= INVALID_ID then
				l_boss["自爆"] = idObj
			elseif CheckBufferByName( idObj , "解体") ~= INVALID_ID then
				l_boss["解体"] = idObj
			elseif CheckBufferByName( idObj , "千蛛万毒") ~= INVALID_ID then
				l_boss["千蛛万毒"] = idObj
				AI:SetAdv("增加威胁对象" , idObj , 10 , "千蛛万毒")
			end

			for i,v in pairs(l_dcq_zb) do
				if GetDist(xObj,yObj,v.x,v.y) < 10 then
					v.count = v.count + 1
				end
			end
		end
	end

	--检查自身状态
	if Player:GetBuffByName("先礼后兵" , 1) ~= INVALID_ID then
		l_boss["先礼后兵"] = Player:GetData("ID")
	end

	if Player:GetBuffByName("自爆" , 1 ) ~= INVALID_ID then
		l_boss["自爆"] = Player:GetData("ID")
	end

	if Player:GetBuffByName("解体" , 1 ) ~= INVALID_ID then
		l_boss["解体"] = Player:GetData("ID")
	end

	local isNext,szMsg = GetDebugMessage()
	while isNext == 1 do
		if szMsg ~= nil then
			if string.find(szMsg ,"鸠摩智已败下阵来") then
				g_step_sss = 1
				g_state_sss["鸠摩智"].die = 1
			elseif string.find(szMsg , "萧远山即将释放焚天灭地") then
				UpdateMsg("quest_sss_ftmd")
			elseif string.find(szMsg , "#{SSS_ZJ_120109_60") then
				local _,_,name = string.find( szMsg , "#{SSS_ZJ_120109_60.+\042.(.+)}")
				if name ~= nil then
					local sName = tostring(name)
					if string.len( sName ) > 0 then
						--findobject
						ShowMessage("发现要分担伤害的玩家 %s" , tostring(sName))
						if sName == Player:GetData("NAME") then
							l_boss["慕容博_分担伤害"] = Player:GetData("ID")
						else
							l_boss["慕容博_分担伤害"] = FindObjectByName( sName , "玩家" )
						end
						if l_boss["慕容博_分担伤害"] ~= INVALID_ID then
							UpdateMsg("quest_sss_mrbfdsh")
						end
					end
				end
			elseif string.find(szMsg ,"庄聚贤已败下阵来") then
				g_step_sss = 2
				g_state_sss["庄聚贤"].die = 1
			elseif string.find(szMsg ,"慕容复已败下阵来") then
				g_step_sss = 3
				g_state_sss["慕容复"].die = 1
			elseif string.find(szMsg ,"慕容博即将出现") then
				UpdateMsg("quest_sss_step5_wait")
			end
		end
		isNext,szMsg = GetDebugMessage()
	end

-- step: 1,杀恶僧 2,鸠摩智 3,庄聚贤 4,杀星宿兵 5,慕容复 6,星宿兵 7,丁春秋 8,萧远山
	if l_boss["吐蕃恶僧头领"] ~= INVALID_ID or l_boss["吐蕃恶僧"] ~= INVALID_ID or l_boss["番僧执事"] ~= INVALID_ID or l_boss["吐蕃番僧"] ~= INVALID_ID then
		return process_jmz_p , 0 
	elseif l_boss["信徒"] ~= INVALID_ID or 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 then 
		return process_boss_kill , 4
	elseif l_boss["萧远山"] ~= INVALID_ID or l_boss["慕容博"] ~= INVALID_ID or l_boss["黑色心魔"] ~= INVALID_ID or l_boss["达摩正心_萧远山"] ~= INVALID_ID or l_boss["达摩正心_慕容博"] ~= INVALID_ID or l_boss["心魔"] ~= INVALID_ID then
		return process_boss_kill , 5
	elseif IsMsgCold("quest_sss_step5_wait" , 8000 ) == false then
		return process_boss_kill , 5
	elseif g_state_sss["慕容博"].die == 1 and l_boss["扫地神僧NPC"] ~= INVALID_ID then
		return process_exit , ""
	elseif l_boss["丁春秋NPC"] ~= INVALID_ID then
		return process_npc_t , "丁春秋"
	elseif l_boss["慕容复NPC"] ~= INVALID_ID then
		return process_npc_t , "慕容复"
	elseif l_boss["庄聚贤NPC"] ~= INVALID_ID then
		return process_npc_t , "庄聚贤"
	elseif l_boss["鸠摩智NPC"] ~= INVALID_ID then
		return process_npc_t , "鸠摩智"
	elseif l_boss["扫地神僧NPC"] ~= INVALID_ID then
		return process_npc_t , "扫地神僧"
	elseif IsMsgCold("quest_sss_step5_wait" , 8000 ) == false then
		return process_boss_kill , 5
	elseif l_boss["萧远山NPC"] ~= INVALID_ID and l_boss["慕容博NPC"] ~= INVALID_ID then
		local id1,x1,y1 = FindObjectByID( l_boss["萧远山NPC"] , "NPC")
		local id2,x2,y2 = FindObjectByID( l_boss["慕容博NPC"] , "NPC")
		if id1 ~= INVALID_ID and GetDist(119,46,x1,y1) < 3 and id2 ~= INVALID_ID and GetDist(125,46,x2,y2) < 3 then
			PushDebugMessage("等待杀心魔步骤..." , 1)
			return process_boss_kill , 5
		end
	end

	return nil , ""
end

function process_mrf_p()
	--慕容复,未见到慕容复时,从庄聚贤处走到慕容复需要按指定路线行走,并要求击杀所见到的星宿弟子 57,94 76,88 133,86 167,86
	local v_road = { [0] = {x=57,y=94} , [1] = {x=76,y=88} , [2] = {x=133,y=86} , [3] = {x=167,y=86} }
	local v_begin = GetNearestPointFromList( v_road ) 
	if v_begin == nil then
		v_begin = 0 
	end

	DoTeamFollow(true)

	for i = v_begin , 3 do
		local result , param = UpdateData()
		if result ~= nil and result ~= process_npc_t then
			return
		end

		MoveTo( v_road[i].x , v_road[i].y , nFubenMapId , "" , 2 , true , _callback_kill )
	end

	DoTeamFollow(false)

	--清空周围的小怪
	AI:SetAI("杀怪")
	AI:SetParameter("初始化")
	AI:Start(true)

	while true do

		System:Sleep(500)

		local result , param = UpdateData()
		if result ~= nil and result ~= process_npc_t then
			break
		end

		if FindObjectByName( "星宿弟子" , "怪物" ) == INVALID_ID and FindObjectByName( "星宿门徒" , "怪物" ) == INVALID_ID then 
			break 
		end
	end

	AI:Stop()

	local result , param = UpdateData()
	if result == nil or result == process_npc_t then
		MoveTo( 195 , 87 , nFubenMapId , "" , 2 , true , _callback )
	end
end


function process_dcq_p()
	--丁春秋,未见到慕容复时,按指定路线行走
	local v_road = { [0] = {x=198,y=91} , [1] = {x=210,y=106} , [2] = {x=211,y=138} , [3] = {x=226,y=162} , [4] = {x=211,y=168} , [5] = {x=162,y=137} , [6] = {x=132,y=129} }
	local v_begin = GetNearestPointFromList( v_road ) 
	if v_begin == nil then
		v_begin = 0 
	end

	DoTeamFollow(true)	

	for i = v_begin , 6 do
		local result , param = UpdateData()
		if result ~= nil and result ~= process_npc_t then
			return
		end

		MoveTo( v_road[i].x , v_road[i].y , nFubenMapId , "" , 2 , true , _callback_kill )
	end

	DoTeamFollow(false)

	--清空周围的小怪
	AI:SetAI("杀怪")
	AI:SetParameter("初始化")
	AI:Start(true)

	while true do

		System:Sleep(500)

		local result , param = UpdateData()
		if result ~= nil and result ~= process_npc_t then
			break
		end

		if FindObjectByName( "星宿弟子" , "怪物" ) == INVALID_ID and FindObjectByName( "星宿门徒" , "怪物" ) == INVALID_ID then 
			break 
		end
	end

	AI:Stop()

	local result , param = UpdateData()
	if result == nil or result == process_npc_t then
		MoveTo( 130 , 122 , nFubenMapId , "" , 2 , true , _callback )
	end
end

function process_jmz_p()

	--设置当前进度
	local pos , menpai = GetTeamStandPos()

	--根据人物所在队伍的位置，设定3个坐标，轮询1次，杀完周边所有怪物
	AI:SetAI("杀怪")
	AI:SetParameter("初始化")
	AI:SetParameter("拾取", 1)
	AI:SetParameter("地图", nFubenMapId )
	if 1 == pos then
		AI:SetParameter("坐标", "添加", 141 , 206 )
		AI:SetParameter("坐标", "添加", 141 , 191 )  
		AI:SetParameter("坐标", "添加", 141 , 178 ) 
	elseif 2 == pos then
		AI:SetParameter("坐标", "添加", 117 , 206 )
		AI:SetParameter("坐标", "添加", 117 , 191 )  
		AI:SetParameter("坐标", "添加", 117 , 178 ) 
	else
		AI:SetParameter("坐标", "添加", 129 , 206 )
		AI:SetParameter("坐标", "添加", 129 , 191 )  
		AI:SetParameter("坐标", "添加", 129 , 178 ) 
	end

	AI:StartEx(0)

	AI:SetParameter("运行参数" ,"引怪", 1 )
	AI:SetParameter("运行参数" , "清除杀怪循环次数")
	AI:SetParameter("运行参数" , "只拾取BOSS掉落" , 1)


	local result = nil
	local r_param = ""

	AI:StartEx(1)

	while true do 

		System:Sleep(500)

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

		result , r_param = UpdateData()
		if result ~= process_jmz_p then
			--正常返回
			break 
		end

		local nRound = AI:GetParameter("杀怪循环次数")

		if nRound > 0 then
			if l_boss["鸠摩智NPC"] ~= INVALID_ID then
				--正常返回
				result = process_npc_t
				r_param = "鸠摩智"
				break
			else
				ShowMessage("clean ss")
				--怪物已经杀完,却未发现boss
				return do_except , "清完小怪但是未发现BOSS"
			end
		end
	end

	AI:Stop()

	return result , r_param
end

function process_exit()
	MoveToNPC(121 , 32 , nFubenMapId ,"扫地神僧" )
	Dismount()

	System:Sleep(500)
	if FindQuestFrameOption( "离开副本" , CMP_PART_MATCH) == true then
		QuestFrameOptionClicked( "离开副本" , CMP_FULL_MATCH)
		System:Sleep(1000)
		DoLuaString("MessageBox_Self_Env" , "MessageBox_Self_OK_Clicked()")
		DoLuaString("MessageBox_Self_Env" , "MessageBox_Self_Cancel_Clicked(0)")
	end
end

function process_npc_t( p_npc )

	local l_npc = {
		["鸠摩智"] = {x=130,y=173,qs="挑战",next=nil} ,
		["庄聚贤"] = {x=72,y=120,qs="挑战",next=nil} ,
		["慕容复"] = {x=195,y=87,qs="挑战",next=nil} ,
		["丁春秋"] = {x=131,y=125,qs="挑战",next=nil} ,
		["扫地神僧"] = {x=135,y=38,qs="随时应战",next=nil} 	--离开副本 x=121,y=32
	}

	if l_npc[p_npc] == nil then
		ShowMessage("process_npc_t 参数 %s 错误!" , tostring(p_npc))
		return do_except , "参数错误"
	end

	local s_npc = p_npc.."NPC" 

	while true do 

		System:Sleep(500)

		local result , v_npc = UpdateData()
		if result ~= nil then
			if result ~= process_npc_t then
				--有其他事情要做
				return result , v_npc
			else
				if v_npc ~= p_npc then
					--对话其他npc
					return result , v_npc 
				end
			end
		end

		if l_boss[s_npc] == INVALID_ID then
			if IsDestination( l_npc[p_npc].x , l_npc[p_npc].y , nFubenMapId  , 3 ) == true  then
				if IsMsgCold( "WaitForBoss" , 5000 ) then
					return do_except , "boss未出现,需要补充处理过程"
				else
					PushDebugMessage( "等待Boss出现..." , 1 )
				end
			else
				--慕容复,未见到慕容复时,从庄聚贤处走到慕容复需要按指定路线行走,并要求击杀所见到的星宿弟子
				if p_npc == "慕容复" then
					if g_step_sss < 3 then
						--未见过慕容复
						--从列表中获取离人物最近的坐标点
						process_mrf_p()
					else
						DoTeamFollow(true)
						MoveTo( l_npc[p_npc].x , l_npc[p_npc].y , nFubenMapId , "" , 2 , true , _callback )
					end
				elseif p_npc == "丁春秋" then
					if g_step_sss < 4 then
						--未见过丁春秋
						process_dcq_p()
					end
				elseif p_npc == "扫地神僧" then
					--查看周围是否有少林弟子 ,先与其对话
					local v_id,v_x,v_y = FindObjectByName("少林弟子" , "NPC")
					if g_step_sss < 5 and v_id ~= INVALID_ID and GetDist( v_x , v_y , 130 , 123 ) < 5 then
						DoTeamFollow(false)
						MoveToNPC( v_x , v_y , nFubenMapId , "少林弟子")
						QuestFrameOptionClicked( "我愿一同前往藏经阁" , CMP_FULL_MATCH )
					else
						DoTeamFollow(true)

						MoveTo( l_npc[p_npc].x , l_npc[p_npc].y , nFubenMapId , "" , 2 , true , _callback )
					end
				else
					DoTeamFollow(true)

					MoveTo( l_npc[p_npc].x , l_npc[p_npc].y , nFubenMapId , "" , 2 , true , _callback )
				end
				UpdateMsg("WaitForBoss")
			end
		else
			MoveToNPC( l_npc[p_npc].x , l_npc[p_npc].y , nFubenMapId , p_npc )
			DoTeamFollow(false)
			Dismount()
			
			System:Sleep(500)
			if FindQuestFrameOption(l_npc[p_npc].qs , CMP_PART_MATCH) == true then
				QuestFrameOptionClicked( l_npc[p_npc].qs , CMP_FULL_MATCH)
				System:Sleep(1000)
				DoLuaString("MessageBox_Self_Env" , "MessageBox_Self_OK_Clicked()")
				DoLuaString("MessageBox_Self_Env" , "MessageBox_Self_Cancel_Clicked(0)")
			end
			UpdateMsg("WaitForBoss")
		end
	end

	return do_except , "未预料的返回"
end

function process_boss_kill( p_step )

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

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

	AI:SetAdv( "清除参数" )

	if p_step == 1 then
		AI:SetAdv( "战场界限" ,  117 , 164 , 146 , 165 )
		AI:SetAdv( "战场界限" ,  146 , 165, 145  , 180 )
		AI:SetAdv( "战场界限" ,  145  , 180, 115  ,180 )
		AI:SetAdv( "战场界限" ,  115  ,180 , 117 , 164 )
		if pos == 1 then
			AI:SetAdv( "主防御圈" , 130 , 166 , 15 )
		elseif pos == 2 then
			AI:SetAdv( "主防御圈" , 123 , 167 , 15 )
		elseif pos == 3 then
			AI:SetAdv( "主防御圈" , 137 , 168 , 15 )
		else
			AI:SetAdv( "主防御圈" , 130 , 170 , 15 )
		end
	elseif p_step == 2 then
		AI:SetAdv( "战场界限" ,  80 , 108 , 80 , 135 )
		AI:SetAdv( "战场界限" ,  80 , 135, 57 , 139 )
		AI:SetAdv( "战场界限" ,  57 , 139 , 51  ,109 )
		AI:SetAdv( "战场界限" ,  51  ,109 , 80 , 108 )
		AI:SetAdv( "主防御圈" , 72 , 120 , 15 )
	elseif p_step == 3 then
		AI:SetAdv( "战场界限" , 182 ,  79 , 212 , 79 )
		AI:SetAdv( "战场界限" , 212 ,  79 , 212 , 103 )
		AI:SetAdv( "战场界限" , 212 , 103 , 182 , 103 )
		AI:SetAdv( "战场界限" , 182 , 103 , 182 ,  79 )
		AI:SetAdv( "主防御圈" , 193 , 86 , 15 )
	elseif p_step == 4 then
		AI:SetAdv( "战场界限" , 107 , 113 , 155 , 113 )
		AI:SetAdv( "战场界限" , 155 , 113 , 154 , 144 )
		AI:SetAdv( "战场界限" , 154 , 144 , 107 , 144 )
		AI:SetAdv( "战场界限" , 107 , 144 , 107 , 113 )
		AI:SetAdv( "主防御圈" , 129 , 129 , 15 )
	elseif p_step == 5 then
		AI:SetAdv( "战场界限" , 137 ,  36 , 103 , 36 )
		AI:SetAdv( "战场界限" , 103 ,  36 , 103 , 58 )
		AI:SetAdv( "战场界限" , 103 ,  58 , 137 , 58 )
		AI:SetAdv( "战场界限" , 137 ,  58 , 137 ,  36 )
		AI:SetAdv( "主防御圈" , 126 ,  42 , 15 )
	end

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

	if nSetNoFight > 0 then
		AI:SetParameter("运行参数" ,"引怪", 0 )
		AI:SetParameter("运行参数" ,"杀怪", 0 )
		AI:SetParameter("运行参数" ,"组队跟随", 1)
		AI:SetParameter("运行参数" ,"辅助攻击", 0)
		AI:SetParameter("运行参数" ,"停止辅助技能", 1)
	end

	AI:StartEx(1)

	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 FollowTarget = -1
		local nCalSafeMode = 0

		System:Sleep(500)

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

		result , r_param = UpdateData()

		--ShowMessage("kill 参数 %d", tonumber(r_param))

		if result ~= process_boss_kill or r_param ~= p_step then
			if IsMsgCold("Quest_SSS_Begin" , 5000 ) then
				break
			elseif p_step == 1 and g_state_sss["鸠摩智"].die == 1 then
				break 
			elseif p_step == 2 and g_state_sss["庄聚贤"].die == 1 then
				break 
			elseif p_step == 3 and g_state_sss["慕容复"].die == 1 then
				break 
			elseif p_step == 4 and g_state_sss["丁春秋"].die == 1 then
				break 
			end
		else
			UpdateMsg("Quest_SSS_Begin")
		end

		if l_boss["信徒"] ~= INVALID_ID then
			AI:SetAdv("指定击杀" , 0 , "信徒" )
			if bRangeAttack == true then
				bYinGuai = 1
			end
		elseif l_boss["冰蚕"] ~= INVALID_ID then
			AI:SetAdv("指定击杀" , 0 , "冰蚕" )
		elseif l_boss["血咒巫蛊"] ~= INVALID_ID then
			AI:SetAdv("指定击杀" , 0 , "血咒巫蛊" )
		elseif l_boss["寒冰"] ~= INVALID_ID then
			AI:SetAdv("指定击杀" , 0 , "寒冰" )
		elseif 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
			AI:SetAdv("删除威胁对象" , "冰蚕丝")
		end

		if l_boss["破天式"] == INVALID_ID then
			AI:SetAdv("删除威胁对象" , "破天式")
		end

		if l_boss["焚天灭地"] == INVALID_ID then
			AI:SetAdv("删除威胁对象" , "焚天灭地")
		end

		if l_boss["千蛛万毒"] == INVALID_ID then
			AI:SetAdv("删除威胁对象" , "千蛛万毒")
		end

		if l_boss["庄聚贤"] == INVALID_ID then
			AI:SetAdv("删除威胁对象" , "庄聚贤")
		else
			if bRangeAttack == true and CheckBufferByName( l_boss["庄聚贤"] , "疯狂" )  ~= INVALID_ID then
				AI:SetAdv("增加威胁对象" , l_boss["庄聚贤"] , 6 , "庄聚贤")
				bYinshen = 1
			else
				AI:SetAdv("删除威胁对象" , "庄聚贤")
			end
		end

		-- 千蛛万毒：万毒侵体 慕容博星宿内息
		if l_boss["自爆"] ~= INVALID_ID then
			if l_boss["自爆"] == l_boss["解体"] then
				--避无可避
			else
				if l_boss["自爆"] == Player:GetData("ID") then
					if IsMsgCold("quest_sss_zb_setsafe",10000) == true then
						--查找4个坐标玩家最少且离自己最近的
						local safe_pos = 0 
						local safe_count = 9999
						local safe_dis = 999999
						local v_X,v_Y = Player:GetPos()
						for i,v in pairs(l_dcq_zb) do
							if v.count < safe_count then
								safe_pos = i
								safe_count = v.count
								safe_dis = GetDistSq( v_X,v_Y,v.x,v.y)
							else
								local new_dis = GetDistSq( v_X,v_Y,v.x,v.y)
								if v.count == safe_count and new_dis < safe_dis then
									safe_pos = i
									safe_count = v.count
									safe_dis = new_dis
								end
							end
						end

						AI:SetAdv( "主防御圈" , l_dcq_zb[safe_pos].x , l_dcq_zb[safe_pos].y  , 3 )
						UpdateMsg("quest_sss_zb_setsafe")
					end
					bCallPet = 0 
					bFixPlace = 1
				else
					--设置对象为威胁对象
					if IsMsgCold("Quest_SSS_zb", 5000) then
						AI:SetAdv("增加威胁对象" , l_boss["自爆"] , 10 , "自爆")
					else
						--暂时不予理会
						PushDebugMessage("发现自爆对象,等待对方调整坐标,超过5秒则自动躲避" , 1)
					end
				end
			end
		else
			DelMsg("quest_sss_zb_setsafe")
			UpdateMsg("Quest_SSS_zb")
			AI:SetAdv("删除威胁对象" , "自爆")
			if p_step == 4 then
				AI:SetAdv( "主防御圈" , 129 , 129 , 15 )
			end
		end

		if l_boss["解体"] ~= INVALID_ID then
			if l_boss["解体"] == Player:GetData("ID") then
				if l_boss["丁春秋"] ~= INVALID_ID then
					FollowTarget = l_boss["丁春秋"]
				end
			else
				FollowTarget = l_boss["解体"]
			end
		end

		if l_boss["黑色心魔"] ~= INVALID_ID or l_boss["达摩正心_萧远山"] ~= INVALID_ID or l_boss["达摩正心_慕容博"] ~= INVALID_ID or l_boss["心魔"]~= INVALID_ID then
			-- 5 的第 3 阶段
			-- AI:SetAdv( "主防御圈" , 126 , 42 , 15 )
		elseif l_boss["焚天灭地"] ~= INVALID_ID or l_boss["萧远山"] ~= INVALID_ID then
			-- 5 的第 1 阶段
			-- 焚天灭地
			if l_boss["焚天灭地"] ~= INVALID_ID then
				PushDebugMessage("boss正在释放 焚天灭地 技能" , 1)
				local safe_point = { [0] = {x=109,y=50} , [1] = {x=133,y=50 } }
				local v_id , v_X , v_Y = FindObjectByID( l_boss["焚天灭地"] , "特殊对象" )
				if v_id ~= INVALID_ID then
					UpdateMsg("quest_sss_ftmd_continue")
					local safe_point = { [0] = {x=109,y=50} , [1] = {x=133,y=50 } }
					local tmp_pos = 0 
					local tmp_dis = 0
					for i,v in pairs(safe_point) do
						local new_dis = GetDistSq( v_X , v_Y , v.x , v.y )
						if new_dis > tmp_dis then
							tmp_pos = i
							tmp_dis = new_dis
						end
					end
					AI:SetAdv( "主防御圈" ,safe_point[tmp_pos].x , safe_point[tmp_pos].y , 4 )
					bFixPlace = 1
					bCallPet = 0
				end
			else
				--npc 准备释放技能,但陷阱还未出现
				--只处理一次该消息
				if IsMsgCold("quest_sss_ftmd" , 10000 ) == false and l_boss["萧远山"] ~= INVALID_ID then 
					local v_id , v_X , v_Y = FindObjectByID( l_boss["萧远山"] , "怪物" )
					local safe_point = { [0] = {x=109,y=50} , [1] = {x=133,y=50 } }
					if v_id ~= INVALID_ID then
						local safe_point = { [0] = {x=109,y=50} , [1] = {x=133,y=50 } }
						local tmp_pos = 0 
						local tmp_dis = 0
						for i,v in pairs(safe_point) do
							local new_dis = GetDistSq( v_X , v_Y , v.x , v.y )
							if new_dis > tmp_dis then
								tmp_pos = i
								tmp_dis = new_dis
							end
						end
						ShowMessage("向远点 %d 躲避焚天灭地技能" , tonumber(tmp_pos))
						AI:SetAdv( "主防御圈" , safe_point[tmp_pos].x , safe_point[tmp_pos].y , 4 )
					end
					UpdateMsg("quest_sss_ftmd_fix")
					DelMsg("quest_sss_ftmd")
				end
			end
		elseif l_boss["慕容博"] ~= INVALID_ID then
			AI:SetAdv( "主防御圈" , 126 , 42 , 15 )
			-- 请众位少侠速速靠近衘V0替他分担伤害！
			-- 冰魂
			if IsMsgCold("quest_sss_mrbfdsh" , 8000 ) == false then
				if l_boss["慕容博_分担伤害"] == Player:GetData("ID") then
					FollowTarget = l_boss["慕容博"]
				else
					FollowTarget = l_boss["慕容博_分担伤害"]
				end
			end
		else
			if p_step == 5 then
				AI:SetAdv( "主防御圈" , 126 , 42 , 15 )
				-- 一般情况
			end
		end

		if IsMsgCold("quest_sss_ftmd_fix",10000) == false or l_boss["焚天灭地"] ~= INVALID_ID or IsMsgCold("quest_sss_ftmd_continue" , 4000) == false then
			bFixPlace = 1
			bCallPet = 0 
			bStopAssistSelf = 1
			bStopAssist = 1
			if bRangeAttack == false then
				bKillMonster = 0
			end
			AI:SetAdv( "主防御圈半径" , 4 )
		end

		if l_boss["先礼后兵"] ~= INVALID_ID then
			bKillMonster = 0
			bCallPet = 0
		end

		if l_boss["慕容复"] ~= INVALID_ID then
			if CheckBufferByName( l_boss["慕容复"] , "以彼之道" )  ~= INVALID_ID then
				bKillMonster = 0
				bCallPet=0
				PushDebugMessage("慕容复使用了技能 以彼之道,暂停攻击!" , 1 )
			elseif CheckBufferByName( l_boss["慕容复"] , "还施彼身" )  ~= INVALID_ID then
				bStopSpecialAttack = 1
				PushDebugMessage("慕容复使用了技能 还施彼身,停止特殊技能攻击!" , 1 )
			end

		end

		--如果自己是萧远山的目标,则设置萧远山为威胁对象,并设置达摩正心[对萧远山造成伤害]为安全点
		if Player:GetBuffByName("萧远山目标") ~= INVALID_ID then
			AI:SetAdv("指定击杀" , 0 , "黑色心魔" ) 
			nCalSafeMode = 1

			if l_boss["萧远山"] ~= INVALID_ID then
				AI:SetAdv("增加威胁对象" , l_boss["萧远山"] , 12 , "萧远山")
			end

			if l_boss["达摩正心_萧远山"] ~= INVALID_ID then
				local vID, vX , vY = FindObjectByID( l_boss["达摩正心_萧远山"] , "NPC" )
				if vID ~= INVALID_ID then
					AI:SetAdv( "主防御圈" , vX , vY , 5 )
					bFixPlace = 1
				end
			else
				AI:SetAdv( "主防御圈" , 126 , 42 , 15 )
			end
		elseif Player:GetBuffByName("慕容博目标") ~= INVALID_ID then
			AI:SetAdv("指定击杀" , 0 , "黑色心魔" ) 
			nCalSafeMode = 1

			if l_boss["慕容博"] ~= INVALID_ID then
				AI:SetAdv("增加威胁对象" , l_boss["慕容博"] , 12 , "慕容博")
			end

			if l_boss["达摩正心_慕容博"] ~= INVALID_ID then
				local vID, vX , vY = FindObjectByID( l_boss["达摩正心_慕容博"] , "NPC" )
				if vID ~= INVALID_ID then
					AI:SetAdv( "主防御圈" , vX , vY , 5 )
					bFixPlace = 1
				end
			else
				AI:SetAdv( "主防御圈" , 126 , 42 , 15 )
			end
		else
			AI:SetAdv("删除威胁对象" , "萧远山")
			AI:SetAdv("删除威胁对象" , "慕容博")

			if l_boss["黑色心魔"] ~= INVALID_ID or l_boss["达摩正心_萧远山"] ~= INVALID_ID or l_boss["达摩正心_慕容博"] ~= INVALID_ID or l_boss["心魔"]~= INVALID_ID then
				AI:SetAdv( "主防御圈" , 126 , 42 , 15 )
			end
		end

		if nSetNoFight > 0 then
			bKillMonster = 0 
			bYinGuai = 0 
			bTeamAttack = 0 
			bYinshen = 1
			bStopAssist = 1
		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 )
		AI:SetAdv("安全点计算方式" , nCalSafeMode )
	end

	AI:Stop()

	OnSweepBattleField()

	--正常返回 nil,""
	return result , r_param
end


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

function FindNextStep()

	if IsFuben() == false then
		return nil,""
	end
	
	local cur_step = g_step_sss
	if cur_step == 0 then
		return process_npc_t, "鸠摩智"
	elseif cur_step == 1 then
		if g_state_sss["鸠摩智"].die == 1 then
			return process_npc_t, "庄聚贤"
		else
			return process_npc_t, "鸠摩智"
		end
	elseif cur_step == 2 then
		if g_state_sss["庄聚贤"].die == 1 then
			return process_npc_t, "慕容复"
		else
			return process_npc_t, "庄聚贤"
		end
	elseif cur_step == 3 then
		if g_state_sss["慕容复"].die == 1 then
			return process_npc_t, "丁春秋"
		else
			return process_npc_t, "慕容复"
		end
	elseif cur_step == 4 then
		if g_state_sss["丁春秋"].die == 1 then
			return process_npc_t, "扫地神僧"
		else
			return process_npc_t, "丁春秋"
		end
	elseif cur_step == 5 then
		if g_state_sss["慕容博"].die == 1 then
			return process_exit, ""
		else
			return process_npc_t, "扫地神僧"
		end
	end

	return nil,""
end

--少林弟子  我愿一同前往藏经阁
function FindProcess()
	local cur_process , cur_param = UpdateData()
	--杀完boss 后,会返回一个 nil
	if cur_process then
		return cur_process , cur_param
	end
	return FindNextStep()
end

function process_team( process )

	AI:SetAI("杀怪")
	AI:SetParameter("初始化")
	AI:SetParameter("地图", nFubenMapId )
	AI:SetParameter("拾取", 1)

	AI:StartEx(0)
	AI:SetParameter("运行参数" ,"引怪", 0 )
	AI:SetParameter("运行参数" ,"杀怪", 0 )
	AI:SetParameter("运行参数" ,"组队跟随", 1)
	AI:SetParameter("运行参数" ,"辅助攻击", 0)
	AI:SetParameter("运行参数" ,"停止辅助技能", 1)
	AI:StartEx(1)
		
	while true do
		if IsFuben() == false then
			break 
		end

		local result , param = UpdateData()
		if process == process_mrf_p or process == process_dcq_p then
			if result ~= nil and result ~= process_npc_t then
				break
			end
		elseif process == process_jmz_p then
			if result ~= process_jmz_p then
				break 
			end
		else
			break 
		end

		System:Sleep(1000)
	end

	AI:Stop()
end

function _SMain()

	nSetNoFight = GetScriptParam( script_name , "attr" , SCRIPT_ATTR_NOFIGHT )
	if nSetNoFight > 0 and DataPool:IsTeamLeader() == true then
		ShowMessage("由于你是队长,因此不打怪的设置在某些情况下无效!")
	end

	LogChatMsg(0)

	while true do

		System:Sleep(500) 

		if IsFuben() == true then

			local process , param = FindProcess()
			--ShowMessage("find process %s" , tostring(param))

			if process ~= nil then
				if nSetNoFight > 0 and DataPool:GetTeamMemCount() > 0 and DataPool:IsTeamLeader() == false then
					if process == process_jmz_p or process == process_mrf_p or process == process_dcq_p then
						--组队跟随
						process_team( process )
					else
						process(param)
					end
				else
					process(param)
				end
			else
				--当前无操作
			end

		else
			--在野外
			reset_sss()

			if GetQuestTimesInfo("少室山") == 0 then
				ShowMessage("今日已经完成少室山")
				break 
			end

			MoveToNPC( 69 , 56 , 2 , "朱丹臣" )
			if DataPool:GetTeamMemCount() < 3 then
				ShowMessage("队伍人数小于 3 人,不能执行 少室山副本")
				return
			end
			QuestFrameOptionClicked("前往少室山", CMP_FULL_MATCH)
			System:Sleep(1000)

			local strType,_,_,_,szText = DataPool:GetNPCEventList_Item(0)
			if strType == "text" then
				if string.find(szText, "#{CJG_101231_75") then
					ShowMessage("今日已经完成少室山")
					break	-- 退出循环，结束脚本
				end
			end

			System:Sleep(2000)
		end

	end

	LogChatMsg(-1)

end

_SMain()


