NCDS
2009-11-15 09:19:55
Made a few changes. Still plan to add some more debug and work on a more accurate way of being 100% positive we have the correct object before we move the mouse.
Still, any suggestions are openly welcome :)
Still, any suggestions are openly welcome :)
{*******************************************************************************}
{ function MSI_FindMSObj(Obj: TMSObj; var x, y: Integer; Action: fnct_ActionOptions): Boolean; }
{ By: NCDS }
{ Rev: 25 }
{ Date: 12 Nov 09 }
{ Description: Searches for Obj specified by TMSObj record. }
{ Returns x and y values.
{ Valid Arguments for 'Action': Nothing. ClickRight. ClickLeft. Move.
{*******************************************************************************}
function MSI_FindMSObj(Obj: TMSObj; var x, y: Integer; Action: fnct_ActionOptions): Boolean;
var
cArr: array of TPoint; i, ii, Tol: Integer; Fail, N, Bool: Boolean;
atpa: T2DPointArray;
begin
if not LoggedIn then Exit;
Tol := 0;
// Set bool for mouse click
if Action = ClickRight then
Bool := False;
// 3 attempts for a succesful result.
for i := 0 to 2 do
begin
Fail := False;
// Loop through Color array.
for ii := 0 to High(Obj.Colors) do
begin
FindColorsSpiralTolerance(
MSCx, MSCy,
cArr, Obj.Colors[ii],
MSx1, MSy1, MSx2, MSy2,
Tol
);
// Check if Color is found.
if Length(cArr) > 3 then
begin
MSIDebug('MSI_FindMSObj', 'Length(cArr) = '+IntToStr(Length(cArr))+';', {number});
Break;
end;
if ii = High(Obj.Colors) then
begin
Fail := True;
IncEx(Tol, 2);
Break;
end;
end;
if Fail then
Continue;
// Convert to T2DPointArray.
atpa := TPAToATPAEx(cArr, Obj.w, Obj.h);
// Sort atpa to search closest points first.
SortATPAFrom(atpa, Point(MSCx, MSCy));
case Action of
Nothing : N := True;
ClickLeft,
ClickRight,
Move :
for ii := 0 to High(atpa) do
begin
MMouse(atpa[ii].x, atpa[ii].y, 2, 2);
Wait(RandomRange(200, 500));
if Action = Move then Break;
if IsUpTextMultiCustom(Obj.UpTexts) then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, bool);
end;
end;
end;
end;// of 3 attempt loop.
if N or x > 0 or y > 0 then
begin
Result := True;
MSIDebug('MSI_FindMSObj', 'Successful.', {number});
end else
MSIDebug('MSI_FindMSObj', 'Failed.', {number});
end;