Skip to content

Commit bb630ff

Browse files
committed
feat(bank): more bank methods
1 parent 5749d95 commit bb630ff

File tree

3 files changed

+135
-5
lines changed

3 files changed

+135
-5
lines changed

osrs/interfaces/interface.simba

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ begin
5151
Self.Bounds.X1 := bounds.X1 + 50;
5252
Self.Bounds.Y1 := bounds.Y1 + 10;
5353
Self.Bounds.X2 := bounds.X2 - 50;
54-
Self.Bounds.Y2 := Self.Bounds.Y1 + 15;
54+
Self.Bounds.Y2 := Self.Bounds.Y1 + 17;
5555

56-
Self.CloseButton.X1 := bounds.X2-28;
57-
Self.CloseButton.X2 := bounds.X2-6;
58-
Self.CloseButton.Y1 := bounds.Y1+6;
56+
Self.CloseButton.X1 := bounds.X2-27;
57+
Self.CloseButton.Y1 := bounds.Y1+8;
58+
Self.CloseButton.X2 := bounds.X2-7;
5959
Self.CloseButton.Y2 := bounds.Y1+28;
6060

6161
Self.TitleOCR := TOCRInvertColorFilter.Create([3358536, 0], [5, 0]) ;
@@ -91,7 +91,7 @@ begin
9191
end;
9292

9393

94-
function TRSInterfaceTitle.Close(const escape: Boolean = True): Boolean;
94+
function TRSInterfaceTitle.Close(const escape: Boolean): Boolean;
9595
begin
9696
if not Self.IsOpen() then Exit(True);
9797

@@ -102,3 +102,8 @@ begin
102102

103103
Result := SleepUntil(not Self.IsOpen(), 50, 600);
104104
end;
105+
106+
function TRSInterfaceTitle.Close(escapeProbability: Single = 0): Boolean; overload;
107+
begin
108+
Result := Self.Close(RandomBoolean(escapeProbability));
109+
end;

osrs/interfaces/interfacecontrols.simba

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,36 @@ begin
226226
Result := Round((Y1 - Self.Bounds.Y1) * 100 / (Self.Height - Height));
227227
end;
228228

229+
function TRSScrollBar.GetScrollArea(): TBox;
230+
begin
231+
Result := Self.ScrollArea; //todo: add antiban to use bounds instead
232+
end;
233+
229234
function TRSScrollBar.SetLevel(value: Integer): Integer;
235+
var
236+
old, new, scrolls: Integer;
237+
direction: Boolean;
238+
area: TBox;
230239
begin
231240
if not Self.CanScroll() then Exit;
232241
value := EnsureRange(value, 0, 100);
242+
243+
old := Self.GetLevel();
244+
direction := old < value;
245+
area := Self.GetScrollArea();
246+
247+
while direction = (old < value) do
248+
begin
249+
Mouse.Move(area);
250+
scrolls := Random(1, 3);
251+
if direction then scrolls := -scrolls;
252+
Target.MouseScroll(scrolls);
253+
new := Self.GetLevel();
254+
255+
//user probably hover them while using RI
256+
if new = old then Mouse.Move(area, True);
257+
old := new;
258+
end;
233259
end;
234260

235261

osrs/interfaces/mainscreen/bank.simba

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ type
3333
Bounds: TBox;
3434
Slots: TRSSlotInterface;
3535
Items: TRSItemInterface;
36+
37+
Title: TRSInterfaceTitle;
3638
Scroll: TRSScrollBar;
3739

3840
CachedQuantity: Int32;
@@ -47,6 +49,7 @@ type
4749
end;
4850
const QUANTITY_ALL: Integer = -1;
4951
const QUANTITY_ALL_BUT_ONE: Integer = -2;
52+
_IsOpenHelperBox: TBox;
5053
end;
5154

5255
(*
@@ -115,6 +118,7 @@ begin
115118
Self.Scroll.ScrollArea.Y2 := Self.Bounds.Y2 - 44;
116119

117120
Self.Scroll.Setup();
121+
Self.Title.Setup(Self.Bounds);
118122

119123
Self.Tabs := TBoxArray.Create(Self.Bounds.TopLeft.Offset(47, 42), 10, 1, 35, 28, [5, 0]);
120124
Self.SlotBoxes := TBoxArray.Create(Self.Bounds.TopLeft.Offset(57, 77), 8, (Self.Bounds.Height - 135) div 35, 31, 31, [17, 5]);
@@ -136,9 +140,104 @@ begin
136140

137141
Self.Slots.Setup('Bank.Slots', Self.SlotBoxes, @Self.FindItemBoundaries);
138142
Self.Items.Setup('Bank.Items', @Self.Slots, [0, 10, 3, 0]);
143+
144+
Self._IsOpenHelperBox.X1 := Self.Bounds.X1 + 240;
145+
Self._IsOpenHelperBox.Y1 := Self.Bounds.Y2 - 39;
146+
Self._IsOpenHelperBox.X2 := Self.Bounds.X2 - 155;
147+
Self._IsOpenHelperBox.Y2 := Self.Bounds.Y2 - 25;
148+
end;
149+
150+
151+
(*
152+
## Bank.IsOpen
153+
```pascal
154+
function TRSBank.IsOpen(): Boolean;
155+
```
156+
Returns true if the bank is open.
157+
158+
Example:
159+
```pascal
160+
WriteLn Bank.IsOpen();
161+
```
162+
*)
163+
function TRSBank.IsOpen(): Boolean;
164+
var
165+
count1, count2: Integer;
166+
begin
167+
count1 := Target.CountColor($0, 0, Self._IsOpenHelperBox);
168+
count2 := Target.CountColor(RSColors.TEXT_ORANGE, 0, Self._IsOpenHelperBox);
169+
Result := ((count1 = 94) and (count2 = 116)) or Self.Title.IsTitle('Bank') or Self.Title.IsTitle('Equip');
170+
end;
171+
172+
(*
173+
## Bank.WaitOpen
174+
```pascal
175+
function TRSBank.WaitOpen(const time: Integer; interval: Integer = -1): Boolean;
176+
```
177+
Returns true if the bank is open within `time` milliseconds.
178+
179+
### Example:
180+
```pascal
181+
WriteLn Bank.WaitOpen();
182+
```
183+
*)
184+
function TRSBank.WaitOpen(const time: Integer; interval: Integer = -1): Boolean;
185+
begin
186+
if interval < 0 then interval := RandomMode(100, 50, 1500);
187+
Result := SleepUntil(Self.IsOpen(), interval, time);
188+
end;
189+
190+
(*
191+
## Bank.Close
192+
```pascal
193+
function TRSBank.Close(escape: Boolean): Boolean;
194+
function TRSBank.Close(escapeProbability: Single = 0): Boolean; overload;
195+
```
196+
Closes the bank, Depending on `escape` or `escapeProbability the function will
197+
either click the button or press escape key.
198+
199+
Example:
200+
```pascal
201+
WriteLn Bank.Close();
202+
```
203+
*)
204+
function TRSBank.Close(escape: Boolean): Boolean;
205+
begin
206+
Result := Self.Title.Close(escape);
207+
end;
208+
209+
function TRSBank.Close(escapeProbability: Single = 0): Boolean; overload;
210+
begin
211+
Result := Self.Close(escapeProbability);
139212
end;
140213

141214

215+
function TRSBank.HasIncinerator(): Boolean;
216+
begin
217+
with Self.Incenerator do //TODO ADD COLOR
218+
Result := Target.HasColor(10551295, 0, 1, [X1, Y1+55, X2, Y2]);
219+
end;
220+
221+
function TRSBank.InceneratorTooltipVisible(): Boolean;
222+
begin
223+
Result := Target.HasColor(10551295, 0, 1, Self.Incenerator);
224+
end;
225+
226+
function TRSBank.UnHoverIncinerator(): Boolean;
227+
var
228+
boxes: TBoxArray;
229+
begin
230+
if not Self.Incenerator.Contains(Target.MouseXY) then
231+
Exit(True);
232+
233+
boxes := Self.Incenerator.Invert(Self.Bounds).SortFrom(Target.MouseXY);
234+
Async.MouseMove(boxes[RandomLeft(0, High(boxes))].RandomPoint());
235+
Result := SleepUntil(not Self.InceneratorTooltipVisible(), 100, 1000);
236+
Async.MouseStop();
237+
end;
238+
239+
240+
142241

143242
var
144243
Bank: TRSBank;

0 commit comments

Comments
 (0)