local g_szNpcName = "刘仲甫"
local g_NpcInfo = {
	[0] = {szNpcName="胡小仙", fX=31, fY=12},
}
local t_Nextindex = 0
local kill_Qi_Pos = {
	[0] = {X=54, Y=54},
	[1] = {X=52, Y=75},
	[2] = {X=78, Y=76},
	[3] = {X=75, Y=51},	
}
FirstObjects(1)
local K = 0
function _ShuaQi()

	if 在地图("休息室") == -1 and 取地图名() ~= "珍珑棋局" then
		if 取地图名() ~= "大理" then 召唤坐骑(1) end
		TeamFollow()
		跨图寻路(288,140,"大理")
		对话npc(g_szNpcName)
		对话选项("进入大理休息室")
		while 在地图("休息室") == -1 do 打印信息("正在传送到休息室..") 延迟(2000) K = K + 1 if K == 5 then K = 0 break end end
	end
	
	if 在地图("休息室") == 1 then
		地图寻路(g_NpcInfo[0].fX, g_NpcInfo[0].fY)
		对话npc(g_NpcInfo[0].szNpcName)
		对话选项("珍珑棋局")
		if 查找对话项文本(1,"{FBJR_091019_1") == 1 then 打印信息("队伍里存在不满足开启副本条件玩家，脚本结束！") return end
		while 在地图("休息室") == 1 do 打印信息("正在传送到副本！") 延迟(2000) K = K + 1 if K == 5 then K = 0 break end end
	end
	
	if 取地图名() == "珍珑棋局" then
		local m = 0
		PlayerStopFollow()
		召唤坐骑(0)
		延迟(20000)
		while true do 
			if 取地图名() ~= "珍珑棋局" then
				break
			end
			local x, y, ID , SzName = 搜索目标("",0)
			打印信息("获取到的ID  = "..ID)
			if ID ~= -1 then
				打怪设置("",1)
				if SzName == "远古棋魂" then
					local x, y, ID , SzName = 搜索目标("",0)
					if SzName == "" then break end
				end
				m = 0
			else
				
				m = m + 1
				if m >= 30 then MoveTo(63,63) end
				-- MoveTo(kill_Qi_Pos[t_Nextindex].X, kill_Qi_Pos[t_Nextindex].Y)
				-- if 取距离(kill_Qi_Pos[t_Nextindex].X, kill_Qi_Pos[t_Nextindex].Y) <= 3 then
					-- t_Nextindex = t_Nextindex + 1
				-- end
				-- if t_Nextindex > 3 then t_Nextindex = 0 end 
			end
			if 取地图名() ~= "珍珑棋局" then return end
			延迟(200)
		end
		TeamFollow()
		地图寻路(40,40)
		对话npc("齐圣")
		对话选项("确定")
		打印信息("棋局：完成副本!!")
		while 取地图名() == "珍珑棋局" do 打印信息("正在传送出副本!!!") 延迟(2000) K = K + 1 if K == 5 then K = 0 break end end
	end
end

function Main()
	if IsTeamLeader() == -1 then
		打印信息("棋局：请使用队长运行脚本")
		return
	end
	
	if DataPoolGetTeamMemCount() < 3 then 
		打印信息("棋局：队伍人数少于3人")
		return 
	end
	TeamFollow()
	_ShuaQi()
end


Main()