Guest User

Untitled

a guest
Jan 23rd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. private boolean interact(Model model, String action) {
  2. for (int i = 0; i < 20; i++) {
  3. if (model == null) {
  4. return false;
  5. }
  6. if (!Calculations.isPointOnScreen(model.getNextPoint())) {
  7. return false;
  8. }
  9. Point p = getRandomPoint(model);
  10. if (p == null) {
  11. p = model.getNextPoint();
  12. }
  13. Point m = p;
  14. int speed = Mouse.getSpeed();
  15. Mouse.setSpeed(Random.nextInt(1, 4));
  16. int xdir = Mouse.getLocation().x - m.x;
  17. int ydir = Mouse.getLocation().y - m.y;
  18. if (xdir > 0) {
  19. m = new Point(m.x + Random.nextInt(-10, 25), m.y);
  20. } else if (xdir < 0) {
  21. m = new Point(m.x - Random.nextInt(-10, 25), m.y);
  22. }
  23. if (ydir > 0) {
  24. m = new Point(m.x, m.y + Random.nextInt(-10, 25));
  25. } else if (ydir < 0) {
  26. m = new Point(m.x, m.y - Random.nextInt(-10, 25));
  27. }
  28. if (Random.nextInt(0, 3) == 1) {
  29. Mouse.move(m);
  30. }
  31. sleep(150, 300);
  32. Mouse.setSpeed(speed);
  33. Mouse.move(p);
  34. String[] items = Menu.getItems();
  35. if (items.length > 0
  36. && items[0].toLowerCase().startsWith(action.toLowerCase())) {
  37. Mouse.click(true);
  38. return true;
  39. } else {
  40. String[] MenuItems = Menu.getItems();
  41. for (String item : MenuItems) {
  42. if (item.toLowerCase().contains(action.toLowerCase())) {
  43. Mouse.click(false);
  44. return interact(action, false);
  45. }
  46. }
  47. }
  48. }
  49. return false;
  50. }
  51.  
  52. private Point getRandomPoint(Model model) {
  53. Polygon[] triangles = model.getTriangles();
  54. if (triangles.length == 0) {
  55. return null;
  56. }
  57. Polygon p = triangles[Random.nextInt(0, triangles.length)];
  58. double a = Math.random();
  59. double b = Math.random();
  60. if (a + b >= 1) {
  61. a = 1 - a;
  62. b = 1 - b;
  63. }
  64. double c = 1 - a - b;
  65. return new Point((int) (a * p.xpoints[0] + b * p.xpoints[1] + c
  66. * p.xpoints[2]), (int) (a * p.ypoints[0] + b * p.ypoints[1] + c
  67. * p.ypoints[2]));
  68. }
  69.  
  70. private boolean interact(String action, boolean mouseKeys) {
  71. action = action.toLowerCase();
  72. int idx = Menu.getIndex(action);
  73. if (!Menu.isOpen()) {
  74. if (idx == -1) {
  75. return false;
  76. }
  77. if (idx == 0) {
  78. Mouse.click(true);
  79. return true;
  80. }
  81. Mouse.click(false);
  82. return clickIndex(idx, mouseKeys);
  83. } else if (idx == -1) {
  84. while (Menu.isOpen()) {
  85. Mouse.moveRandomly(750);
  86. sleep(Random.nextInt(100, 500));
  87. }
  88. return false;
  89. }
  90. return clickIndex(idx, mouseKeys);
  91. }
  92.  
  93. private boolean clickIndex(int i, boolean mouseKeys) {
  94. if (!Menu.isOpen()) {
  95. return false;
  96. }
  97. String[] items = Menu.getItems();
  98. if (items.length <= i) {
  99. return false;
  100. }
  101. return clickMain(items, i, mouseKeys);
  102. }
  103.  
  104. private boolean clickMain(String[] items, int i, boolean mouseKeys) {
  105. Point Menul = Menu.getLocation();
  106. int xOff = Random.nextInt(4, items[i].length() * 4);
  107. int yOff = 21 + 15 * i + Random.nextInt(3, 12);
  108. if (mouseKeys) {
  109. Mouse.hop(Menul.x + xOff, Menul.y + yOff, 2, 2);
  110. } else {
  111. Mouse.move(Menul.x + xOff, Menul.y + yOff, 2, 2);
  112. }
  113. if (Menu.isOpen()) {
  114. Mouse.click(true);
  115. return true;
  116. }
  117. return false;
  118. }
Add Comment
Please, Sign In to add comment