ShowMessage("ȡÿз $Rev: 214 $")

--[[
[author]
descript="ÿȡ1"
cmd0str=ȡѷ
cmd0=1
cmd1str=ȡ2η
cmd1=2
cmd2str=ȡ3η
cmd2=3
cmd3str=ȡ4η
cmd3=4
cmd4str=ȡ5η
cmd4=5
cmd_default=0
]]--

perday_max=1
script_name="ȡÿз"


local nMaxClick = 1
function OnMission()

	local nRunTick = 0 
	while true do

		if nRunTick == 0 or UI:IsWindowShow("DanrenFB_Get") == false then

			local nowScene = GetActiveDataSceneID()

			if nowScene == 1 then
	  	 		MoveToNPC(200, 334, 1, "»")
			elseif nowScene == 2 then
	   			MoveToNPC(206, 56, 2, "")
			else
	    			MoveToNPC(218, 243, 0, "")
			end
	
			QuestFrameOptionClicked(script_name , CMP_PART_MATCH)
		end

		nRunTick = nRunTick + 1

		System:Sleep(1000)
		local uClick = 6
		if UI:IsWindowShow("DanrenFB_Get") then
			
			uClick = GetConfimDataBySid( 20151207 , 0 , "data" )
			DbgPrintf("зǰ:%d,%d" , uClick , GetConfimDataBySid( 20151207 , 1 , "data" ) )
			uClick = uClick + 1
			if uClick > 10 then
				uClick = 0 
			end

			if uClick >= nMaxClick then
				ShowMessage("ȡÿз,ȡ %d Σ" , uClick )
				System:UpdateRecord( script_name )
				return
			end

			DoLuaString("DanrenFB_Get_Env" , "DanrenFB_Get_Click()")
		end
		
		if uClick < 5 then

			System:Sleep(500)
			if ( UI:IsWindowShow("LoginSelectServerQuest") ) then
				local jz = Player:GetData("MONEY_JZ")
				DbgPrintf("ǰ:%d" , jz ) 

				local isHadMoney = true 
				if uClick < 3 then
					if jz < 100000 then
						isHadMoney = false
					end
				elseif uClick < 4 then
					if jz < 150000 then
						isHadMoney = false
					end
				else
					if jz < 200000 then
						isHadMoney = false
					end
				end

				if isHadMoney == false then
					ShowMessage("ȡÿзӲ㣡")
					return
				end

				DoLuaString("LoginSelectServerQuest_Env" , "SelectServerQuest_Bn1Click()")
			end

			local isNext,szMsg = GetDebugMessage()
			while isNext == 1 do

				if string.find(szMsg, "Ѿȡ") then
					ShowMessage("ȡÿзѾȡ")
					System:UpdateRecord( script_name )
					return
				elseif string.find(szMsg, "Ѿȡ") then
					ShowMessage("ȡÿзѾȫȡϣ")
					System:UpdateRecord( script_name )
					return
				elseif string.find(szMsg,"ռ䲻") then
					return
				end
				isNext,szMsg = GetDebugMessage()

			end
		elseif uClick == 5 then
			ShowMessage("ȡÿзѾȫȡϣ")
			System:UpdateRecord( script_name )
			return
		end
	end

end

function _SMain(...)

	if _CommandLine ~= nil then 
		nMaxClick =tonumber(_CommandLine)
	end

	OnMission()

	UI:WindowHide()
end

_SMain()


