Advertisement
Guest User

Untitled

a guest
Nov 14th, 2016
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. import org.osbot.rs07.api.ui.RS2Widget;
  2. import org.osbot.rs07.constants.ResponseCode;
  3. import org.osbot.rs07.event.Event;
  4. import org.osbot.rs07.input.mouse.RectangleDestination;
  5. import org.osbot.rs07.listener.LoginResponseCodeListener;
  6. import org.osbot.rs07.utility.ConditionalSleep;
  7.  
  8. import java.awt.*;
  9.  
  10. public final class LoginEvent extends Event implements LoginResponseCodeListener {
  11.  
  12. private String username, password;
  13.  
  14. public LoginEvent() {}
  15.  
  16. public LoginEvent(final String username, final String password) {
  17. this.username = username;
  18. this.password = password;
  19. }
  20.  
  21. public final void setUsername(final String username) {
  22. this.username = username;
  23. }
  24.  
  25. public final void setPassword(final String password) {
  26. this.password = password;
  27. }
  28.  
  29. @ Override
  30. public int execute() throws InterruptedException {
  31. if (getClient().isLoggedIn() && getLobbyButton() == null) {
  32. setFinished();
  33. } else if (getLobbyButton() != null) {
  34. clickLobbyButton();
  35. } else if (isOnWorldSelectorScreen()) {
  36. cancelWorldSelection();
  37. } else {
  38. login();
  39. }
  40. return random(100, 152);
  41. }
  42.  
  43. private boolean isOnWorldSelectorScreen() {
  44. return getColorPicker().isColorAt(50, 50, Color.BLACK);
  45. }
  46.  
  47. private void cancelWorldSelection() {
  48. if (getMouse().click(new RectangleDestination(getBot(), 712, 8, 42, 8))) {
  49. new ConditionalSleep(3000) {
  50. @ Override
  51. public boolean condition() throws InterruptedException {
  52. return !isOnWorldSelectorScreen();
  53. }
  54. }.sleep();
  55. }
  56. }
  57.  
  58. private void login() {
  59. switch (getClient().getLoginUIState()) {
  60. case 0:
  61. clickExistingUsersButton();
  62. break;
  63. case 1:
  64. clickLoginButton();
  65. break;
  66. case 2:
  67. enterUserDetails();
  68. break;
  69. }
  70. }
  71.  
  72. private void clickExistingUsersButton() {
  73. getMouse().click(new RectangleDestination(getBot(), 400, 280, 120, 20));
  74. }
  75.  
  76. private void clickLoginButton() {
  77. getMouse().click(new RectangleDestination(getBot(), 240, 310, 120, 20));
  78. }
  79.  
  80. private void enterUserDetails() {
  81. if (!getKeyboard().typeString(username)) {
  82. setFailed();
  83. return;
  84. }
  85. if (!getKeyboard().typeString(password)) {
  86. setFailed();
  87. return;
  88. }
  89. new ConditionalSleep(21_000) {
  90. @ Override
  91. public boolean condition() throws InterruptedException {
  92. return getLobbyButton() != null;
  93. }
  94. }.sleep();
  95. }
  96.  
  97. private void clickLobbyButton() {
  98. if (getLobbyButton().interact()) {
  99. new ConditionalSleep(10_000) {
  100. @ Override
  101. public boolean condition() throws InterruptedException {
  102. return getLobbyButton() == null;
  103. }
  104. }.sleep();
  105. }
  106. }
  107.  
  108. private RS2Widget getLobbyButton() {
  109. return getWidgets().getWidgetContainingText("CLICK HERE TO PLAY");
  110. }
  111.  
  112. @ Override
  113. public final void onResponseCode(final int responseCode) throws InterruptedException {
  114. if(ResponseCode.isDisabledError(responseCode)) {
  115. log("Login failed, account is disabled");
  116. setFailed();
  117. return;
  118. }
  119.  
  120.  
  121. if(ResponseCode.isConnectionError(responseCode)) {
  122. log("Connection error, attempts exceeded");
  123. setFailed();
  124. return;
  125. }
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement