Skip to content
33 changes: 31 additions & 2 deletions osrs/interfaces/mainscreen/grandexchange/grandexchange.simba
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ EGESlotType = enum(EMPTY, SELL, BUY);
```
Enum to represent the type of Grand Exchange offer slot.
*)
EGESlotType = enum(EMPTY, SELL, BUY);
EGESlotType = enum(EMPTY, SELL, BUY, UNAVAILABLE);

(*
## TRSGrandExchangeSlot
Expand Down Expand Up @@ -164,7 +164,11 @@ begin
//no need for ocr, color count is lighter and should work fine.
count := Target.CountColor(RSFonts.ORANGE, 0, Self.Header);
case count of
154: Result := EGESlotType.EMPTY;
154:
if Target.HasColor($6082AB, 0, 1, Self.BuyButton) then
Result := EGESlotType.UNAVAILABLE
else
Result := EGESlotType.EMPTY;
90: Result := EGESlotType.SELL;
101: Result := EGESlotType.BUY;
end;
Expand Down Expand Up @@ -281,6 +285,31 @@ begin
Result := EGEOfferStatus.NONE;
end;

(*
## TRSGrandExchangeSlot.Progress
```pascal
property TRSGrandExchangeSlot.Progress: Integer;
```
Returns the progress percentage of the slot.

Example:
```pascal
WriteLn GrandExchange.Slots[2].Progress;
```
*)
property TRSGrandExchangeSlot.Progress: Integer;
var
tpa: TPointArray;
begin
tpa := Target.FindColor($1964A8, 0, Self.StatusBox);
if not (tpa = []) then
Result := Round(tpa.Bounds.Width() / 105 * 100)
else if Target.HasColor($004A00, 0, 1, Self.StatusBox) then
Result := 100
else
Result := -1;
end;

(*
## TRSGrandExchangeSlot.Open
```pascal
Expand Down
13 changes: 10 additions & 3 deletions osrs/interfaces/mainscreen/grandexchange/grandexchange_chat.simba
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,18 @@ WriteLn GrandExchangeChat.Click('Abyssal whip');
function TRSGrandExchangeChat.Click(item: TRSItem): Boolean;
var
bounds: TBox;
i: Integer;
begin
if Self.Find(item, bounds) then
for i := 0 to 4 do
begin
Mouse.Click(bounds, EMouseButton.LEFT);
Result := SleepUntil(Self.IsOpen(), 200, 2400);
if Self.Find(item, bounds) then
begin
Mouse.Click(bounds, EMouseButton.LEFT);
Exit(SleepUntil(not Self.IsOpen(), 200, 2400));
end;

if not Self.IsOpen() then Exit;
Sleep(50, 150);
end;
end;

Expand Down
57 changes: 57 additions & 0 deletions osrs/interfaces/mainscreen/grandexchange/grandexchange_offer.simba
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,63 @@ begin
Result := SleepUntil(not Self.HasItems(), 200, 2000);
end;

(*
## GrandExchangeOffer.CreateBuyOffer
```pascal
function TRSGrandExchangeOffer.CreateBuyOffer(itemName : String; price, quantity : Integer = -1) : Boolean;
```

Attempts to create a buy offer for the specified `itemName`, `price` and `quantity`.

Example:
```pascal
if GrandExchangeOffer.CreateBuyOffer('Abyssal whip', 1500000, 1) then
WriteLn('Buy offer created successfully!');
```
*)
function TRSGrandExchangeOffer.CreateBuyOffer(itemName: String; price, quantity: Integer = -1) : Boolean;
begin
if not Self.IsOpen() then Exit;
if (Self.OfferInterface <> EGEOfferInterface.SETUP) or (Self.OfferType <> EGEOfferType.BUY) then Exit;

if not GrandExchangeChat.WaitOpen(2000, 250) then Exit;
if not GrandExchangeChat.SearchText[itemName] then Exit;
if not GrandExchangeChat.Click(itemName) then Exit;
if not SleepUntil(Self.Item.ToLower() = itemName.ToLower(), 250, 2000) then Exit;

if (quantity <> -1) and not Self.Quantity[quantity] then Exit;
if (price <> -1) and not Self.Price[price] then Exit;

Result := Self.Confirm();
end;

(*
## GrandExchangeOffer.CreateSellOffer
```pascal
function TRSGrandExchangeOffer.CreateSellOffer(itemName : String; price, quantity : Integer = -1) : Boolean;
```

Attempts to create a sell offer for the specified `itemName`, `price` and `quantity`.

Example:
```pascal
if GrandExchangeOffer.CreateSellOffer('Abyssal whip', 1500000, 1) then
WriteLn('Sell offer created successfully!');
```
*)
function TRSGrandExchangeOffer.CreateSellOffer(itemName: String; price, quantity: Integer = -1) : Boolean;
begin
if not Self.IsOpen() then Exit;
if (Self.OfferInterface <> EGEOfferInterface.SETUP) or (Self.OfferType <> EGEOfferType.SELL) then Exit;

if not Inventory.Items.Click(itemName) then Exit;
if not SleepUntil(Self.Item.ToLower() = itemName.ToLower(), 250, 2000) then Exit;

if (quantity <> -1) and not Self.Quantity[quantity] then Exit;
if (price <> -1) and not Self.Price[price] then Exit;

Result := Self.Confirm();
end;

var
(*
Expand Down