Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private boolean interact(Model model, String action) {
- for (int i = 0; i < 20; i++) {
- if (model == null) {
- return false;
- }
- if (!Calculations.isPointOnScreen(model.getNextPoint())) {
- return false;
- }
- Point p = getRandomPoint(model);
- if (p == null) {
- p = model.getNextPoint();
- }
- Point m = p;
- int speed = Mouse.getSpeed();
- Mouse.setSpeed(Random.nextInt(1, 4));
- int xdir = Mouse.getLocation().x - m.x;
- int ydir = Mouse.getLocation().y - m.y;
- if (xdir > 0) {
- m = new Point(m.x + Random.nextInt(-10, 25), m.y);
- } else if (xdir < 0) {
- m = new Point(m.x - Random.nextInt(-10, 25), m.y);
- }
- if (ydir > 0) {
- m = new Point(m.x, m.y + Random.nextInt(-10, 25));
- } else if (ydir < 0) {
- m = new Point(m.x, m.y - Random.nextInt(-10, 25));
- }
- if (Random.nextInt(0, 3) == 1) {
- Mouse.move(m);
- }
- sleep(150, 300);
- Mouse.setSpeed(speed);
- Mouse.move(p);
- String[] items = Menu.getItems();
- if (items.length > 0
- && items[0].toLowerCase().startsWith(action.toLowerCase())) {
- Mouse.click(true);
- return true;
- } else {
- String[] MenuItems = Menu.getItems();
- for (String item : MenuItems) {
- if (item.toLowerCase().contains(action.toLowerCase())) {
- Mouse.click(false);
- return interact(action, false);
- }
- }
- }
- }
- return false;
- }
- private Point getRandomPoint(Model model) {
- Polygon[] triangles = model.getTriangles();
- if (triangles.length == 0) {
- return null;
- }
- Polygon p = triangles[Random.nextInt(0, triangles.length)];
- double a = Math.random();
- double b = Math.random();
- if (a + b >= 1) {
- a = 1 - a;
- b = 1 - b;
- }
- double c = 1 - a - b;
- return new Point((int) (a * p.xpoints[0] + b * p.xpoints[1] + c
- * p.xpoints[2]), (int) (a * p.ypoints[0] + b * p.ypoints[1] + c
- * p.ypoints[2]));
- }
- private boolean interact(String action, boolean mouseKeys) {
- action = action.toLowerCase();
- int idx = Menu.getIndex(action);
- if (!Menu.isOpen()) {
- if (idx == -1) {
- return false;
- }
- if (idx == 0) {
- Mouse.click(true);
- return true;
- }
- Mouse.click(false);
- return clickIndex(idx, mouseKeys);
- } else if (idx == -1) {
- while (Menu.isOpen()) {
- Mouse.moveRandomly(750);
- sleep(Random.nextInt(100, 500));
- }
- return false;
- }
- return clickIndex(idx, mouseKeys);
- }
- private boolean clickIndex(int i, boolean mouseKeys) {
- if (!Menu.isOpen()) {
- return false;
- }
- String[] items = Menu.getItems();
- if (items.length <= i) {
- return false;
- }
- return clickMain(items, i, mouseKeys);
- }
- private boolean clickMain(String[] items, int i, boolean mouseKeys) {
- Point Menul = Menu.getLocation();
- int xOff = Random.nextInt(4, items[i].length() * 4);
- int yOff = 21 + 15 * i + Random.nextInt(3, 12);
- if (mouseKeys) {
- Mouse.hop(Menul.x + xOff, Menul.y + yOff, 2, 2);
- } else {
- Mouse.move(Menul.x + xOff, Menul.y + yOff, 2, 2);
- }
- if (Menu.isOpen()) {
- Mouse.click(true);
- return true;
- }
- return false;
- }
Add Comment
Please, Sign In to add comment