|
| 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 | + |
0 commit comments