Skip to content

Commit 668eed8

Browse files
committed
fix: finished TRSLogout
also completed the antiban todo's that needed the logout done first
1 parent a19b13c commit 668eed8

File tree

4 files changed

+62
-23
lines changed

4 files changed

+62
-23
lines changed

osrs/antiban/antiban.simba

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ begin
225225
if RandomBoolean(task.LogoutChance) then
226226
begin
227227
WriteLn GetDebugLn('Antiban', 'Logging out.');
228-
//TODO:
229-
//Logout.ClickLogout();
228+
Logout.Logout();
230229
end;
231230

232231
if RandomBoolean(0.7) then RSClient.LoseFocus();
@@ -289,8 +288,7 @@ begin
289288
if RandomBoolean(task.LogoutChance) then
290289
begin
291290
WriteLn GetDebugLn('Antiban', 'Logging out.');
292-
//TODO:
293-
//Logout.ClickLogout();
291+
Logout.Logout();
294292
end;
295293

296294
if RandomBoolean(0.50) then

osrs/antiban/antibantasks.simba

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -496,21 +496,6 @@ begin
496496
end;
497497

498498

499-
procedure TAntiban.RandomKeyboard();
500-
begin
501-
case Random(100) of
502-
0..74:
503-
case Random(3) of
504-
0: Keyboard.PressKey(EKeyCode.LEFT);
505-
1: Keyboard.PressKey(EKeyCode.RIGHT);
506-
2: Keyboard.PressKey(EKeyCode.UP);
507-
end;
508-
75..89: Keyboard.PressKey(Keyboard.FKEYS.Random());
509-
90..99: Keyboard.PressKey(Keyboard.MISC.Random());
510-
end;
511-
end;
512-
513-
514499
procedure TAntiban.ToggleRun();
515500
begin
516501
WriteLn GetDebugLn('Antiban', 'Toggling energy');

osrs/interfaces/gametabs/logout.simba

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ Methods to interact with the logout tab.
99

1010
type
1111
ERSLogoutButton = (WORLD_SWITCHER, CLICK_HERE);
12-
ERSLogoutRating = (ONE, TWO, THREE, FOUR, FIVE);
13-
1412
TRSLogout = record
1513
Buttons: array [ERSLoginButton] of TRSButton;
16-
Ratings: array [ERSLogoutRating] of TRSButton;
14+
Ratings: array [0..4] of TRSButton;
1715
end;
1816

1917
procedure TRSLogout.SetupInterface();
@@ -87,7 +85,49 @@ WriteLn Logout.IsRated();
8785
*)
8886
function TRSLogout.IsRated(): Boolean;
8987
begin
90-
Result := Self.Ratings[ERSLogoutRating.ONE].Enabled();
88+
Result := Self.Ratings[0].Enabled();
89+
end;
90+
91+
(*
92+
## Logout.ClickLogout
93+
```pascal
94+
function TRSLogout.ClickLogout(attempts: Int32 = 5; time: Int32 = 20000): Boolean;
95+
```
96+
Clicks the logout button. Returns true if we succesfully logout of the game.
97+
98+
Example:
99+
```pascal
100+
WriteLn Logout.ClickLogout();
101+
```
102+
*)
103+
function TRSLogout.Logout(const attempts: UInt32 = 5; const time: UInt32 = 20000): Boolean;
104+
var
105+
i: Integer;
106+
interval: UInt32;
107+
begin
108+
if not Self.Open() then Exit; //TODO: or (not Self.CloseWorldSwitcher()) then
109+
interval := time div attempts;
110+
111+
if Biometrics.RandomBoolean(EBiometric.RATING) then
112+
begin
113+
if Biometrics.RandomBoolean(EBiometric.LIKES) then
114+
i := RandomLeft(4, 0)
115+
else
116+
i := RandomLeft(0, 4);
117+
118+
WriteLn GetDebugLn('Logout', 'Rating the game with ' + ToStr(i+1) + ' stars before logging out.');
119+
Self.Ratings[i].Enable();
120+
end;
121+
122+
if Keyboard.LastKey = EKeyCode.RETURN then
123+
Keyboard.RandomKey(); //unlock enter if using remote input
124+
125+
for i := 1 to attempts do
126+
begin
127+
Self.Buttons[ERSLogoutButton.CLICK_HERE].Click();
128+
if SleepUntil(not RSClient.IsLoggedIn(), 500, interval + Random(-2000, 2000)) then
129+
Exit(True);
130+
end;
91131
end;
92132

93133
var

utils/input/keyboard.simba

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ begin
113113
Self.PressKey(keyPressAfter);
114114
end;
115115

116+
117+
procedure TKeyboard.RandomKey();
118+
begin
119+
case Random(100) of
120+
0..74:
121+
case Random(3) of
122+
0: Self.PressKey(EKeyCode.LEFT);
123+
1: Self.PressKey(EKeyCode.RIGHT);
124+
2: Self.PressKey(EKeyCode.UP);
125+
end;
126+
75..89: Self.PressKey(Self.FKEYS.Random());
127+
90..99: Self.PressKey(Self.MISC.Random());
128+
end;
129+
end;
130+
131+
116132
var
117133
Keyboard: TKeyboard;
118134

0 commit comments

Comments
 (0)