Nava2
2009-02-26 23:19:57
I wrote some reward box functions:
It now looks for specific text, and will click that option. It will scroll through the scroll bar, if it doesn't find the item you want. It will pick the mystery box! :)
Use:
Please test this..
Comments tell how it works, I want some feeeeeedback! :)
It now looks for specific text, and will click that option. It will scroll through the scroll bar, if it doesn't find the item you want. It will pick the mystery box! :)
var
SRL_RewardOption: String;
// Finds the option using TPA Text, returns the corresponding box.
function _FindOption(var Box: TBox): Boolean;
var
x, y, I, H: Integer;
Text, TPA, xTPA: TPointArray;
ATPA: T2DPointArray;
Scroll: Boolean;
begin
Scroll := FindTextTPA(2070783, 3, Msx1, msy1, msx2, msy2, 'croll', StatChars, Nothing);
Text := LoadTextTPA(SRL_RewardOption, UpChars, H);
FindColorsTolerance(TPA, 2070783, 35, 69, 362, 311, 3);
Result := FindTextTPAInTPA(H, Text, TPA, xTPA);
if (not Result) and Scroll then
begin
x := RandomRange(371, 384);
y := RandomRange(304, 317);
MMouse(x, y, 0, 0);
Wait(RandomRange(30, 60));
HoldMouse(x, y, True);
while (not FindColorTolerance(x, y, 657930, 374, 295, 380, 302, 3)) and (not Result) do
begin
if not LoggedIn then Exit;
Wait(RandomRange(40, 50));
FindColorsTolerance(TPA, 2070783, 35, 69, 362, 311, 3);
Result := FindTextTPAInTPA(H, Text, TPA, xTPA);
end;
ReleaseMouse(x, y, True);
end;
if not Result then
begin
Text := LoadTextTPA('box', UpChars, H);
Result := FindTextTPAInTPA(H, Text, TPA, xTPA);
end;
if not Result then Exit;
FindColorsTolerance(TPA, 2634297, 35, 69, 362, 311, 3);
ATPA := TPAToATPAEx(TPA, 147 + Integer( Scroll) * 2, 62 + Integer( Scroll) * 2);
SortATPAFrom(ATPA, xTPA[0]);
Result := True;
Box := GetTPABounds(ATPA[0]);
end;
// Waits until the Reward Screen Appears.
function _WaitForRewardScreen: Boolean;
var
Text, TPA: TPointArray;
Height, Time: Integer;
begin
Result := False;
Text := LoadTextTPA('hoose', UpChars, Height);
Time := GetTimeRunning + 2000;
FindColorsTolerance(TPA, 2070783, 185, 34, 327, 50, 3);
while not Result and (GetTimeRunning < Time) do
begin
Wait(RandomRange(80, 100));
FindColorsTolerance(TPA, 2070783, 185, 34, 327, 50, 3);
if Length(TPA) > 10 then
Result := FindTextTPAinTPA(Height, Text, TPA, TPA);
end;
end;
// Finds the box in the inventory using a TPA
function _FindRewardBox(var fx, fy: Integer): Boolean;
var
I, Tol: Integer;
B: TBox;
TPA: TPointArray;
begin
Result := False;
if not LoggedIn then
begin
fx := 0;
fy := 0;
Exit;
end;
GameTab(4);
Tol := GetColorToleranceSpeed;
try
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.02, 0.11);
for I := 1 to 28 do
begin
B := InvBox(I);
if FindColorsTolerance(TPA, 5574780, b.x1, b.y1, b.x2, b.y2, 13) then
Result := High(TPA) >= 250;
if Result then
begin
MiddleTPAEx(TPA, fx, fy);
Exit;
end;
end;
fx := 0;
fy := 0;
finally
ColorToleranceSpeed(Tol);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
end;
// Opens the Box at fx, fy. Gets the reward presented by the global var.
function _UseRewardBox(fx, fy: Integer): Boolean;
var
Time: Integer;
TPA: TPointArray;
B: TBox;
begin
Result := False;
if (fx = 0) or (fy = 0) then Exit;
MMouse(fx, fy, 5, 5);
Wait(RandomRange(80, 100));
if IsUpText('event gift') then
begin
GetMousePos(fx, fy);
Mouse(fx, fy, 0, 0, True);
if not _WaitForRewardScreen then
begin
SRL_Warn('OpenRewardBox', 'Could not open Reward Screen', Warn_AllVersions);
Exit;
end;
Wait(Random(100));
if not _FindOption(B) then
begin
SRL_Warn('UseRewardBox', 'Could not find a usable option.', Warn_AllVersions);
Exit;
end;
MouseBox(B.x1, B.y1, B.x2, B.y2, 1);
Time := GetTimeRunning + 500;
while (not Result) and (GetTimeRunning < Time) do
begin
FindColorsTolerance(TPA, 1317148, B.x1, B.y1, B.x2, B.y2, 3);
Result := Length(TPA) > 50;
end;
if not Result then
begin
CloseWindow;
Exit;
end;
Mouse(393, 166, 77, 39, True);
end;
end;Use:
var
SRL_RewardOption: String;
SRL_RewardOption := 'XP';
//... Somewhere in SetupSRL ...
if SRL_RewardOption = '' then SRL_RewardOption := 'ystery box';
//...
if _FindRewardBox(fx, fy) then
_UseRewardBox(fx, fy);Please test this..
Comments tell how it works, I want some feeeeeedback! :)