require "global";
require "local";
--日常"BEA32C","0|-10|BEA32C,-1|-10|000000,-3|-10|BEA32C,-5|-8|BEA32C,-6|-8|000000,-15|0|BEA32C"
function checkDailyTask()
	intW, intH = GetWindowRect(); --获取窗体的高和宽
	intX = intW - 240;
	intY = 200;
	intMaxX = intW;
	intMaxY = intH;
	strFirstClr = "BEA32C";
	strParamter = "0|-10|BEA32C,-1|-10|000000,-3|-10|BEA32C,-5|-8|BEA32C,-6|-8|000000,-15|0|BEA32C";
	intResult, intX, intY  = FindMultiColor(intX, intY, intMaxX, intMaxY, strFirstClr, strParamter);
	if intResult == 1  then
		if checkReverseGreen(intW, intY + 30, intX , intY) then
			return  true;
		else
			return  false;
		end
	else
		return  false;
	end
end



function checkOK()
	intResult,intX,intY = checkDialog();
	if intResult == 1 then
		n = compareGreen(intX - 300, intY,intX, intY + 220);
		--WriteLog('n:',n);
		if (n > 0 and n < 20)  then
			t = checkOverDailyTask();
			if not t then
				intResult,intX,intY = checkDialog();
				if intResult == 1 then
					if  checkGreen(intX - 300, intY,intX, intY + 220) then
						return  true;
					else
						return  false;
					end
				else
					return  false;
				end
			else
				return  false;
			end
		elseif (n > 20 and n < 180) then
			intResult,intX,intY = checkDialog();
			if intResult == 1 then
				if checkReverseGreen(intX, intY + 220, intX - 300 , intY) then
					return  true;
				else
					return  false;
				end
			else
				return  false;
			end
		elseif (n > 180 and n < 250) then
			intResult,intX,intY = checkDialog();
			if intResult == 1 then
				if checkGreen(intX - 300, intY,intX, intY + 220) then
					return  true;
				else
					return  false;
				end
			else
				return  false;
			end
		else
			return  false;
		end
	else
		return  false;
	end
end

i=os.time() - 6;
j=os.time() - 1;
k=os.time() - 1;
l=os.time() - 1;
while api_checkThread(4)  do
	if ((os.time()-i) >= 7) and (not checkHangUp()) and (not checkXunLu())then
--		api_sendKey('27');--Esc
		if checkDailyTask() then
			i=os.time();
		end
	elseif ((os.time()-j) >= 1) and checkOK() then
		j=os.time();
	elseif ((os.time()-l) >= 1) and checkOverDailyTask() then
		l=os.time();
	elseif ((os.time()-k) >= 1) and checkGoTo() then
		k=os.time();
	end
	api_LuaSleep(100);
--	WriteLog('time:', os.time() );
end
