pwnaz0r
2007-09-14 18:06:50
Here are a few functions i put together for the bank browsing section. It will find any box in the bank accurately by finding the distance from the scroll up arrow ad the scroll bar, multiplying it by the ratio of bankscreen to scrollbar , and subtracting that from the bank box positions. Anyways post feedback :)
From: Boreas
Slots:
Inv/Bank/Shop/Trade all have slots. They are lined up and in fixed positions. Global arrays for these so coords only need to be updated in one place.
type
boolint = record
bool: boolean;
int: integer;
end;
function GetBarDistance: integer; // Will return -1 if false
var
dist: integer;
begin
if not GetColor(476, 74) = 2436403 then
begin
result:= -1;
exit;
end else
begin
for dist:= 1 to 175 do
begin
if GetColor(477, 74 + dist) = 5531254 then
begin
result:= dist;
exit;
end;
end;
end;
result:= -1;
end;
function CreateDifference: boolint; // return difference ratio
var
dis: integer;
begin
dis:= GetBarDistance;
result.int := Round((dis - 1) * 9.6);
result.bool := Result.int > 0;
end;
function HandleScreenShift(i: integer): integer;
var
tmpx,tmpy,t: integer;
begin
result:= i;
if getcolor(475,75) = 5531254 then
exit;
try
findcolor(tmpx, tmpy, 65535, 73, i-15, 443, i+15);
result:=tmpy;
except
FixBank;
wait(600);
try
findcolor(tmpx, tmpy, 65535, 73, i-15, 443, i+15);
result:=tmpy;
except
Writeln('Error');
exit;
end;
end;
end;
function BankBox(i :Integer): TBox;
var
row, col: Integer;
tmp: boolint;
begin
col := i mod 8; if col = 0 then col:= 8; // Columns are Vertical
row := i / 8; if i mod 8 <> 0 then Inc(row); // Rows are Horizontal
Result.x1 := 32 + (col * 47);
tmp:= CreateDifference;
if tmp.bool then
begin
Result.y1 := 24 + (row * 38) - tmp.int;
Result.y1 := HandleScreenShift(Result.y1);
end else Result.y1 := 24 + (row * 38);
Result.x2 := Result.x1 + 31;
Result.y2 := Result.y1 + 31;
end;
function BoxVisible(i: integer): Boolean;
var
TheBankBox: TBox;
begin
TheBankBox:= BankBox(i);
Writeln(IntToStr(TheBankBox.y1));
if (TheBankBox.y1 >= 62) and (TheBankBox.y1 <= 254) then result:= True;
end;
function ResetForBox(i: integer): boolean;
var
BoxMark, bx, by: integer;
begin
FixBank;
If BoxVisible(i) then
begin
result:= true;
exit;
end;
HoldMouse(475 + random(6) - random(6), 281 + random(6) - random(6), true);
GetMousePos(bx, by);
MarkTime(BoxMark);
repeat
begin
Wait(1);
If TimeFromMark(BoxMark) >= 20000 then
begin
result:= false;
ReleaseMouse(bx, by, true);
exit;
end;
end;
until(BoxVisible(i));
ReleaseMouse(bx, by, true);
result:= true;
end;
function MakeBoxVisible(i: integer): boolean;
var
TheBankBox: TBox;
begin
if not BoxVisible(i) then
begin
// WriteLn('Bank box not visible');
ResetForBox(i);
end;
end;
function MakeMiddlePoint(i: integer): TPoint;
var
TheBankBox: TBox;
begin
TheBankBox:= BankBox(i);
result.x:= ((TheBankBox.x2 - TheBankBox.x1) / 2) + TheBankBox.x1;
result.y:= ((TheBankBox.y2 - TheBankBox.y1) / 2) + TheBankBox.y1;
end;
procedure MMouseSlot(i: integer);
var
Mid: Tpoint;
TheBankBox: TBox;
begin
MakeBoxVisible(i);
TheBankBox:= BankBox(i);
MMouse(TheBankBox.x1 + 2 + random(27), TheBankBox.y1 + 2 + random(27), 0, 0);
end;
procedure MouseSlot(i: integer; left: boolean);
var
bx, by: integer;
begin
MMouseSlot(i);
GetMousePos(bx, by);
Mouse(bx, by, 0, 0, left);
end;
function ChooseOptionSlot(i: integer; s: string): boolean;
begin
MouseSlot(i, false);
wait(400);
result:= ChooseOption(s);
end;
function ItemExistsSlot(i: integer): boolean;
var
rx, ry: integer;
TheBankBox: TBox;
begin
MakeBoxVisible(i);
TheBankBox:= BankBox(i);
result:= FindColor(rx, ry, 65536, TheBankBox.x1, TheBankBox.y1, TheBankBox.x2, TheBankBox.y2);
end;