ZephyrsFury
2009-05-03 15:18:52
Its been finished and added to the Open Developer's SVN. Those that are using that SVN may now update to get the solver.
Its only at the beta stage right now and I still need people to test it. If you do encounter any bugs make sure you:
The more detailed your reports the better.
Remember we can only help you if you help us… :)
Special mention to the various people who have sent in Certer accounts - thank you and well done! :D
Cheers,
ZephyrsFury.
Its only at the beta stage right now and I still need people to test it. If you do encounter any bugs make sure you:
- Explain what exactly the problem is.
- Post what is in the debug.
- Post any screenshots that may help us diagnose the problem.
The more detailed your reports the better.
Remember we can only help you if you help us… :)
Special mention to the various people who have sent in Certer accounts - thank you and well done! :D
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ยป Certer Solver Routines --//
//-----------------------------------------------------------------//
// * function InCerterRandom: Boolean; // * by ZephyrsFury
// * function CerterScreen: Boolean; // * by ZephyrsFury
// * procedure LoadCerterItems; // * by ZephyrsFury
// * procedure GetItemInfo(var Count, W, H, Area, Cover: Integer); // * by ZephyrsFury
// * function GetItem: string; // * by ZephyrsFury
// * function ExitPortal: Boolean; // * by Iron Man
// * function LeaveCerter: Boolean; // * by ZephyrsFury
// * function SolveCerter: Boolean; // * by ZephyrsFury
//-----------------------------------------------------------------//
type
TCerterItem = record
Name: string;
AvgCount, W, H, Area, PercentCover, AvgTime: Integer;
end;
var
CerterItems: array of TCerterItem;
const
cert_AnalysisTime = 30000;
{*******************************************************************************
function InCerterRandom: Boolean;
by: ZephyrsFury
Description: Checks if we're in the Certer random.
*******************************************************************************}
function InCerterRandom: Boolean;
begin
if (InBlack) then
Result := (InRange(PercentBlackMM, 85, 90));
end;
{*******************************************************************************
function CerterScreen: Boolean;
by: ZephyrsFury
Description: Returns True if the Certer screen is open.
*******************************************************************************}
function CerterScreen: Boolean;
begin
Result := (FindTextTpa(1060404, 0, 118, 23, 169, 42, 'this', NPCChars, Nothing)) and (LoggedIn);
end;
{*******************************************************************************
procedure LoadCerterItems;
by: ZephyrsFury
Description: Loads Certer items information.
*******************************************************************************}
procedure LoadCerterItems;
var
NoOfItems: Integer;
begin
NoOfItems := 10;
if (Length(CerterItems) = NoOfItems) then Exit;
SetLength(CerterItems, NoOfItems);
with CerterItems[0] do //
begin
Name := 'helmet';
AvgCount := 1125;
W := 39;
H := 37;
Area := 1500;
PercentCover := 75;
end;
with CerterItems[1] do //
begin
Name := 'hatchet';
AvgCount := 980;
W := 65;
H := 51;
Area := 3150;
PercentCover := 33;
end;
with CerterItems[2] do //
begin
Name := 'fish';
AvgCount := 2121;
W := 80;
H := 64;
Area := 4930;
PercentCover := 45;
end;
with CerterItems[3] do //
begin
Name := 'fish';
AvgCount := 1980;
W := 68;
H := 74;
Area := 4973;
PercentCover := 43;
end;
with CerterItems[4] do //
begin
Name := 'sword';
AvgCount := 401;
W := 64;
H := 35;
Area := 2365;
PercentCover := 24;
end;
with CerterItems[5] do //
begin
Name := 'shears';
AvgCount := 588;
W := 46;
H := 32;
Area := 1363;
PercentCover := 49;
end;
with CerterItems[6] do //
begin
Name := 'bowl';
AvgCount := 2585;
W := 60;
H := 56;
Area := 3400;
PercentCover := 75;
end;
with CerterItems[7] do //
begin
Name := 'ring';
AvgCount := 703;
W := 38;
H := 30;
Area := 1094;
PercentCover := 65;
end;
with CerterItems[8] do //
begin
Name := 'shield';
AvgCount := 1750;
W := 65;
H := 49;
Area := 3100;
PercentCover := 52;
end;
with CerterItems[9] do //
begin
Name := 'spade';
AvgCount := 748;
W := 69;
H := 48;
Area := 2950;
PercentCover := 33;
end;
end;
{*******************************************************************************
procedure GetItemInfo(var Count, W, H, Area, Cover: Integer);
by: ZephyrsFury
Description: Gets the item's Count, Width, Height, Area and Percentage Cover.
*******************************************************************************}
procedure GetItemInfo(var Count, W, H, Area, Cover: Integer);
var
X1, Y1, X2, Y2, I, BMP: Integer;
colArr, TPA: TPointArray;
B: TBox;
DC: HDC;
begin
X1 := 147;
Y1 := 151;
X2 := 351;
Y2 := 294;
BMP := BitmapFromString(X2 - X1, Y2 - Y1, '');
CopyClientToBitmap(BMP, X1, Y1, X2, Y2);
DC := GetTargetDC;
SetTargetDC(GetBitmapDC(BMP));
FindColorsTolerance(TPA, FastGetPixel(BMP, 0, 0), 0, 0, X2 - X1, Y2 - Y1, 4);
colArr := ReturnPointsNotInTPA(TPA, IntToBox(0, 0, X2 - X1, Y2 - Y1));
for I := 0 to High(colArr) do
FastSetPixel(BMP, colArr[I].X, colArr[I].Y, 255);
DisplayDebugImgWindow(X2 - X1, Y2 - Y1);
CopyCanvas(GetBitmapCanvas(BMP), GetDebugCanvas, 0, 0, X2 - X1, Y2 - Y1, 0, 0, X2 - X1, Y2 - Y1);
FreeBitmap(BMP);
SetTargetDC(DC);
Count := 0;
W := 0;
H := 0;
Area := 0;
Cover := 0;
Count := Length(colArr);
B := GetTPABounds(colArr);
if (Count = 0) then Exit;
W := B.X2 - B.X1;
H := B.Y2 - B.Y1;
Area := W * H;
Cover := Round(Count * 100.0 / Area);
end;
{*******************************************************************************
function GetItem: string;
by: ZephyrsFury
Description: Gets the item and returns it name.
*******************************************************************************}
function GetItem: string;
var
C, W, H, A, Cov, X, Y, M, I, TotalCount, ScoreIndex, TH: Integer;
AvgCount, AvgW, AvgH, AvgA, AvgCov, MaxScore: Integer;
Score: TIntegerArray;
textPts, textTPA, Matches: TPointArray;
Possibilities: TIntegerArray;
begin
LoadCerterItems;
FindColorsTolerance(textPts, 1060404, 124, 45, 294, 142, 0);
for I := 0 to High(CerterItems) do
begin
textTPA := LoadTextTPA(CerterItems[I].Name, NPCChars, TH);
if (FindTextTPAInTPA(TH, textTPA, textPts, Matches)) then
begin
SetLength(Possibilities, Length(Possibilities) + 1);
Possibilities[High(Possibilities)] := I;
end;
end;
WriteLn('Possible Items: ');
for I := 0 to High(Possibilities) do
WriteLn(CerterItems[Possibilities[I]].Name);
M := GetSystemTime;
WriteLn('Analysing Item...');
repeat
GetItemInfo(C, W, H, A, Cov);
IncEx(AvgCount, C);
IncEx(AvgW, W);
IncEx(AvgH, H);
IncEx(AvgA, A);
IncEx(AvgCov, Cov);
Inc(TotalCount);
GetMousePos(X, Y);
if (not(PointInBox(Point(X, Y), IntToBox(360, 162, 367, 169)))) then
MMouse(364, 165, 0,0);
GetMousePos(X, Y);
HoldMouse(X, Y, True);
Wait(50 + Random(10));
ReleaseMouse(X, Y, True);
Wait(50 + Random(10));
until(GetSystemTime - M > cert_AnalysisTime) or (not(CerterScreen));
AvgCount := AvgCount / TotalCount;
AvgW := AvgW / TotalCount;
AvgH := AvgH / TotalCount;
AvgA := AvgA / TotalCount;
AvgCov := AvgCov / TotalCount;
WriteLn('Avg Count: ' + IntToStr(AvgCount));
WriteLn('Avg Width: ' + IntToStr(AvgW));
WriteLn('Avg Height: ' + IntToStr(AvgH));
WriteLn('Avg Area: ' + IntToStr(AvgA));
WriteLn('Avg Cover: ' + IntToStr(AvgCov));
SetLength(Score, Length(CerterItems));
for I := 0 to High(CerterItems) do
begin
if (not(InIntArray(Possibilities, I))) then Continue;
if ((iAbs(AvgCount - CerterItems[I].AvgCount) * 100.0) / CerterItems[I].AvgCount <= 15.0) then
IncEx(Score[I], 1);
if ((iAbs(AvgW - CerterItems[I].W) * 100.0) / CerterItems[I].W <= 8.0) then
IncEx(Score[I], 1);
if ((iAbs(AvgH - CerterItems[I].H) * 100.0) / CerterItems[I].H <= 8.0) then
IncEx(Score[I], 1);
if ((iAbs(AvgA - CerterItems[I].Area) * 100.0) / CerterItems[I].Area <= 15.0) then
IncEx(Score[I], 1);
if ((iAbs(AvgCov - CerterItems[I].PercentCover) * 100.0) / CerterItems[I].PercentCover <= 10.0) then
IncEx(Score[I], 1);
end;
MaxScore := 0;
for I := 0 to High(Score) do
if (Score[I] > MaxScore) then
begin
ScoreIndex := I;
MaxScore := Score[I];
end;
Result := CerterItems[ScoreIndex].Name;
WriteLn('Item: ' + Result + ', Score: ' + IntToStr(Score[ScoreIndex]) + '/5');
end;
{*******************************************************************************
function ExitPortal: Boolean;
by: Iron Man
Description: Finds and clicks on the exit portal.
*******************************************************************************}
function ExitPortal: Boolean;
var
TPA: TPointArray;
ATPA: T2DPointArray;
x, y, hATPA, CTS, i: integer;
begin
if not LoggedIn then exit;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.19, 0.37);
FindColorsTolerance(TPA, 6988174, msx1, msy1, msx2, msy2, 13); //green portal color
SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(CTS);
ATPA := SplitTPA(TPA, 30);
if (Length(ATPA) = 0) then exit;
hATPA := High(ATPA);
for i := 0 to hATPA do
begin
MiddleTPAEx(ATPA[i], x, y);
MMouse(x, y, 5, 5);
Wait(175 + random(75));
if IsUpTextMultiCustom(['xit', 'ortal']) then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, True);
FFlag(0);
Result := True;
Exit;
end;
end;
end;
{*******************************************************************************
function LeaveCerter: Boolean;
by: ZephyrsFury
Description: Leaves the certer area, returns True if successful.
*******************************************************************************}
function LeaveCerter: Boolean;
var
T, M: Integer;
begin
T := GetSystemTime;
WriteLn('Leaving Certer Area...');
MakeCompass('N');
SetAngle(True);
while (LoggedIn) and (GetSystemTime - T < 30000) do
begin
if (TabExists(4)) then
begin
Result := True;
WriteLn('Successfully left Certer Area');
Exit;
end;
if (ExitPortal) then
begin
M := GetSystemTime;
while (GetSystemTime - M < 10000) do
begin
if (TabExists(4)) then Break;
Wait(100);
end;
end;
Wait(500);
end;
WriteLn('Leaving Certer Area Failed!');
end;
{*******************************************************************************
function SolveCerter: Boolean;
by: ZephyrsFury
Description: Solves the Certer Random.
*******************************************************************************}
function SolveCerter: Boolean;
var
T, X, Y: Integer;
Answer: string;
begin
WriteLn('We are in the Certer random...');
T := GetSystemTime;
repeat
ClickContinue(True, True);
Wait(500 + Random(500));
until (CerterScreen) or (not(LoggedIn)) or (GetSystemTime - T > 30000);
if (CerterScreen) then
begin
Answer := GetItem;
WriteLn('GetItem gave ''' + Answer + '''');
Wait(1000 + Random(1000));
if (Answer <> '') then
if FindText(X, Y, Answer, NPCChars, 124, 44, 236, 140) then
begin
Mouse(X, Y, 15, 10, True);
WriteLn('Solved Certer: ' + Answer);
T := GetSystemTime;
Wait(2000 + Random(1000));
while (CerterScreen) and (GetSystemTime - T < 30000) do
Wait(1000);
end;
Result := FindTextTpa(0, 0, MCX1, MCY1, MCX2, MCY2, 'orrect', NPCChars, Nothing);
while (ClickContinue(True, True)) do
Wait(100);
if (LeaveCerter) then
if (Result) then
Result := (TabExists(4));
end;
if (Result) then Exit;
if (CerterScreen) then
Mouse(445, 40, 5, 5, True);
while (LoggedIn) do
begin
LogOut;
Wait(10000);
end;
end;
Cheers,
ZephyrsFury.