Simba Code:
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- Freaky Forester Solver Routines --//
//-----------------------------------------------------------------//
// * function ForesterCenter(var x, y: Integer): Boolean; // * by Sumilion
// * function PickUpDroppedItem: Boolean; // * by TRiLeZ
// * function InForesterRandom: Boolean; // * by ZephyrsFury
// * function TalkToFreakyForester: Boolean; // * by IceFire908
// * 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, SKy Scripter, & IceFire908
{*******************************************************************************
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 PickUpDroppedItem: Boolean;
by: TRiLeZ
Description: Picks up a dropped item.
Date: February 7, 2010
*******************************************************************************}
function PickUpDroppedItem: Boolean;
var
cx, cy: Integer;
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
Result := True;
if IsUpText('ake') then Mouse(MSCX, MSCX, 0, 0, True)
else
begin
Mouse(MSCX, MSCY, 0, 0, False);
Wait(250 + Random(100));
Result := ChooseOption('ake');
end;
Wait(500 + Random(250));
end;
end;
end;
{*******************************************************************************
function InForesterRandom: Boolean;
by: TRiLeZ / IceFire908.
Description: Checks if we're in the Freaky Forester Random.
Date: October 8, 2010
*******************************************************************************}
function InForesterRandom: Boolean;
var
Count, fX, fY, CTS: Integer;
Hue, Sat: Extended;
Pts: TPointArray;
begin
GetColorspeed2Modifiers(Hue, Sat);
CTS := GetColorToleranceSpeed;
if (CountColorTolerance(15726327, MMX1, MMY1, MMX2, MMY2, 30) < 40) and //White walls
(not (InBlack)) then
begin
Pts := GetMiniMapDots('npc');
Count := Length(Pts);
if (Count < 10) then
Exit;
if (not (ForesterCenter(fX, fY))) then
Exit;
{$ifdef Simba}
FilterPointsDist(pts,0,50,fx,fy);
{$else}
FilterPointsPie(Pts, 0.0, 360.0, 0.0, 50.0, fX, fY);
{$endif}
if (Length(Pts) = count) then
begin
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.67, 1.68);
if ((PercentColorMM(1397796, 8) > 5) and
(PercentColorMM(3634254, 8) > 3)) then
Result := True;
end;
end;
ColorToleranceSpeed(CTS);
SetColorspeed2Modifiers(Hue, Sat);
end;
{*******************************************************************************
function TalkToFreakyForester: Boolean;
by: IceFire908
Description: Talks to the forester.
*******************************************************************************}
function TalkToFreakyForester: Boolean;
var
TempHue, TempSat: Extended;
TPAA: T2DPointArray;
I, CTS, T: LongInt;
TPA: TPointArray;
TTFF: TPoint;
begin
CTS := GetColorToleranceSpeed;
GetColorspeed2Modifiers(TempHue, TempSat);
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.03, 0.21);
FindColorsTolerance(TPA, 1262986, MSX1, MSY1, MSX2, MSY2, 8);
SetColorSpeed2Modifiers(TempHue, TempSat);
ColorToleranceSpeed(CTS);
repeat
if (Length(TPA) < 1) then
Break;
TPAA := TPAToATPAEx(TPA, 20, 20);
if (Length(TPAA) < 1) then
Break;
SortATPASize(TPAA, True);
for I := 0 to High(TPAA) do
begin
TTFF := MiddleTPA(TPAA[I]);
MMouse(TTFF.X, TTFF.Y, 0, 0);
Wait(200 + Random(50));
if (CountColorTolerance(648165, 7, 7, 100, 25, 50) > 50) then
begin
Mouse(TTFF.X, TTFF.Y, 0, 0, False);
Wait(100 + Random(200));
if (ChooseOptionMulti(['alk-to', 'o F', 'k-t', 'Talk'])) then
begin
Wait(500);
FFlag(0);
T := GetSystemTime;
while ((not (AreTalking)) and ((GetSystemTime - T) < 5000)) do
Wait(100);
Result := True;
Exit;
end;
end;
end;
until (True);
WriteLn('Did not find Freaky Forester!');
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, 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;
Mouse(dx - 2, dy + 2, 0, 0, True);
Flag;
Wait(1500 + Random(500));
MarkTime(t);
repeat;
Wait(100 + Random(100));
until TalkToFreakyForester 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;
if FindNPCChatText('portal', Nothing) then
Result := -1;
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));
if (Result > 0) then
Writeln('Forester: Kill The ' + inttostr(Result) + ' Tailed Pheasant.')
else
Writeln('Forester: Already killed the 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, D: TPointArray;
Pheasant, NTails: T2DPointArray;
B: TBox;
I, x, y, T, A, TempS: Integer;
begin
MakeCompass(0);
TempS := MouseSpeed;
MouseSpeed := 35;
MarkTime(t);
repeat
Wait(200);
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.37, 0.33);
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, 2, 12) then Continue;
3: if not InRange(A, 36, 62) then Continue;
4: if not InRange(A, 80, 160) then Continue;
end;
Tail := Pheasant[i];
NTails := TPAtoATPA(Tail, 3);
if (Tails = Length(NTails)) then
begin
SetColorspeed2Modifiers(0.09, 0.74);
case Tails of
1: if not InRange(CountColorTolerance(2641004, b.x1 - 5, b.y1 - 5, b.x2 + 5, b.y2 + 5, 12), 4, 8) then Continue;
2: if not InRange(CountColorTolerance(2641004, b.x1 - 5, b.y1 - 5, b.x2 + 5, b.y2 + 5, 12), 10, 18) then Continue;
3: if not InRange(CountColorTolerance(2641004, b.x1 - 5, b.y1 - 5, b.x2 + 5, b.y2 + 5, 12), 30, 56) then Continue;
4: if not InRange(CountColorTolerance(2641004, b.x1 - 5, b.y1 - 5, b.x2 + 5, b.y2 + 5, 12), 70, 110) then Continue;
end;
MiddleTPAEx(Pheasant[i], x, y);
if FindColorsTolerance(D, 2641004, x - 80, y - 80, x + 80, y + 80, 12) then
begin
SortTPAFrom(D, Point(x, y));
Mouse(D[0].x, D[0].y, 0, 0, False);
Wait(300 + Random(200));
Result := ChooseOption('Attack');
if (not Result) then Break;
end;
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, t: Integer;
B: Boolean;
{
Objs: T2DPointArray;
Done: Boolean;
I, cts: Integer;
P: TPointArray;
}
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;
Wait(1500 + Random(500));
MarkTime(t);
repeat;
Wait(100 + Random(100));
if TimeFromMark(t) > 20000 then
if not B then
begin
B := True;
Mouse(MSCX, MSCY, 3, 3, False);
end;
until TalkToFreakyForester 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 := 4240276;
HueMod := 0.13;
SatMod := 0.47;
LumTol := 9;
MinR := 128; MaxR := 162;
MinG := 147; MaxG := 201;
MinB := 53; MaxB := 84;
MinX := 20.29; MaxX := 36.93;
MinY := 26.09; MaxY := 49.53;
MinZ := 7.44; MaxZ := 15.81;
end;
ForesterCenter(fx, fy);
Mouse(fx + 45, 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.');
Exit;
end;
Flag;
Wait(2000);
T := GetSystemTime;
while (GetSystemTime - T < 20000) do
begin
if WarningScreen then MouseBox(144, 195, 392, 204, 1);
Wait(4000 + Random(1000));
Result := (GetMusic <> 'Pheasant Peasant') or (not InForesterRandom);
if (Result) then Break;
Wait(1000);
end;
end;
{*******************************************************************************
function SolveForester: Boolean;
by: TRiLeZ, Sumilion, SKy Scripter, & IceFire908
Description: Main solving procedure.
Date: December 17, 2009
*******************************************************************************}
function SolveForester: Boolean;
var
Task, t, TempCTS: Integer;
TempHue, TempSat: Extended;
ItemDropped: Boolean;
begin
TempCTS := GetColorToleranceSpeed;
GetColorspeed2Modifiers(TempHue, TempSat);
Task := forester_GetTask;
if not InForesterRandom then Exit;
if (Task > 0) then
begin
if InvFull then
begin
DropItem(28);
ItemDropped := True;
end;
if (not KillPheasant(Task)) then
begin
Writeln('Forester: ForesterSolver failed to find the pheasant.');
if ItemDropped then PickUpDroppedItem;
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 PickUpDroppedItem;
end;
if not InForesterRandom then Exit;
Result := LeaveForester;
if (not Result) then
begin
Mouse(690, 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.');
while ClickContinue(True, True) do Wait(700 + random(500));
end else begin
Writeln('Forester: Failed to exit the forester');
LogOut;
Exit;
end;
end;