Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.64 KB | None | 0 0
  1. import java.awt.*;
  2. import java.util.Properties;
  3. import java.io.*;
  4.  
  5. import org.rsbot.script.Script;
  6. import org.rsbot.script.ScriptManifest;
  7. import org.rsbot.script.wrappers.*;
  8. import org.rsbot.script.methods.*;
  9. import org.rsbot.event.listeners.PaintListener;
  10. import org.rsbot.Configuration;
  11.  
  12. @ScriptManifest(authors = {"rewsky"}, keywords = {""}, name = "runeMysteries", description = "Completes the Rune Mysteries quest.", version = 1.21)
  13. public class runeMysteries extends Script implements PaintListener {
  14. private static final boolean endInVarrock = true; // Set to TRUE to walk to varrock after quest
  15. // FALSE to stay at wizard tower
  16.  
  17.  
  18. /* ID's of all the NPCs in the quest */
  19. private static final int DUKE = 741;
  20. private static final int SEDRIDOR = 300;
  21. private static final int AUBREY = 553;
  22.  
  23. /* ID's of all the items recieved during the quest */
  24. private static final int AIR_TALISMAN = 15361;
  25. private static final int END_AIR_TALISMAN = 1438;
  26. private static final int RESEARCH_NOTES = 290;
  27. private static final int FURTHER_NOTES = 291;
  28.  
  29. /* ID's of objects that may need to be interacted with during quest */
  30. private static final int CLOSED_DOOR = 36844;
  31. private static final int OPEN_DOOR = 36845;
  32. private static final int LUMB_STAIRS_DOWN = 36774;
  33. private static final int LUMB_STAIRS_UP = 36773;
  34. private static final int WT_OPEN_DOOR = 11994;
  35. private static final int WT_CLOSED_DOOR = 11993;
  36. private static final int WT_OPEN_BIG_DOOR = 31828;
  37. private static final int WT_CLOSED_BIG_DOOR = 33060;
  38. private static final int WT_LADDER_UP = 32015;
  39. private static final int WT_LADDER_DOWN = 2147;
  40. private static final int AUBREY_CLOSED_DOOR = 24381;
  41. private static final int AUBREY_OPEN_DOOR = 24379;
  42.  
  43. /* Areas key to detecting which stage of the quest we're on */
  44. private static final RSArea DUKE_ROOM = new RSArea(new RSTile(3208, 3218), new RSTile(3212, 3225));
  45. private static final RSArea LUMB_STAIRCASE_LOWER = new RSArea(new RSTile(3200, 3206), new RSTile(3212, 3214));
  46. private static final RSArea WIZARD_TOWER = new RSArea(new RSTile(3111, 3160), new RSTile(3103, 3166));
  47. private static final RSArea WIZARD_BASEMENT = new RSArea(new RSTile(3115, 9563), new RSTile(3095, 9577));
  48. private static final RSArea SEDRIDORS_ROOM = new RSArea(new RSTile(3108, 9575), new RSTile(3094, 9565));
  49. private static final RSArea SHOP_AREA = new RSArea(new RSTile(3250, 3404), new RSTile(3255, 3398));
  50.  
  51. private static final RSTile[] TOWER_PATH = {new RSTile(3205, 3209), new RSTile(3202, 3219),
  52. new RSTile(3190, 3216), new RSTile(3178, 3215), new RSTile(3168, 3212), new RSTile(3159, 3216),
  53. new RSTile(3147, 3217), new RSTile(3138, 3210), new RSTile(3127, 3210), new RSTile(3115, 3210),
  54. new RSTile(3112, 3202), new RSTile(3114, 3194), new RSTile(3113, 3186), new RSTile(3113, 3175),
  55. new RSTile(3109, 3163), new RSTile(3109, 3167), new RSTile(3109, 3163)};
  56. private static final RSTile[] VARROCK_PATH = {new RSTile(3104, 3161),
  57. new RSTile(3110, 3169), new RSTile(3113, 3181), new RSTile(3114, 3191), new RSTile(3113, 3202),
  58. new RSTile(3119, 3211), new RSTile(3127, 3219), new RSTile(3134, 3225), new RSTile(3145, 3231),
  59. new RSTile(3157, 3236), new RSTile(3167, 3238), new RSTile(3178, 3244), new RSTile(3189, 3244),
  60. new RSTile(3199, 3247), new RSTile(3212, 3247), new RSTile(3218, 3257), new RSTile(3229, 3262),
  61. new RSTile(3241, 3267), new RSTile(3238, 3278), new RSTile(3238, 3293), new RSTile(3238, 3306),
  62. new RSTile(3246, 3317), new RSTile(3254, 3325), new RSTile(3266, 3332), new RSTile(3278, 3339),
  63. new RSTile(3286, 3349), new RSTile(3296, 3357), new RSTile(3294, 3370), new RSTile(3293, 3380),
  64. new RSTile(3293, 3387), new RSTile(3290, 3399), new RSTile(3290, 3410), new RSTile(3285, 3420),
  65. new RSTile(3274, 3427), new RSTile(3266, 3416), new RSTile(3259, 3406), new RSTile(3253, 3401)};
  66.  
  67. private enum state {
  68. TO_LUMBRIDGE, GET_QUEST, TO_TOWER, GET_NOTES, TO_VARROCK, GET_NEW_NOTES, FINISH_QUEST, END, WAIT, NEXT_ACCOUNT, LOGGING_IN
  69. };
  70.  
  71. private state currentState = null;
  72. private String st = null;
  73.  
  74. /* Variables for time-keeping */
  75. private long startTime = 0;
  76. private long millis = 0;
  77. private long hours = 0;
  78. private long minutes = 0;
  79. private long seconds = 0;
  80. private long last = 0;
  81.  
  82. /* Method called when user chooses to run this script. Return True = continue, False = terminate */
  83. @Override
  84. public boolean onStart() {
  85. try {
  86. Acc.load(new FileInputStream(new File(Configuration.Paths.getScriptCacheDirectory(), "AccountsMade.ini")));
  87. } catch (Throwable e) {
  88. }
  89. startTime = System.currentTimeMillis();
  90. if (!game.isLoggedIn())
  91. currentState = state.NEXT_ACCOUNT;
  92. if (inventory.contains(END_AIR_TALISMAN))
  93. currentState = state.END;
  94.  
  95. getState();
  96.  
  97. if (currentState == null)
  98. currentState = state.TO_LUMBRIDGE;
  99. return true;
  100. }
  101.  
  102. /* Returns a value denoting what floor the character is on
  103. * 0 = Ground floor / dungeons
  104. * 1 = Middle floor
  105. * 2 = Top floor
  106. */
  107. public int getFloor() {
  108. return game.getPlane();
  109. }
  110.  
  111. /* Opens a closed door if needed */
  112. public boolean openDoor(int objectID, RSTile tile) {
  113. RSObject myDoor = null;
  114. RSObject[] onTile = null;
  115.  
  116. onTile = objects.getAllAt(tile);
  117. for (RSObject tempObject : onTile) {
  118. if (tempObject.getID() == objectID) {
  119. myDoor = tempObject;
  120. break;
  121. }
  122. }
  123.  
  124. if (myDoor != null)
  125. if (myDoor.isOnScreen()) {
  126. myDoor.doAction("Open");
  127. sleep(1500, 2000);
  128. return true;
  129. }
  130.  
  131. return false;
  132. }
  133.  
  134. /* If the interface where you accept the quest is open, it is returned, else null */
  135. public RSInterface questInterfaceOpen() {
  136. RSInterface[] allInterfaces = interfaces.getAll();
  137. RSComponent[] allComponents = null;
  138.  
  139. // Loop through all the interfaces on screen
  140. for (RSInterface myInterface : allInterfaces) {
  141. allComponents = myInterface.getComponents();
  142.  
  143. // Loop through all the components in the current interface
  144. for (RSComponent myComponent : allComponents) {
  145. if (myComponent.containsText("Rune Mysteries"))
  146. return myInterface;
  147. }
  148. }
  149. return null;
  150. }
  151.  
  152. /* Uses the free teleport to lumbridge */
  153. public void teleToLumb() {
  154. if (!getMyPlayer().isIdle()) {
  155. sleep(500, 1000);
  156. } else {
  157. magic.castSpell(magic.SPELL_HOME_TELEPORT);
  158. }
  159. }
  160.  
  161. /* Walks to the next tile in a given RSTile array (path) */
  162. public void walkNext(RSTile[] path, RSTile position, int randomX, int randomY) {
  163. int myX = position.getX();
  164. int myY = position.getY();
  165. RSTile nextTile = null;
  166. RSArea currentTileArea = new RSArea(new RSTile(myX - (randomX + 1), myY - (randomY + 1)),
  167. new RSTile(myX + (randomX + 1), myY + (randomY + 1)));
  168.  
  169. for (int i = 0; i < path.length; i++) {
  170. if (currentTileArea.contains(path[i])) {
  171. if (i < (path.length - 1))
  172. nextTile = path[i + 1];
  173. else
  174. nextTile = path[i];
  175. break;
  176. }
  177. }
  178.  
  179. if (nextTile != null) {
  180. walking.walkTileMM(nextTile, randomX, randomY);
  181. }
  182.  
  183. }
  184.  
  185. /* Walks from anywhere, to the duke of lumbridge's room */
  186. public void walkToDuke() {
  187. RSTile currentTile = getMyPlayer().getLocation();
  188. RSObject stairs = null;
  189.  
  190. if (currentTile.getX() < 3191 || currentTile.getX() > 3242 || currentTile.getY() > 3264 ||
  191. currentTile.getY () < 3199) {
  192. teleToLumb();
  193. } else {
  194. if (getFloor() == 0) {
  195. if (LUMB_STAIRCASE_LOWER.contains(currentTile)) {
  196. stairs = objects.getNearest(LUMB_STAIRS_UP);
  197. if (stairs != null)
  198. stairs.doAction("Climb-up");
  199. } else {
  200. walking.walkTo(new RSTile(3206, 3209));
  201. }
  202. } else if (getFloor() == 1) {
  203. if (!DUKE_ROOM.contains(currentTile)) {
  204. openDoor(CLOSED_DOOR, new RSTile(3207, 3222));
  205. walking.walkTileMM(new RSTile(3210, 3221));
  206. } else {
  207. currentState = state.GET_QUEST;
  208. }
  209. } else if (getFloor() == 2) {
  210. stairs = objects.getNearest(36775);
  211. if (stairs != null)
  212. stairs.doAction("Climb-down");
  213. } else {
  214. log("Bot lost on username: "+userNames()[questsDone]+", moving on.");
  215. nextACC();
  216. }
  217. }
  218. }
  219.  
  220. /* Walks from anywhere, to the basement of the wizards tower */
  221. public void walkToSedridor() {
  222. RSTile currentTile = getMyPlayer().getLocation();
  223. RSObject wizLadder = null;
  224. RSObject lumbStairs = null;
  225.  
  226. if (!openDoor(WT_CLOSED_DOOR, new RSTile(3109, 3167))) {
  227. if (!openDoor(WT_CLOSED_DOOR, new RSTile(3107, 3162))) {
  228. if ((getFloor() == 1) && (DUKE_ROOM.contains(currentTile))) {
  229. openDoor(CLOSED_DOOR, new RSTile(3207, 3222));
  230. walking.walkTileMM(new RSTile(3206, 3209));
  231. } else if (getFloor() == 1) {
  232. lumbStairs = objects.getNearest(LUMB_STAIRS_DOWN);
  233. if (lumbStairs != null)
  234. lumbStairs.doAction("Climb-down");
  235.  
  236. // If in sedridors room, we've arrived!
  237. } else if (SEDRIDORS_ROOM.contains(currentTile)) {
  238. currentState = state.GET_NOTES;
  239.  
  240. // If in the basement of the tower, get into sedridors room
  241. } else if (WIZARD_BASEMENT.contains(currentTile)) {
  242. if (!openDoor(WT_CLOSED_BIG_DOOR, new RSTile(3108, 9570))) {
  243. walking.walkTileMM(new RSTile(3105, 9569));
  244. }
  245.  
  246. // Walk to the wizards tower
  247. } else if ((getFloor() == 0) && !WIZARD_TOWER.contains(currentTile)) {
  248. walkNext(TOWER_PATH, currentTile, 2, 2);
  249.  
  250. // Climb down to basement of the tower
  251. } else {
  252. wizLadder = objects.getNearest(WT_LADDER_DOWN);
  253. if (wizLadder != null)
  254. wizLadder.doAction("Climb-down");
  255. }
  256. }
  257. }
  258. }
  259.  
  260. /* Walks from anywhere, to the magic shop in varrock */
  261. public void walkToAubrey() {
  262. RSTile currentTile = getMyPlayer().getLocation();
  263. RSObject wizLadder = null;
  264.  
  265. // Exit the wizards tower basement
  266. if (WIZARD_BASEMENT.contains(currentTile)) {
  267. if (SEDRIDORS_ROOM.contains(currentTile)) {
  268. if (!openDoor(WT_CLOSED_BIG_DOOR, new RSTile(3108, 9570)))
  269. walking.walkTileMM(new RSTile(3109, 9574));
  270.  
  271. } else {
  272. wizLadder = objects.getNearest(WT_LADDER_UP);
  273. if ((wizLadder != null) && (wizLadder.isOnScreen())) {
  274. wizLadder.doAction("Climb-up");
  275. } else {
  276. walking.walkTileMM(new RSTile(3109, 9574));
  277. }
  278. }
  279. } else if (!openDoor(WT_CLOSED_DOOR, new RSTile(3107, 3162))) {
  280. if (!openDoor(WT_CLOSED_DOOR, new RSTile(3109, 3167))) {
  281. if (!openDoor(AUBREY_CLOSED_DOOR, new RSTile(3253, 3398))) {
  282.  
  283. if (interfaces.get(212).isValid()) {
  284. interfaces.getComponent(212, 4).doClick();
  285. } else if (interfaces.get(236).isValid()) {
  286. interfaces.getComponent(236, 1).doClick();
  287. } else if (SHOP_AREA.contains(currentTile)) {
  288. if (inventory.contains(END_AIR_TALISMAN)) {
  289. log("Script finished.");
  290. nextACC();
  291. } else {
  292. currentState = state.GET_NEW_NOTES;
  293. }
  294. } else {
  295. walkNext(VARROCK_PATH, currentTile, 3, 3);
  296. }
  297. }
  298. }
  299. }
  300. }
  301.  
  302. /* Handles conversation with the duke */
  303. public void talkToDuke() {
  304. RSNPC myDuke = npcs.getNearest(DUKE);
  305.  
  306. // If player is not in the dukes room, set state to walk to lumbridge
  307. if (!DUKE_ROOM.contains(getMyPlayer().getLocation())) {
  308. currentState = state.TO_LUMBRIDGE;
  309. } else {
  310. // If quest acceptance interface is open, click yes, otherwise converse with duke
  311. if (questInterfaceOpen() == null) {
  312.  
  313. // If chat interface is open, continue talking, otherwise initiate conversation
  314. if (interfaces.get(241).isValid()) {
  315. interfaces.getComponent(241, 5).doClick();
  316. } else if (interfaces.get(228).isValid()) {
  317. interfaces.getComponent(228, 2).doClick();
  318. } else if (interfaces.get(64).isValid()) {
  319. interfaces.getComponent(64, 5).doClick();
  320. } else if (interfaces.get(242).isValid()) {
  321. interfaces.getComponent(242, 6).doClick();
  322. } else {
  323.  
  324. // If the duke is on screen, talk to him, otherwise set the state as walk to lumbridge
  325. if (myDuke.isOnScreen()) {
  326. myDuke.doAction("Talk");
  327. }
  328. }
  329. } else {
  330. mouse.click(170, 305, 30, 10, true);
  331. sleep(1000, 500);
  332. currentState = state.TO_TOWER;
  333. }
  334. }
  335. }
  336. private int questsDone = 0;
  337. private Properties Acc = new Properties();
  338. private String[] userNames() {
  339. try {
  340. Acc.load(new FileInputStream(new File(Configuration.Paths.getScriptCacheDirectory(), "AccountsMade.ini")));
  341. } catch (FileNotFoundException e) {
  342. log.warning("[FUNDAMENTAL ERROR] Account made file was not found!");
  343. stopScript();
  344. return null;
  345. } catch (IOException e) {
  346. log.warning("[Account] Error loading names settings!");
  347. return null;
  348. }
  349. Object[] names = Acc.stringPropertyNames().toArray();
  350. String[] usernames = new String[names.length];
  351. System.arraycopy( names, 0, usernames, 0, names.length );
  352. return usernames;
  353. }
  354. public String[] passwords() {
  355. try {
  356. Acc.load(new FileInputStream(new File(Configuration.Paths.getScriptCacheDirectory(), "AccountsMade.ini")));
  357. } catch (FileNotFoundException e) {
  358. log.warning("[FUNDAMENTAL ERROR] Account made file was not found!");
  359. stopScript();
  360. return null;
  361. } catch (IOException e) {
  362. log.warning("[Account] Error loading passwwords settings!");
  363. return null;
  364.  
  365. }
  366. String[] findPass = userNames();
  367. for (int i = 0; i < userNames().length; i++) {
  368. findPass[i] = Acc.getProperty(userNames()[i]);
  369. }
  370. return findPass;
  371. }
  372. //Logs out and then goes to
  373. public void nextACC() {
  374. while (passwords()[questsDone].contains("done")){
  375. questsDone += 1;
  376. }
  377. game.logout(false);
  378. sleep(5000,1000);
  379. if(userNames()[questsDone] == null || passwords()[questsDone] == null){
  380. log("Finished all accounts");
  381. stopScript();
  382. }
  383. Acc.setProperty(userNames()[questsDone], passwords()[questsDone]+" done");
  384. login(userNames()[questsDone],passwords()[questsDone]);
  385. currentState = state.LOGGING_IN;
  386. }
  387. /* Handles conversation with sedridor */
  388. public void talkToSedridor() {
  389. RSNPC mySed = npcs.getNearest(SEDRIDOR);
  390.  
  391. // When research package is received, go to varrock
  392. if (inventory.contains(RESEARCH_NOTES)) {
  393. currentState = state.TO_VARROCK;
  394. } else if (inventory.contains(END_AIR_TALISMAN)) {
  395. currentState = state.FINISH_QUEST;
  396. mouse.click(443, 75, 10, 10, true);
  397. } else if (interfaces.get(241).isValid()) {
  398. interfaces.getComponent(241, 5).doClick();
  399. } else if (interfaces.get(242).isValid()) {
  400. interfaces.getComponent(242, 6).doClick();
  401. } else if (interfaces.get(243).isValid()) {
  402. interfaces.getComponent(243, 7).doClick();
  403. } else if (interfaces.get(244).isValid()) {
  404. interfaces.getComponent(244, 8).doClick();
  405. } else if (interfaces.get(230).isValid()) {
  406. interfaces.getComponent(230, 4).doClick();
  407. } else if (interfaces.get(64).isValid()) {
  408. interfaces.getComponent(64, 5).doClick();
  409. } else if (interfaces.get(65).isValid()) {
  410. interfaces.getComponent(65, 6).doClick();
  411. } else if (interfaces.get(66).isValid()) {
  412. interfaces.getComponent(66, 7).doClick();
  413. } else if (interfaces.get(519).isValid()) {
  414. interfaces.getComponent(519, 2).doClick();
  415. } else if (interfaces.get(228).isValid()) {
  416. interfaces.getComponent(228, 2).doClick();
  417. } else {
  418. // If sedridor is on screen, talk to him, otherwise set the state as walk to tower
  419. if (mySed.isOnScreen()) {
  420. mySed.doAction("Talk");
  421. } else {
  422. currentState = state.TO_TOWER;
  423. }
  424. }
  425. }
  426.  
  427. /* Handles conversation with aubrey */
  428. public void talkToAubrey() {
  429. RSNPC myAubrey = npcs.getNearest(AUBREY);
  430. RSTile currentTile = getMyPlayer().getLocation();
  431.  
  432. if (getMyPlayer().isIdle()) {
  433. if (inventory.contains(FURTHER_NOTES) && !SHOP_AREA.contains(currentTile)) {
  434. currentState = state.TO_TOWER;
  435. } else if (interfaces.get(241).isValid()) {
  436. interfaces.getComponent(241, 5).doClick();
  437. } else if (interfaces.get(242).isValid()) {
  438. interfaces.getComponent(242, 6).doClick();
  439. } else if (interfaces.get(243).isValid()) {
  440. interfaces.getComponent(243, 7).doClick();
  441. } else if (interfaces.get(244).isValid()) {
  442. interfaces.getComponent(244, 8).doClick();
  443. } else if (interfaces.get(230).isValid()) {
  444. interfaces.getComponent(230, 4).doClick();
  445. } else if (interfaces.get(64).isValid()) {
  446. interfaces.getComponent(64, 5).doClick();
  447. } else if (interfaces.get(65).isValid()) {
  448. interfaces.getComponent(65, 6).doClick();
  449. } else if (interfaces.get(228).isValid()) {
  450. interfaces.getComponent(228, 2).doClick();
  451. } else if (interfaces.get(210).isValid()) {
  452. interfaces.getComponent(210, 2).doClick();
  453. } else if (inventory.contains(FURTHER_NOTES)) {
  454. currentState = state.TO_TOWER;
  455. } else {
  456. // If aubrey is on screen, talk to him, otherwise set the state as walk to varrock
  457. if (myAubrey.isOnScreen()) {
  458. myAubrey.doAction("Talk");
  459. } else {
  460. currentState = state.TO_VARROCK;
  461. }
  462. }
  463. }
  464. }
  465.  
  466. public void getState() {
  467. if (DUKE_ROOM.contains(getMyPlayer().getLocation()) && !inventory.contains(AIR_TALISMAN)) {
  468. currentState = state.GET_QUEST;
  469. } else if (inventory.contains(AIR_TALISMAN)) {
  470. if (!SEDRIDORS_ROOM.contains(getMyPlayer().getLocation()))
  471. currentState = state.TO_TOWER;
  472. else
  473. currentState = state.GET_NOTES;
  474. } else if (inventory.contains(RESEARCH_NOTES)) {
  475. if (!SHOP_AREA.contains(getMyPlayer().getLocation()))
  476. currentState = state.TO_VARROCK;
  477. else
  478. currentState = state.GET_NEW_NOTES;
  479. } else if (inventory.contains(FURTHER_NOTES))
  480. currentState = state.TO_TOWER;
  481. }
  482.  
  483. /* Main body of the script, called continuously till value < 0 is returned */
  484. @Override
  485. public int loop() {
  486.  
  487. // If the player is moving, wait.
  488. if (!getMyPlayer().isIdle())
  489. return random(500, 1500);
  490.  
  491. switch (currentState) {
  492. case TO_LUMBRIDGE:
  493. st = "Walking to the Duke's room.";
  494. walkToDuke();
  495. break;
  496. case GET_QUEST:
  497. st = "Getting quest from the Duke.";
  498. talkToDuke();
  499. break;
  500. case TO_TOWER:
  501. st = "Walking to the Wizard Tower.";
  502. walkToSedridor();
  503. break;
  504. case GET_NOTES:
  505. if (inventory.contains(FURTHER_NOTES))
  506. st = "Giving notes to Sedridor";
  507. else
  508. st = "Getting notes from Sedridor.";
  509. talkToSedridor();
  510. break;
  511. case TO_VARROCK:
  512. if (!inventory.contains(END_AIR_TALISMAN))
  513. st = "Walking to Aubrey.";
  514. walkToAubrey();
  515. break;
  516. case GET_NEW_NOTES:
  517. st = "Getting notes from Aubrey.";
  518. talkToAubrey();
  519. break;
  520. case FINISH_QUEST:
  521. st = "Finished quest.";
  522. if (endInVarrock)
  523. currentState = state.TO_VARROCK;
  524. else
  525. currentState = state.NEXT_ACCOUNT;
  526. break;
  527. case NEXT_ACCOUNT:
  528. nextACC();
  529. break;
  530. case LOGGING_IN:
  531. login(userNames()[questsDone],passwords()[questsDone]);
  532. break;
  533. case END:
  534. return -1;
  535. default:
  536. return -1;
  537. }
  538.  
  539. // Turn on run and open inventory if needed
  540. if ((walking.getEnergy() > 30) && (currentState != state.GET_NOTES) && (currentState != state.GET_NEW_NOTES))
  541. walking.setRun(true);
  542. game.openTab(4);
  543.  
  544. return random(500, 1500);
  545. }
  546.  
  547. /* Handles painting of the progress report */
  548. public void onRepaint(Graphics g) {
  549. Graphics2D g2d = (Graphics2D)g;
  550. Color colour1 = new Color(255, 255, 255);
  551. Font font1 = new Font("Monospaced", 0, 12);
  552.  
  553. int y = 310;
  554. int x = 95;
  555.  
  556. millis = System.currentTimeMillis() - startTime;
  557. hours = millis / (1000 * 60 * 60);
  558. millis -= hours * (1000 * 60 * 60);
  559. minutes = millis / (1000 * 60);
  560. millis -= minutes * (1000 * 60);
  561. seconds = millis / 1000;
  562.  
  563. g2d.setColor(new Color(69, 139, 0, 125));
  564. g2d.fillRect(x, y, 330, 28);
  565. g2d.setColor(new Color(69, 139, 0, 100));
  566. g2d.fillRect(x, y + 14, 330, 14);
  567. g2d.setColor(new Color(20, 20, 20, 200));
  568. g2d.drawRect(x, y, 330, 28);
  569.  
  570. g2d.setColor(colour1);
  571. g2d.setFont(font1);
  572. g2d.drawString("Time elapsed: " + hours + " hours, " + minutes + " minutes, " + seconds + " seconds.", 105, 322);
  573. g2d.drawString("Current state: " + st, 105, 335);
  574. }
  575.  
  576. /* Any code to run as script terminates */
  577. @Override
  578. public void onFinish() {
  579.  
  580. }
  581.  
  582. public static final int INTERFACE_LOGIN_SCREEN = 596;
  583. public static final int INTERFACE_LOGIN_SCREEN_ENTER_GAME = 60;
  584. public static final int INTERFACE_LOGIN_SCREEN_USERNAME_TEXT = 73;
  585. public static final int INTERFACE_LOGIN_SCREEN_PASSWORD_TEXT = 79;
  586. public static final int INTERFACE_LOGIN_SCREEN_ALERT_TEXT = 14;
  587. public static final int INTERFACE_LOGIN_SCREEN_ALERT_BACK = 68;
  588. public static final int INTERFACE_GRAPHICS_NOTICE = 976;
  589. public static final int INTERFACE_GRAPHICS_LEAVE_ALONE = 6;
  590. public static final int INTERFACE_LOBBY_HIGH_RISK_WORLD_TEXT = 98;
  591. public static final int INTERFACE_LOBBY_HIGH_RISK_WORLD_LOGIN_BUTTON = 104;
  592. private boolean isUsernameCorrect = false;
  593. private boolean isPasswordValid = false;
  594.  
  595. public int login(String u, String p) {
  596. if (lobby.inLobby()) {
  597. if (lobby.getSelectedTab() != Lobby.TAB_PLAYERS) {
  598. lobby.open(Lobby.TAB_PLAYERS);
  599. return random(500, 800);
  600. }
  601. if (lobby.clickPlay()) {
  602. for (int i = 0; i < 4 && game.getClientState() == 6; i++) {
  603. sleep(500);
  604. }
  605. final String returnText = interfaces.getComponent(Lobby.INTERFACE_LOBBY, Lobby.INTERFACE_LOBBY_ALERT_TEXT).getText().toLowerCase().trim();
  606. if (interfaces.getComponent(Lobby.INTERFACE_LOBBY, Lobby.INTERFACE_LOBBY_ALERT_CLOSE).isValid()) {
  607. interfaces.getComponent(Lobby.INTERFACE_LOBBY, Lobby.INTERFACE_LOBBY_ALERT_CLOSE).doClick();
  608. }
  609. for (solution subSolution : lobbySolutions) {
  610. if (subSolution.canApply(returnText)) {
  611. return subSolution.apply();
  612. }
  613. }
  614. }
  615. }
  616. if (game.getClientState() == Game.INDEX_LOGIN_SCREEN) {
  617. if (interfaces.getComponent(INTERFACE_GRAPHICS_NOTICE, INTERFACE_GRAPHICS_LEAVE_ALONE).isValid()) {
  618. interfaces.getComponent(INTERFACE_GRAPHICS_NOTICE, INTERFACE_GRAPHICS_LEAVE_ALONE).doClick();
  619. return random(500, 600);
  620. }
  621. final String returnText = interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_ALERT_TEXT).getText().toLowerCase().trim();
  622. if (interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_ALERT_BACK).isValid()) {
  623. interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_ALERT_BACK).doClick();
  624. }
  625. for (solution subSolution : loginSolutions) {
  626. if (subSolution.canApply(returnText)) {
  627. return subSolution.apply();
  628. }
  629. }
  630. if (isUsernameCorrect() && isPasswordValid()) {
  631. attemptLogin();
  632. return random(1200, 1500);
  633. }
  634. if (!isUsernameCorrect()) {
  635. atLoginInterface(interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_USERNAME_TEXT));
  636. sleep(random(500, 700));
  637. final int textLength = interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_USERNAME_TEXT).getText().length();
  638. if (textLength > 0) {
  639. for (int i = 0; i <= textLength + random(1, 5); i++) {
  640. keyboard.sendText("\b", false);
  641. if (random(0, 2) == 1) {
  642. sleep(random(25, 100));
  643. }
  644. }
  645. return random(500, 600);
  646. }
  647. keyboard.sendText(u, false);
  648. return random(500, 600);
  649. }
  650. if (isUsernameCorrect() && !isPasswordValid()) {
  651. atLoginInterface(interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_PASSWORD_TEXT));
  652. sleep(random(500, 700));
  653. final int textLength = interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_PASSWORD_TEXT).getText().length();
  654. if (textLength > 0) {
  655. for (int i = 0; i <= textLength + random(1, 5); i++) {
  656. keyboard.sendText("\b", false);
  657. if (random(0, 2) == 1) {
  658. sleep(random(25, 100));
  659. }
  660. }
  661. return random(500, 600);
  662. }
  663. keyboard.sendText(p, false);
  664. return random(500, 600);
  665. }
  666. }
  667. if(game.isLoggedIn){
  668. currentState = state.TO_LUMBRIDGE;
  669. }
  670. return -1;
  671. }
  672. private boolean switchingWorlds() {
  673. return interfaces.getComponent(Lobby.INTERFACE_LOBBY, Lobby.INTERFACE_LOBBY_ALERT_TEXT).isValid() &&
  674. interfaces.getComponent(Lobby.INTERFACE_LOBBY, Lobby.INTERFACE_LOBBY_ALERT_TEXT).containsText("just left another world");
  675. }
  676.  
  677. private boolean atLoginInterface(final RSComponent i) {
  678. if (!i.isValid()) {
  679. return false;
  680. }
  681. final Rectangle pos = i.getArea();
  682. if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1) {
  683. return false;
  684. }
  685. final int dy = (int) (pos.getHeight() - 4) / 2;
  686. final int maxRandomX = (int) (pos.getMaxX() - pos.getCenterX());
  687. final int midx = (int) pos.getCenterX();
  688. final int midy = (int) (pos.getMinY() + pos.getHeight() / 2);
  689. if (i.getIndex() == INTERFACE_LOGIN_SCREEN_PASSWORD_TEXT) {
  690. mouse.click(minX(i), midy + random(-dy, dy), true);
  691. } else {
  692. mouse.click(midx + random(1, maxRandomX), midy + random(-dy, dy), true);
  693. }
  694. return true;
  695. }
  696.  
  697. private int minX(final RSComponent a) {
  698. int x = 0;
  699. final Rectangle pos = a.getArea();
  700. final int dx = (int) (pos.getWidth() - 4) / 2;
  701. final int midx = (int) (pos.getMinX() + pos.getWidth() / 2);
  702. if (pos.x == -1 || pos.y == -1 || pos.width == -1 || pos.height == -1) {
  703. return 0;
  704. }
  705. for (int i = 0; i < interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_PASSWORD_TEXT).getText().length(); i++) {
  706. x += 11;
  707. }
  708. if (x > 44) {
  709. return (int) (pos.getMinX() + x + 15);
  710. } else {
  711. return midx + random(-dx, dx);
  712. }
  713. }
  714.  
  715. private void attemptLogin() {
  716. if (random(0, 2) == 0) {
  717. keyboard.sendKey('\n');
  718. } else {
  719. interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_ENTER_GAME).doClick();
  720. }
  721. }
  722.  
  723. private boolean isUsernameCorrect() {
  724. final String userName = userNames()[questsDone];
  725. return interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_USERNAME_TEXT).getText().toLowerCase().equalsIgnoreCase(userName);
  726. }
  727.  
  728. private boolean isPasswordValid() {
  729. String passWord = passwords()[questsDone];
  730. if (passWord.isEmpty()) {
  731. passWord = passwords()[questsDone];
  732. }
  733. return interfaces.getComponent(INTERFACE_LOGIN_SCREEN, INTERFACE_LOGIN_SCREEN_PASSWORD_TEXT).getText().length() == (passWord == null ? 0 : passWord.length());
  734. }
  735. } // end of script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement