import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
public class HelloWorld extends JFrame implements ActionListener {
private static JTextField text;
private static JButton button;
private static String loads = "";
public static void main(String[] args) throws Exception {
Robot bot1 = new Robot();
Box boxCoords;
Point bankOp = new Point();
Random makeRand = new Random();
new HelloWorld();
while (loads.equals("")) bot1.delay(1000);
for (int p = 0; p < Integer.parseInt(loads); p++) {
bot1.delay(1500 + makeRand.nextInt(2500));
for (int i = 1; i < 29; i++) {
boxCoords = getInvCoords(i);
moveMouseBox(boxCoords.x1, boxCoords.y1, boxCoords.x2, boxCoords.y2, 1, 1);
bot1.delay(50 + makeRand.nextInt(85));
mouseClick(true);
bot1.delay(1000 + makeRand.nextInt(1500));
}
moveMouseHuman(374, 345, 3, 3);
mouseClick(false);
bot1.delay(1000 + makeRand.nextInt(1000));
bankOp = findColorRight(new Color(0, 255, 255), 308, 207, 487, 544);
moveMouseHuman(bankOp.x - 4, bankOp.y, 2, 1);
mouseClick(true);
while (bot1.getPixelColor(309, 244).equals(new Color(0, 0, 0)) == false) bot1.delay(1000);
bot1.delay(1000 + makeRand.nextInt(1000));
moveMouseHuman(212, 283, 4, 4);
mouseClick(false);
bot1.delay(750 + makeRand.nextInt(1000));
moveMouseHuman(221, 350, 8, 2);
mouseClick(true);
bot1.delay(750 + makeRand.nextInt(1000));
moveMouseHuman(606, 247, 2, 2);
bot1.delay(200 + makeRand.nextInt(450));
mouseClick(true);
}
}
public HelloWorld() throws Exception {
button = new JButton("Start!");
text = new JTextField(10);
JPanel panel = new JPanel();
panel.add(button);
panel.add(text);
button.setBounds(0, 0, 100, 75);
text.setBounds(0, 150, 75, 25);
panel.setBounds(0, 0, 400, 400);
button.addActionListener(this);
JFrame frame = new JFrame("Town's Bone Burrier");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(0, 0, 400, 200);
frame.add(panel, BorderLayout.NORTH);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
loads = text.getText();
button.setEnabled(false);
text.setEnabled(false);
};
public static double Distance(int x1, int y1, int x2, int y2) {
return Math.sqrt(Math.pow(x2-x1, 2) + Math.pow(y2-y1, 2));
}
private static void moveMouseHuman(int x, int y, int Rx, int Ry) throws Exception { /* Borrowed */
try {
Random makeRand = new Random();
if (makeRand.nextInt(2) == 1) {x = x - makeRand.nextInt(Rx);}
else {x = x + makeRand.nextInt(Rx);}
if (makeRand.nextInt(2) == 1) {y = y - makeRand.nextInt(Ry);}
else {y = y + makeRand.nextInt(Ry);}
Robot robot = new Robot();
PointerInfo PInfo = MouseInfo.getPointerInfo();
Point origin = PInfo.getLocation();
Point Difference = new Point((int)(x - PInfo.getLocation().getX()),(int)(y - PInfo.getLocation().getY()));
for(double Current = 0; Current < 1; Current+= (15/Math.sqrt(Math.pow(Difference.getX(),2) + Math.pow(Difference.getY(),2)))){
PInfo = MouseInfo.getPointerInfo();
robot.mouseMove((int)origin.getX() + (int)(Difference.getX() * Current),(int)origin.getY() + (int)(Difference.getY() * Current));
robot.setAutoDelay(3);
}
robot.waitForIdle();
}catch(java.awt.AWTException exc) {}
}
public static void moveMouseBox(int x1, int y1, int x2, int y2, int Rx, int Ry) throws Exception {
Random makeRand = new Random();
int x = 0;
int y = 0;
try {x = makeRand.nextInt(Math.abs(x2 - x1));
y = makeRand.nextInt(Math.abs(y2 - y1));}
catch (IllegalArgumentException e) {x = x1; y = y1;}
moveMouseHuman(x1 + x, y1 + y, Rx, Ry);
}
public static void mouseClick(boolean Left) throws Exception {
Robot bot1 = new Robot();
Random makeRand = new Random();
if (Left) bot1.mousePress(InputEvent.BUTTON1_MASK);
else bot1.mousePress(InputEvent.BUTTON3_MASK);
bot1.delay(45 + makeRand.nextInt(105));
if (Left) bot1.mouseRelease(InputEvent.BUTTON1_MASK);
else bot1.mouseRelease(InputEvent.BUTTON3_MASK);
}
public static Point findColorRight(Color color, int x1, int y1, int x2, int y2) throws Exception {
Robot bot1 = new Robot();
Point Points[] = new Point[(x2 - x1) * (y2 - y1)];
Point Temp = new Point(-1, -1);
Color pixelCol = new Color(0, 0, 0);
int p = 0;
for (int no = 0; no < Points.length - 1; no++) Points[no] = new Point();
for (int y = y1; y < y2; y++) {
for (int x = x1; x < x2; x++) {
pixelCol = bot1.getPixelColor(x, y);
if (color.equals(pixelCol) == true) {
Points[p] = new Point(x, y);
p = p + 1;
}
}
}
for (int i = 0; i < p; i++) {
if (Temp.x < Points[i].x) {
Temp = Points[i];
}
}
return Temp;
}
public static Box getInvCoords(int Slot) {
int row;
int col;
row = Slot % 4;
if (row == 0) row = 4;
col = Slot / 4 ;
if (Slot % 4 != 0) col = col + 1;
return new Box(658 + (row * 42) - 2, 399 + (col * 36) - 5, 658 + (row * 42) + 5, 399 + (col * 36) + 2);
}
}
class Box {
public int x1;
public int y1;
public int x2;
public int y2;
public Box(int Nx1, int Ny1, int Nx2, int Ny2) {
x1 = Nx1;
y1 = Ny1;
x2 = Nx2;
y2 = Ny2;
}
}