diff --git a/bin/Cursor.class b/bin/Cursor.class index 225efe9..e74b4b4 100644 Binary files a/bin/Cursor.class and b/bin/Cursor.class differ diff --git a/bin/CursorTask.class b/bin/CursorTask.class index aabb339..01a8865 100644 Binary files a/bin/CursorTask.class and b/bin/CursorTask.class differ diff --git a/bin/main.class b/bin/main.class index 55b94c3..2e9c9c7 100644 Binary files a/bin/main.class and b/bin/main.class differ diff --git a/src/Cursor.java b/src/Cursor.java index 24dd423..05b76db 100644 --- a/src/Cursor.java +++ b/src/Cursor.java @@ -70,7 +70,7 @@ public class Cursor { } - + // TODO: make sure these are reasonable private int getRandomClickLength() { return random.nextInt(MAXIMUM_CLICK_LENGTH - MINIMUM_CLICK_LENGTH) + MINIMUM_CLICK_LENGTH; } @@ -84,7 +84,7 @@ public class Cursor { public void rightClickCursor() throws InterruptedException { robot.mousePress(InputEvent.BUTTON3_DOWN_MASK); - Thread.sleep(50 + getRandomClickLength()); + Thread.sleep(20 + getRandomClickLength()); robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK); Thread.sleep(getRandomClickLength()); } diff --git a/src/CursorTask.java b/src/CursorTask.java index 09fcf34..86ab0a4 100644 --- a/src/CursorTask.java +++ b/src/CursorTask.java @@ -6,6 +6,27 @@ public class CursorTask { public static final int DROP_OFFSET = 40; public static final int DROP_BOTTOM_ROW = 539; + + // Human drop time: 29 seconds + + // Measured: + public void optimizedDropAllItemsInInventory(Cursor cursor, Inventory inventory) throws InterruptedException { + for (int row = 0; row < 4; row++) { + Point coordinatesToClick = dropItem(cursor, inventory, row, 0); + for (int column = 1; column < 7; column++) { + if (distanceBetweenPoints(coordinatesToClick, inventory.getClickCoordinatesCoordinatesForInventorySlot(row, column)) > 12) { + coordinatesToClick = inventory.getClickCoordinatesCoordinatesForInventorySlot(row, column); + } + rightClickItemSlot(cursor, coordinatesToClick); + coordinatesToClick = leftClickDropOption(cursor, coordinatesToClick, column); + } + } + } + + private int distanceBetweenPoints(Point a, Point b) { + return (int) (Math.hypot(a.x - b.x, a.y - b.y)); + } + public void dropAllItemsInInventory(Cursor cursor, Inventory inventory) throws InterruptedException { for (int row = 0; row < 4; row++) { for (int column = 0; column < 7; column++) { @@ -14,25 +35,28 @@ public class CursorTask { } } - public void dropBottomRow(Cursor cursor, Inventory inventory) throws InterruptedException { + /*public void dropBottomRow(Cursor cursor, Inventory inventory) throws InterruptedException { for (int row = 0; row < 4; row++) { dropItem(cursor, inventory, row, 6); } - } + }*/ - public void dropItem(Cursor cursor, Inventory inventory, int row, int column) throws InterruptedException { - System.out.println("Dropping item..."); + public Point dropItem(Cursor cursor, Inventory inventory, int row, int column) throws InterruptedException { Point coordinatesToRightClick = inventory.getClickCoordinatesCoordinatesForInventorySlot(row, column); - Point clickedCoordinates = rightClickItemSlot(cursor, coordinatesToRightClick); - leftClickDropOption(cursor, clickedCoordinates, column); + Point clickedCoordinates = rightClickItemSlotWithRandomness(cursor, coordinatesToRightClick); + return leftClickDropOption(cursor, clickedCoordinates, column); } - public Point rightClickItemSlot(Cursor cursor, Point coordinatesToRightClick) throws InterruptedException { - Point clickedCoordinates = cursor.moveAndRightlickAtCoordinatesWithRandomness(coordinatesToRightClick, 10, 10); + public void rightClickItemSlot(Cursor cursor, Point coordinatesToRightClick) throws InterruptedException { + cursor.moveAndRightClickAtCoordinates(coordinatesToRightClick); + } + + public Point rightClickItemSlotWithRandomness(Cursor cursor, Point coordinatesToRightClick) throws InterruptedException { + Point clickedCoordinates = cursor.moveAndRightlickAtCoordinatesWithRandomness(coordinatesToRightClick, 6, 6); return clickedCoordinates; } - private void leftClickDropOption(Cursor cursor, Point coordinatesToLeftClick, int column) throws InterruptedException { + private Point leftClickDropOption(Cursor cursor, Point coordinatesToLeftClick, int column) throws InterruptedException { Point offsetCoordinatesToLeftClick = coordinatesToLeftClick; if (column < 6) { offsetCoordinatesToLeftClick.y += DROP_OFFSET; @@ -40,7 +64,6 @@ public class CursorTask { else { offsetCoordinatesToLeftClick.y = DROP_BOTTOM_ROW; } - Point p = cursor.moveAndLeftClickAtCoordinatesWithRandomness(offsetCoordinatesToLeftClick, 10, 6); - System.out.println(p.x + "," + p.y); + return cursor.moveAndLeftClickAtCoordinatesWithRandomness(offsetCoordinatesToLeftClick, 10, 6); } } diff --git a/src/main.java b/src/main.java index a741460..e43685f 100644 --- a/src/main.java +++ b/src/main.java @@ -13,14 +13,8 @@ public class main { //cursor.displayCursorPaths(); Inventory inventory = new Inventory(); //inventory.update(); - cursorTask.dropBottomRow(cursor, inventory); - /*cursorTask.dropItem(cursor, inventory, 0, 0); - Thread.sleep(3000); - cursorTask.dropItem(cursor, inventory, 3, 5); - Thread.sleep(3000); - cursorTask.dropItem(cursor, inventory, 0, 6);*/ - //Items items = new Items("/home/dpapp/Desktop/RunescapeAIPics/Items/"); - //items.displayItems(); + cursorTask.optimizedDropAllItemsInInventory(cursor, inventory); + System.out.println("Success!"); //cursor.moveCursorToCoordinates(new Point(620, 420));