Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.35 KB | None | 0 0
  1. import java.awt.*;
  2.  
  3. import org.rsbot.script.Script;
  4. import org.rsbot.script.ScriptManifest;
  5. import org.rsbot.script.wrappers.*;
  6. import org.rsbot.script.methods.*;
  7. import org.rsbot.event.listeners.PaintListener;
  8.  
  9. @ScriptManifest(authors = {"rewsky"}, keywords = {""}, name = "runeMysteries", description = "Completes the Rune Mysteries quest.", version = 1.21)
  10. public class runeMysteries extends Script implements PaintListener {
  11. private static final boolean endInVarrock = true; // Set to TRUE to walk to varrock after quest
  12. // FALSE to stay at wizard tower
  13.  
  14.  
  15. /* ID's of all the NPCs in the quest */
  16. private static final int DUKE = 741;
  17. private static final int SEDRIDOR = 300;
  18. private static final int AUBREY = 553;
  19.  
  20. /* ID's of all the items recieved during the quest */
  21. private static final int AIR_TALISMAN = 15361;
  22. private static final int END_AIR_TALISMAN = 1438;
  23. private static final int RESEARCH_NOTES = 290;
  24. private static final int FURTHER_NOTES = 291;
  25.  
  26. /* ID's of objects that may need to be interacted with during quest */
  27. private static final int CLOSED_DOOR = 36844;
  28. private static final int OPEN_DOOR = 36845;
  29. private static final int LUMB_STAIRS_DOWN = 36774;
  30. private static final int LUMB_STAIRS_UP = 36773;
  31. private static final int WT_OPEN_DOOR = 11994;
  32. private static final int WT_CLOSED_DOOR = 11993;
  33. private static final int WT_OPEN_BIG_DOOR = 31828;
  34. private static final int WT_CLOSED_BIG_DOOR = 33060;
  35. private static final int WT_LADDER_UP = 32015;
  36. private static final int WT_LADDER_DOWN = 2147;
  37. private static final int AUBREY_CLOSED_DOOR = 24381;
  38. private static final int AUBREY_OPEN_DOOR = 24379;
  39.  
  40. /* Areas key to detecting which stage of the quest we're on */
  41. private static final RSArea DUKE_ROOM = new RSArea(new RSTile(3208, 3218), new RSTile(3212, 3225));
  42. private static final RSArea LUMB_STAIRCASE_LOWER = new RSArea(new RSTile(3200, 3206), new RSTile(3212, 3214));
  43. private static final RSArea WIZARD_TOWER = new RSArea(new RSTile(3111, 3160), new RSTile(3103, 3166));
  44. private static final RSArea WIZARD_BASEMENT = new RSArea(new RSTile(3115, 9563), new RSTile(3095, 9577));
  45. private static final RSArea SEDRIDORS_ROOM = new RSArea(new RSTile(3108, 9575), new RSTile(3094, 9565));
  46. private static final RSArea SHOP_AREA = new RSArea(new RSTile(3250, 3404), new RSTile(3255, 3398));
  47.  
  48. private static final RSTile[] TOWER_PATH = {new RSTile(3205, 3209), new RSTile(3202, 3219),
  49. new RSTile(3190, 3216), new RSTile(3178, 3215), new RSTile(3168, 3212), new RSTile(3159, 3216),
  50. new RSTile(3147, 3217), new RSTile(3138, 3210), new RSTile(3127, 3210), new RSTile(3115, 3210),
  51. new RSTile(3112, 3202), new RSTile(3114, 3194), new RSTile(3113, 3186), new RSTile(3113, 3175),
  52. new RSTile(3109, 3163), new RSTile(3109, 3167), new RSTile(3109, 3163)};
  53. private static final RSTile[] VARROCK_PATH = {new RSTile(3104, 3161),
  54. new RSTile(3110, 3169), new RSTile(3113, 3181), new RSTile(3114, 3191), new RSTile(3113, 3202),
  55. new RSTile(3119, 3211), new RSTile(3127, 3219), new RSTile(3134, 3225), new RSTile(3145, 3231),
  56. new RSTile(3157, 3236), new RSTile(3167, 3238), new RSTile(3178, 3244), new RSTile(3189, 3244),
  57. new RSTile(3199, 3247), new RSTile(3212, 3247), new RSTile(3218, 3257), new RSTile(3229, 3262),
  58. new RSTile(3241, 3267), new RSTile(3238, 3278), new RSTile(3238, 3293), new RSTile(3238, 3306),
  59. new RSTile(3246, 3317), new RSTile(3254, 3325), new RSTile(3266, 3332), new RSTile(3278, 3339),
  60. new RSTile(3286, 3349), new RSTile(3296, 3357), new RSTile(3294, 3370), new RSTile(3293, 3380),
  61. new RSTile(3293, 3387), new RSTile(3290, 3399), new RSTile(3290, 3410), new RSTile(3285, 3420),
  62. new RSTile(3274, 3427), new RSTile(3266, 3416), new RSTile(3259, 3406), new RSTile(3253, 3401)};
  63.  
  64. private enum state {
  65. TO_LUMBRIDGE, GET_QUEST, TO_TOWER, GET_NOTES, TO_VARROCK, GET_NEW_NOTES, FINISH_QUEST, END, WAIT
  66. };
  67.  
  68. private state currentState = null;
  69. private String st = null;
  70.  
  71. /* Variables for time-keeping */
  72. private long startTime = 0;
  73. private long millis = 0;
  74. private long hours = 0;
  75. private long minutes = 0;
  76. private long seconds = 0;
  77. private long last = 0;
  78.  
  79. /* Method called when user chooses to run this script. Return True = continue, False = terminate */
  80. @Override
  81. public boolean onStart() {
  82. startTime = System.currentTimeMillis();
  83.  
  84. if (inventory.contains(END_AIR_TALISMAN))
  85. currentState = state.END;
  86.  
  87. getState();
  88.  
  89. if (currentState == null)
  90. currentState = state.TO_LUMBRIDGE;
  91. return true;
  92. }
  93.  
  94. /* Returns a value denoting what floor the character is on
  95. * 0 = Ground floor / dungeons
  96. * 1 = Middle floor
  97. * 2 = Top floor
  98. */
  99. public int getFloor() {
  100. return game.getPlane();
  101. }
  102.  
  103. /* Opens a closed door if needed */
  104. public boolean openDoor(int objectID, RSTile tile) {
  105. RSObject myDoor = null;
  106. RSObject[] onTile = null;
  107.  
  108. onTile = objects.getAllAt(tile);
  109. for (RSObject tempObject : onTile) {
  110. if (tempObject.getID() == objectID) {
  111. myDoor = tempObject;
  112. break;
  113. }
  114. }
  115.  
  116. if (myDoor != null)
  117. if (myDoor.isOnScreen()) {
  118. myDoor.doAction("Open");
  119. sleep(1500, 2000);
  120. return true;
  121. }
  122.  
  123. return false;
  124. }
  125.  
  126. /* If the interface where you accept the quest is open, it is returned, else null */
  127. public RSInterface questInterfaceOpen() {
  128. RSInterface[] allInterfaces = interfaces.getAll();
  129. RSComponent[] allComponents = null;
  130.  
  131. // Loop through all the interfaces on screen
  132. for (RSInterface myInterface : allInterfaces) {
  133. allComponents = myInterface.getComponents();
  134.  
  135. // Loop through all the components in the current interface
  136. for (RSComponent myComponent : allComponents) {
  137. if (myComponent.containsText("Rune Mysteries"))
  138. return myInterface;
  139. }
  140. }
  141. return null;
  142. }
  143.  
  144. /* Uses the free teleport to lumbridge */
  145. public void teleToLumb() {
  146. if (!getMyPlayer().isIdle()) {
  147. sleep(500, 1000);
  148. } else {
  149. magic.castSpell(magic.SPELL_HOME_TELEPORT);
  150. }
  151. }
  152.  
  153. /* Walks to the next tile in a given RSTile array (path) */
  154. public void walkNext(RSTile[] path, RSTile position, int randomX, int randomY) {
  155. int myX = position.getX();
  156. int myY = position.getY();
  157. RSTile nextTile = null;
  158. RSArea currentTileArea = new RSArea(new RSTile(myX - (randomX + 1), myY - (randomY + 1)),
  159. new RSTile(myX + (randomX + 1), myY + (randomY + 1)));
  160.  
  161. for (int i = 0; i < path.length; i++) {
  162. if (currentTileArea.contains(path[i])) {
  163. if (i < (path.length - 1))
  164. nextTile = path[i + 1];
  165. else
  166. nextTile = path[i];
  167. break;
  168. }
  169. }
  170.  
  171. if (nextTile != null) {
  172. walking.walkTileMM(nextTile, randomX, randomY);
  173. }
  174.  
  175. }
  176.  
  177. /* Walks from anywhere, to the duke of lumbridge's room */
  178. public void walkToDuke() {
  179. RSTile currentTile = getMyPlayer().getLocation();
  180. RSObject stairs = null;
  181.  
  182. if (currentTile.getX() < 3191 || currentTile.getX() > 3242 || currentTile.getY() > 3264 ||
  183. currentTile.getY () < 3199) {
  184. teleToLumb();
  185. } else {
  186. if (getFloor() == 0) {
  187. if (LUMB_STAIRCASE_LOWER.contains(currentTile)) {
  188. stairs = objects.getNearest(LUMB_STAIRS_UP);
  189. if (stairs != null)
  190. stairs.doAction("Climb-up");
  191. } else {
  192. walking.walkTo(new RSTile(3206, 3209));
  193. }
  194. } else if (getFloor() == 1) {
  195. if (!DUKE_ROOM.contains(currentTile)) {
  196. openDoor(CLOSED_DOOR, new RSTile(3207, 3222));
  197. walking.walkTileMM(new RSTile(3210, 3221));
  198. } else {
  199. currentState = state.GET_QUEST;
  200. }
  201. } else if (getFloor() == 2) {
  202. stairs = objects.getNearest(36775);
  203. if (stairs != null)
  204. stairs.doAction("Climb-down");
  205. } else {
  206. log("Bot lost, script stopping.");
  207. stopScript();
  208. }
  209. }
  210. }
  211.  
  212. /* Walks from anywhere, to the basement of the wizards tower */
  213. public void walkToSedridor() {
  214. RSTile currentTile = getMyPlayer().getLocation();
  215. RSObject wizLadder = null;
  216. RSObject lumbStairs = null;
  217.  
  218. if (!openDoor(WT_CLOSED_DOOR, new RSTile(3109, 3167))) {
  219. if (!openDoor(WT_CLOSED_DOOR, new RSTile(3107, 3162))) {
  220. if ((getFloor() == 1) && (DUKE_ROOM.contains(currentTile))) {
  221. openDoor(CLOSED_DOOR, new RSTile(3207, 3222));
  222. walking.walkTileMM(new RSTile(3206, 3209));
  223. } else if (getFloor() == 1) {
  224. lumbStairs = objects.getNearest(LUMB_STAIRS_DOWN);
  225. if (lumbStairs != null)
  226. lumbStairs.doAction("Climb-down");
  227.  
  228. // If in sedridors room, we've arrived!
  229. } else if (SEDRIDORS_ROOM.contains(currentTile)) {
  230. currentState = state.GET_NOTES;
  231.  
  232. // If in the basement of the tower, get into sedridors room
  233. } else if (WIZARD_BASEMENT.contains(currentTile)) {
  234. if (!openDoor(WT_CLOSED_BIG_DOOR, new RSTile(3108, 9570))) {
  235. walking.walkTileMM(new RSTile(3105, 9569));
  236. }
  237.  
  238. // Walk to the wizards tower
  239. } else if ((getFloor() == 0) && !WIZARD_TOWER.contains(currentTile)) {
  240. walkNext(TOWER_PATH, currentTile, 2, 2);
  241.  
  242. // Climb down to basement of the tower
  243. } else {
  244. wizLadder = objects.getNearest(WT_LADDER_DOWN);
  245. if (wizLadder != null)
  246. wizLadder.doAction("Climb-down");
  247. }
  248. }
  249. }
  250. }
  251.  
  252. /* Walks from anywhere, to the magic shop in varrock */
  253. public void walkToAubrey() {
  254. RSTile currentTile = getMyPlayer().getLocation();
  255. RSObject wizLadder = null;
  256.  
  257. // Exit the wizards tower basement
  258. if (WIZARD_BASEMENT.contains(currentTile)) {
  259. if (SEDRIDORS_ROOM.contains(currentTile)) {
  260. if (!openDoor(WT_CLOSED_BIG_DOOR, new RSTile(3108, 9570)))
  261. walking.walkTileMM(new RSTile(3109, 9574));
  262.  
  263. } else {
  264. wizLadder = objects.getNearest(WT_LADDER_UP);
  265. if ((wizLadder != null) && (wizLadder.isOnScreen())) {
  266. wizLadder.doAction("Climb-up");
  267. } else {
  268. walking.walkTileMM(new RSTile(3109, 9574));
  269. }
  270. }
  271. } else if (!openDoor(WT_CLOSED_DOOR, new RSTile(3107, 3162))) {
  272. if (!openDoor(WT_CLOSED_DOOR, new RSTile(3109, 3167))) {
  273. if (!openDoor(AUBREY_CLOSED_DOOR, new RSTile(3253, 3398))) {
  274.  
  275. if (interfaces.get(212).isValid()) {
  276. interfaces.getComponent(212, 4).doClick();
  277. } else if (interfaces.get(236).isValid()) {
  278. interfaces.getComponent(236, 1).doClick();
  279. } else if (SHOP_AREA.contains(currentTile)) {
  280. if (inventory.contains(END_AIR_TALISMAN)) {
  281. log("Script finished.");
  282. stopScript();
  283. } else {
  284. currentState = state.GET_NEW_NOTES;
  285. }
  286. } else {
  287. walkNext(VARROCK_PATH, currentTile, 3, 3);
  288. }
  289. }
  290. }
  291. }
  292. }
  293.  
  294. /* Handles conversation with the duke */
  295. public void talkToDuke() {
  296. RSNPC myDuke = npcs.getNearest(DUKE);
  297.  
  298. // If player is not in the dukes room, set state to walk to lumbridge
  299. if (!DUKE_ROOM.contains(getMyPlayer().getLocation())) {
  300. currentState = state.TO_LUMBRIDGE;
  301. } else {
  302. // If quest acceptance interface is open, click yes, otherwise converse with duke
  303. if (questInterfaceOpen() == null) {
  304.  
  305. // If chat interface is open, continue talking, otherwise initiate conversation
  306. if (interfaces.get(241).isValid()) {
  307. interfaces.getComponent(241, 5).doClick();
  308. } else if (interfaces.get(228).isValid()) {
  309. interfaces.getComponent(228, 2).doClick();
  310. } else if (interfaces.get(64).isValid()) {
  311. interfaces.getComponent(64, 5).doClick();
  312. } else if (interfaces.get(242).isValid()) {
  313. interfaces.getComponent(242, 6).doClick();
  314. } else {
  315.  
  316. // If the duke is on screen, talk to him, otherwise set the state as walk to lumbridge
  317. if (myDuke.isOnScreen()) {
  318. myDuke.doAction("Talk");
  319. }
  320. }
  321. } else {
  322. mouse.click(170, 305, 30, 10, true);
  323. sleep(1000, 500);
  324. currentState = state.TO_TOWER;
  325. }
  326. }
  327. }
  328.  
  329. /* Handles conversation with sedridor */
  330. public void talkToSedridor() {
  331. RSNPC mySed = npcs.getNearest(SEDRIDOR);
  332.  
  333. // When research package is received, go to varrock
  334. if (inventory.contains(RESEARCH_NOTES)) {
  335. currentState = state.TO_VARROCK;
  336. } else if (inventory.contains(END_AIR_TALISMAN)) {
  337. currentState = state.FINISH_QUEST;
  338. mouse.click(443, 75, 10, 10, true);
  339. } else if (interfaces.get(241).isValid()) {
  340. interfaces.getComponent(241, 5).doClick();
  341. } else if (interfaces.get(242).isValid()) {
  342. interfaces.getComponent(242, 6).doClick();
  343. } else if (interfaces.get(243).isValid()) {
  344. interfaces.getComponent(243, 7).doClick();
  345. } else if (interfaces.get(244).isValid()) {
  346. interfaces.getComponent(244, 8).doClick();
  347. } else if (interfaces.get(230).isValid()) {
  348. interfaces.getComponent(230, 4).doClick();
  349. } else if (interfaces.get(64).isValid()) {
  350. interfaces.getComponent(64, 5).doClick();
  351. } else if (interfaces.get(65).isValid()) {
  352. interfaces.getComponent(65, 6).doClick();
  353. } else if (interfaces.get(66).isValid()) {
  354. interfaces.getComponent(66, 7).doClick();
  355. } else if (interfaces.get(519).isValid()) {
  356. interfaces.getComponent(519, 2).doClick();
  357. } else if (interfaces.get(228).isValid()) {
  358. interfaces.getComponent(228, 2).doClick();
  359. } else {
  360. // If sedridor is on screen, talk to him, otherwise set the state as walk to tower
  361. if (mySed.isOnScreen()) {
  362. mySed.doAction("Talk");
  363. } else {
  364. currentState = state.TO_TOWER;
  365. }
  366. }
  367. }
  368.  
  369. /* Handles conversation with aubrey */
  370. public void talkToAubrey() {
  371. RSNPC myAubrey = npcs.getNearest(AUBREY);
  372. RSTile currentTile = getMyPlayer().getLocation();
  373.  
  374. if (getMyPlayer().isIdle()) {
  375. if (inventory.contains(FURTHER_NOTES) && !SHOP_AREA.contains(currentTile)) {
  376. currentState = state.TO_TOWER;
  377. } else if (interfaces.get(241).isValid()) {
  378. interfaces.getComponent(241, 5).doClick();
  379. } else if (interfaces.get(242).isValid()) {
  380. interfaces.getComponent(242, 6).doClick();
  381. } else if (interfaces.get(243).isValid()) {
  382. interfaces.getComponent(243, 7).doClick();
  383. } else if (interfaces.get(244).isValid()) {
  384. interfaces.getComponent(244, 8).doClick();
  385. } else if (interfaces.get(230).isValid()) {
  386. interfaces.getComponent(230, 4).doClick();
  387. } else if (interfaces.get(64).isValid()) {
  388. interfaces.getComponent(64, 5).doClick();
  389. } else if (interfaces.get(65).isValid()) {
  390. interfaces.getComponent(65, 6).doClick();
  391. } else if (interfaces.get(228).isValid()) {
  392. interfaces.getComponent(228, 2).doClick();
  393. } else if (interfaces.get(210).isValid()) {
  394. interfaces.getComponent(210, 2).doClick();
  395. } else if (inventory.contains(FURTHER_NOTES)) {
  396. currentState = state.TO_TOWER;
  397. } else {
  398. // If aubrey is on screen, talk to him, otherwise set the state as walk to varrock
  399. if (myAubrey.isOnScreen()) {
  400. myAubrey.doAction("Talk");
  401. } else {
  402. currentState = state.TO_VARROCK;
  403. }
  404. }
  405. }
  406. }
  407.  
  408. public void getState() {
  409. if (DUKE_ROOM.contains(getMyPlayer().getLocation()) && !inventory.contains(AIR_TALISMAN)) {
  410. currentState = state.GET_QUEST;
  411. } else if (inventory.contains(AIR_TALISMAN)) {
  412. if (!SEDRIDORS_ROOM.contains(getMyPlayer().getLocation()))
  413. currentState = state.TO_TOWER;
  414. else
  415. currentState = state.GET_NOTES;
  416. } else if (inventory.contains(RESEARCH_NOTES)) {
  417. if (!SHOP_AREA.contains(getMyPlayer().getLocation()))
  418. currentState = state.TO_VARROCK;
  419. else
  420. currentState = state.GET_NEW_NOTES;
  421. } else if (inventory.contains(FURTHER_NOTES))
  422. currentState = state.TO_TOWER;
  423. }
  424.  
  425. /* Main body of the script, called continuously till value < 0 is returned */
  426. @Override
  427. public int loop() {
  428.  
  429. // If the player is moving, wait.
  430. if (!getMyPlayer().isIdle())
  431. return random(500, 1500);
  432.  
  433. switch (currentState) {
  434. case TO_LUMBRIDGE:
  435. st = "Walking to the Duke's room.";
  436. walkToDuke();
  437. break;
  438. case GET_QUEST:
  439. st = "Getting quest from the Duke.";
  440. talkToDuke();
  441. break;
  442. case TO_TOWER:
  443. st = "Walking to the Wizard Tower.";
  444. walkToSedridor();
  445. break;
  446. case GET_NOTES:
  447. if (inventory.contains(FURTHER_NOTES))
  448. st = "Giving notes to Sedridor";
  449. else
  450. st = "Getting notes from Sedridor.";
  451. talkToSedridor();
  452. break;
  453. case TO_VARROCK:
  454. if (!inventory.contains(END_AIR_TALISMAN))
  455. st = "Walking to Aubrey.";
  456. walkToAubrey();
  457. break;
  458. case GET_NEW_NOTES:
  459. st = "Getting notes from Aubrey.";
  460. talkToAubrey();
  461. break;
  462. case FINISH_QUEST:
  463. st = "Finished quest.";
  464. if (endInVarrock)
  465. currentState = state.TO_VARROCK;
  466. else
  467. currentState = state.END;
  468. break;
  469. case END:
  470. return -1;
  471. default:
  472. return -1;
  473. }
  474.  
  475. // Turn on run and open inventory if needed
  476. if ((walking.getEnergy() > 30) && (currentState != state.GET_NOTES) && (currentState != state.GET_NEW_NOTES))
  477. walking.setRun(true);
  478. game.openTab(4);
  479.  
  480. return random(500, 1500);
  481. }
  482.  
  483. /* Handles painting of the progress report */
  484. public void onRepaint(Graphics g) {
  485. Graphics2D g2d = (Graphics2D)g;
  486. Color colour1 = new Color(255, 255, 255);
  487. Font font1 = new Font("Monospaced", 0, 12);
  488.  
  489. int y = 310;
  490. int x = 95;
  491.  
  492. millis = System.currentTimeMillis() - startTime;
  493. hours = millis / (1000 * 60 * 60);
  494. millis -= hours * (1000 * 60 * 60);
  495. minutes = millis / (1000 * 60);
  496. millis -= minutes * (1000 * 60);
  497. seconds = millis / 1000;
  498.  
  499. g2d.setColor(new Color(69, 139, 0, 125));
  500. g2d.fillRect(x, y, 330, 28);
  501. g2d.setColor(new Color(69, 139, 0, 100));
  502. g2d.fillRect(x, y + 14, 330, 14);
  503. g2d.setColor(new Color(20, 20, 20, 200));
  504. g2d.drawRect(x, y, 330, 28);
  505.  
  506. g2d.setColor(colour1);
  507. g2d.setFont(font1);
  508. g2d.drawString("Time elapsed: " + hours + " hours, " + minutes + " minutes, " + seconds + " seconds.", 105, 322);
  509. g2d.drawString("Current state: " + st, 105, 335);
  510. }
  511.  
  512. /* Any code to run as script terminates */
  513. @Override
  514. public void onFinish() {
  515.  
  516. }
  517.  
  518. } // end of script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement