ShowMessage("ʦű汾 $Rev: 194 $")

--[[
[author]
descript=ʦ,ɱxxʱԶ,һ60
perday_max=1
cmd0str=ֻ20(ɵ)
cmd0={count=20,skip=BPM_ABNEGATE}
cmd1str=ֻ40(ɵ)
cmd1={count=40,skip=BPM_ABNEGATE}
cmd2str=ȫ(ɵ)
cmd2={count=60,skip=BPM_ABNEGATE}
cmd3str=ֻ20(ʱͣ)
cmd3={count=60,skip=BPM_TIP}
cmd4str=ֻ40(ʱͣ)
cmd4={count=60,skip=BPM_TIP}
cmd5str=ȫ(ʱͣ)
cmd5={count=60,skip=BPM_TIP}
cmd_default=0
]]--
script_name="ʦ"

local g_dwNextTime = 0

g_Shimen_Npc = {
	--
	[0] = {szNpcName="۷", fX=96, fY=83, nSceneID=9},
	--
	[1] = {szNpcName="", fX=98, fY=105, nSceneID=11},
	--ؤ
	[2] = {szNpcName="ͨ", fX=91, fY=77, nSceneID=10},
	--䵱
	[3] = {szNpcName="", fX=78, fY=95, nSceneID=12},
	--
	[4] = {szNpcName="", fX=96, fY=88, nSceneID=15},
	--
	[5] = {szNpcName="", fX=96, fY=92, nSceneID=16},
	--
	[6] = {szNpcName="", fX=95, fY=88, nSceneID=13},
	--ɽ
	[7] = {szNpcName="", fX=95, fY=60, nSceneID=17},
	--ң
	[8] = {szNpcName="ع", fX=119, fY=152, nSceneID=14},
	--
	[9] = {szNpcName="", fX=0, fY=0, nSceneID=0},
	--Ī
	[10] = {szNpcName="Ľʤ", fX=68, fY=127, nSceneID=284},
	--
	[11] = {szNpcName="", fX=100, fY=64, nSceneID=615}
}

g_Shime_Pos = {
	--
	["۱"] = {fX=94, fY=70, nSceneID=9},
	["ؾ"] = {fX=134, fY=135, nSceneID=9},
	["ɽ"] = {fX=96, fY=125, nSceneID=9},
	["¥"] = {fX=69, fY=62, nSceneID=9},
	--
	[""] = {fX=59, fY=52, nSceneID=11},
	["ľ"] = {fX=132, fY=139, nSceneID=11},
	["׽"] = {fX=60, fY=141, nSceneID=11},
	["ˮ"] = {fX=143, fY=57, nSceneID=11},
	--ؤ
	["С԰"] = {fX=39, fY=147, nSceneID=10},
	["ſ"] = {fX=132, fY=112, nSceneID=10},
	["ݱ̳"] = {fX=46, fY=36, nSceneID=10},
	["᷿"] = {fX=53, fY=88, nSceneID=10},
	--䵱
	[""] = {fX=88, fY=53, nSceneID=12},
	["⽣"] = {fX=47, fY=177, nSceneID=12},
	["̨"] = {fX=79, fY=137, nSceneID=12},
	[""] = {fX=46, fY=75, nSceneID=12},
	--
	[""] = {fX=45, fY=44, nSceneID=15},
	["ˮ"] = {fX=146, fY=48, nSceneID=15},
	["˽̨"] = {fX=41, fY=148, nSceneID=15},
	[""] = {fX=148, fY=153, nSceneID=15},
	--
	[""] = {fX=95, fY=56, nSceneID=16},
	[""] = {fX=87, fY=97, nSceneID=16},
	["֩"] = {fX=104, fY=96, nSceneID=16},
	["Ы"] = {fX=126, fY=73, nSceneID=16},
	--
	["̫ξͭ"] = {fX=62, fY=90, nSceneID=13},
	["ͭ"] = {fX=85, fY=85, nSceneID=13},
	["θͭ"] = {fX=107, fY=85, nSceneID=13},
	["̫Ƣͭ"] = {fX=127, fY=90, nSceneID=13},
	--ɽ
	[""] = {fX=61, fY=37, nSceneID=17},
	[""] = {fX=74, fY=63, nSceneID=17},
	[""] = {fX=123, fY=89, nSceneID=17},
	["ұ"] = {fX=128, fY=50, nSceneID=17},	
	--ң
	[""] = {fX=55, fY=146, nSceneID=14},
	["ÿ"] = {fX=152, fY=144, nSceneID=14},
	["ʥ"] = {fX=49, fY=51, nSceneID=14},
	["໭"] = {fX=145, fY=57, nSceneID=14},
	--Ī
	["ˮ"] = {fX=154, fY=93, nSceneID=284},
	["С"] = {fX=78, fY=142, nSceneID=284},
	["κׯ"] = {fX=28, fY=28, nSceneID=284},
	["԰"] = {fX=119, fY=36, nSceneID=284},
	--
	["䳡"] = {fX=48, fY=80, nSceneID=615},
	["Ƽڱ"] = {fX=80, fY=46, nSceneID=615},
	["ǧ"] = {fX=56, fY=136, nSceneID=615},
	["¥"] = {fX=102, fY=97, nSceneID=615}
}

g_Shime_Collect = {
	[0] = 
	{
		{x=69, y=42},{x=42,y=66},{x=56,y=147},{x=65,y=118},{x=62,y=87},{x=129,y=57},{x=133,y=143}
	},
	[1] = 
	{
		{x=97, y=33},{x=42,y=36},{x=38,y=150},{x=158,y=140},{x=145,y=35},{x=97,y=92}
	},
	[2] = {
		{x=124,y=60},{x=117,y=39},{x=149,y=36},{x=150,y=155},{x=129,y=110},{x=82,y=140},{x=44,y=114},{x=55,y=55}	
	},
	[3] = {
		{x=70,y=82},{x=100,y=128},{x=78,y=46},{x=94,y=59},{x=79,y=127},{x=75,y=135}
	},
	[4] = {
		{x=97,y=37},{x=144,y=39},{x=145,y=154},{x=89,y=139},{x=95,y=87},{x=38,y=150},{x=42,y=38}
	},
	[5] = {
		{x=67,y=143},{x=48,y=53},{x=95,y=50},{x=126,y=73},{x=140,y=93},{x=142,y=142},{x=95,y=127}
	},
	[6] = {
		{x=152,y=35},{x=42,y=43},{x=40,y=135},{x=64,y=150},{x=149,y=154},{x=150,y=90}
	},
	[7] = {
		{x=60,y=35},{x=74,y=67},{x=39,y=37},{x=41,y=145},{x=95,y=99},{x=146,y=140},{x=153,y=57}
	},
	[8] = {
		{x=52,y=148},{x=89,y=124},{x=50,y=60},{x=142,y=42},{x=148,y=150}
	},
	[10] = {
		{x=86,y=59},{x=28,y=58},{x=28,y=27},{x=130,y=34}	
	},
	[11] = {
		{x=80,y=30},{x=32,y=34},{x=45,y=135},{x=95,y=150},{x=126,y=108},{x=169,y=159}
	},
}

g_Shimen_Fuben = {
	[0] = {szNpc="", X=61, Y=62, nSceneID=9, szName=""},
	[1] = {szNpc="", X=89, Y=56, nSceneID=11, szName=""},
	[2] = {szNpc="ӡ", X=41, Y=144, nSceneID=10, szName="ƽ"},
	[3] = {szNpc="", X=58, Y=73, nSceneID=12, szName="Է"},
	[4] = {szNpc="", X=96, Y=73, nSceneID=15, szName="һ"},
	[5] = {szNpc="", X=128, Y=78, nSceneID=16, szName=""},
	[6] = {szNpc="", X=35, Y=86, nSceneID=13, szName=""},
	[7] = {szNpc="ս", X=101, Y=44, nSceneID=17, szName="÷"},
	[8] = {szNpc="밢", X=62, Y=68, nSceneID=14, szName="ȵ"},
	[10] = {szNpc="Ľݴ", X=69, Y=109, nSceneID=284, szName="Ѳˮ"},
	[11] = {szNpc="", X=66, Y=30, nSceneID=615, szName=""}
}


-- ȡ
local g_szMission = "ʦ"
local g_nMenPai = Player:GetData("MENPAI")
local g_nParam = {}
local g_nIndex = -1
local g_idMission = 0
local g_idScript = 0

-----------------------------------------------------------------------
--þûм
function OnShimen0()
	MissionMoveToNPC(tonumber(g_nParam[5]))
	QuestFrameOptionClicked("ʦ", CMP_PART_MATCH)	-- ѡѡ
end

-----------------------------------------------------------------------
--ҵXXôˣܰһ
function OnShimen1()
	DbgPrintf("OnShimen1")

	local nItemID = g_nParam[5]
	
	-- ȡƷϢ

	local _,_,BuyLink = DataBase:GetMissionItemInfo(nItemID)

	if DataPool:UserBag_CountItemByIDTable(nItemID) > 0 then
		return
	end

	local _,_,_, fX, fY, nScene , szNpcName = string.find(BuyLink ,"#.(.-)#.+_INFOAIM(%d+),(%d+),(%d+),(.+)}")

	-- жǷֱӹ
	if szNpcName == nil or szNpcName == "" then
		ShowMessage("ʦ1ûв鵽Ϣ%s", szItem)
		MissionBlockProcess(g_idScript)
		return
	end

--[[
	-- ȡƷĹ۸
	local _, nBuyPrice = DataBase:GetCommonItemInfo(nItemID)

	if nBuyPrice == 0 then
		_, nBuyPrice = DataBase:GetEquipItemInfo(nItemID)
	end

	if nBuyPrice == 0 then
		ShowMessage("ʦ1%sûвѯƷۼ۸", szItem)
		return
	end

	-- ȡӵн
	local nMoney = Player:GetData("MONEY")

	-- жǷԹƷ
	if nBuyPrice > nMoney then
		ShowMessage(string.format("ʦ1Ҳ㣬ƷҪ%d, Ŀǰӵ%d", nBuyPrice, nMoney))
		MissionBlockProcess(g_idScript)
		return
	end
]]--
	MoveToNPC(tonumber(fX), tonumber(fY), tonumber(nScene), szNpcName)
	QuestFrameOptionClicked("", CMP_PART_MATCH)
	ShopBuy(nItemID, 1)

	System:Sleep(1000)

	if DataPool:IsMissionCanCommit(g_idMission) == false then
		if GetMyLastError() == LASTERROR_NOMONEY then
			ShowMessage("%s񣺽Ҳ", g_szMission )
			MissionBlockProcess(g_idScript)
		end 
	end
end

-----------------------------------------------------------------------
--XXΪȥѵһ£ϧûʱ
function OnShimen2()
	ShowMessage("ʦ2ָ֧")
	MissionBlockProcess(g_idScript)
end

-----------------------------------------------------------------------
--ʹXXXXXX
function OnShimen3()
	DbgPrintf("OnShimen3")

	local	szPos = ""
	local	szToolsName = ""

	local nMax = DataPool:CollectPlayerMission_StrList(g_idMission)
	for i=0,nMax do
		local Ret = DataPool:GetPlayerMission_StrListInCollect(i)
		DbgPrintf("===[%d]%s", i, tostring(Ret))
	end

	DbgPrintf("ǰ:%d" , tonumber(g_nMenPai))

	--ȡλ, ʹƷ
	if g_nMenPai == 0 or g_nMenPai == 1 or g_nMenPai == 2 or g_nMenPai == 3 then					
		szPos = DataPool:GetPlayerMission_StrList(g_nIndex,g_nParam[6])
		szToolsName = DataPool:GetPlayerMission_StrList(g_nIndex,g_nParam[5])
	elseif g_nMenPai == 4 then
		szPos = DataPool:GetPlayerMission_StrList(g_nIndex,g_nParam[5])
		szToolsName = DataPool:GetPlayerMission_StrList(g_nIndex,g_nParam[7])
	elseif g_nMenPai == 5 or g_nMenPai == 6 then
		szPos = DataPool:GetPlayerMission_StrList(g_nIndex,g_nParam[6])
		szToolsName = DataPool:GetPlayerMission_StrList(g_nIndex,g_nParam[7])
	elseif g_nMenPai == 7 then
		szPos = DataPool:GetPlayerMission_StrList(g_nIndex,g_nParam[5])
		szToolsName = DataPool:GetPlayerMission_StrList(g_nIndex,g_nParam[6])
	elseif g_nMenPai == 8 then
		szPos = DataPool:GetPlayerMission_StrList(g_nIndex,g_nParam[6])
		szToolsName = DataPool:GetPlayerMission_StrList(g_nIndex,g_nParam[7])
	elseif g_nMenPai == 10 then
		szPos = DataPool:GetPlayerMission_StrList(g_nIndex,g_nParam[7])
		szToolsName = DataPool:GetPlayerMission_StrList(g_nIndex,g_nParam[6])
	elseif  g_nMenPai == 11 then
		szPos = DataPool:GetPlayerMission_StrList(g_nIndex,g_nParam[6])
		szToolsName = DataPool:GetPlayerMission_StrList(g_nIndex,g_nParam[7])
	end

	local i = string.find(szPos, "#{")
	if i then
		szPos = string.sub(szPos, 0, i - 1)
	end
	DbgPrintf("%s, %s", szPos, szToolsName)

	-- жλǷȷ
	if g_Shime_Pos[szPos] == nil then
		ShowMessage("ʦ3ûҵ[%s]", szPos)
		return
	end

	-- жʹƷǷȷ
	if szToolsName == "" then
		ShowMessage("ʦ3ƷΪգ")
		return
	end

	MoveTo(g_Shime_Pos[szPos].fX, g_Shime_Pos[szPos].fY, g_Shime_Pos[szPos].nSceneID, "", 1)
	Dismount()
	UseItem(szToolsName, "")
end

-----------------------------------------------------------------------
--ȥҵXX ȥսXXġ
function OnShimen4()
	ShowMessage("ʦ4ָ֧")
	MissionBlockProcess(g_idScript)
end

function MatchInfomation( szText )
	local _,_,szName,nX ,nY,nScene = string.find(szText ,"ץһֻ#.#R(.-)#.-_INFOAIM(%d+),(%d+),(%d+),")
	return tostring(szName),tonumber(nX),tonumber(nY),tonumber(nScene)
end

-----------------------------------------------------------------------
--ץһֻXX
function OnShimen5()
	DbgPrintf("OnShimen5")

	local nMax = DataPool:CollectPlayerMission_StrList(g_idMission)
	for i=0,nMax do
		local Ret = DataPool:GetPlayerMission_StrListInCollect(i)
		DbgPrintf("[%d]%s", i, tostring(Ret))
	end

	local szName = ""
	local nX = 0
	local nY = 0
	local nScene = -1

	if nMax > 0 then
		local MapInfomation = DataPool:GetPlayerMission_StrListInCollect(0)
		szName, nX, nY, nScene = GetMapInfomationLink(MapInfomation)
	else
		local MapInfomation = DataPool:GetPlayerMission_StrListInCollect(-1)
		szName, nX, nY, nScene = MatchInfomation( MapInfomation)
	end

	DbgPrintf("%s %d %d %d" , tostring(szName) , tonumber(nX) , tonumber(nY) , tonumber(nScene))

	if szName == "" then
		ShowMessage("ʦ5޷ȡץ")
		DataPool:GetPlayerMission_Display(g_idMission)
		return
	end

	-- 
	--if DataPool:IsMissionCanCommit(g_idMission) then
		for i=1, PET_MAX_NUMBER do			--õǰ޵ĿΪмĳЩΪ
			if Pet:IsPresent(i-1) == true then
				if szName == Pet:GetName(i-1) then
					local Npc = g_Shimen_Npc[g_nMenPai]
					MoveToNPC(Npc.fX, Npc.fY, Npc.nSceneID, Npc.szNpcName)
					QuestFrameOptionClicked(g_szMission, CMP_PART_MATCH)	-- ѡѡ

					if UI:IsWindowShow("MissionReply") then
						local txt = string.format("MissionReply:OnContinue(%d);", i-1)
						DoLuaString("MissionReply_Env", txt)
					end

					DbgPrintf("")
					System:Sleep(500)
					QuestFrameMissionClose()
					return
				end
			end
		end
	--end

	if szName == "걱" then 
		nX = 227
		nY = 203
	end

	MoveTo(nX, nY, nScene)

	AI:SetAI("ɱ")
	AI:SetParameter("Ŀ", "", szName)
	AI:SetParameter("", "", szName)
	AI:SetParameter("ʰȡ", PM_NOPICKUP)
	AI:SetParameter("ͼ", nScene)
	AI:SetParameter("", "", nX, nY)
	AI:Start(false)

	while Pet_GetPetByName(szName) == -1 do 

		local sid, x, y, die = FindCharacterByName("")
		if sid ~= INVALID_ID and die == 0 then
			local xNow, yNow = Player:GetPos()
			if GetDistSq(xNow, yNow, x, y) < 10 then
				AI:Stop()
				while Player_GetBuff("") == -1 do
					Pet_Relax()
					UseSkill("")
					System:Sleep(200)
				end

				while Player_GetBuff("") ~= -1 do
					System:Sleep(200)
				end
				break
			end
		end

		System:Sleep(1000) 
	end

	AI:Stop()
end

-----------------------------------------------------------------------
--XXĴ5XX
function OnShimen6()

	local nSceneID = GetActiveDataSceneID()

	if nSceneID ~= g_Shimen_Npc[g_nMenPai].nSceneID then
		local Npc = g_Shimen_Npc[g_nMenPai]
		MoveToNPC(Npc.fX, Npc.fY, Npc.nSceneID, Npc.szNpcName)
		return
	end

--	local szItemName = DataPool:GetPlayerMission_StrList(g_nParam[5])
	local szItemName = DataPool:GetItemText(g_nParam[6])
	DbgPrintf("ѰƷΪ:%s", tostring(szItemName))

	if g_nMenPai == 4 then
		if szItemName == "ʧ" then
			szItemName = "Сƺ"
		elseif szItemName == "ʧļƷ" then
			szItemName = "Сں"
		elseif szItemName == "ʧ鱦" then
			szItemName = "С׺"
		end
	end

	if szItemName == "" then
		ShowMessage("ʦ6޷ȡòɼƷ")
		return
	end

	--DbgPrintf("[%s]", szItemName)

	if g_Shime_Collect[g_nMenPai] == nil then
		ShowMessage("ʦ6ûҵɵĲɼ")
		return
	end
	
	AI:SetAI("ɼ")
	AI:SetParameter("ʼ")
	AI:SetParameter("Ŀ", "", szItemName)
	AI:SetParameter("ͼ", g_Shimen_Npc[g_nMenPai].nSceneID)

	for i, pos in ipairs(g_Shime_Collect[g_nMenPai]) do
		AI:SetParameter("", "", pos.x, pos.y)
	end

	AI:Start(false)

	while DataPool:IsMissionCanCommit(g_idMission) == false do
		System:Sleep(500)
	end

	AI:Stop()
end

-----------------------------------------------------------------------
--XXȥһXXɣ³֮һ㱨ģ
function OnShimen7()
	ShowMessage("ʦ7ָ֧")
	MissionBlockProcess(g_idScript)
end

-----------------------------------------------------------------------
--ȥɱXXXX
function OnShimen8()
	ShowMessage("ʦ8ָ֧")
	MissionBlockProcess(g_idScript)
end

-----------------------------------------------------------------------
--ҵXXXX
function OnShimen9()

	if g_Shimen_Fuben[g_nMenPai] == nil then
		ShowMessage("ʦ9޷ȡø")
		return
	end

	local Fuben = g_Shimen_Fuben[g_nMenPai]

	MoveToNPC(Fuben.X, Fuben.Y, Fuben.nSceneID, Fuben.szNpc)
	QuestFrameOptionClicked(Fuben.szName, CMP_PART_MATCH)
	QuestFrameAcceptClicked()
end

-----------------------------------------------------------------------
-- NPC
function OnShimen_Visit_NPC_Of_Other()
	
	local szPosString = DataPool:GetPlayerMission_StrList(g_nIndex,g_nParam[6])

	if szPosString == nil then
		ShowMessage("ʦŷ޷Ҫȡ÷ʵNPCַ")
		return
	end

	--DbgPrintf("%s", szPosString)

	local fX, fY, nSceneID, szNpcName

	-- ⴦ȡóӵĵַ
	if string.find(szPosString, "_INFOAIM") then	-- Ʒûгӣؿֵ
		
		szPosString = string.gsub(szPosString, "_INFOAIM", "")

		 _, _, fX, fY, nSceneID, szNpcName = string.find(szPosString, "{(%d+),(%d+),(%d+),(.+)}")

		if szNpcName == "-1" then
			szNpcName = ""
		end
	end

	if szNpcName == "" then
		ShowMessage("ʦŷ޷ҪʵNPC")
		return
	end

	OptionItem = {
		[0] = {npc="", item=""},
		[1] = {npc="", item=""},
		[2] = {npc="ӡ", item="ƽ"},
		[3] = {npc="", item="Է"},
		[4] = {npc="", item="һ"},
		[5] = {npc="", item=""},
		[6] = {npc="", item=""},
		[7] = {npc="ս", item="÷"},
		[8] = {npc="밢", item="ȵ"},
		[10] = {npc="Ľݴ", item="Ѳˮ"},
		[11] = {npc="", item=""},
		}

	local szOptItem = ""
	for i, v in pairs(OptionItem) do
		if v.npc == szNpcName then
			szOptItem = v.item
			break
		end
	end

	if szOptItem == nil then
		ShowMessage("ʦŷûҵΧ˵ѡ")
		return
	end

	MoveToNPC(tonumber(fX), tonumber(fY), tonumber(nSceneID), szNpcName)
	QuestFrameOptionClicked(szOptItem, CMP_FULL_MATCH)	-- ѡѡ
	QuestFrameAcceptClicked()
end


-----------------------------------------------------------------------

local g_MaxCount = 9999

function _SMain(...)

	if _CommandLine ~= nil then 
		if _CommandLine.skip ~= nil then
			BLOCK_PROCESS_MODE = _CommandLine.skip
		end
		if _CommandLine.count ~= nil then
			g_MaxCount = tonumber(_CommandLine.count)
		end
	end

	DbgPrintf("ʦ %d , :%d" , tonumber(g_MaxCount) , tonumber(BLOCK_PROCESS_MODE)) 

	while true do

		LuoYangRestore()

		g_nIndex, g_idMission, g_idScript = DataPool:GetPlayerMission(g_szMission)

		if g_nIndex ~= -1 then

			DbgPrintf("%s Index:%d MissionID:%d ScriptID:%d", g_szMission, g_nIndex, g_idMission, g_idScript)

			-- ȡ
			for i=0,7 do
				g_nParam[i] = DataPool:GetPlayerMission_Variable(g_nIndex, i)
				DbgPrintf("[%d]%d", i, g_nParam[i])
			end

			if DataPool:IsMissionCanCommit(g_idMission) then

				DbgPrintf("")
				-- 

				-- ץ⴦
				if g_nParam[4] == 5 then
					OnShimen5()
				else
					local Npc = g_Shimen_Npc[g_nMenPai]
					MoveToNPC(Npc.fX, Npc.fY, Npc.nSceneID, Npc.szNpcName)
					QuestFrameOptionClicked(g_szMission, CMP_PART_MATCH)	-- ѡѡ
					QuestFrameMissionContinue()	-- 
					QuestFrameMissionComplete()	-- 
					QuestFrameMissionClose()
				end

			else

				DbgPrintf("")

				-- ʦŷNPC
				if g_idScript == 229010 then

					OnShimen_Visit_NPC_Of_Other()
				else

					local nFunc = g_nParam[4]

					if g_nMenPai == 0 then
						if nFunc > 8 then
							nFunc = nFunc - 1
						end
					elseif g_nMenPai == 5 then
						if nFunc == 8 then
							nFunc = 9
						end
					end

					-- ʦų
					-- δ
					if nFunc == 0 then
						OnShimen0()
					elseif nFunc == 1 then
						OnShimen1()
					elseif nFunc == 2 then
						OnShimen2()
					elseif nFunc == 3 then
						OnShimen3()
					elseif nFunc == 4 then
						OnShimen4()
					elseif nFunc == 5 then
						OnShimen5()
					elseif nFunc == 6 then
						OnShimen6()
					elseif nFunc == 7 then
						OnShimen7()
					elseif nFunc == 8 then
						OnShimen8()
					elseif nFunc == 9 then
						OnShimen9()
					end
				end
			end
		else
			-------------------------------------------------------------------------------------
			-- ȡ
			local nRound = 0 

			local isNext,szMsg = GetDebugMessage()
			while isNext == 1 do
				local _,_,nRd = string.find(szMsg ,"Ѿ#.(%d+)#.ʦ")
				if nRd ~= nil then
					nRound = tonumber(nRd)
				end
				isNext,szMsg = GetDebugMessage()
			end

			if nRound >= g_MaxCount then
				ShowMessage("ʦѾ %d " , nRound )
				System:UpdateRecord( script_name )
				break 
			end
			
			local dwNow = System:GetTickCount()

			if dwNow > g_dwNextTime then

				local Npc = g_Shimen_Npc[g_nMenPai]

				MoveToNPC(Npc.fX, Npc.fY, Npc.nSceneID, Npc.szNpcName)
				QuestFrameOptionClicked(g_szMission, CMP_PART_MATCH)	-- ѡѡ

				local strType,_,_,_,szText = DataPool:GetNPCEventList_Item(1);

				if strType == "text" then
					if string.find(szText, "15") then
						ShowMessage("ʦ15ڲܽʦ")
						g_dwNextTime = dwNow + 1000 * 60
					elseif string.find(szText, "һֻ60") then
						ShowMessage("ʦѾ60ʦ")
						System:UpdateRecord( script_name )
						break	-- ˳ѭű
					end
				end

				QuestFrameMissionClose()
			else
				-- ȴʦ
				ShowMessage("ʦ15ڲܽʦ")
				System:Sleep(1500)
			end
		end

		System:Sleep(500)
	end
end

--BPM_TIP
_SMain()