Skip to content

Commit c702839

Browse files
committed
fix: more work on the worldswitcher
finally added the jagex account advert failsafe to TRSBank
1 parent c4ce25a commit c702839

File tree

3 files changed

+145
-5
lines changed

3 files changed

+145
-5
lines changed

osrs/interfaces/gametabs/logout.simba

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ WriteLn Logout.Open();
6969
function TRSLogout.Open(): Boolean;
7070
begin
7171
Result := GameTabs.Open(ERSGameTab.LOGOUT);
72+
if Result and WorldSwitcher._IsOpen() then
73+
Result := WorldSwitcher.Close();
7274
end;
7375

7476

@@ -128,6 +130,7 @@ function TRSLogout.Logout(const attempts: UInt32 = 5; const time: UInt32 = 20000
128130
var
129131
i: Integer;
130132
interval: UInt32;
133+
stars: ERSRating;
131134
begin
132135
if not Self.Open() then Exit;
133136
if WorldSwitcher.Logout() then Exit(True);
@@ -141,8 +144,9 @@ begin
141144
else
142145
i := RandomLeft(0, 4);
143146

144-
WriteLn GetDebugLn('Logout', 'Rating the game with ' + ToStr(ERSRating(i)) + ' stars before logging out.');
145-
Self.Ratings[i].Enable();
147+
stars := ERSRating(i);
148+
WriteLn GetDebugLn('Logout', 'Rating the game with ' + ToStr(stars) + ' stars before logging out.');
149+
Self.Rate(stars);
146150
end;
147151

148152
if Keyboard.LastKey = EKeyCode.RETURN then
@@ -158,4 +162,3 @@ end;
158162

159163
var
160164
Logout: TRSLogout;
161-

osrs/interfaces/gametabs/worldswitcher.simba

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,41 @@ switcher in the {ref}`Logout` gametab.
77
{$INCLUDE_ONCE SRLT/osrs.simba}
88

99
type
10+
(*
11+
(ERSWorldSwitcherButton)=
12+
## Enum ERSWorldSwitcherButton
13+
```pascal
14+
ERSWorldSwitcherButton = enum(CONFIGURE, CLOSE, LOGOUT);
15+
```
16+
Enum representing the world switcher buttons.
17+
*)
1018
ERSWorldSwitcherButton = enum(CONFIGURE, CLOSE, LOGOUT);
19+
20+
TRSWorld = record
21+
Number: Integer;
22+
Bounds: TBox;
23+
end;
24+
TRSWorldArray = array of TRSWorld;
25+
26+
procedure ShowOnClient(worlds: TRSWorldArray); overload;
27+
var
28+
img: TImage;
29+
i: Integer;
30+
begin
31+
img := TImage.CreateFromTarget();
32+
33+
img.DrawColor := $FFFFFF;
34+
for i := 0 to High(worlds) do
35+
begin
36+
WriteLn worlds[i].Number;
37+
img.DrawBox(worlds[i].Bounds);
38+
end;
39+
40+
img.Show();
41+
img.Free();
42+
end;
43+
44+
type
1145
(*
1246
(TRSWorldSwitcher)=
1347
## type TRSWorldSwitcher
@@ -154,7 +188,56 @@ begin
154188
Result := OCR.RecognizeNumber(Self.CurrentWorldBounds, RSFonts.BOLD, [RSColors.TEXT_ORANGE], 0);
155189
end;
156190

191+
function TRSWorldSwitcher.GetWorlds(): TRSWorldArray;
192+
var
193+
tpa: TPointArray;
194+
atpa: T2DPointArray;
195+
weights: TIntegerArray;
196+
world: TRSWorld;
197+
begin
198+
tpa := Target.FindColor(Self.SILVER, 0, Self.Scroll.Area) +
199+
Target.FindColor(Self.YELLOW, 0, Self.Scroll.Area);
200+
201+
atpa := tpa.Cluster(5, 1.5);
202+
for tpa in atpa do
203+
with tpa.Bounds() do
204+
begin
205+
if Height <> 10 then Continue;
206+
207+
world.Number := OCR.RecognizeNumber([X1-3, Y1-2, X2+3, Y2+2], RSFonts.PLAIN_12, [Self.SILVER, Self.YELLOW], 0);
208+
if world.Number = -1 then Continue;
209+
210+
world.Bounds := [Self.Scroll.Area.X1, Y1-2, Self.Scroll.Area.X2, Y2+3];
211+
212+
weights += Y1;
213+
Result += World;
214+
end;
157215

216+
Result.Sort(weights, True);
217+
end;
218+
219+
function TRSWorldSwitcher.FindWorld(number: Integer; out world: TRSWorld): Boolean;
158220
var
159-
WorldSwitcher: TRSWorldSwitcher;
221+
tpa: TPointArray;
222+
atpa: T2DPointArray;
223+
begin
224+
tpa := Target.FindColor(Self.SILVER, 0, Self.Scroll.Area) +
225+
Target.FindColor(Self.YELLOW, 0, Self.Scroll.Area);
160226

227+
atpa := tpa.Cluster(5, 1.5);
228+
for tpa in atpa do
229+
with tpa.Bounds() do
230+
begin
231+
if Height <> 10 then Continue;
232+
233+
world.Number := OCR.RecognizeNumber([X1-3, Y1-2, X2+3, Y2+2], RSFonts.PLAIN_12, [Self.SILVER, Self.YELLOW], 0);
234+
if world.Number <> number then Continue;
235+
236+
world.Bounds := [Self.Scroll.Area.X1, Y1-2, Self.Scroll.Area.X2, Y2+3];
237+
Exit(True);
238+
end;
239+
end;
240+
241+
242+
var
243+
WorldSwitcher: TRSWorldSwitcher;

osrs/interfaces/mainscreen/bank.simba

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ Record responsible to handle the bank interface.
5858
DynamicButtons: array [ERSBankDynamicButtons] of TRSButton;
5959
ButtonsOffset: Integer;
6060

61+
JagexAccountAd: record
62+
NotNow, MoreInfo: TBox;
63+
end;
64+
6165
Cache: record
6266
Quantity: Integer;
6367
Items: TStringMap<TBankPosition>;
@@ -148,6 +152,12 @@ begin
148152
Self.SlotsArea.X2 := Self.Bounds.X2 - 63;
149153
Self.SlotsArea.Y2 := Self.Bounds.Y2 - 44;
150154

155+
with Self.SlotsArea.Center.Offset(0,-1) do
156+
Self.JagexAccountAd.NotNow := [X-120, Y+43, X-49, Y+66];
157+
158+
with Self.SlotsArea.Center.Offset(0,-1) do
159+
Self.JagexAccountAd.MoreInfo := [X+39, Y+43, X+108, Y+66];
160+
151161
Self.Incenerator.X1 := Self.Bounds.X1 + 5;
152162
Self.Incenerator.Y1 := Self.Bounds.Y2 - 113;
153163
Self.Incenerator.X2 := Self.Bounds.X1 + 51;
@@ -233,6 +243,45 @@ begin
233243
Self.DynamicButtons[i].Bounds := Self.DynamicButtons[i].Bounds.Offset([offset, 0]);
234244
end;
235245

246+
247+
(*
248+
## Bank.HasJagexAccountAd
249+
```pascal
250+
function TRSBank.HasJagexAccountAd(): Boolean;
251+
```
252+
Returns true if the bank has the jagex account ad pop-up.
253+
This only ever shows up on non jagex accounts and tries to buy you in with bank space.
254+
255+
Example:
256+
```pascal
257+
WriteLn Bank.HasJagexAccountAd();
258+
```
259+
*)
260+
function TRSBank.HasJagexAccountAd(): Boolean;
261+
begin
262+
Result := (Target.CountColor($0000FF, 0, Self.JagexAccountAd.NotNow) = 98) and
263+
(Target.CountColor($0DC10D, 0, Self.JagexAccountAd.MoreInfo) = 112);
264+
end;
265+
266+
(*
267+
## Bank.CloseJagexAccountAd
268+
```pascal
269+
function TRSBank.CloseJagexAccountAd(): Boolean;
270+
```
271+
Attempts to close the jagex account advert. Returns true on success.
272+
273+
Example:
274+
```pascal
275+
WriteLn Bank.CloseJagexAccountAd();
276+
```
277+
*)
278+
function TRSBank.CloseJagexAccountAd(): Boolean;
279+
begin
280+
Mouse.Click(Self.JagexAccountAd.NotNow, EMouseButton.LEFT);
281+
Result := SleepUntil(not Self.HasJagexAccountAd(), 50, 600);
282+
end;
283+
284+
236285
(*
237286
## Bank.IsOpen
238287
```pascal
@@ -257,7 +306,12 @@ begin
257306

258307
if Result then
259308
begin
260-
if tpa = [] then Exit;
309+
if tpa = [] then
310+
begin
311+
if not Self.HasJagexAccountAd() then Exit;
312+
if not Self.CloseJagexAccountAd() then Exit;
313+
Exit(Self.IsOpen()); //ad closed, restart
314+
end;
261315

262316
offset := tpa.First.X;
263317
offset -= Self.Bounds.X1+244;

0 commit comments

Comments
 (0)