Metagen
2008-11-07 08:52:16
Something i whipped together, it is currently missing CloseGE… Please test and tell me if you spot something it is missing :)
If you read it, you will notice i keep my functions as succinct as possible.
If you read it, you will notice i keep my functions as succinct as possible.
//-----------------------------------------------------------------//
//-- ยป Grand Exchange Routines --//
//-----------------------------------------------------------------//
// * function FindGESearchText(Text : String; Click : Boolean) : TPoint; // * By Metagen
// * function GESlotCoords(Slot : Integer) : TPoint; // * By Metagen
// * function GetGESlotItemName(Slot : Integer) : String; // * By Metagen
// * function IsGESlotItemName(Slot : Integer; text : String) : Boolean;// * By Metagen
// * function GetGESlotItemAmount(Slot : Integer) : Integer; // * By Metagen
// * function GetGESlotItemCost(Slot : Integer) : Integer; // * By Metagen
// * function GetGEPercentComplete(Slot : Integer) : Integer; // * By Metagen
// * function GetGETradeBox(Buy : Boolean; Slot : Integer) : TBox; // * By Metagen
// * function IsGESlotEnabled(Slot : Integer) : Boolean; // * By Metagen
// * function IsGESlotEmpty(Slot : Integer) : Boolean;// * By Metagen
// * function IsGESlotSell(Slot : Integer) : Boolean; // * By Metagen
// * function IsGESlotBuy(Slot : Integer) : Boolean; // * By Metagen
// * function GetGESlotStatus(Slot : Integer) : Integer; // * By Metagen
// * function GetGEEmptySlots : TIntegerArray; // * By Metagen
// * procedure ClickGETradeBox(buy : Boolean; Slot : Integer); // * By Metagen
// * function GEScreen : Boolean; // * By Metagen
// * function GEBuyScreen : Boolean; // * By Metagen
// * function GESellScreen : Boolean; // * By Metagen
//
{*******************************************************************************
function FindGESearchText(Text : String; Click : Boolean) : TPoint;
By: Metagen
Description: Checks the text in the first mage of Item Search and returns
its location in a TPoint
Text: Part of the name ex. Bronze mace 'ronz'
Click: Option to click text
*******************************************************************************}
function FindGESearchText(Text : String; Click : Boolean) : TPoint;
var dy, cx, cy, row : integer;
begin
dy := 15;
cx := 69;
cy := 343;
for row := 0 to 6 do
begin
if pos(text, GetTextAtEx(cx, cy+(row*dy), 0, SmallChars, false,
false, 0, 1, 23200, 60, false, tr_AllChars)) <> 0 then
begin
result.x := cx;
result.y := cy+(row*dy);
break;
end;
end;
if (Click) and (result.x <> 0) then
Mouse(result.x, result.y, Length(Text)*5, 10, true);
end;
{*******************************************************************************
function GESlotCoords(Slot : Integer) : TPoint;
By: Metagen
Description: Returns where the topleft point of the text Empty would be
for a slot. Recommended not to use this unless you are me.
Slots are 0 to 5
*******************************************************************************}
function GESlotCoords(Slot : Integer) : TPoint;
begin
if Inrange(Slot, 0, 5) then
begin
result.x := 85 + ((Slot mod 3) * 156)
result.y := 89 + Floor(Slot/3) * 120
end else
WriteLn('Warning: Invalid GE Slot ' + IntToStr(Slot));
end;
{*******************************************************************************
function GetGESlotItemName(Slot : Integer) : String;
By: Metagen
Description: Returns the name of the item being traded in a slot
Slots are from 0 to 5
*******************************************************************************}
function GetGESlotItemName(Slot : Integer) : String;
var a : TPoint;
begin
a := GESlotCoords(Slot);
a.x := a.x - 2;
a.y := a.y + 25;
result := Trim(GetTextAtEx(a.x, a.y, 0, StatChars, true, false, 0, 1, 39372, 25, false, tr_AllChars));
end;
{*******************************************************************************
function IsGESlotItemName(Slot : Integer; text : String) : Boolean;
By: Metagen
Description: Checks if the text is in the Item Name in the slot
*******************************************************************************}
function IsGESlotItemName(Slot : Integer; text : String) : Boolean;
begin
result := (Pos(text, GetGESlotItemName(Slot)) <> 0);
end;
{*******************************************************************************
function GetGESlotItemAmount(Slot : Integer) : Integer;
By: Metagen
Description: Returns the amount of items being traded in a slot
on the first screen
*******************************************************************************}
function GetGESlotItemAmount(Slot : Integer) : Integer;
var a : TPoint;
begin
a := GESlotCoords(Slot);
a.x := a.x - 42;
a.y := a.y + 30;
result := GetAmount(a.x, a.y - 4);
end;
{*******************************************************************************
function GetGESlotItemCost(Slot : Integer) : Integer;
By: Metagen
Description: Returns the gp being traded in a slot
*******************************************************************************}
function GetGESlotItemCost(Slot : Integer) : Integer;
var a : TPoint;
begin
a := GESlotCoords(Slot);
a.x := a.x - 2;
a.y := a.y + 53;
result := GetAmount(a.x, a.y - 4);
// NOTE amount.scar needs to be updated
// with the color 6011837 in GetAmount();
// for this function to work
{
if color = 0 then
if findcolor(tempx, tempy, 6011837, itemx, itemy, itemx + 10, itemy + 10) then
color := 6011837;
}
end;
{*******************************************************************************
function GetGEPercentComplete(Slot : Integer) : Integer;
By: Metagen
Description: Analyzes the trade bar and approximates a percent complete
(within 1%)
*******************************************************************************}
function GetGEPercentComplete(Slot : Integer) : Integer;
var a : TPoint;
x1, x2, y, i : Integer;
begin
a := GESlotCoords(Slot);
x1 := a.x - 43;
x2 := a.x + 80;
y := a.y + 77;
if (GetColor(x1, y) = 786539) or (GetColor(x1, y) = 1533233) then
begin
result := 100;
exit;
end;
for i := x1 to x2 do
begin
if not (GetColor(i, y) = 27802) then Break;
end;
i := i - x1;
result := round((i / (x2 - x1)) * 100);
if result = 100 then result := 99;
end;
{*******************************************************************************
function GetGETradeBox(Buy : Boolean; Slot : Integer) : TBox;
By: Metagen
Description: Returns the box surrounding the buy/sell
*******************************************************************************}
function GetGETradeBox(Buy : Boolean; Slot : Integer) : TBox;
var Origin : TPoint;
begin
Origin := GESlotCoords(Slot);
if not Buy then
Origin.x := Origin.x + 64;
result.x1 := Origin.x - 36;
result.x2 := Origin.x + 8;
result.y1 := Origin.y + 40;
result.y2 := Origin.y + 81;
end;
{*******************************************************************************
function IsGESlotEnabled(Slot : Integer) : Boolean;
By: Metagen
Description: Returns whether or not the box is Enabled
Nonmembers only have 2 trade slots available
*******************************************************************************}
function IsGESlotEnabled(Slot : Integer) : Boolean;
var a : TPoint;
begin
a := GESlotCoords(Slot);
result := not (GetColor(a.x, a.y) = 65536);
end;
{*******************************************************************************
function IsGESlotEmpty(Slot : Integer) : Boolean;
By: Metagen
Description: Returns whether or not anything is being traded in a slot
*******************************************************************************}
function IsGESlotEmpty(Slot : Integer) : Boolean;
var aPoint : TPoint;
begin
aPoint := GESlotCoords(Slot);
result := GetColor(aPoint.x, aPoint.y) = 39372;
end;
{*******************************************************************************
function IsGESlotSell(Slot : Integer) : Boolean;
By: Metagen
Description: Returns whether or not anything is being sold in a slot
*******************************************************************************}
function IsGESlotSell(Slot : Integer) : Boolean;
var aPoint : TPoint;
begin
aPoint := GESlotCoords(Slot);
result := GetColor(aPoint.x+25, aPoint.y) = 39372;
end;
{*******************************************************************************
function IsGESlotBuy(Slot : Integer) : Boolean;
By: Metagen
Description: Returns whether or not anything is being purchased in a slot
*******************************************************************************}
function IsGESlotBuy(Slot : Integer) : Boolean;
var aPoint : TPoint;
begin
aPoint := GESlotCoords(Slot);
result := GetColor(aPoint.x + 26, aPoint.y + 13) = 39372;
end;
{*******************************************************************************
function GetGESlotStatus(Slot : Integer) : Integer;
By: Metagen
Description: Returns the status of the slot in an integer
0: Buying
1: Selling
2: Empty
*******************************************************************************}
function GetGESlotStatus(Slot : Integer) : Integer;
begin
result := 2;
if IsGESlotEmpty(Slot) then Exit;
result := 1;
if IsGESlotSell(Slot) then Exit;
result := 0;
if IsGeSlotBuy(Slot) then Exit;
result := -1;
end;
{*******************************************************************************
function GetGEEmptySlots : TIntegerArray;
By: Metagen
Description: Returns an array of empty slots ex.
0, 2, 3 Means that those slots are empty
*******************************************************************************}
function GetGEEmptySlots : TIntegerArray;
var i : Integer;
begin
for i := 0 to 5 do
begin
if IsGESlotEmpty(i) then
begin
SetLength(Result, Length(Result)+1);
Result[High(Result)] := i;
end;
end;
end;
{*******************************************************************************
procedure ClickGETradeBox(buy : Boolean; Slot : Integer);
By: Metagen
Description: Clicks the Buy/Sell box in a slot
*******************************************************************************}
procedure ClickGETradeBox(buy : Boolean; Slot : Integer);
var a : TBox;
begin
a := GetGESlotBox(buy, Slot);
Mouse(a.x1, a.y1, a.x2-a.x1, a.y2-a.y1, true);
end;
{*******************************************************************************
procedure ClickGETradeBox(buy : Boolean; Slot : Integer);
By: Metagen
Description: True you are using the GE Menus
*******************************************************************************}
function GEScreen : Boolean;
begin
result := (GetColor(40, 37) = 48615) and (GetColor(41, 40) = 1587588)
end;
{*******************************************************************************
procedure ClickGETradeBox(buy : Boolean; Slot : Integer);
By: Metagen
Description: True you are using the GE Buy Menu
*******************************************************************************}
function GEBuyScreen : Boolean;
begin
result := GEScreen and (GetColor(187, 73) = 61385)
end;
{*******************************************************************************
procedure ClickGETradeBox(buy : Boolean; Slot : Integer);
By: Metagen
Description: True you are using the GE Sell Menu
*******************************************************************************}
function GESellScreen : Boolean;
begin
result := GEScreen and (GetColor(187, 73) = 45055)
end;