SCAR Code:
program AgilityRunner;
{.include srl/srl.scar}
type
Rinfo = Record
position, failed, success: string;
aStrArr: TStringArray;
col, tol, x, y: integer;
hue, sat: Extended;
end;
Pinfo = Record
f, a: integer;
xp, lvl: integer;
end;
var Progress: array of Pinfo; GnC: array of Rinfo; down: Boolean;
Function GetMMPoints(x, y, color, width, height, tolerance: Integer): TpointArray;
var tpa: TpointArray; atpa: T2DpointArray; l, i, p: Integer;
begin
FindColorsSpiralTolerance(x, y, tpa, color, MMx1, MMy1, MMx2, MMy2, tolerance);
Atpa := TPAtoATPAEx(Tpa, width, height);
for i := 0 to High(atpa) do
begin
if Length(atpa) > 5 then
begin
l := getarraylength(Result);
SetArrayLength(Result, l+1);
Result[l] := MiddleTpa(atpa[i]);
end;
end;
if Length(result) = 0 then Exit;
for i := 0 to High(Result) do
if rs_OnMiniMap(result[i].x, result[i].y) then Inc(p);
if p = 0 then SetArrayLength(Result, 0);
WriteLn('Found: '+IntToStr(l)+' Result(s)');
end;
Function ClickMMpoint(tpa: TpointArray; xmod, ymod: Integer): Boolean;
var i: integer;
begin
for i := 0 to High(tpa) do
begin
WriteLn('Current Point at: ('+IntToStr(Tpa[i].x)+', '+IntToStr(tpa[i].y)+');');
if not rs_OnMiniMap(tpa[i].x, tpa[i].y) then Continue;
Mouse(tpa[i].x+xmod, tpa[i].y+ymod, 5, 5, True);
Wait(150+random(200));
if FlagPresent then
begin
Result := True;
Flag;
Break;
end else
Continue;
end;
wait(500+random(750));
end;
Function DeturmineWalkColor: Integer;
begin
Tpa := GetMMPoints(MMx1, MMy1, 2447722, 10, 10, 25);
sortTPAfrom(tpa, Point(575, 89));
ClickMMPoint(Tpa, 10, -12);
end;
Function CreateWalkingPoints(col: Integer): Integer;
var MainPoint: TDTMPointDef; dtmSubPoints: Array [1..4] of TDTMPointDef; TempTDTM: TDTM; i: Integer;
begin
with MainPoint do
begin
x := 840;
y := 248;
AreaSize := 2;
AreaShape := 0;
Color := 15527148;
Tolerance := 422;
end;
dtmSubPoints[1].x := 832;
dtmSubPoints[1].y := 275;
dtmSubPoints[2].x := 848;
dtmSubPoints[2].y := 275;
dtmSubPoints[3].x := 847;
dtmSubPoints[3].y := 256;
dtmSubPoints[4].x := 832;
dtmSubPoints[4].y := 256;
for i := 1 to High(dtmSubPoints) do
begin
dtmSubPoints[i].Color := col;
dtmSubPoints[i].Tolerance := 25;
dtmSubPoints[i].AreaSize := 1;
end;
TempTDTM.MainPoint := MainPoint;
TempTDTM.SubPoints := dtmSubPoints;
Result := AddDTM(TempTDTM);
end;
Function ClickWalkingPoint: Boolean;
var dtm, col, x, y: Integer;
begin
col := DeturmineWalkColor;
if col = 0 then Exit;
dtm := CreateWalkingPoints(col);
Result := DTMRotated(dtm, x, y, MMx1, MMy1, MMcx+50, MMy2);
FreeDtm(dtm);
if not Result then Exit;
WriteLn('Dtm located at: ('+IntToStr(x)+','+IntToStr(y)+')');
Mouse(x, y-5, 5, 5, True);
FFlag(0);
Wait(750+random(300));
end;
Procedure CreateObjectRecord;
begin
SetArrayLength(GnC, 7);
with GnC[0] do
begin
position := 'log';
failed := '';
success := 'afe';
aStrArr := ['alk', 'og'];
hue := 0.03;
sat := 0.20;
col := 668758;
tol := 7;
end;
with GnC[1] do
begin
position := 'net';
failed := '';
success := 'ett';
aStrArr := ['et', 'et'];
hue := 0.04;
sat := 0.16;
col := 801892;
tol := 10;
y := MSy2;
end;
with GnC[2] do
begin
position := 'branch';
failed := '';
success := 'bove';
aStrArr := ['anch', 'limb'];
hue := 0.07;
sat := 1.96;
col := 2182241;
tol := 6;
y := MSy1;
end;
with GnC[3] do
begin
position := 'rope';
failed := '';
success := 'ross';
aStrArr := ['ope', 'ope'];
hue := 0.03;
sat := 0.02;
col := 5469841;
tol := 75;
x := 427;
end;
with GnC[4] do
begin
position := 'branch';
failed := '';
success := 'ound';
aStrArr := ['anch', 'limb'];
hue := 0.07;
sat := 1.96;
col := 2182241;
tol := 6;
y := 183;
x := 362;
end;
with GnC[5] do
begin
position := 'net';
failed := '';
success := 'ett';
aStrArr := ['et', 'et'];
hue := 0.04;
sat := 0.16;
col := 801892;
tol := 15;
y := MSy1;
end;
with GnC[6] do
begin
position := 'pipe';
failed := 'sed';
success := 'ueeze';
aStrArr := ['ipe', 'ipe'];
hue := 0.11;
sat := 0.06;
col := 6447979;
tol := 19;
end;
end;
Function FindRopePoints: TpointArray;
var tpa: TpointArray; atpa: T2DPointArray; l, i, cts: Integer;
begin
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(GnC[3].hue, GnC[3].sat);
FindColorsSpiralTolerance(430, 148, tpa, GnC[3].col, 420, 148, 480, 176, GnC[3].tol);
SortTpaFrom(tpa, Point(GnC[3].x, GnC[3].y));
Atpa := SplitTPAEx(Tpa, 1, 1);
for i := 0 to High(atpa) do
begin
if Length(atpa) > 0 then
begin
l := getarraylength(Result);
SetArrayLength(Result, l+1);
Result[l] := MiddleTpa(atpa[i]);
end;
end;
ColorToleranceSpeed(cts);
SetColorSpeed2Modifiers(0.2, 0.2);
WriteLn('Found: '+IntToStr(l)+' Point(s)') {else Inc(Progress[CurrentPlayer].f)};
end;
procedure FilterPointsBlackEx(var TPA : TPointArray); // ty Da0wner
var
i, h : integer;
TIA : TIntegerArray;
begin
TIA := GetColors(TPA);
h := high(TIA);
for i := 0 to h do
if TIA[i] = 0 then
begin
Swap(TPA[i], TPA[h]);
SetArrayLength(TPA, h);
h := high(TPA);
end;
end;
procedure FilterPointBlack(var tpa :TPointArray);
begin
FilterPointsBlackEx(TPA);
end;
Function FindObjPoints(Index: Integer): TpointArray;
var tpa: TpointArray; atpa: T2DPointArray; l, i, cts: Integer;
begin
if GnC[index].x = 0 then GnC[index].x := MScx;
if GnC[index].y = 0 then GnC[index].y := MScy;
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(GnC[index].hue, GnC[index].sat);
FindColorsSpiralTolerance(MScx, MScy, tpa, GnC[index].col, MSx1, MSy1, MSx2, MSy2, GnC[index].tol);
SortTpaFrom(tpa, Point(GnC[index].x, GnC[index].y));
Atpa := TpatoAtpaEx(Tpa, 10, 10);
for i := 0 to High(atpa) do
begin
if Length(atpa) > 5 then
begin
l := getarraylength(Result);
SetArrayLength(Result, l+1);
Result[l] := MiddleTpa(atpa[i]);
end;
end;
ColorToleranceSpeed(cts);
SetColorSpeed2Modifiers(0.2, 0.2);
if (l > 0) then WriteLn('Found: '+IntToStr(l)+' Point(s)') {else Inc(Progress[CurrentPlayer].f)};
end;
Function ClickMSpoint(Index: Integer; tpa: TpointArray; StrArr: TStringArray; RClick: Boolean): Boolean;
var i, h: integer; Bool: Boolean;
begin
//h := 5;
//if Length(tpa) < 5 then Exit;
for i := 0 to high(tpa) do
begin
if Index = 3 then MMouse(tpa[i].x, tpa[i].y, 0, 0) else MMouse(tpa[i].x, tpa[i].y, 3, 3);
Wait(350+random(200));
If IsUpText(StrArr[0]) then
begin
GetMousePos(GnC[index].x, GnC[index].y);
Wait(Random(100));
bool := random(4) <> 1;
if Rclick then Bool := False;
Mouse(GnC[index].x, GnC[index].y, 0, 0, Bool);
Wait(100+random(150));
ChooseOption(StrArr[1]);
Wait(100+random(100));
Result := True;
Exit;
end else
Continue;
end;
end;
Function CompleteObstacle(Index: Integer): Boolean;
var i, a, attempts, t: Integer; tpa: TpointArray; Bool, ReRun, AngleSet: Boolean;
begin
if not LoggedIn then Exit;
i := index;
Status(GnC[i].Position);
WriteLn(GnC[i].Position);
if i = 3 then tpa := FindRopePoints else tpa := FindObjPoints(i);
if i = 2 then Bool := True;
if Length(tpa) <= 0 then CompleteObstacle(i);
ClickMSpoint(i, tpa, GnC[i].aStrArr, Bool);
a := Getsystemtime;
while not FindBlackChatMessage(GnC[i].Success) do
begin
if FindBlackChatMessage(GnC[i].Failed) or (GetSystemTime-a >= 25000) then
begin
ReRun := True;
Break;
end;
wait(150+random(200));
Down := False;
end;
if not ReRun then
begin
WriteLn('Completed. Object: ['+IntToStr(i)+']; Continuing.');
if AngleSet then
begin
SetAngle(True);
AngleSet := False;
end;
Result := True;
if i = 3 then Wait(4000+random(1000)) else wait(2550+random(750));
Exit;
end;
WriteLn('Failed. Object: ['+IntToStr(i)+']; Reinitiating.');
if i = 4 then
begin
SetAngle(False);
AngleSet := True;
end;
inc(Attempts);
WriteLn('Attempted to Solve Object: ['+IntToStr(i)+']: '+IntToStr(attempts)+' times.');
if Attempts > 1 then
begin
Result := False;
Exit;
end;
CompleteObstacle(Index);
end;
Function ObstacleLoop(Index: Integer): Boolean;
begin
case Index of
0..4, 6: Result := CompleteObstacle(Index);
5:
begin
Result := CompleteObstacle(Index);
if not Result then
begin
Mouse(MMcx, MMcy-10, 5, 5, True);
Flag;
Result := CompleteObstacle(Index);
end;
end;
end;
end;
Function Mainloop: Boolean;
var i: Integer;
begin
for i := 0 to 6 do
Result := ObstacleLoop(i);
end;
begin
SetUpSRL;
ActivateClient;
CreateObjectRecord;
DeturmineWalkColor;
MainLoop;
end.