Drop Item timing and placement improved

This commit is contained in:
davpapp 2018-02-02 12:17:47 -05:00
parent f8e4a55283
commit f3b759cb04
8 changed files with 46 additions and 18 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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(200 + getRandomClickLength() * 2); Thread.sleep(50 + getRandomClickLength());
robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK); robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
Thread.sleep(getRandomClickLength()); Thread.sleep(getRandomClickLength());
} }
@ -94,10 +94,11 @@ public class Cursor {
leftClickCursor(); leftClickCursor();
} }
public void moveAndLeftClickAtCoordinatesWithRandomness(Point goalPoint, int xTolerance, int yTolerance) throws InterruptedException { public Point moveAndLeftClickAtCoordinatesWithRandomness(Point goalPoint, int xTolerance, int yTolerance) throws InterruptedException {
Point randomizedGoalPoint = randomizePoint(goalPoint, xTolerance, yTolerance); Point randomizedGoalPoint = randomizePoint(goalPoint, xTolerance, yTolerance);
moveCursorToCoordinates(randomizedGoalPoint); moveCursorToCoordinates(randomizedGoalPoint);
leftClickCursor(); leftClickCursor();
return randomizedGoalPoint; // Return the point in case we need precise movement afterwards
} }
public void moveAndRightClickAtCoordinates(Point goalPoint) throws InterruptedException { public void moveAndRightClickAtCoordinates(Point goalPoint) throws InterruptedException {
@ -105,16 +106,21 @@ public class Cursor {
rightClickCursor(); rightClickCursor();
} }
public void moveAndRightlickAtCoordinatesWithRandomness(Point goalPoint, int xTolerance, int yTolerance) throws InterruptedException { public Point moveAndRightlickAtCoordinatesWithRandomness(Point goalPoint, int xTolerance, int yTolerance) throws InterruptedException {
Point randomizedGoalPoint = randomizePoint(goalPoint, xTolerance, yTolerance); Point randomizedGoalPoint = randomizePoint(goalPoint, xTolerance, yTolerance);
moveCursorToCoordinates(randomizedGoalPoint); moveCursorToCoordinates(randomizedGoalPoint);
rightClickCursor(); rightClickCursor();
return randomizedGoalPoint; // Return the point in case we need precise movement afterwards
} }
public void moveCursorToCoordinates(Point goalPoint) throws InterruptedException { public void moveCursorToCoordinates(Point goalPoint) throws InterruptedException {
Point startingCursorPoint = getCurrentCursorPoint(); Point startingCursorPoint = getCurrentCursorPoint();
int distanceToMoveCursor = calculateDistanceBetweenPoints(startingCursorPoint, goalPoint); int distanceToMoveCursor = calculateDistanceBetweenPoints(startingCursorPoint, goalPoint);
if (distanceToMoveCursor == 0) {
return;
}
double angleToMoveCursor = calculateThetaBetweenPoints(startingCursorPoint, goalPoint); double angleToMoveCursor = calculateThetaBetweenPoints(startingCursorPoint, goalPoint);
// TODO: check if exists // TODO: check if exists
CursorPath cursorPathToFollow = chooseCursorPathToFollowBasedOnDistance(distanceToMoveCursor); CursorPath cursorPathToFollow = chooseCursorPathToFollowBasedOnDistance(distanceToMoveCursor);
double angleToTranslatePathBy = angleToMoveCursor - cursorPathToFollow.getCursorPathTheta(); double angleToTranslatePathBy = angleToMoveCursor - cursorPathToFollow.getCursorPathTheta();
@ -142,6 +148,10 @@ public class Cursor {
private CursorPath chooseCursorPathToFollowBasedOnDistance(int distanceToMoveCursor) { private CursorPath chooseCursorPathToFollowBasedOnDistance(int distanceToMoveCursor) {
ArrayList<CursorPath> cursorPathsWithSameDistance = cursorPathsByDistance.get(distanceToMoveCursor); ArrayList<CursorPath> cursorPathsWithSameDistance = cursorPathsByDistance.get(distanceToMoveCursor);
// TODO: Error check if path of this size exists // TODO: Error check if path of this size exists
if (cursorPathsWithSameDistance.size() == 0) {
System.out.println("No movement required! Returning empty list of CursorPoints.");
return new CursorPath(new ArrayList<CursorPoint>());
}
return cursorPathsWithSameDistance.get(new Random().nextInt(cursorPathsWithSameDistance.size())); return cursorPathsWithSameDistance.get(new Random().nextInt(cursorPathsWithSameDistance.size()));
} }
@ -164,4 +174,15 @@ public class Cursor {
private Point randomizePoint(Point goalPoint, int xTolerance, int yTolerance) { private Point randomizePoint(Point goalPoint, int xTolerance, int yTolerance) {
return new Point(goalPoint.x + getRandomIntSigned(xTolerance), goalPoint.y + getRandomIntSigned(yTolerance)); return new Point(goalPoint.x + getRandomIntSigned(xTolerance), goalPoint.y + getRandomIntSigned(yTolerance));
} }
public void displayCursorPaths() {
for (int i = 0; i < 200; i++) {
System.out.println("There are " + cursorPathsByDistance.get(i).size() + " paths of size " + i);
}
System.out.println("--------------");
for (int i = 0; i < cursorPathsByDistance.get(1).size(); i++) {
cursorPathsByDistance.get(1).get(i).displayCursorPoints();
}
//cursorPathsByDistance.get(0).get(0).displayCursorPoints();
}
} }

View File

@ -77,15 +77,15 @@ public class CursorPath {
} }
private boolean isCursorPathTimespanReasonable() { private boolean isCursorPathTimespanReasonable() {
return (this.pathTimespanMilliseconds > 100 && this.pathTimespanMilliseconds < 400); return (this.pathTimespanMilliseconds > 50 && this.pathTimespanMilliseconds < 400);
} }
private boolean isCursorPathDistanceReasonable() { private boolean isCursorPathDistanceReasonable() {
return (this.pathDistance > 5 && this.pathDistance < 1000); return (this.pathDistance > 0 && this.pathDistance < 1000);
} }
private boolean isCursorPathNumPointsReasonable() { private boolean isCursorPathNumPointsReasonable() {
return (this.pathNumPoints > 5 && this.pathNumPoints < 50); return (this.pathNumPoints > 0 && this.pathNumPoints < 50);
} }
public ArrayList<CursorPoint> getCursorPathPoints() { public ArrayList<CursorPoint> getCursorPathPoints() {

View File

@ -4,7 +4,7 @@ import java.awt.Point;
public class CursorTask { public class CursorTask {
public static final int DROP_OFFSET = 40; public static final int DROP_OFFSET = 40;
public static final int DROP_OFFSET_BOTTOM_ROW = 10; public static final int DROP_BOTTOM_ROW = 539;
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++) {
@ -14,25 +14,33 @@ public class CursorTask {
} }
} }
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 { public void dropItem(Cursor cursor, Inventory inventory, int row, int column) throws InterruptedException {
System.out.println("Dropping item..."); System.out.println("Dropping item...");
Point coordinatesToRightClick = inventory.getClickCoordinatesCoordinatesForInventorySlot(row, column); Point coordinatesToRightClick = inventory.getClickCoordinatesCoordinatesForInventorySlot(row, column);
rightClickItemSlot(cursor, coordinatesToRightClick); Point clickedCoordinates = rightClickItemSlot(cursor, coordinatesToRightClick);
leftClickDropOption(cursor, coordinatesToRightClick, row); leftClickDropOption(cursor, clickedCoordinates, column);
} }
public void rightClickItemSlot(Cursor cursor, Point coordinatesToRightClick) throws InterruptedException { public Point rightClickItemSlot(Cursor cursor, Point coordinatesToRightClick) throws InterruptedException {
cursor.moveAndRightlickAtCoordinatesWithRandomness(coordinatesToRightClick, 10, 10); Point clickedCoordinates = cursor.moveAndRightlickAtCoordinatesWithRandomness(coordinatesToRightClick, 10, 10);
return clickedCoordinates;
} }
private void leftClickDropOption(Cursor cursor, Point coordinatesToLeftClick, int row) throws InterruptedException { private void leftClickDropOption(Cursor cursor, Point coordinatesToLeftClick, int column) throws InterruptedException {
Point offsetCoordinatesToLeftClick = coordinatesToLeftClick; Point offsetCoordinatesToLeftClick = coordinatesToLeftClick;
if (row < 6) { if (column < 6) {
offsetCoordinatesToLeftClick.y += DROP_OFFSET; offsetCoordinatesToLeftClick.y += DROP_OFFSET;
} }
else { else {
offsetCoordinatesToLeftClick.y += DROP_OFFSET_BOTTOM_ROW; offsetCoordinatesToLeftClick.y = DROP_BOTTOM_ROW;
} }
cursor.moveAndLeftClickAtCoordinatesWithRandomness(coordinatesToLeftClick, 10, 10); Point p = cursor.moveAndLeftClickAtCoordinatesWithRandomness(offsetCoordinatesToLeftClick, 10, 6);
System.out.println(p.x + "," + p.y);
} }
} }

View File

@ -10,11 +10,10 @@ public class main {
Cursor cursor = new Cursor(); Cursor cursor = new Cursor();
CursorTask cursorTask = new CursorTask(); CursorTask cursorTask = new CursorTask();
//Inventory inventory = new Inventory(); //cursor.displayCursorPaths();
//inventory.update();
Inventory inventory = new Inventory(); Inventory inventory = new Inventory();
//inventory.update(); //inventory.update();
cursorTask.dropAllItemsInInventory(cursor, inventory); cursorTask.dropBottomRow(cursor, inventory);
/*cursorTask.dropItem(cursor, inventory, 0, 0); /*cursorTask.dropItem(cursor, inventory, 0, 0);
Thread.sleep(3000); Thread.sleep(3000);
cursorTask.dropItem(cursor, inventory, 3, 5); cursorTask.dropItem(cursor, inventory, 3, 5);