Advertisement
Guest User

WorldSwitcher

a guest
Oct 4th, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. package scripts.Liam;
  2.  
  3. import java.awt.Rectangle;
  4.  
  5. import org.tribot.api.General;
  6. import org.tribot.api.Timing;
  7. import org.tribot.api.input.Mouse;
  8. import org.tribot.api.types.generic.Condition;
  9. import org.tribot.api2007.Game;
  10. import org.tribot.api2007.GameTab.TABS;
  11. import org.tribot.api2007.Interfaces;
  12. import org.tribot.api2007.NPCChat;
  13. import org.tribot.api2007.types.RSInterfaceChild;
  14. import org.tribot.api2007.types.RSInterfaceComponent;
  15.  
  16. public class WorldSwitcher {
  17.  
  18. public static Condition switchedWorld(final int world) {
  19. return new Condition() {
  20. public boolean active() {
  21. return Game.getCurrentWorld() == world;
  22. }
  23. };
  24. }
  25.  
  26. public static RSInterfaceComponent getWorldComponent(int world) {
  27. RSInterfaceChild worldList = Interfaces.get(69, 7);
  28.  
  29. if (worldList != null) {
  30. for (RSInterfaceComponent i : worldList.getChildren()) {
  31. if (i.getText().equals(String.valueOf(world))) {
  32. return worldList.getChildren()[i.getIndex() - 2];
  33. }
  34. }
  35. }
  36. return null;
  37. }
  38.  
  39. public static void scrollToWorld(int world) {
  40. RSInterfaceComponent worldComponent = getWorldComponent(world);
  41. Rectangle rect = new Rectangle(547, 234, 190, 190);
  42.  
  43. if (worldComponent != null) {
  44. if (rect.contains(Mouse.getPos())) {
  45. while (!rect.contains(worldComponent.getAbsolutePosition())) {
  46. General.println(worldComponent.getAbsoluteBounds().y);
  47. Mouse.scroll(worldComponent.getAbsoluteBounds().y < rect.y);
  48. General.sleep(50, 100);
  49. }
  50. } else {
  51. Mouse.moveBox(rect);
  52. }
  53. }
  54. }
  55.  
  56. public static void switchWorld(int world) {
  57. RSInterfaceChild worldList = Interfaces.get(69, 7);
  58. RSInterfaceChild btnWorldSwitcher = Interfaces.get(182, 1);
  59. Rectangle rect = new Rectangle(547, 234, 190, 190);
  60.  
  61. if (TABS.LOGOUT.isOpen()) {
  62. if (worldList != null) {
  63. RSInterfaceComponent worldComponent = getWorldComponent(world);
  64.  
  65. if (NPCChat.getOptions() != null) {
  66. if (NPCChat.getOptions()[0] != null && NPCChat.getOptions()[0].contains("Yes")) {
  67. if (NPCChat.selectOption("Yes", true)) {
  68. Timing.waitCondition(switchedWorld(world), General.random(3000, 6000));
  69. }
  70. } else if (NPCChat.getOptions()[1] != null && NPCChat.getOptions()[1].contains("Switch")) {
  71. if (NPCChat.selectOption(NPCChat.getOptions()[1], true)) {
  72. Timing.waitCondition(switchedWorld(world), General.random(3000, 6000));
  73. }
  74. }
  75. }
  76.  
  77. General.println(worldComponent.getIndex());
  78.  
  79. if (worldComponent != null) {
  80. if (rect.contains(worldComponent.getAbsolutePosition())) {
  81. worldComponent.click("Switch");
  82. } else {
  83. scrollToWorld(world);
  84. }
  85. }
  86. } else {
  87. if (btnWorldSwitcher != null) {
  88. btnWorldSwitcher.click("World Switcher");
  89. }
  90. }
  91. } else {
  92. TABS.LOGOUT.open();
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement