SCAR Code:
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- Freaky Forester Solver Routines --//
//-----------------------------------------------------------------//
// * function ForesterCenter(var x, y: Integer): Boolean; // * by Sumilion
// * function InForesterRandom: Boolean; // * by ZephyrsFury
// * function forester_GetTask: Integer; // * by Sumilion
// * function KillPheasant(Tails: Integer): Boolean; // * by TRiLeZ
// * function WarningScreen: Boolean; // * by TRiLeZ
// * procedure BringRawPheasant; // * by Sumilion
// * function LeaveForester: Boolean; // * by Sumilion
// * function SolveForester: Boolean; // * by TRiLeZ & Sumilion and SKy Scripter
{*******************************************************************************
function ForesterCenter(var x, y: Integer): Boolean;
by: Sumilion
Description: Returns position of the center.
*******************************************************************************}
function ForesterCenter(var x, y: Integer): Boolean;
var
arP: TPointArray;
tmpCTS: Integer;
P: TPoint;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(0);
if not(FindColorsTolerance(arP, 195836, MMX1, MMY1, MMX2, MMY2, 25)) then
begin
ColorToleranceSpeed(tmpCTS);
Exit;
end;
P := MiddleTPA(arP);
Result := True;
x := P.x;
y := P.y;
end;
{*******************************************************************************
function InForesterRandom: Boolean;
by: ZephyrsFury
Description: Checks if we're in the Freaky Forester Random.
*******************************************************************************}
function InForesterRandom: Boolean;
var
Count, fX, fY, X, Y: Integer;
Pts: TPointArray;
begin
if (FindColor(X, Y, 60909, MMCX - 20, MMCY - 20, MMCX + 20, MMCY + 20)) then //Exists NPC dots
if (not(InBlack)) then //No black in Forester
begin
FindColorsTolerance(Pts, 60909, MMX1, MMY1, MMX2, MMY2, 0);
Count := Length(Pts);
if (Count < 10) then Exit; //More than 10 NPC dots (pheasants)
if (CountColorTolerance(clWhite, MMX1, MMY1, MMX2, MMY2, 50) < 20) then //No white walls
begin
ForesterCenter(fX, fY);
FilterPointsPie(Pts, 0.0, 360.0, 0.0, 50.0, fX, fY);
Result := (Length(Pts) = Count); //All NPC's concentrated in centre
end;
end;
end;
{*******************************************************************************
function forester_GetTask: Integer;
by: Sumilion
Description: Reads what kind of pheasant SRL needs to search for.
*******************************************************************************}
function forester_GetTask: Integer;
var
dx, dy, fx, fy, t: Integer;
begin
if not FindNPCChatText('Freaky Forester', Nothing) then
begin
Writeln('Forester: We should talk to the freaky forester.');
if not ForesterCenter(dx, dy) then
begin
Writeln('Forester: Forester center not found.');
LogOut;
Exit;
end;
// Prevents it from clicking on the yellow dot lol.
dx := dx + 8;
dy := dy - 1;
if not FindColorTolerance(fx, fy, 2461584, dx - 10, dy - 10, dx + 10, dy + 10, 30) then
begin
fx := dx;
fy := dy;
end;
Mouse(fx, fy, 0, 0, True);
Flag;
Wait(1500 + Random(500));
MarkTime(t);
repeat;
if (FindObjTPA(dx, dy, 1465001, 20, 2, 5, 5, 10, ['alk'])) then
begin
GetMousePos(dx, dy);
Mouse(dx, dy, 0, 0, False);
end;
Wait(100 + Random(100));
until ChooseOption('alk-to') or
(TimeFromMark(t) > 30000);
if (TimeFromMark(t) > 30000) then
begin
Writeln('Forester: Can''t find the Forester.');
LogOut
Exit;
end;
Flag;
T := GetSystemTime;
while (not(InConvo)) and (GetSystemTime - T < 30000) do
Wait(100);
Wait(500 + Random(100));
if (TimeFromMark(t) > 30000) then
begin
Writeln('Forester: Failed to talk to the Forester.');
LogOut;
Exit;
end;
end;
while (InConvo) and (Result = 0) do
begin
if FindNPCChatText('one', Nothing) then
Result := 1;
if FindNPCChatText('two', Nothing) then
Result := 2;
if FindNPCChatText('three', Nothing) then
Result := 3;
if FindNPCChatText('four', Nothing) then
Result := 4;
ClickContinue(True, True);
end;
if (Result = 0) then
begin
Writeln('Forester: Can''t find what the Forester wants us to do.');
LogOut;
Exit;
end;
marktime(t);
while ClickContinue(True, True) and (TimeFromMark(t) < 5000) do Wait(700 + random(500));
Writeln('Forester: Kill The ' + inttostr(Result) + ' Tailed Pheasant.');
end;
{*******************************************************************************
function KillPheasant(Tails: Integer): Boolean;
by: TRiLeZ
Description: Attempts to kill a pheasant with given tail size.
Date: December 17, 2009
*******************************************************************************}
function KillPheasant(Tails: Integer): Boolean;
var
Tail: TPointArray;
Pheasant, NTails: T2DPointArray;
B: TBox;
I, x, y, T, A, TempS: Integer;
begin
MakeCompass(0);
TempS := MouseSpeed;
MouseSpeed := 25;
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.37, 0.33);
MarkTime(t);
repeat
Wait(2000 + Random(1000));
if FindColorsTolerance(Tail, 9740459, MSX1+20, MSY1+20, MSX2-20, MSY2-20, 2) then //White tail tip
begin
Pheasant := TPAtoATPA(Tail, 25);
SortATPASize(Pheasant, (Tails = 3) or (Tails = 4));
for I := 0 to High(Pheasant) do
begin
B := GetTPABounds(Pheasant[i]);
A := (B.x2 - B.x1) * (B.y2 - B.y1);
case Tails of
1: if not InRange(A, 0, 4) then Continue;
2: if not InRange(A, 16, 24) then Continue;
3: if not InRange(A, 40, 72) then Continue;
4: if not InRange(A, 100, 140) then Continue;
end;
FindColorsTolerance(Tail, 9740459, B.x1-2, B.y1-2, B.x2+2, B.y2+2, 2);
NTails := TPAtoATPA(Tail, 3);
if (Tails = Length(NTails)) then
begin
MiddleTPAEx(Pheasant[i], x, y);
Mouse(x, y, 0, 0, false);
Wait(300 + Random(200));
Result := ChooseOption('Attack');
if (not Result) then Break;
end;
end;
end else
Wait(10);
until Result or (TimeFromMark(t) >= 120000) or (not InForesterRandom);
MouseSpeed := TempS;
end;
{*******************************************************************************
function WarningScreen: Boolean;
by: TRiLeZ
Description: Results true if there is a warning screen about dropped items.
Date: December 29, 2009
*******************************************************************************}
function WarningScreen: Boolean;
begin
if (CountColor(0, MSX1, MSY1, MSX2, MSY2) > 1400) then
Result := FindTextTPA(2070783, 20, 240, 48, 300, 66, 'Warning', upchars, Nothing);
end;
{*******************************************************************************
procedure BringRawPheasant;
by: Sumilion
Description: Brings the raw pheasant to the forester.
*******************************************************************************}
procedure BringRawPheasant;
var
rx, ry, I, t, cts: Integer;
P: TPointArray;
Objs: T2DPointArray;
Done, B: Boolean;
begin
MarkTime(t);
cts := GetColorToleranceSpeed;
repeat;
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.02, 0.09);
FindColorsSpiralTolerance(MSCX, MSCY, P, 2444664, MSCX - 100, MSCY - 100, MSCX + 100, MSCY + 100, 9);
Objs := TPAtoATPA(P, 20);
if (Length(Objs) = 0) then Break;
if ((Length(Objs) = 1) and (Length(Objs[0]) < 40)) then Break;
for I := 0 to High(Objs) do
if (Length(Objs[I]) > 40) then
begin
MiddleTPAEx(Objs[I], rx, ry);
MMouse(rx, ry, 0, 0);
wait(10 + random(20));
ColorToleranceSpeed(1);
if (IsUpText('ake')) then
begin
Mouse(rx, ry, 0, 0, True);
Flag;
Wait(1000 + random(500));
Done := True;
Break;
end;
end;
Wait(500 + random(200));
until (Done) or (TimeFromMark(t) > 30000);
ColorToleranceSpeed(cts);
if (TimeFromMark(t) > 30000) or (not(done)) then
begin
Writeln('Forester: Can''t find the Dead Pheasant.');
LogOut
Exit;
end;
Flag;
Wait(500 + Random(500));
if not ForesterCenter(rx, ry) then
begin
Writeln('Forester: Forester center not found.');
LogOut;
Exit;
end;
Mouse(rx, ry, 1, 1, True);
Flag;
MarkTime(t);
repeat;
if (FindObjTPA(rx, ry, 1465001, 20, 2, 5, 5, 10, ['alk'])) then
Mouse(rx, ry, 0, 0, False);
Wait(100 + Random(100));
if TimeFromMark(t) > 20000 then
if not B then
begin
B := True;
Mouse(MSCX, MSCY, 3, 3, False);
end;
until ChooseOption('alk-to') or
(TimeFromMark(t) > 30000);
if (TimeFromMark(t) > 30000) then
begin
Writeln('Forester: Can''t find the Forester.');
LogOut
Exit;
end;
Flag;
T := GetSystemTime;
while (not(InConvo)) and (GetSystemTime - T < 10000) do
Wait(100);
Wait(100 + Random(200));
marktime(t);
while ClickContinue(True, True) and (TimeFromMark(t) < 5000) do Wait(700 + random(500));
end;
{*******************************************************************************
function LeaveForester: Boolean;
by: Sumilion
Description: Leaves the random through the portal.
*******************************************************************************}
function LeaveForester: Boolean;
var
PortalInfo: TAutoColorInfo;
fx, fy, t: Integer;
begin
Writeln('Forester: Leaving Forester.');
with PortalInfo do
begin
UpText := 'Enter';
MaxDist := 15;
Color := 6203300;
HueMod := 0.03;
SatMod := 0.32;
LumTol := 7;
MinR := 147; MaxR := 244;
MinG := 148; MaxG := 243;
MinB := 87; MaxB := 187;
MinX := 24.70; MaxX := 77.60;
MinY := 28.48; MaxY := 86.13;
MinZ := 13.41; MaxZ := 58.99;
end;
ForesterCenter(fx, fy);
Mouse(fx + 25, fy, 0, 0, True);
Flag;
MarkTime(t);
repeat;
if FindObjRecordEx(fx, fy, PortalInfo, MSX1, MSY1, MSX2, MSY2, False, True) then
Mouse(fx, fy, 0, 0, False);
Wait(100 + Random(100));
until ChooseOption('Enter') or
(TimeFromMark(t) > 30000);
if (TimeFromMark(t) > 30000) then
begin
Writeln('Forester: Can''t find the portal.');
LogOut
Exit;
end;
Flag;
Wait(2000);
T := GetSystemTime;
while (GetSystemTime - T < 20000) do
begin
if WarningScreen then MouseBox(144, 195, 392, 204, 1);
Result := (GetMusic <> 'Pheasant Peasant');
if (Result) then Break;
Wait(1000);
end;
end;
{*******************************************************************************
function SolveForester: Boolean;
by: TRiLeZ & Sumilion and SKy Scripter
Description: Main solving procedure.
Date: December 17, 2009
*******************************************************************************}
function SolveForester: Boolean;
var
Task, t, cx, cy, TempCTS: Integer;
TempHue, TempSat: Extended;
ItemDropped: Boolean;
begin
TempCTS := GetColorToleranceSpeed;
GetColorspeed2Modifiers(TempHue, TempSat);
Task := forester_GetTask;
if not InForesterRandom then Exit;
if InvFull then
begin
DropItem(28);
ItemDropped := True;
end;
if (not KillPheasant(Task)) then
begin
Writeln('Forester: ForesterSolver failed to find the pheasant.');
LogOut;
Exit;
end;
Flag;
MarkTime(t);
while (TimeFromMark(t) < 10000) do
begin
Wait(10);
if ClickContinue(True, True) then Break;
end;
Writeln('Forester: Killed Pheasant.');
Wait(1000 + Random(500));
BringRawPheasant;
if ItemDropped then
begin
if FindColor(cx, cy, 237, MMX1, MMY1, MMX2, MMY2) then
begin
Mouse(cx, cy, 0, 0, True);
Flag;
Wait(1500 + Random(500));
MMouse(MSCX, MSCY, 0, 0);
if (not IsUpText('ere')) then
begin
if IsUpText('ake') then Mouse(MSCX, MSCX, 0, 0, True)
else
begin
Mouse(MSCX, MSCY, 0, 0, False);
Wait(250 + Random(100));
ChooseOption('ake');
end;
Wait(500 + Random(250));
end;
end;
end;
if not InForesterRandom then Exit;
Result := LeaveForester;
if (not Result) then
begin
Mouse(684, 86, 4, 4, True);
Flag;
Wait(3000 + Random(1000));
Result := LeaveForester;
end;
ColorToleranceSpeed(TempCTS);
SetColorspeed2Modifiers(TempHue, TempSat);
if Result then
begin
Writeln('Forester: Forester random solved.')
marktime(t);
while ClickContinue(True, True) and (TimeFromMark(t) < 5000) do Wait(700 + random(500));
end else begin
Writeln('Forester: Failed to exit the forester');
LogOut;
Exit;
end;
end;