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 {
robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
Thread.sleep(200 + getRandomClickLength() * 2);
Thread.sleep(50 + getRandomClickLength());
robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
Thread.sleep(getRandomClickLength());
}
@ -94,10 +94,11 @@ public class Cursor {
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);
moveCursorToCoordinates(randomizedGoalPoint);
leftClickCursor();
return randomizedGoalPoint; // Return the point in case we need precise movement afterwards
}
public void moveAndRightClickAtCoordinates(Point goalPoint) throws InterruptedException {
@ -105,16 +106,21 @@ public class Cursor {
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);
moveCursorToCoordinates(randomizedGoalPoint);
rightClickCursor();
return randomizedGoalPoint; // Return the point in case we need precise movement afterwards
}
public void moveCursorToCoordinates(Point goalPoint) throws InterruptedException {
Point startingCursorPoint = getCurrentCursorPoint();
int distanceToMoveCursor = calculateDistanceBetweenPoints(startingCursorPoint, goalPoint);
if (distanceToMoveCursor == 0) {
return;
}
double angleToMoveCursor = calculateThetaBetweenPoints(startingCursorPoint, goalPoint);
// TODO: check if exists
CursorPath cursorPathToFollow = chooseCursorPathToFollowBasedOnDistance(distanceToMoveCursor);
double angleToTranslatePathBy = angleToMoveCursor - cursorPathToFollow.getCursorPathTheta();
@ -142,6 +148,10 @@ public class Cursor {
private CursorPath chooseCursorPathToFollowBasedOnDistance(int distanceToMoveCursor) {
ArrayList<CursorPath> cursorPathsWithSameDistance = cursorPathsByDistance.get(distanceToMoveCursor);
// 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()));
}
@ -164,4 +174,15 @@ public class Cursor {
private Point randomizePoint(Point goalPoint, int xTolerance, int 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() {
return (this.pathTimespanMilliseconds > 100 && this.pathTimespanMilliseconds < 400);
return (this.pathTimespanMilliseconds > 50 && this.pathTimespanMilliseconds < 400);
}
private boolean isCursorPathDistanceReasonable() {
return (this.pathDistance > 5 && this.pathDistance < 1000);
return (this.pathDistance > 0 && this.pathDistance < 1000);
}
private boolean isCursorPathNumPointsReasonable() {
return (this.pathNumPoints > 5 && this.pathNumPoints < 50);
return (this.pathNumPoints > 0 && this.pathNumPoints < 50);
}
public ArrayList<CursorPoint> getCursorPathPoints() {

View File

@ -4,7 +4,7 @@ import java.awt.Point;
public class CursorTask {
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 {
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 {
System.out.println("Dropping item...");
Point coordinatesToRightClick = inventory.getClickCoordinatesCoordinatesForInventorySlot(row, column);
rightClickItemSlot(cursor, coordinatesToRightClick);
leftClickDropOption(cursor, coordinatesToRightClick, row);
Point clickedCoordinates = rightClickItemSlot(cursor, coordinatesToRightClick);
leftClickDropOption(cursor, clickedCoordinates, column);
}
public void rightClickItemSlot(Cursor cursor, Point coordinatesToRightClick) throws InterruptedException {
cursor.moveAndRightlickAtCoordinatesWithRandomness(coordinatesToRightClick, 10, 10);
public Point rightClickItemSlot(Cursor cursor, Point coordinatesToRightClick) throws InterruptedException {
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;
if (row < 6) {
if (column < 6) {
offsetCoordinatesToLeftClick.y += DROP_OFFSET;
}
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();
CursorTask cursorTask = new CursorTask();
//Inventory inventory = new Inventory();
//inventory.update();
//cursor.displayCursorPaths();
Inventory inventory = new Inventory();
//inventory.update();
cursorTask.dropAllItemsInInventory(cursor, inventory);
cursorTask.dropBottomRow(cursor, inventory);
/*cursorTask.dropItem(cursor, inventory, 0, 0);
Thread.sleep(3000);
cursorTask.dropItem(cursor, inventory, 3, 5);