When I get on my PC, I'll post my interact method so you can get a feel for it
EDIT Here it is. It's not the best example, it uses while loops (which you shouldn't typically use), and obviously you need external vars (biasDeviation and contextMenuDeviation) for tihs to work.
public boolean interactWith(NPC e, String action) throws InterruptedException {
if (e == null) {
return false;
}
if (getMenuAPI().isOpen()) {
getMouse().click(false);
sleep(sleepDeviateRand(5, 15));
}
//e.hover();
while (!getMouse().isOnCursor(e)) { e.hover(); /*sleep(sleepDeviateRand(1, 2));*/ } //hover
String tooltip = getMenuAPI().getTooltip().toLowerCase();
String estimatedToolTip = (action + " " + e.getName()).toLowerCase();
if ((getFirstAction(e).equals(action) && getMouse().getOnCursorCount() == 1) || tooltip.startsWith(estimatedToolTip)) {
getMouse().click(false);
log("Left clicked!");
return true;
}
while (!getMenuAPI().isOpen()) { getMouse().click(true); sleep(sleepDeviateRand(5, 15)); } //open interface
sleep(sleepDeviateRand(5, 15));
List<Option> options = getMenuAPI().getMenu();
int rectIndex = -1;
for (int i = 0; i < options.size(); i++) {
Option o = options.get(i);
String s = o.action;
if (s.equals(action)) {
rectIndex = i;
break;
}
}
if (rectIndex == -1) {
return false;
}
Rectangle optionRect = getMenuAPI().getOptionRectangle(rectIndex);
int height = optionRect.height;
int startX = optionRect.x;
int startY = optionRect.y;
int width = optionRect.width;
int endX = startX + width;
int endY = startY + height;
int perc = 0;
if (contextMenuDeviation > 10) { //We want to get the correct context values if (and only if) we have a suitable context menu dev. value (otherwise we just go for the entire object)
float percentage = width / 100; //Keep as much precision as possible
percentage *= contextMenuDeviation;
perc = (int) percentage;
}
int centreX = (startX + (width / 2));
if (biasDeviation) {
Point p = getMouse().getPosition();
int mouseX = (int) p.getX();
if (mouseX > centreX) { //Right side of the context menu
startX = centreX;
if (perc > 0) {
endX = (startX + (perc / 2)); //We do (perc / 2) because in the calculation we account for the entire width
}
}
else { //Left side of the context menu
endX = centreX;
if (perc > 0) {
startX = (centreX - (perc / 2));
}
}
}
else {
startX += (perc / 2);
endX -= (perc / 2);
}
//2px bounds incase the bounding boxes are fucked
int randX = getRandom(startX + 1, endX - 1);
int randY = getRandom(startY + 1, endY - 1);
Area mouseArea = createArea(new Point(randX, randY), 2); //Create a 3x3 box
while (!mouseArea.contains((int) getMouse().getPosition().getX(), (int) getMouse().getPosition().getY())) { getMouse().move(randX, randY); sleep(sleepDeviateRand(5, 15)); } //move to option
sleep(sleepDeviateRand(5, 15));
while (getMenuAPI().isOpen()) { getMouse().click(false); sleep(sleepDeviateRand(5, 15)); } //click
sleep(sleepDeviateRand(25, 45));
return true;
}