Advertisement
Guest User

Untitled

a guest
Sep 10th, 2015
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.08 KB | None | 0 0
  1. import java.awt.AWTException;
  2. import java.awt.Color;
  3. import java.awt.MouseInfo;
  4. import java.awt.Rectangle;
  5. import java.awt.Robot;
  6. import java.awt.event.InputEvent;
  7. import java.awt.event.KeyEvent;
  8. import java.awt.image.BufferedImage;
  9. import java.io.File;
  10. import java.io.IOException;
  11.  
  12. import javax.imageio.ImageIO;
  13.  
  14. import com.sun.jna.platform.win32.User32;
  15. import com.sun.jna.platform.win32.WinDef.HWND;
  16. import com.sun.jna.platform.win32.WinDef.RECT;
  17.  
  18.  
  19. public class Main
  20. {
  21.     public static Robot robot;
  22.     public static boolean fightingBoss = false;
  23.     public static int timeOffBoss = 10 * 60;
  24.    
  25.     public static Color lightBlue = new Color(0, 103, 255);
  26.     public static Color darkBlue = new Color(0, 26, 64);
  27.    
  28.     public static void main(String[] args) throws AWTException
  29.     {
  30.         robot = new Robot();
  31.        
  32.         while(true)
  33.         {
  34.             robot.delay(100);
  35.            
  36.             if(!isFocused())
  37.                 continue;
  38.            
  39.             //Check for loosing boss battle
  40.             Color color1 = robot.getPixelColor(570, 185);
  41.             Color color2 = robot.getPixelColor(580, 185);
  42.            
  43.             /* This code was used for grinding on the stage before the boss, I've found that rainbow balls on boss stages
  44.              * outweigh the gains of grinding on pre-boss stages
  45.             if(color1.equals(bossBlue))
  46.             {
  47.                 fightingBoss = true;
  48.             }*/
  49.            
  50.             // 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
  51.             if(fightingBoss && !color1.equals(color2))
  52.             {
  53.                 fightingBoss = false;
  54.                 timeOffBoss = 0;
  55.                 //robot.mouseMove(600, 70);
  56.                 //robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
  57.                 //robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
  58.             }
  59.            
  60.             // If not currently fighting the boss, wait 10 minutes and try to beat the boss
  61.             // We reset the boss timer by going back 1 stage and then forward
  62.             // Use all our skills
  63.             // The point of this is to make sure we use our skills at the correct time when fighting a boss
  64.             // If we used our skills whenever possible, they might be activated in the middle of a bosses
  65.             // time running out.
  66.             if(fightingBoss == false)
  67.             {
  68.                 timeOffBoss++;
  69.                 if(timeOffBoss > 60*10)
  70.                 {
  71.                     robot.mouseMove(600, 70);
  72.                     robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
  73.                     robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
  74.                     robot.delay(1000);
  75.                     robot.mouseMove(750, 70);
  76.                     robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
  77.                     robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
  78.                     useSkills();
  79.                     fightingBoss = true;
  80.                 }
  81.             }
  82.                        
  83.             dimShift();
  84.            
  85.             upgradeWeapons();
  86.            
  87.             // Click 10 times with a 100ms delay between each
  88.             for(int i = 0; i < 10; i++)
  89.             {
  90.                 if(!isFocused())
  91.                     return;
  92.                
  93.                 robot.delay(100);
  94.                 click();
  95.             }
  96.  
  97.             // Pause if the window is not in focus
  98.             if(!isFocused())
  99.                 continue;
  100.            
  101.             // Try to hit the rainbow ball
  102.             if(!fightingBoss) // Don't waste time on this if try to kill boss
  103.             {
  104.                 robot.delay(100);
  105.                 robot.mouseMove(875, 375);  // The ball will always end up at this point along it's path
  106.                 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
  107.                 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
  108.             }
  109.         }
  110.     }
  111.  
  112.     // Magic
  113.     public static String getWindowName()
  114.     {
  115.         char[] buffer = new char[100 * 2];
  116.         HWND hwnd = User32.INSTANCE.GetForegroundWindow();
  117.         User32.INSTANCE.GetWindowText(hwnd, buffer, 100);
  118.         RECT rect = new RECT();
  119.         User32.INSTANCE.GetWindowRect(hwnd, rect);        
  120.         return String.valueOf(buffer);
  121.     }
  122.  
  123.     // Check to make sure the Time Clickers window is in focues
  124.     static boolean isFocused()
  125.     {
  126.         String window = getWindowName();
  127.        
  128.         if(!window.contains("Time Clickers"))
  129.             return false;
  130.        
  131.         return true;
  132.     }
  133.    
  134.     public static void dimShift()
  135.     {
  136.         robot.keyPress(KeyEvent.VK_7);
  137.         robot.keyRelease(KeyEvent.VK_7);
  138.         robot.keyPress(KeyEvent.VK_0);
  139.         robot.keyRelease(KeyEvent.VK_0);
  140.     }
  141.    
  142.     public static void useSkills()
  143.     {
  144.         robot.keyPress(KeyEvent.VK_SPACE);
  145.         robot.keyRelease(KeyEvent.VK_SPACE);
  146.     }
  147.    
  148.     public static int[] upgradeKeys = new int[] {KeyEvent.VK_A, KeyEvent.VK_S, KeyEvent.VK_D, KeyEvent.VK_F, KeyEvent.VK_G};
  149.    
  150.     public static void upgradeWeapons()
  151.     {
  152.         // Grab the color of the upgrade button for each weapon
  153.         Color[] color = new Color[5];
  154.         color[0] = robot.getPixelColor(64, 260);
  155.         color[1] = robot.getPixelColor(64, 360);
  156.         color[2] = robot.getPixelColor(64, 460);
  157.         color[3] = robot.getPixelColor(64, 560);
  158.         color[4] = robot.getPixelColor(64, 660);
  159.        
  160.         // Find if any weapon's next upgrade is a promotion
  161.         boolean promoting = false;
  162.         for(int i = 0; i < 5; i++)
  163.         {
  164.             if(!color[i].equals(lightBlue) && !color[i].equals(darkBlue))
  165.             {
  166.                 // This weapon is promoting, so click the button
  167.                 robot.keyPress(upgradeKeys[i]);
  168.                 robot.keyRelease(upgradeKeys[i]);
  169.                 promoting = true;  // There may not have been enough gold, so this cancels the rest of the weapon upgrades
  170.             }
  171.         }
  172.    
  173.         // One of the weapons may be waiting for a promotion, so don't level any others
  174.         if(promoting)
  175.         {
  176.             return;
  177.         }
  178.        
  179.         // Upgrade all the weapons
  180.         robot.keyPress(KeyEvent.VK_A);
  181.         robot.keyRelease(KeyEvent.VK_A);
  182.         robot.keyPress(KeyEvent.VK_S);
  183.         robot.keyRelease(KeyEvent.VK_S);
  184.         robot.keyPress(KeyEvent.VK_D);
  185.         robot.keyRelease(KeyEvent.VK_D);
  186.         robot.keyPress(KeyEvent.VK_F);
  187.         robot.keyRelease(KeyEvent.VK_F);
  188.         robot.keyPress(KeyEvent.VK_G);
  189.         robot.keyRelease(KeyEvent.VK_G);
  190.     }
  191.    
  192.     static Color brown = new Color(49, 0, 0);
  193.    
  194.     static int x;
  195.     static int y;
  196.    
  197.     public static void click()
  198.     {
  199.        
  200.         BufferedImage screen = robot.createScreenCapture(new Rectangle(500, 250, 400, 400));
  201.         int color = 0;
  202.        
  203.         // Check the color of the point last clicked
  204.         // try/catch is needed to catch out of bounds exception
  205.         try
  206.         {
  207.             color = screen.getRGB(x, y);
  208.         } catch(Exception e)
  209.         {}
  210.        
  211.         // Loop through points on the screen looking for the correct color brown
  212.         // or is a time cube (time cubes pulse, so there isn't just one color)
  213.         // The first position checked is the last point clicked, if there is no
  214.         // cube there, check up to 400 random points.
  215.         int count = 0;
  216.         while(color != brown.getRGB() && !isTimeCube(color))
  217.         {
  218.             count++;
  219.             if(count > 400)
  220.                 break;
  221.            
  222.             x = (int) (Math.random() * 400);
  223.             y = (int) (Math.random() * 400);
  224.            
  225.             color = screen.getRGB(x, y);
  226.         }
  227.        
  228.         robot.mouseMove(500 + x, 250 + y);
  229.         robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
  230.         robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
  231.     }
  232.  
  233.    
  234.     // Time cubes background color pulses between (0, 0, 0) and (100, 0, 0) so look for a color in that range
  235.     public static boolean isTimeCube(int color)
  236.     {
  237.         Color c = new Color(color);
  238.        
  239.         // Some stages backgrounds has a red color that matches this, on those stages comment out the code and just put return false
  240.         // Unfortunately this isn't something the code is designed to handle and has to be manually done, it could be run with
  241.         // "return false" all the time without loosing too much efficiency
  242.         //return false;
  243.         return c.getRed() > 0 && c.getRed() < 100 && c.getBlue() == 0 && c.getGreen() == 0;
  244.     }
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement