Drop item optimization working -- timing is close to perfect
This commit is contained in:
parent
f3b759cb04
commit
faab5a5577
BIN
bin/Cursor.class
BIN
bin/Cursor.class
Binary file not shown.
Binary file not shown.
BIN
bin/main.class
BIN
bin/main.class
Binary file not shown.
|
@ -70,7 +70,7 @@ public class Cursor {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: make sure these are reasonable
|
||||||
private int getRandomClickLength() {
|
private int getRandomClickLength() {
|
||||||
return random.nextInt(MAXIMUM_CLICK_LENGTH - MINIMUM_CLICK_LENGTH) + MINIMUM_CLICK_LENGTH;
|
return random.nextInt(MAXIMUM_CLICK_LENGTH - MINIMUM_CLICK_LENGTH) + MINIMUM_CLICK_LENGTH;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ public class Cursor {
|
||||||
|
|
||||||
public void rightClickCursor() throws InterruptedException {
|
public void rightClickCursor() throws InterruptedException {
|
||||||
robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
|
robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
|
||||||
Thread.sleep(50 + getRandomClickLength());
|
Thread.sleep(20 + getRandomClickLength());
|
||||||
robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
|
robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
|
||||||
Thread.sleep(getRandomClickLength());
|
Thread.sleep(getRandomClickLength());
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,27 @@ public class CursorTask {
|
||||||
public static final int DROP_OFFSET = 40;
|
public static final int DROP_OFFSET = 40;
|
||||||
public static final int DROP_BOTTOM_ROW = 539;
|
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 {
|
public void dropAllItemsInInventory(Cursor cursor, Inventory inventory) throws InterruptedException {
|
||||||
for (int row = 0; row < 4; row++) {
|
for (int row = 0; row < 4; row++) {
|
||||||
for (int column = 0; column < 7; column++) {
|
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++) {
|
for (int row = 0; row < 4; row++) {
|
||||||
dropItem(cursor, inventory, row, 6);
|
dropItem(cursor, inventory, row, 6);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public void dropItem(Cursor cursor, Inventory inventory, int row, int column) throws InterruptedException {
|
public Point dropItem(Cursor cursor, Inventory inventory, int row, int column) throws InterruptedException {
|
||||||
System.out.println("Dropping item...");
|
|
||||||
Point coordinatesToRightClick = inventory.getClickCoordinatesCoordinatesForInventorySlot(row, column);
|
Point coordinatesToRightClick = inventory.getClickCoordinatesCoordinatesForInventorySlot(row, column);
|
||||||
Point clickedCoordinates = rightClickItemSlot(cursor, coordinatesToRightClick);
|
Point clickedCoordinates = rightClickItemSlotWithRandomness(cursor, coordinatesToRightClick);
|
||||||
leftClickDropOption(cursor, clickedCoordinates, column);
|
return leftClickDropOption(cursor, clickedCoordinates, column);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point rightClickItemSlot(Cursor cursor, Point coordinatesToRightClick) throws InterruptedException {
|
public void rightClickItemSlot(Cursor cursor, Point coordinatesToRightClick) throws InterruptedException {
|
||||||
Point clickedCoordinates = cursor.moveAndRightlickAtCoordinatesWithRandomness(coordinatesToRightClick, 10, 10);
|
cursor.moveAndRightClickAtCoordinates(coordinatesToRightClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point rightClickItemSlotWithRandomness(Cursor cursor, Point coordinatesToRightClick) throws InterruptedException {
|
||||||
|
Point clickedCoordinates = cursor.moveAndRightlickAtCoordinatesWithRandomness(coordinatesToRightClick, 6, 6);
|
||||||
return clickedCoordinates;
|
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;
|
Point offsetCoordinatesToLeftClick = coordinatesToLeftClick;
|
||||||
if (column < 6) {
|
if (column < 6) {
|
||||||
offsetCoordinatesToLeftClick.y += DROP_OFFSET;
|
offsetCoordinatesToLeftClick.y += DROP_OFFSET;
|
||||||
|
@ -40,7 +64,6 @@ public class CursorTask {
|
||||||
else {
|
else {
|
||||||
offsetCoordinatesToLeftClick.y = DROP_BOTTOM_ROW;
|
offsetCoordinatesToLeftClick.y = DROP_BOTTOM_ROW;
|
||||||
}
|
}
|
||||||
Point p = cursor.moveAndLeftClickAtCoordinatesWithRandomness(offsetCoordinatesToLeftClick, 10, 6);
|
return cursor.moveAndLeftClickAtCoordinatesWithRandomness(offsetCoordinatesToLeftClick, 10, 6);
|
||||||
System.out.println(p.x + "," + p.y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,8 @@ public class main {
|
||||||
//cursor.displayCursorPaths();
|
//cursor.displayCursorPaths();
|
||||||
Inventory inventory = new Inventory();
|
Inventory inventory = new Inventory();
|
||||||
//inventory.update();
|
//inventory.update();
|
||||||
cursorTask.dropBottomRow(cursor, inventory);
|
cursorTask.optimizedDropAllItemsInInventory(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();
|
|
||||||
|
|
||||||
System.out.println("Success!");
|
System.out.println("Success!");
|
||||||
//cursor.moveCursorToCoordinates(new Point(620, 420));
|
//cursor.moveCursorToCoordinates(new Point(620, 420));
|
||||||
|
|
Loading…
Reference in New Issue