Skip to content

Commit 3361b98

Browse files
committed
feat: partial done world switcher (gametab)
1 parent df6dc5f commit 3361b98

File tree

7 files changed

+193
-21
lines changed

7 files changed

+193
-21
lines changed

osrs.simba

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
{$IFNDEF SRLT_MAGIC_INCLUDED} {$INCLUDE_ONCE osrs/interfaces/gametabs/magic.simba}
3535
{$IFNDEF SRLT_OPTIONS_INCLUDED} {$INCLUDE_ONCE osrs/interfaces/gametabs/options.simba}
3636
{$IFNDEF SRLT_PRAYER_INCLUDED} {$INCLUDE_ONCE osrs/interfaces/gametabs/prayer.simba}
37+
{$IFNDEF SRLT_WORLDSWITCHER_INCLUDED} {$INCLUDE_ONCE osrs/interfaces/gametabs/worldswitcher.simba}
3738
{$IFNDEF SRLT_LOGOUT_INCLUDED} {$INCLUDE_ONCE osrs/interfaces/gametabs/logout.simba}
3839

3940
{$IFNDEF SRLT_MM2MS_PROJECTOR_INCLUDED} {$INCLUDE_ONCE osrs/interfaces/mm2ms_projector.simba}
@@ -93,3 +94,4 @@
9394
{$ENDIF}
9495
{$ENDIF}
9596
{$ENDIF}
97+
{$ENDIF}

osrs/interfaces/chat/chat.simba

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ begin
4545
Self.InputLine.X2 += 17;
4646
Self.InputLine.Y2 += 2;
4747

48-
Self.Scroll.ScrollArea.X1 := Self.Bounds.X1 + 6;
49-
Self.Scroll.ScrollArea.Y1 := Self.Bounds.Y1 + 6;
50-
Self.Scroll.ScrollArea.X2 := Self.Bounds.X2 - 23;
51-
Self.Scroll.ScrollArea.Y2 := Self.InputLine.Y1 - 1;
48+
Self.Scroll.Area.X1 := Self.Bounds.X1 + 6;
49+
Self.Scroll.Area.Y1 := Self.Bounds.Y1 + 6;
50+
Self.Scroll.Area.X2 := Self.Bounds.X2 - 23;
51+
Self.Scroll.Area.Y2 := Self.InputLine.Y1 - 1;
5252

5353
Self.Scroll.Setup();
5454
end;

osrs/interfaces/gametabs/logout.simba

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,24 @@ end;
114114
(*
115115
## Logout.Logout
116116
```pascal
117-
function TRSLogout.Logout(attempts: UInt32 = 5; time: UInt32 = 20000): Boolean;
117+
function TRSLogout.Logout(const attempts: UInt32 = 5; const time: UInt32 = 20000): Boolean;
118118
```
119-
Clicks the logout button. Returns true if we succesfully logout of the game.
119+
Attempts to logout of the game. Returns true if we succesfully logout of the game.
120+
If the {ref}`WorldSwitcher` is open, we will use {ref}`WorldSwitcher.Logout` instead.
120121

121122
Example:
122123
```pascal
123-
WriteLn Logout.ClickLogout();
124+
WriteLn Logout.Logout();
124125
```
125126
*)
126127
function TRSLogout.Logout(const attempts: UInt32 = 5; const time: UInt32 = 20000): Boolean;
127128
var
128129
i: Integer;
129130
interval: UInt32;
130131
begin
131-
if not Self.Open() then Exit; //TODO: or (not Self.CloseWorldSwitcher()) then
132+
if not Self.Open() then Exit;
133+
if WorldSwitcher.Logout() then Exit(True);
134+
132135
interval := time div attempts;
133136

134137
if Biometrics.RandomBoolean(EBiometric.RATING) then
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
(*
2+
# WorldSwitcher
3+
WorldSwitcher is resposible for changing worlds with the logged in world
4+
switcher in the {ref}`Logout` gametab.
5+
*)
6+
{$DEFINE SRLT_WORLDSWITCHER_INCLUDED}
7+
{$INCLUDE_ONCE SRLT/osrs.simba}
8+
9+
type
10+
ERSWorldSwitcherButton = enum(CONFIGURE, CLOSE, LOGOUT);
11+
(*
12+
(TRSWorldSwitcher)=
13+
## type TRSWorldSwitcher
14+
Main record that holds all the world switching methods.
15+
*)
16+
TRSWorldSwitcher = record
17+
Scroll: TRSScrollBar;
18+
ServerMessageBox: TBox;
19+
Cooldown: TCountDown;
20+
CurrentWorldBounds: TBox;
21+
Buttons: array [ERSWorldSwitcherButton] of TRSButton;
22+
const SILVER: TColor = $E0E0E0;
23+
const YELLOW: TColor = $00F0F0;
24+
end;
25+
26+
procedure TRSWorldSwitcher.SetupInterface();
27+
begin
28+
Self.ServerMessageBox.X1 := MainScreen.Bounds.X1 + 4;
29+
Self.ServerMessageBox.Y1 := MainScreen.Bounds.Y1 + 4;
30+
Self.ServerMessageBox.X2 := Self.ServerMessageBox.X1 + 79;
31+
Self.ServerMessageBox.Y2 := Self.ServerMessageBox.Y1 + 20;
32+
33+
with GameTab.Bounds do
34+
begin
35+
Self.CurrentWorldBounds.X1 := X2 - 52;
36+
Self.CurrentWorldBounds.Y1 := Y1 + 4;
37+
Self.CurrentWorldBounds.X2 := X2 - 25;
38+
Self.CurrentWorldBounds.Y2 := Y1 + 17;
39+
40+
Self.Buttons[ERSWorldSwitcherButton.CONFIGURE].Bounds.X1 := X1;
41+
Self.Buttons[ERSWorldSwitcherButton.CONFIGURE].Bounds.Y1 := Y1 + 4;
42+
Self.Buttons[ERSWorldSwitcherButton.CONFIGURE].Bounds.X2 := X1 + 15;
43+
Self.Buttons[ERSWorldSwitcherButton.CONFIGURE].Bounds.Y2 := Y1 + 19;
44+
45+
Self.Buttons[ERSWorldSwitcherButton.CLOSE].Bounds.X1 := X2 - 17;
46+
Self.Buttons[ERSWorldSwitcherButton.CLOSE].Bounds.Y1 := Y1 + 2;
47+
Self.Buttons[ERSWorldSwitcherButton.CLOSE].Bounds.X2 := X2 + 3;
48+
Self.Buttons[ERSWorldSwitcherButton.CLOSE].Bounds.Y2 := Y1 + 22;
49+
50+
Self.Buttons[ERSWorldSwitcherButton.LOGOUT].Bounds.X1 := X2 - 19;
51+
Self.Buttons[ERSWorldSwitcherButton.LOGOUT].Bounds.Y1 := Y2 - 30;
52+
Self.Buttons[ERSWorldSwitcherButton.LOGOUT].Bounds.X2 := X2 + 1;
53+
Self.Buttons[ERSWorldSwitcherButton.LOGOUT].Bounds.Y2 := Y2 - 1;
54+
55+
Self.Scroll.Area.X1 := X1 - 3;
56+
Self.Scroll.Area.Y1 := Y1 + 36;
57+
Self.Scroll.Area.X2 := X2 - 13;
58+
Self.Scroll.Area.Y2 := Y2 - 33;
59+
end;
60+
61+
Self.Scroll.Setup();
62+
end;
63+
64+
65+
{%codetools off}
66+
function TRSWorldSwitcher._IsOpen(): Boolean;
67+
begin
68+
Result := Target.HasColor($0C0E10, 3, 134, Self.Buttons[ERSWorldSwitcherButton.CLOSE].Bounds);
69+
end;
70+
{%codetools on}
71+
72+
(*
73+
## WorldSwitcher.IsOpen
74+
```pascal
75+
function TRSWorldSwitcher.IsOpen(): Boolean;
76+
```
77+
Returns true if the world switcher is open.
78+
79+
Example:
80+
```pascal
81+
WriteLn WorldSwitcher.IsOpen();
82+
```
83+
*)
84+
function TRSWorldSwitcher.IsOpen(): Boolean;
85+
begin
86+
Result := GameTabs.IsOpen(ERSGameTab.LOGOUT) and Self._IsOpen();
87+
end;
88+
89+
(*
90+
## Logout.CloseWorldSwitcher
91+
```pascal
92+
function TRSLogout.CloseWorldSwitcher(): Boolean;
93+
```
94+
Closes the world switcher.
95+
96+
Example:
97+
```pascal
98+
Logout.CloseWorldSwitcher();
99+
```
100+
*)
101+
function TRSWorldSwitcher.Close(): Boolean;
102+
begin
103+
if not Self.IsOpen() then Exit(True);
104+
Self.Buttons[ERSWorldSwitcherButton.CLOSE].Click();
105+
Result := SleepUntil(not Self._IsOpen(), RandomMode(100, 50, 1500), 600);
106+
end;
107+
108+
(*
109+
## WorldSwitcher.Logout
110+
```pascal
111+
function TRSWorldSwitcher.Logout(const attempts: UInt32 = 5; const time: UInt32 = 20000): Boolean;
112+
```
113+
Clicks the logout button. Returns true if we succesfully logout of the game.
114+
115+
Example:
116+
```pascal
117+
WriteLn WorldSwitcher.Logout();
118+
```
119+
*)
120+
function TRSWorldSwitcher.Logout(const attempts: UInt32 = 5; const time: UInt32 = 20000): Boolean;
121+
var
122+
i: Integer;
123+
interval: UInt32;
124+
begin
125+
if not Self.IsOpen() then Exit;
126+
interval := time div attempts;
127+
128+
if Keyboard.LastKey = EKeyCode.RETURN then
129+
Keyboard.RandomKey(); //unlock enter if using remote input
130+
131+
for i := 1 to attempts do
132+
begin
133+
Self.Buttons[ERSWorldSwitcherButton.LOGOUT].Click();
134+
if SleepUntil(not RSClient.IsLoggedIn(), 500, interval + Random(-2000, 2000)) then
135+
Exit(True);
136+
end;
137+
end;
138+
139+
140+
(*
141+
## WorldSwitcher.GetCurrentWorld
142+
```pascal
143+
function TRSWorldSwitcher.GetCurrentWorld(): Integer;
144+
```
145+
Returns the current world we are on.
146+
147+
Example:
148+
```pascal
149+
WriteLn WorldSwitcher.GetCurrentWorld();
150+
```
151+
*)
152+
function TRSWorldSwitcher.GetCurrentWorld(): Integer;
153+
begin
154+
Result := OCR.RecognizeNumber(Self.CurrentWorldBounds, RSFonts.BOLD, [RSColors.TEXT_ORANGE], 0);
155+
end;
156+
157+
158+
var
159+
WorldSwitcher: TRSWorldSwitcher;
160+

osrs/interfaces/interfacecontrols.simba

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,33 +136,33 @@ end;
136136

137137
type
138138
TRSScrollBar = record
139-
ScrollArea, Up, Down: TBox;
139+
Area, Up, Down: TBox;
140140
Bounds: TBox;
141141
Width, Height: Integer;
142142
end;
143143

144144
procedure TRSScrollBar.Setup();
145145
begin
146-
if Self.ScrollArea = Default(TBox) then
147-
raise GetDebugLn('ScrollBar', 'You need to set a ScrollArea to use the TRSScrollBar.Setup() method.');
146+
if Self.Area = Default(TBox) then
147+
raise GetDebugLn('ScrollBar', 'You need to set a Area to use the TRSScrollBar.Setup() method.');
148148

149-
Self.Bounds.X1 := Self.ScrollArea.X2 + 1;
150-
Self.Bounds.Y1 := Self.ScrollArea.Y1 + 16;
149+
Self.Bounds.X1 := Self.Area.X2 + 1;
150+
Self.Bounds.Y1 := Self.Area.Y1 + 16;
151151
Self.Bounds.X2 := Self.Bounds.X1 + 15;
152-
Self.Bounds.Y2 := Self.ScrollArea.Y2 - 16;
152+
Self.Bounds.Y2 := Self.Area.Y2 - 16;
153153

154154
Self.Width := Self.Bounds.Width;
155155
Self.Height := Self.Bounds.Height;
156156

157157
Self.Up.X1 := Self.Bounds.X1;
158-
Self.Up.Y1 := Self.ScrollArea.Y1;
158+
Self.Up.Y1 := Self.Area.Y1;
159159
Self.Up.X2 := Self.Bounds.X2;
160160
Self.Up.Y2 := Self.Bounds.Y1 - 1;
161161

162162
Self.Down.X1 := Self.Bounds.X1;
163163
Self.Down.Y1 := Self.Bounds.Y2 + 1;
164164
Self.Down.X2 := Self.Bounds.X2;
165-
Self.Down.Y2 := Self.ScrollArea.Y2;
165+
Self.Down.Y2 := Self.Area.Y2;
166166
end;
167167

168168
function TRSScrollBar.IsVisible(): Boolean;
@@ -200,7 +200,10 @@ end;
200200

201201
function TRSScrollBar.GetScrollArea(): TBox;
202202
begin
203-
Result := Self.ScrollArea; //todo: add antiban to use bounds instead
203+
if Biometrics.RandomBoolean(0.9) then
204+
Result := Self.Area
205+
else
206+
Result := Self.Bounds;
204207
end;
205208

206209
function TRSScrollBar.SetLevel(value: Integer): Integer;
@@ -239,6 +242,9 @@ var
239242
begin
240243
img := TImage.CreateFromTarget();
241244

245+
img.DrawColor := $00FF00;
246+
img.DrawBox(scroll.Area);
247+
242248
img.DrawColor := $FFFF00;
243249
img.DrawBox(scroll.Bounds);
244250

osrs/interfaces/mainscreen/bank.simba

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ begin
132132
Self.Bounds.Y2 := Min(Floor(Center.Y+(Height-3)/2), Floor(Center.Y+799/2));
133133
end;
134134

135-
Self.Scroll.ScrollArea.X1 := Self.Bounds.X1 + 5;
136-
Self.Scroll.ScrollArea.Y1 := Self.Bounds.Y1 + 78;
137-
Self.Scroll.ScrollArea.X2 := Self.Bounds.X2 - 22;
138-
Self.Scroll.ScrollArea.Y2 := Self.Bounds.Y2 - 44;
135+
Self.Scroll.Area.X1 := Self.Bounds.X1 + 5;
136+
Self.Scroll.Area.Y1 := Self.Bounds.Y1 + 78;
137+
Self.Scroll.Area.X2 := Self.Bounds.X2 - 22;
138+
Self.Scroll.Area.Y2 := Self.Bounds.Y2 - 44;
139139

140140
Self.Scroll.Setup();
141141
Self.Title.Setup(Self.Bounds);

osrs/interfaces/setup.simba

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ begin
1313
Inventory.SetupInterface();
1414
Equipment.SetupInterface();
1515
Options.SetupInterface();
16+
WorldSwitcher.SetupInterface();
1617
Logout.SetupInterface();
1718
MM2MS.Projector.SetupProjection();
1819
Chat.SetupInterface();

0 commit comments

Comments
 (0)