Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.AWTException;
- import java.awt.Color;
- import java.awt.MouseInfo;
- import java.awt.Rectangle;
- import java.awt.Robot;
- import java.awt.event.InputEvent;
- import java.awt.event.KeyEvent;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import javax.imageio.ImageIO;
- import com.sun.jna.platform.win32.User32;
- import com.sun.jna.platform.win32.WinDef.HWND;
- import com.sun.jna.platform.win32.WinDef.RECT;
- public class Main
- {
- public static Robot robot;
- public static boolean fightingBoss = false;
- public static int timeOffBoss = 10 * 60;
- public static Color lightBlue = new Color(0, 103, 255);
- public static Color darkBlue = new Color(0, 26, 64);
- public static void main(String[] args) throws AWTException
- {
- robot = new Robot();
- while(true)
- {
- robot.delay(100);
- if(!isFocused())
- continue;
- //Check for loosing boss battle
- Color color1 = robot.getPixelColor(570, 185);
- Color color2 = robot.getPixelColor(580, 185);
- /* This code was used for grinding on the stage before the boss, I've found that rainbow balls on boss stages
- * outweigh the gains of grinding on pre-boss stages
- if(color1.equals(bossBlue))
- {
- fightingBoss = true;
- }*/
- // This checks to see if the timer bar has less that ~1 sec left, if that is the case, give up on the boss fight
- if(fightingBoss && !color1.equals(color2))
- {
- fightingBoss = false;
- timeOffBoss = 0;
- //robot.mouseMove(600, 70);
- //robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
- //robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
- }
- // If not currently fighting the boss, wait 10 minutes and try to beat the boss
- // We reset the boss timer by going back 1 stage and then forward
- // Use all our skills
- // The point of this is to make sure we use our skills at the correct time when fighting a boss
- // If we used our skills whenever possible, they might be activated in the middle of a bosses
- // time running out.
- if(fightingBoss == false)
- {
- timeOffBoss++;
- if(timeOffBoss > 60*10)
- {
- robot.mouseMove(600, 70);
- robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
- robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
- robot.delay(1000);
- robot.mouseMove(750, 70);
- robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
- robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
- useSkills();
- fightingBoss = true;
- }
- }
- dimShift();
- upgradeWeapons();
- // Click 10 times with a 100ms delay between each
- for(int i = 0; i < 10; i++)
- {
- if(!isFocused())
- return;
- robot.delay(100);
- click();
- }
- // Pause if the window is not in focus
- if(!isFocused())
- continue;
- // Try to hit the rainbow ball
- if(!fightingBoss) // Don't waste time on this if try to kill boss
- {
- robot.delay(100);
- robot.mouseMove(875, 375); // The ball will always end up at this point along it's path
- robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
- robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
- }
- }
- }
- // Magic
- public static String getWindowName()
- {
- char[] buffer = new char[100 * 2];
- HWND hwnd = User32.INSTANCE.GetForegroundWindow();
- User32.INSTANCE.GetWindowText(hwnd, buffer, 100);
- RECT rect = new RECT();
- User32.INSTANCE.GetWindowRect(hwnd, rect);
- return String.valueOf(buffer);
- }
- // Check to make sure the Time Clickers window is in focues
- static boolean isFocused()
- {
- String window = getWindowName();
- if(!window.contains("Time Clickers"))
- return false;
- return true;
- }
- public static void dimShift()
- {
- robot.keyPress(KeyEvent.VK_7);
- robot.keyRelease(KeyEvent.VK_7);
- robot.keyPress(KeyEvent.VK_0);
- robot.keyRelease(KeyEvent.VK_0);
- }
- public static void useSkills()
- {
- robot.keyPress(KeyEvent.VK_SPACE);
- robot.keyRelease(KeyEvent.VK_SPACE);
- }
- public static int[] upgradeKeys = new int[] {KeyEvent.VK_A, KeyEvent.VK_S, KeyEvent.VK_D, KeyEvent.VK_F, KeyEvent.VK_G};
- public static void upgradeWeapons()
- {
- // Grab the color of the upgrade button for each weapon
- Color[] color = new Color[5];
- color[0] = robot.getPixelColor(64, 260);
- color[1] = robot.getPixelColor(64, 360);
- color[2] = robot.getPixelColor(64, 460);
- color[3] = robot.getPixelColor(64, 560);
- color[4] = robot.getPixelColor(64, 660);
- // Find if any weapon's next upgrade is a promotion
- boolean promoting = false;
- for(int i = 0; i < 5; i++)
- {
- if(!color[i].equals(lightBlue) && !color[i].equals(darkBlue))
- {
- // This weapon is promoting, so click the button
- robot.keyPress(upgradeKeys[i]);
- robot.keyRelease(upgradeKeys[i]);
- promoting = true; // There may not have been enough gold, so this cancels the rest of the weapon upgrades
- }
- }
- // One of the weapons may be waiting for a promotion, so don't level any others
- if(promoting)
- {
- return;
- }
- // Upgrade all the weapons
- robot.keyPress(KeyEvent.VK_A);
- robot.keyRelease(KeyEvent.VK_A);
- robot.keyPress(KeyEvent.VK_S);
- robot.keyRelease(KeyEvent.VK_S);
- robot.keyPress(KeyEvent.VK_D);
- robot.keyRelease(KeyEvent.VK_D);
- robot.keyPress(KeyEvent.VK_F);
- robot.keyRelease(KeyEvent.VK_F);
- robot.keyPress(KeyEvent.VK_G);
- robot.keyRelease(KeyEvent.VK_G);
- }
- static Color brown = new Color(49, 0, 0);
- static int x;
- static int y;
- public static void click()
- {
- BufferedImage screen = robot.createScreenCapture(new Rectangle(500, 250, 400, 400));
- int color = 0;
- // Check the color of the point last clicked
- // try/catch is needed to catch out of bounds exception
- try
- {
- color = screen.getRGB(x, y);
- } catch(Exception e)
- {}
- // Loop through points on the screen looking for the correct color brown
- // or is a time cube (time cubes pulse, so there isn't just one color)
- // The first position checked is the last point clicked, if there is no
- // cube there, check up to 400 random points.
- int count = 0;
- while(color != brown.getRGB() && !isTimeCube(color))
- {
- count++;
- if(count > 400)
- break;
- x = (int) (Math.random() * 400);
- y = (int) (Math.random() * 400);
- color = screen.getRGB(x, y);
- }
- robot.mouseMove(500 + x, 250 + y);
- robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
- robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
- }
- // Time cubes background color pulses between (0, 0, 0) and (100, 0, 0) so look for a color in that range
- public static boolean isTimeCube(int color)
- {
- Color c = new Color(color);
- // Some stages backgrounds has a red color that matches this, on those stages comment out the code and just put return false
- // Unfortunately this isn't something the code is designed to handle and has to be manually done, it could be run with
- // "return false" all the time without loosing too much efficiency
- //return false;
- return c.getRed() > 0 && c.getRed() < 100 && c.getBlue() == 0 && c.getGreen() == 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement