require "global";
require "local";

local	intW, intH = GetWindowRect(); --获取窗体的高和宽


--主线"000000","0|1|BEA32C,5|2|BEA32C,6|2|000000,7|11|000000,6|11|BEA32C,-4|11|BEA32C"
function checkTask()
	intW, intH = GetWindowRect(); --获取窗体的高和宽
	intX = intW - 240;
	intY = 200;
	intMaxX = intW;
	intMaxY = intH;
	strFirstClr = "000000";
	strParamter = "0|1|BEA32C,5|2|BEA32C,6|2|000000,7|11|000000,6|11|BEA32C,-4|11|BEA32C";
	intResult, intX, intY  = FindMultiColor(intX, intY, intMaxX, intMaxY, strFirstClr, strParamter);
	if intResult == 1  then
		if checkReverseGreen(intW, intY + 35, intX , intY) then
			return  true;
		else
			return  false;
		end
	else
--	WriteLog('false');
		return  false;
	end
end

function checkOK()
	intResult,intX,intY = checkDialog();
	--WriteLog( 'X:', intX, 'Y:', intY, 'Result:', intResult );
	if intResult == 1 then
		if checkYellow(intX - 300, intY,intX, intY + 220) then
			return  true;
		elseif checkTGreen(intX - 300, intY,intX, intY + 220) then
			return  true;
		else
			return  false;
		end
	else
		return  false;
	end
end
function  sendEsc()
	api_sendKey('27');--Esc
	return true;
end

sendMouseClick(5, 5);
iT=os.time() - 6;
jT=os.time() - 1;
kT=os.time() - 1;
while api_checkThread(1)  do
	if ((os.time()-iT) >= 9) and (not checkHangUp()) and (not checkXunLu())then
		if checkTask() then
			iT=os.time();
		else
			sendMouseClick(5, 5);
			iT = iT + 2;
		end
	elseif ((os.time()-jT) >= 1) and checkOK() then
		jT=os.time();
	elseif ((os.time()-kT) >= 1) and checkWear() then
		kT=os.time();
	end
	api_LuaSleep(100);
--	WriteLog('time:', os.time() );
end


