This commit is contained in:
Nabtrap 2017-10-02 13:56:31 +00:00 committed by GitHub
commit e56093458d
3 changed files with 43 additions and 46 deletions

View File

@ -37,9 +37,7 @@ public class Clicker implements Runnable{
private final int waittime = 50;//time between mouse teleports and clicks private final int waittime = 50;//time between mouse teleports and clicks
private int mincolordistance = 35; private int mincolordistance = 35;
OSType os; OSType os;
long started = -1; long started = -1;
private void sleep( int ms) { private void sleep( int ms) {
@ -57,15 +55,14 @@ public class Clicker implements Runnable{
while(paused & should_run) { while(paused & should_run) {
Thread.sleep(75); Thread.sleep(75);
} }
} catch (InterruptedException e) { } //when skip is applyed, or the bot gets stopped } catch (InterruptedException e) { } //when skip is applied, or the bot gets stopped
} }
public void start() { public void start() {
should_run = true; should_run = true;
if(!running) { if(!running) {
running = true; running = true;
thread = new Thread(this, "BOT"); (thread = new Thread(this, "BOT")).start();;
thread.start();
started = System.currentTimeMillis(); started = System.currentTimeMillis();
} }
} }
@ -74,7 +71,7 @@ public class Clicker implements Runnable{
should_run = false; should_run = false;
skipbattle = true; skipbattle = true;
while(running) { while(running) {
thread.interrupt();//stop that shit (its maybe sleeping) thread.interrupt();//stop that shit (its maybe sleepin)
} }
} }
@ -82,7 +79,7 @@ public class Clicker implements Runnable{
if(isRunning()) if(isRunning())
if(inbattle) if(inbattle)
skipbattle = true; skipbattle = true;
thread.interrupt(); thread.interrupt(); //Stop
} }
public boolean isRunning() { public boolean isRunning() {
@ -91,29 +88,29 @@ public class Clicker implements Runnable{
@Override @Override
public void run() { public void run() {
sleep(1000);//chill ma sleep(1000);//chill for a second.
//determine os //determine os
String oss = System.getProperty("os.name").toLowerCase(); String ostype = System.getProperty("os.name").toLowerCase();
if(oss.contains("nix") | oss.contains("nux") | oss.contains("aix")) if(ostype.contains("nix") | ostype.contains("nux") | ostype.contains("aix"))
os = OSType.Linux; os = OSType.Linux;
else if(oss.contains("win")) else if(ostype.contains("win"))
os = OSType.Windows; os = OSType.Windows;
else if(oss.contains("mac")) else if(ostype.contains("mac"))
os = OSType.OSX; os = OSType.OSX;
else else
Main.get().ui.info("OS not supported for backfocus: " + oss); Main.get().ui.info("OS not supported for backfocus: " + ostype);
int card = 0; int card = 0;
try { try {
Robot rob = new Robot(); Robot rob = new Robot();
while(should_run) { while(should_run) {
sleep(500); sleep(500);
clickL(rob, battle);//smash the start button clickL(rob, battle);//click the start button
sleep(1000); sleep(1000);
clickL(rob, battle);//press start again (if there is an alert poping up) clickL(rob, battle);//Press again (in case of alert).
backfocus(rob); backfocus(rob);
//battle is starting up // Start of battle
sleep(9000);//wait for the battle to start (loading screen) sleep(9000);//wait for the battle to start (loading screen)
Main.get().ui.info("Battle started."); Main.get().ui.info("Battle started.");
inbattle = true; inbattle = true;
@ -122,8 +119,8 @@ public class Clicker implements Runnable{
long lastwait = start;//actions like moving mouse and do stuff gets messured and subtracted of the wait's long lastwait = start;//actions like moving mouse and do stuff gets messured and subtracted of the wait's
while( ((System.currentTimeMillis() - start) / 6000) < 41 & should_run & !skipbattle) { while( ((System.currentTimeMillis() - start) / 6000) < 41 & should_run & !skipbattle) {
//check r ok-button //check for ok-button
if(round(start) > 20) {//game is older then 20 seconds if(round(start) > 20) {//game is older than 20 seconds
if(checkOK(end, rob,ok_button)) {//check if(checkOK(end, rob,ok_button)) {//check
Main.get().ui.info("OK-button detected!"); Main.get().ui.info("OK-button detected!");
skipbattle = true; skipbattle = true;
@ -145,11 +142,11 @@ public class Clicker implements Runnable{
if(round(start) >= 115) //game older than 2 minutes -> speed the playout process up! if(round(start) >= 115) //game older than 2 minutes -> speed the playout process up!
modifier = 2; modifier = 2;
else if(round(start) >= (115 - (truppenwait / 2))) //remove half waittime and do half speed. else if(round(start) >= (115 - (truppenwait / 2))) //remove half of the waiting time and do half speed.
modifier = 1.5f; modifier = 1.5f;
// eingestellter wert (0.1 sec) ggf. durch 2 teilen vergangene zeit abziehen (zeit fürs setztem der letzten truppen) // eingestellter wert (0.1 sec) ggf. durch 2 teilen vergangene zeit abziehen (zeit fürs setztem der letzten truppen) / Some calculation...
int waittime = ( (int) (((truppenwait * 100) / modifier) - (System.currentTimeMillis()- lastwait)) );//how long to wait? int waittime = ( (int) (((truppenwait * 100) / modifier) - (System.currentTimeMillis()- lastwait)) );//how long to wait?
Main.get().ui.info("Waiting for: " + (waittime / 1000) + "s"); Main.get().ui.info("Waiting for: " + (waittime / 1000) + "seconds");
while (waittime > 1500 & !skipbattle & should_run) {//check for the ok-button every 3 seconds while (waittime > 1500 & !skipbattle & should_run) {//check for the ok-button every 3 seconds
long startwait = System.currentTimeMillis();//record needed time long startwait = System.currentTimeMillis();//record needed time
if(checkOK(end, rob, ok_button)) {//check if(checkOK(end, rob, ok_button)) {//check
@ -158,7 +155,7 @@ public class Clicker implements Runnable{
break; break;
} }
sleep((int) (1500 - (System.currentTimeMillis() - startwait)));//sleep the rest of 3 seconds, that was not gone for checking sleep((int) (1500 - (System.currentTimeMillis() - startwait)));//sleep the rest of 3 seconds, that was not gone for checking
waittime = (int) (waittime - (System.currentTimeMillis() - startwait));//calculate waittime that is left waittime = (int) (waittime - (System.currentTimeMillis() - startwait));//calculate waiting time that's left
} }
sleep(waittime);//wait sleep(waittime);//wait
@ -184,7 +181,7 @@ public class Clicker implements Runnable{
running= false;//remove the running flag running= false;//remove the running flag
} }
private float round(long start) {//returns how old the round is in 0.1 seconds private float round(long start) {//returns how old the round is in 0.1 second
return ((System.currentTimeMillis() - start) / 1000); return ((System.currentTimeMillis() - start) / 1000);
} }
@ -298,7 +295,7 @@ public class Clicker implements Runnable{
sleep(50); sleep(50);
} }
private void clickL(Robot b) {//40 ms delay private void clickL(Robot b) {//40 milli seconds delay
b.mousePress(InputEvent.BUTTON1_MASK); b.mousePress(InputEvent.BUTTON1_MASK);
sleep(waittime); sleep(waittime);
b.mouseRelease(InputEvent.BUTTON1_MASK); b.mouseRelease(InputEvent.BUTTON1_MASK);
@ -328,7 +325,7 @@ public class Clicker implements Runnable{
for (int y = 0; y < 20; y++) { for (int y = 0; y < 20; y++) {
int color = img.getRGB(x, y); int color = img.getRGB(x, y);
int red = (color & 0x00ff0000) >> 16; int red = (color & 0x00ff0000) >> 16;
int green = (color & 0x0000ff00) >> 8; int green = (color & 0x0000ff00) >> 8; // WTF DUDE
int blue = color & 0x000000ff; int blue = color & 0x000000ff;
double distance = Math.sqrt(Math.pow((blue - goalcolor.getBlue()), 2) double distance = Math.sqrt(Math.pow((blue - goalcolor.getBlue()), 2)
+ Math.pow((red - goalcolor.getRed()), 2) + Math.pow((green - goalcolor.getGreen()), 2));//calculate the distance between the goalcolor and the test color + Math.pow((red - goalcolor.getRed()), 2) + Math.pow((green - goalcolor.getGreen()), 2));//calculate the distance between the goalcolor and the test color
@ -381,17 +378,17 @@ public class Clicker implements Runnable{
public boolean isPaused() { public boolean isPaused() {
return paused; return this.paused;
} }
public void setPause(boolean b) { public void setPause(boolean b) {
paused = b; this.paused = b;
} }
private enum OSType { private enum OSType {
Linux, Linux,
Windows, Windows,
OSX, OSX,
unsupported Unsupported
} }
} }

View File

@ -25,7 +25,7 @@ public class PosColSelector extends PosSelector {
Robot rob = new Robot(); Robot rob = new Robot();
Point p = ui.bot.getMouse(); Point p = ui.bot.getMouse();
BufferedImage img = rob.createScreenCapture(new Rectangle(p.x-10, p.y-10, 20, 20)); BufferedImage img = rob.createScreenCapture(new Rectangle(p.x-10, p.y-10, 20, 20));
//calculate avg color; //calculate average color;
int red = 0; int red = 0;
int green = 0; int green = 0;
int blue = 0; int blue = 0;

View File

@ -30,7 +30,7 @@ public class UI implements ActionListener {
private boolean isSelectionRunning = false; //true if an selection Thread is working, private boolean isSelectionRunning = false; //true if an selection Thread is working,
private JFrame frame = new JFrame("Clash Royale Bot · by MrBesen");; private JFrame frame = new JFrame("Clash Royale Bot by MrBesen");;
private JPanel root = new JPanel(); private JPanel root = new JPanel();
private JPanel top = new JPanel(); private JPanel top = new JPanel();
@ -120,7 +120,7 @@ public class UI implements ActionListener {
top.add(poss.button); top.add(poss.button);
} }
middle.add(start);//construct button paneö middle.add(start);//construct button panel
middle.add(skip); middle.add(skip);
middle.add(pause); middle.add(pause);
middle.add(exit); middle.add(exit);
@ -136,7 +136,7 @@ public class UI implements ActionListener {
bottom.add(Box.createRigidArea(new Dimension(150, 5))); bottom.add(Box.createRigidArea(new Dimension(150, 5)));
bottom.add(time); bottom.add(time);
root.add(top);//add every pannel root.add(top);//add every panel
root.add(middle); root.add(middle);
root.add(sliderpanel); root.add(sliderpanel);
root.add(bottom); root.add(bottom);
@ -151,7 +151,7 @@ public class UI implements ActionListener {
if(src instanceof JButton) { if(src instanceof JButton) {
JButton srcb = (JButton) src; JButton srcb = (JButton) src;
//check for the Posselectors //check for the Position selectors
for(PosSelector poss : posselctors) { for(PosSelector poss : posselctors) {
if(poss.button.equals(srcb)) { if(poss.button.equals(srcb)) {
if(!isSelectionRunning) if(!isSelectionRunning)
@ -219,7 +219,7 @@ public class UI implements ActionListener {
if(!split[1].equals("null")) { if(!split[1].equals("null")) {
int num = Integer.parseInt(split[0]); int num = Integer.parseInt(split[0]);
if(num > 100) {//special settings (slider / checkboxes) if(num > 100) {//special settings (slider / checkboxes)
if(num == 101) {//truppenwait if(num == 101) {//group wait
int wait = Integer.parseInt(split[1]); int wait = Integer.parseInt(split[1]);
slider[0].setValue(wait); slider[0].setValue(wait);
} else if(num == 102) { // double playout } else if(num == 102) { // double playout
@ -237,14 +237,14 @@ public class UI implements ActionListener {
Color c = new Color(Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3])); Color c = new Color(Integer.parseInt(split[1]), Integer.parseInt(split[2]), Integer.parseInt(split[3]));
bot.setColor(c, 0,35); bot.setColor(c, 0,35);
} }
} else //standard Point Obj. } else //standard Point object.
bot.set(new Point(split[1]), num); bot.set(new Point(split[1]), num);
} }
} }
s.close(); s.close();
refresh(); refresh();
if(info) if(info)
info("loaded!"); info("Loaded!");
} catch(IOException | NumberFormatException e) { } catch(IOException | NumberFormatException e) {
e.printStackTrace(); e.printStackTrace();
if(info) if(info)
@ -264,7 +264,7 @@ public class UI implements ActionListener {
cancel = 2*/ cancel = 2*/
int choose = JOptionPane.showConfirmDialog(null, "You are going to override the old profile!", "Override", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); int choose = JOptionPane.showConfirmDialog(null, "You are going to override the old profile!", "Override", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
if(choose == 2) { if(choose == 2) {
info("canceled."); info("Canceled.");
return; return;
} }
@ -275,7 +275,7 @@ public class UI implements ActionListener {
fw.flush(); fw.flush();
fw.close(); fw.close();
info("saved!"); info("Saved!");
} catch(IOException e) { } catch(IOException e) {
e.printStackTrace(); e.printStackTrace();
info("Error."); info("Error.");
@ -409,13 +409,13 @@ public class UI implements ActionListener {
private int offset; private int offset;
/** /**
* @param prefix the text of the Label * @param prefix the text of the Label
* @param sufix thge text of the Label * @param suffix thge text of the Label
* @param minvalue start vlaue * @param minvalue start value
* @param maxvalue last value * @param maxvalue last value
* @param startvalue inital value * @param startvalue initial value
* @param komma 10^x offset for komma digits * @param comma 10^x offset for comma digits
*/ */
public Slider(String prefix, String sufix, int minvalue, int maxvalue, int startvalue, int komma, @Nullable ChangeListener cl,@Nullable Updater upd, boolean enabled) {//ChangeListener or Updater could be Null! public Slider(String prefix, String suffix, int minvalue, int maxvalue, int startvalue, int comma, @Nullable ChangeListener cl,@Nullable Updater upd, boolean enabled) {//ChangeListener or Updater could be Null!
slider = new JSlider(minvalue, maxvalue, startvalue); slider = new JSlider(minvalue, maxvalue, startvalue);
slider.addChangeListener(this); slider.addChangeListener(this);
if(prefix != null) if(prefix != null)
@ -423,7 +423,7 @@ public class UI implements ActionListener {
if(sufix != null) { if(sufix != null) {
this.sufix = sufix; this.sufix = sufix;
} }
offset = komma; offset = comma;
label = new JLabel(getLabelText()); label = new JLabel(getLabelText());
add(slider); add(slider);
add(label); add(label);
@ -453,9 +453,9 @@ public class UI implements ActionListener {
@Override @Override
public void stateChanged(ChangeEvent e) { public void stateChanged(ChangeEvent e) {
label.setText(getLabelText());//update info label.setText(getLabelText());//update information
if(listener != null) if(listener != null)
listener.stateChanged(e);//forward Event listener.stateChanged(e);//forward event
if(updater != null) if(updater != null)
updater.update(slider.getValue()); updater.update(slider.getValue());
} }