SCAR Code:
program New;
{.include SRL/SRL.scar}
var
I: Integer;
type
TItemDef = record
Name: string;
Count, W, H: Integer;
UniquePts: TPointArray;
UniqueCols: TIntegerArray;
end;
const
cTol = 10; //Tolerance for the unique colour points
function LoadItemDef(ItemNo: Integer): TItemDef;
begin
case ItemNo of
0: with Result do
begin
Name := 'Iron Scimitar';
Count := 71;
W := 26;
H := 29;
UniquePts := [Point(15, 12), Point(4, 23)];
UniqueCols := [5132116, 1818328];
end;
end;
end;
function FindItem(var x, y: Integer; Item: TItemDef; x1, y1, x2, y2: Integer): Boolean;
var
bPts: TPointArray;
bATPA: T2DPointArray;
II, G: Integer;
TB: TBox;
begin
x := 0; y := 0;
if (FindColorsTolerance(bPts, 65536, x1, y1, x2, y2, 0)) then
begin
bATPA := SplitTPAEx(bPts, 42, 36);
for II := 0 to High(bATPA) do
begin
if (Length(bATPA[II]) <> Item.Count) then Continue;
TB := GetTPABounds(bATPA[II]);
if (TB.x2 - TB.x1 <> Item.W) then Continue;
if (TB.y2 - TB.y1 <> Item.H) then Continue;
for G := 0 to High(Item.UniquePts) do
begin
try
Result := SimilarColors(GetColor(TB.x1 + Item.UniquePts[G].x, TB.y1 + Item.UniquePts[G].y), Item.UniqueCols[G], cTol);
except
WriteLn('No of Pts don''t match number of colours.');
end;
end;
if (Result) then
begin
x := (TB.x2 - TB.x1) shr 1;
y := (TB.x2 - TB.x1) shr 1;
Break;
end;
end;
end;
end;
function FindItems(var Points: TPointArray; Item: TItemDef; x1, y1, x2, y2: Integer): Boolean;
var
tBool: Boolean;
II, G: Integer;
bPts: TPointArray;
bATPA: T2DPointArray;
TB: TBox;
begin
SetLength(Points, 0);
if (FindColorsTolerance(bPts, 65536, x1, y1, x2, y2, 0)) then
begin
bATPA := SplitTPAEx(bPts, 50, 50);
for II := 0 to High(bATPA) do
begin
if (Length(bATPA[II]) <> Item.Count) then Continue;
TB := GetTPABounds(bATPA[II]);
if (TB.x2 - TB.x1 <> Item.W) then Continue;
if (TB.y2 - TB.y1 <> Item.H) then Continue;
for G := 0 to High(Item.UniquePts) do
begin
try
tBool := SimilarColors(GetColor(TB.x1 + Item.UniquePts[G].x, TB.y1 + Item.UniquePts[G].y), Item.UniqueCols[G], cTol);
except
WriteLn('No of Pts don''t match number of colours.');
end;
end;
if (tBool) then
begin
SetLength(Points, Length(Result) + 1);
Points[High(Points)] := Point((TB.x2 - TB.x1) shr 2, (TB.x2 - TB.x1) shr 2);
end;
end;
end;
Result := Length(Points) > 0;
end;
procedure CaptureImage(x1, y1, x2, y2: Integer);
var
Pts: TPointArray;
TB: Tbox;
BMP: INteger;
begin
if (FindColorsTolerance(Pts, 65536, x1, y1, x2, y2, 0)) then
begin
Tb := GetTPABounds(Pts);
BMP := BitmapFromString(TB.x2 - tb.x1, tb.y2 - tb.y1, '');
CopyCanvas(GetClientCanvas, GetBitmapCanvas(BMP), Tb.x1, tb.y1, tb.x2, tb.y2, 0, 0, tb.x2-tb.x1, tb.y2-tb.y1);
DisplayDebugImgWindow(tb.x2 - tb.x1, tb.y2 - tb.y1);
CopyCanvas(GetBitmapCanvas(BMP), GetDebugCanvas, 0, 0, tb.x2-tb.x1, tb.y2-tb.y1, 0, 0, tb.x2-tb.x1, tb.y2-tb.y1);
WriteLn('Count: ' + IntToStr(Length(Pts)));
Writeln('W: ' + Inttostr(tb.x2-tb.x1) + ', H: ' + inttostr(tb.y2-tb.y1));
end;
end;
var
AirRune: TItemDef;
x, y: integer;
begin
SetupSRL;
//ActivateClient;
Wait(100);
//CaptureIMage(562, 211, 599, 250);
AirRune := LoadItemDef(0);
i := getsystemtime;
if (FindItem(x, y, AirRune, 555, 211, 731, 458)) then
Writeln('woot');
writeln(inttostr(getsystemtime - i));
end.