require "global";
require "local";


local tbpkgPoint = {   --快键的x位置 相对于窗口中间
		[1] = -385,
		[2] = -349,
		[3] = -314,
		[4] = -279,
		[5] = -244,
		[6] = -209,
		[7] = -174,
		[8] = -139,
		[9] = -104,
		[10] = -69,
		[11] = -34,
		[12] = 1,
		[13] = -174,
		[14] = -139,
		[15] = -104,
		[16] = -69,
		[17] = -34,
		[18] = 1,
	}

function CheckHP()
	local	i = 204;
	local	n = 0;
	local  ai = 203;
	while i > 86 do
		i=i-1;
		pH = GetPixColor( i,30 );
		intB, intG, intR = ColorToRGB(pH); --获取相应点上面的颜色
			--WriteLog('R:',intR);
			--WriteLog(intG);
			--WriteLog(intB);
		if intR ~= 97 and ((intR ~= intG) and (intG ~= intB)) and intR ~= 48 and intR ~= 57 and intR ~= 77 and intR ~= 42 and intR ~= 81 and intR ~= 100  and intR ~= 89 then  --去灰,滤色
			if i < 200  and n ==0 then
				ai = i;
				i = i + 3;
				n = n + 1;
			elseif	i < 200  and n ~=0 then
				if	i == ai then
					break;
				else
					i = 203;
					break;
				end
			else
				break;
			end
		elseif	i == 86 then
			i = 203;
			break;
		end
	end
--	if  i > 85 then
		intHP = (i - 84) / 1.19;
		if intHP < 97 then
			pH = GetPixColor( i + 1,30 );
			intB, intG, intR = ColorToRGB(pH); --获取相应点上面的颜色
			if (intR == 97) or (intR == 48) or (intR == 57) or (intR == 77) or (intR == 42) or (intR == 81) or (intR == 89) or (intR == 100) or ((intR == intG) and (intG == intB)) then
				SetHP(intHP); --设置血量
			else
				WriteLog("出错:intHP:",intHP,',','i:',i,';r:',intR,';g:',intG,';B:',intB); --出错
				pH = GetPixColor( i ,30 );
				intB, intG, intR = ColorToRGB(pH); --获取相应点上面的颜色
				WriteLog("oldintHP:",intHP,',','i:',i,';r:',intR,';g:',intG,';B:',intB);
			end
		else
			SetHP(100); --设置血量
		end
--		else
--			SetHP(-66); --设置血量
--		end
	end


function CheckMP()
	local	j =204;
--	n = 0;
	while j > 86 do
		j=j-1;
		pM = GetPixColor( j,41 );
		intB, intG, intR = ColorToRGB(pM); --获取相应点上面的颜色
		if intB ~= 135 and ((intR ~= intG) and (intG ~= intB)) and intB ~= 63 and intB ~= 139 and intB ~= 79 and intB ~= 68 and intB ~= 124 and intB ~= 107 then  --去灰,滤色
--			n = 1;
			break;
		end
	end
	if  j > 90 then
		intMP = (j - 84) / 1.19;
		--WriteLog("intMP",intMP);
		SetMP(intMP); --设置蓝量
--	else
--		SetMP(-66); --设置蓝量
	end
end





function CheckPKG()
--	WriteLog("n");
	local a = {} ;
	AintW, AintH = GetWindowRect(); --获取窗体的高和宽
	intBeginY = AintH-27;
	intMaxY = intBeginY + 18;
	intBeginY0 = AintH-68;
	intMaxY0 = intBeginY0 + 18;
	for n in pairs(tbpkgPoint) do
		intBeginX = (AintW/2) + tbpkgPoint[n];
		intMaxX = intBeginX + 35;
		if n <= 12  then
			if	(tostring(getImageText( intBeginX, intBeginY, intMaxX, intMaxY, 58, 206, 0, 3 , 3)) == '0' ) then
				a[n]= 0;
			else
				a[n]=1;
			end
		else
			if	(tostring(getImageText( intBeginX, intBeginY0, intMaxX, intMaxY0, 58, 206, 0, 3 , 3)) == '0' ) then
				a[n]= 0;
			else
				a[n]=1;
			end
		end
	end
	SetPkgState( a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15],a[16],a[17],a[18] );
end



CheckHP(); --检测血量
CheckMP(); --检测魔法量
CheckPKG(); --检测包裹状态
