Updated main loop to use a while loop instead, added full try{}catch()

block. Added proper threading on displays and force updating of fields.
secondmonitor
sigonasr2 5 years ago
parent 6eee74a868
commit f6c627f3c1
  1. BIN
      DivaBot/DivaBot.jar
  2. 8
      DivaBot/calibration_data.txt
  3. BIN
      DivaBot/capture.png
  4. BIN
      DivaBot/capture_2.png
  5. BIN
      DivaBot/capture_3.png
  6. BIN
      DivaBot/capture_4.png
  7. BIN
      DivaBot/capture_5.png
  8. 2
      DivaBot/config.txt
  9. 4
      DivaBot/src/sig/Calibrator.java
  10. 48
      DivaBot/src/sig/Display.java
  11. 10
      DivaBot/src/sig/DrawCanvas.java
  12. 581
      DivaBot/src/sig/MyRobot.java

Binary file not shown.

@ -1,4 +1,4 @@
768 746
504 577
1548 1527
940 1014

Binary file not shown.

Before

Width:  |  Height:  |  Size: 531 KiB

After

Width:  |  Height:  |  Size: 536 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 531 KiB

After

Width:  |  Height:  |  Size: 535 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 530 KiB

After

Width:  |  Height:  |  Size: 534 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 530 KiB

After

Width:  |  Height:  |  Size: 534 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 528 KiB

After

Width:  |  Height:  |  Size: 529 KiB

@ -1,4 +1,4 @@
DISPLAYDATA -16776961*-13369549*100*Gungsuh*600*90*300*Song Title (Japanese+Romanized)*176*136*~-16776961*-13369549*24*Gulim*400*40*300*Overall Rating|Song Title (Romanized)|FC Count*176*240* DISPLAYDATA -16776961*-13369549*100*Gungsuh*600*90*5000*Song Title (Japanese+Romanized)*176*136*~-16776961*-13369549*24*Gulim*400*40*300*Overall Rating|Song Title (Romanized)|FC Count*176*240*~-16776961*-13369549*24*Gulim*400*40*300*Best Play*0*0*
LAST_HEIGHT 40 LAST_HEIGHT 40
WIDTH 1127 WIDTH 1127
HEIGHT 765 HEIGHT 765

@ -63,6 +63,8 @@ public class Calibrator{
MyRobot.FRAME.setCursor(Cursor.getDefaultCursor()); MyRobot.FRAME.setCursor(Cursor.getDefaultCursor());
Overlay.started=false; Overlay.started=false;
MyRobot.FRAME.setAlwaysOnTop(false);
Overlay.OVERLAY.setVisible(true);
if (((float)(MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x)/(MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y))<=16/9f-0.04|| if (((float)(MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x)/(MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y))<=16/9f-0.04||
((float)(MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x)/(MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y))>=16/9f+0.04) { ((float)(MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x)/(MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y))>=16/9f+0.04) {
int dialogResult = JOptionPane.showConfirmDialog (null, "Could not detect Megamix properly!\n\nYour calibration cut a bit "+((((float)(MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x)/(MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y))<=16/9f-0.04)?"more":"less")+" than expected. Do you want to try selecting a more accurate region?","Warning",JOptionPane.YES_NO_OPTION); int dialogResult = JOptionPane.showConfirmDialog (null, "Could not detect Megamix properly!\n\nYour calibration cut a bit "+((((float)(MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x)/(MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y))<=16/9f-0.04)?"more":"less")+" than expected. Do you want to try selecting a more accurate region?","Warning",JOptionPane.YES_NO_OPTION);
@ -74,7 +76,7 @@ public class Calibrator{
return; return;
} }
} }
Overlay.OVERLAY.setVisible(true); MyRobot.FRAME.setAlwaysOnTop(true);
// failed=CalibrationStage3(p); // failed=CalibrationStage3(p);
// if (failed) {return;} // if (failed) {return;}

@ -20,6 +20,8 @@ public class Display {
int width=200; int width=200;
int height=48; int height=48;
int delay=10000; int delay=10000;
long nextUpdateTime = System.currentTimeMillis();
boolean forceUpdate=false;
String[] labels; String[] labels;
String currentText; String currentText;
int cycle=0; int cycle=0;
@ -101,10 +103,17 @@ public class Display {
public void run() { public void run() {
try { try {
while (!deleted) { while (!deleted) {
AdvanceCycle(); if (System.currentTimeMillis()>nextUpdateTime) {
updateFont(); if (!forceUpdate) {
MyRobot.p.repaint(); AdvanceCycle();
Thread.sleep(delay); }
updateFont();
currentText=interpretLabel(labels[cycle]);
MyRobot.p.repaint();
nextUpdateTime=System.currentTimeMillis()+delay;
forceUpdate=false;
}
Thread.sleep(50);
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
@ -205,19 +214,40 @@ public class Display {
return (data.songname + " - " + ((data.romanizedname.length()>0)?(data.romanizedname.equalsIgnoreCase(data.englishname))?data.romanizedname:data.romanizedname+" ("+data.englishname+")":data.englishname)) + " by "+data.artist; return (data.songname + " - " + ((data.romanizedname.length()>0)?(data.romanizedname.equalsIgnoreCase(data.englishname))?data.romanizedname:data.romanizedname+" ("+data.englishname+")":data.englishname)) + " by "+data.artist;
} }
case "Play Count":{ case "Play Count":{
return Integer.toString(data.plays)+" play"+((data.plays!=1)?"s":""); if (data.plays>0) {
return Integer.toString(data.plays)+" play"+((data.plays!=1)?"s":"");
} else {
return "No Plays";
}
} }
case "Pass/Play Count":{ case "Pass/Play Count":{
return Integer.toString(data.passes) + "/" + Integer.toString(data.plays)+" play"+((data.plays!=1)?"s":""); if (data.plays>0) {
return Integer.toString(data.passes) + "/" + Integer.toString(data.plays)+" play"+((data.plays!=1)?"s":"");
}
else {
return "No Plays";
}
} }
case "Pass/Play Count (+%)":{ case "Pass/Play Count (+%)":{
return (data.passes)+"/"+(data.plays)+" play"+((data.plays!=1)?"s":"")+" "+"("+((int)(Math.floor(((float)data.passes)/data.plays*100)))+"% pass rate)"; if (data.plays>0) {
return (data.passes)+"/"+(data.plays)+" play"+((data.plays!=1)?"s":"")+" "+"("+((int)(Math.floor(((float)data.passes)/data.plays*100)))+"% pass rate)";
} else {
return "No Plays";
}
} }
case "FC Count":{ case "FC Count":{
return data.fcCount +" FC"+(data.fcCount==1?"":"s"); if (data.plays>0) {
return data.fcCount +" FC"+(data.fcCount==1?"":"s");
} else {
return "No Plays";
}
} }
case "FC Count (+%)":{ case "FC Count (+%)":{
return data.fcCount +" FC"+(data.fcCount==1?"":"s")+" "+((int)(Math.floor(((float)data.fcCount)/data.plays*100)))+"% FC rate"; if (data.plays>0) {
return data.fcCount +" FC"+(data.fcCount==1?"":"s")+" "+((int)(Math.floor(((float)data.fcCount)/data.plays*100)))+"% FC rate";
} else {
return "No Plays";
}
} }
default:{ default:{
return string; return string;

@ -80,7 +80,7 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
boolean targetBuffer=false; boolean targetBuffer=false;
static Color background = new Color(170,170,170); static Color background = new Color(170,170,170);
public static HashMap<String,String> configData = new HashMap<String,String>(); public static HashMap<String,String> configData = new HashMap<String,String>();
List<Display> displays = new ArrayList<Display>(); static List<Display> displays = new ArrayList<Display>();
public static Display selectedDisplay = null; public static Display selectedDisplay = null;
public static Display draggedDisplay = null; public static Display draggedDisplay = null;
DrawCanvas() throws FontFormatException, IOException { DrawCanvas() throws FontFormatException, IOException {
@ -103,6 +103,13 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
t.start(); t.start();
} }
public static void refreshAllLabels() {
for (Display d : displays) {
d.forceUpdate=true;
d.nextUpdateTime=System.currentTimeMillis()-1;
}
}
public void pullData(final String songname,final String difficulty) { public void pullData(final String songname,final String difficulty) {
this.songname=(songname.equalsIgnoreCase("PIANOGIRL")?"PIANO*GIRL":(songname.equalsIgnoreCase("16 -out of the gravity-"))?"1/6 -out of the gravity-":songname); this.songname=(songname.equalsIgnoreCase("PIANOGIRL")?"PIANO*GIRL":(songname.equalsIgnoreCase("16 -out of the gravity-"))?"1/6 -out of the gravity-":songname);
this.difficulty=difficulty; this.difficulty=difficulty;
@ -162,6 +169,7 @@ public class DrawCanvas extends JPanel implements KeyListener,ComponentListener,
} }
scrollX = 0;*/ scrollX = 0;*/
MyRobot.p.repaint(); MyRobot.p.repaint();
MyRobot.p.refreshAllLabels();
} }
} }
} catch (JSONException | IOException e) { } catch (JSONException | IOException e) {

@ -162,7 +162,7 @@ public class MyRobot{
public static String USERNAME = ""; public static String USERNAME = "";
public static String AUTHTOKEN = ""; public static String AUTHTOKEN = "";
public static ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); public static long lastmainlooptime = 0;
public static void main(String[] args) throws JSONException, IOException, FontFormatException { public static void main(String[] args) throws JSONException, IOException, FontFormatException {
@ -266,315 +266,322 @@ public class MyRobot{
} }
void BotMain() { void BotMain() {
lastmainlooptime=System.currentTimeMillis();
while (true) {
try {
RunMainLoop();
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private void RunMainLoop() {
try {
try { try {
JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/"+USERNAME); JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/"+USERNAME);
p.lastRating = p.overallrating; p.lastRating = p.overallrating;
p.overallrating = (int)obj.getDouble("rating"); if (obj.has("rating")) {
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();} p.overallrating = (int)obj.getDouble("rating");
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
}
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
Timer t = new Timer(); if (CALIBRATION_MODE) {
t.scheduleAtFixedRate(new TimerTask() { if (MyRobot.calibrating) {
@Override MyRobot.calibrating=false;
public void run() { Overlay.OVERLAY.setVisible(false);
try { Thread.sleep(1000);
if (CALIBRATION_MODE) { Calibrator c = new Calibrator();
if (MyRobot.calibrating) { }
MyRobot.calibrating=false; } else {
Overlay.OVERLAY.setVisible(false); //ImageIO.write(MYROBOT.createScreenCapture(),"png",new File("testscreen.png"));
Thread.sleep(1000); if (checkSongSelect()) {
Calibrator c = new Calibrator(); if (!overlayHidden) {
} overlayHidden=true;
} else { MyRobot.p.repaint();
//ImageIO.write(MYROBOT.createScreenCapture(),"png",new File("testscreen.png")); }
if (checkSongSelect()) { GetCurrentSong();
if (!overlayHidden) { GetCurrentDifficulty();
overlayHidden=true; recordedResults=false;
MyRobot.p.repaint(); if (selectedSong!=null && difficulty!=null) {
} if (!prevSongTitle.equalsIgnoreCase(selectedSong.title) || !prevDifficulty.equalsIgnoreCase(difficulty)) {
GetCurrentSong(); System.out.println("On Song Select Screen: Current Song-"+selectedSong.title+" Diff:"+difficulty);
GetCurrentDifficulty(); MyRobot.p.refreshAllLabels();
recordedResults=false; p.pullData(selectedSong.title,difficulty);
if (selectedSong!=null && difficulty!=null) { prevSongTitle=selectedSong.title;
if (!prevSongTitle.equalsIgnoreCase(selectedSong.title) || !prevDifficulty.equalsIgnoreCase(difficulty)) { prevDifficulty=difficulty;
System.out.println("On Song Select Screen: Current Song-"+selectedSong.title+" Diff:"+difficulty); MyRobot.p.repaint();
p.pullData(selectedSong.title,difficulty); MYROBOT.keyPress(KeyEvent.VK_CONTROL);
prevSongTitle=selectedSong.title; MYROBOT.keyPress(KeyEvent.VK_SHIFT);
prevDifficulty=difficulty; MYROBOT.keyPress(KeyEvent.VK_F11);
MyRobot.p.repaint(); MYROBOT.keyRelease(KeyEvent.VK_F11);
MYROBOT.keyPress(KeyEvent.VK_CONTROL); MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_SHIFT); MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
}
}
lastSongSelectTime = System.currentTimeMillis();
} else {
if (overlayHidden) {
overlayHidden=false;
MyRobot.p.repaint();
}
if ((selectedSong!=null && difficulty!=null)) {
if (OnResultsScreen() && !recordedResults && !recordingResults && results.size()==0) {
lastSongSelectTime=System.currentTimeMillis();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
Thread.sleep(200);
MYROBOT.refreshScoreScreen();
ImageIO.write(MYROBOT.createScoreScreenCapture(),"png",new File("scoreimage.png"));
File tmp = new File("tmp");
if (tmp.exists()) {
FileUtils.deleteFile(tmp);
} else {
tmp.mkdir();
}
try {
Result data = typeface1.getAllData(MYROBOT.createScoreScreenCapture());
System.out.println(data);
//ImageIO.write(MYROBOT.,"png",new File("test.png"));
if (data.cool==-1 || data.fine==-1 || data.safe==-1 || data.sad==-1 || data.worst==-1 || data.percent<0f || data.percent>110f || data.combo==-1 || data.score==-1) {
System.out.println("Waiting for results to populate...");
} else
if ((data.combo!=lastcombo || data.fail!=lastfail || data.cool!=lastcool || lastfine!=data.fine || lastsafe!=data.safe || lastsad!=data.sad || lastworst!=data.worst)
&& data.score!=lastscore /*|| lastpercent!=percent*/){
//System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+data.cool+"/"+data.fine+"/"+data.safe+"/"+data.sad+"/"+data.worst+" "+data.percent+"%");
System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+data.display());
File songFolder = new File(selectedSong.title+"/"+difficulty);
if (!songFolder.exists()) {
songFolder.mkdirs();
}
File[] songFolderFiles = songFolder.listFiles();
int playId = songFolderFiles.length;
File playFolder = new File(selectedSong.title+"/"+difficulty+"/"+playId);
playFolder.mkdir();
recordedResults=true;
lastcool=data.cool;
lastfine=data.fine;
lastsafe=data.safe;
lastsad=data.sad;
lastworst=data.worst;
lastpercent=data.percent;
lastcombo=data.combo;
lastscore=data.score;
lastfail=data.fail;
new File("scoreimage.png").renameTo(new File(playFolder,selectedSong.title+"_"+difficulty+"play_"+data.cool+"_"+data.fine+"_"+data.safe+"_"+data.sad+"_"+data.worst+"_"+data.percent+""
+ "_"+data.combo+"_"+data.score+".png"));
results.add(new Result(selectedSong.title,difficulty,data.cool,data.fine,data.safe,data.sad,data.worst,data.percent,data.mod,data.combo,data.score,data.fail));
SoundUtils.playSound("collect_item.wav");
//gotoxy(800,64);
//click();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
}
} catch (IOException|NumberFormatException|IndexOutOfBoundsException e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
} else {
if (results.size()>0) {
recordingResults=true;
for (Result r : results) {
r.songName=r.songName.equalsIgnoreCase("PIANOGIRL")?"PIANO*GIRL":(r.songName.equalsIgnoreCase("16 -out of the gravity-"))?"1/6 -out of the gravity-":r.songName;
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://45.33.13.215:4501/submit");
// Request parameters and other properties.
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("song", r.songName));
params.add(new BasicNameValuePair("username", USERNAME));
params.add(new BasicNameValuePair("authentication_token", AUTHTOKEN));
params.add(new BasicNameValuePair("difficulty", r.difficulty));
params.add(new BasicNameValuePair("cool", Integer.toString(r.cool)));
params.add(new BasicNameValuePair("fine", Integer.toString(r.fine)));
params.add(new BasicNameValuePair("safe", Integer.toString(r.safe)));
params.add(new BasicNameValuePair("sad", Integer.toString(r.sad)));
params.add(new BasicNameValuePair("worst", Integer.toString(r.worst)));
params.add(new BasicNameValuePair("percent", Float.toString(r.percent)));
params.add(new BasicNameValuePair("fail", Boolean.toString(r.fail)));
params.add(new BasicNameValuePair("mod", r.mod));
params.add(new BasicNameValuePair("combo", Integer.toString(r.combo)));
params.add(new BasicNameValuePair("gameScore", Integer.toString(r.score)));
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
//Execute and get the response.
HttpResponse response = null;
try {
response = httpclient.execute(httppost);
} catch (IOException e) {
e.printStackTrace();
}
HttpEntity entity = response.getEntity();
if (entity != null) {
try (InputStream instream = entity.getContent()) {
Scanner s = new Scanner(instream).useDelimiter("\\A");
String result = s.hasNext() ? s.next() : "";
System.out.println(result);
instream.close();
} catch (UnsupportedOperationException | IOException e) {
e.printStackTrace();
}
}
}
results.clear();
try {
JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/"+USERNAME);
JSONObject obj2 = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/bestplay/"+USERNAME+"/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
p.lastRating = p.overallrating;
if (obj2.has("score")) {
double newScore = obj2.getDouble("score");
if (newScore>p.lastScore) {
p.bestPlayTime=System.currentTimeMillis();
}
p.lastScore = newScore;
}
p.overallrating = (int)obj.getDouble("rating");
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
p.pullData(selectedSong.title, difficulty);
} catch (JSONException | IOException e) {
e.printStackTrace();
}
recordingResults=false;
}
if (!OnResultsScreen() && recordedResults) {
recordedResults=false;
}
}
}
}
MYROBOT.refreshScreen();
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
} }
}
private boolean OnResultsScreen() throws IOException { lastSongSelectTime = System.currentTimeMillis();
//r.x-418, r.y-204 } else {
/*ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)),"png",new File("color1.png")); if (overlayHidden) {
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,196,40,40)),"png",new File("color2.png")); overlayHidden=false;
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)),"png",new File("color3.png"));*/ MyRobot.p.repaint();
Color c1 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)).getRGB(0, 0)); }
Color c2 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,196,40,40)).getRGB(0, 0)); if ((selectedSong!=null && difficulty!=null)) {
Color c3 = new Color(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)).getRGB(0, 0)); if (OnResultsScreen() && !recordedResults && !recordingResults && results.size()==0) {
//System.out.println(c1+"/"+c2+"/"+c3); lastSongSelectTime=System.currentTimeMillis();
return c1.getRed()>=250 && c1.getGreen()>=250 && c1.getBlue()>=250 && c2.getRed()>=10 && c2.getRed()<=25 && c2.getGreen()>=200 && c2.getGreen()<=240 && c2.getBlue()>=180 && c2.getBlue()<=220 && MYROBOT.setAutoDelay(0);
c3.getRed()>=200 && c3.getRed()<=255 && c3.getGreen()>=200 && c3.getGreen()<=255 && c3.getBlue()>=140 && c3.getBlue()<=220; MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_F12);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
Thread.sleep(200);
MYROBOT.refreshScoreScreen();
ImageIO.write(MYROBOT.createScoreScreenCapture(),"png",new File("scoreimage.png"));
File tmp = new File("tmp");
if (tmp.exists()) {
FileUtils.deleteFile(tmp);
} else {
tmp.mkdir();
} }
try {
private void GetCurrentDifficulty() { Result data = typeface1.getAllData(MYROBOT.createScoreScreenCapture());
Color c = new Color(MYROBOT.createScreenCapture(new Rectangle(320,274,10,10)).getRGB(0, 0)); System.out.println(data);
//return c.getRed()==43 && c.getGreen()==88 && c.getBlue()==213; //ImageIO.write(MYROBOT.,"png",new File("test.png"));
if (c.getRed()>100 && c.getRed()<200 && c.getBlue()>200 && c.getBlue()<255 && c.getGreen()<50) { if (data.cool==-1 || data.fine==-1 || data.safe==-1 || data.sad==-1 || data.worst==-1 || data.percent<0f || data.percent>110f || data.combo==-1 || data.score==-1) {
difficulty="EXEX"; System.out.println("Waiting for results to populate...");
} else
if (c.getRed()>150 && c.getRed()<255 && c.getBlue()<50 && c.getGreen()<50) {
difficulty="EX";
} else
if (c.getRed()>175 && c.getRed()<225 && c.getBlue()<50 && c.getGreen()<175 && c.getGreen()>135) {
difficulty="H";
} else
if (c.getRed()>0 && c.getRed()<50 && c.getBlue()<50 && c.getGreen()<255 && c.getGreen()>190) {
difficulty="N";
} else } else
if (c.getRed()>0 && c.getRed()<50 && c.getBlue()>170 && c.getBlue()<230 && c.getGreen()<190 && c.getGreen()>150) { if ((data.combo!=lastcombo || data.fail!=lastfail || data.cool!=lastcool || lastfine!=data.fine || lastsafe!=data.safe || lastsad!=data.sad || lastworst!=data.worst)
difficulty="E"; && data.score!=lastscore /*|| lastpercent!=percent*/){
//System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+data.cool+"/"+data.fine+"/"+data.safe+"/"+data.sad+"/"+data.worst+" "+data.percent+"%");
System.out.println("Results for "+selectedSong.title+" "+difficulty+": "+data.display());
File songFolder = new File(selectedSong.title+"/"+difficulty);
if (!songFolder.exists()) {
songFolder.mkdirs();
}
File[] songFolderFiles = songFolder.listFiles();
int playId = songFolderFiles.length;
File playFolder = new File(selectedSong.title+"/"+difficulty+"/"+playId);
playFolder.mkdir();
recordedResults=true;
lastcool=data.cool;
lastfine=data.fine;
lastsafe=data.safe;
lastsad=data.sad;
lastworst=data.worst;
lastpercent=data.percent;
lastcombo=data.combo;
lastscore=data.score;
lastfail=data.fail;
new File("scoreimage.png").renameTo(new File(playFolder,selectedSong.title+"_"+difficulty+"play_"+data.cool+"_"+data.fine+"_"+data.safe+"_"+data.sad+"_"+data.worst+"_"+data.percent+""
+ "_"+data.combo+"_"+data.score+".png"));
results.add(new Result(selectedSong.title,difficulty,data.cool,data.fine,data.safe,data.sad,data.worst,data.percent,data.mod,data.combo,data.score,data.fail));
SoundUtils.playSound("collect_item.wav");
//gotoxy(800,64);
//click();
MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_CONTROL);
MYROBOT.keyPress(KeyEvent.VK_SHIFT);
MYROBOT.keyPress(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_F11);
MYROBOT.keyRelease(KeyEvent.VK_SHIFT);
MYROBOT.keyRelease(KeyEvent.VK_CONTROL);
} }
} catch (IOException|NumberFormatException|IndexOutOfBoundsException e) {
e.printStackTrace();
System.out.println(e.getMessage());
} }
private void GetCurrentSong() throws IOException { } else {
BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(812-10,380-10,WIDTH+20,HEIGHT+20))); if (results.size()>0) {
boolean found=false; recordingResults=true;
LOOP1: for (Result r : results) {
for (int x=0;x<10;x++) { r.songName=r.songName.equalsIgnoreCase("PIANOGIRL")?"PIANO*GIRL":(r.songName.equalsIgnoreCase("16 -out of the gravity-"))?"1/6 -out of the gravity-":r.songName;
for (int y=0;y<10;y++) { HttpClient httpclient = HttpClients.createDefault();
Color[] col = new Color[WIDTH*HEIGHT]; HttpPost httppost = new HttpPost("http://45.33.13.215:4501/submit");
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) { // Request parameters and other properties.
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true); List<NameValuePair> params = new ArrayList<NameValuePair>();
} params.add(new BasicNameValuePair("song", r.songName));
} params.add(new BasicNameValuePair("username", USERNAME));
SongData ss = SongData.compareData(col); params.add(new BasicNameValuePair("authentication_token", AUTHTOKEN));
if (ss!=null) { params.add(new BasicNameValuePair("difficulty", r.difficulty));
selectedSong = ss; params.add(new BasicNameValuePair("cool", Integer.toString(r.cool)));
found=true; params.add(new BasicNameValuePair("fine", Integer.toString(r.fine)));
break LOOP1; params.add(new BasicNameValuePair("safe", Integer.toString(r.safe)));
} params.add(new BasicNameValuePair("sad", Integer.toString(r.sad)));
params.add(new BasicNameValuePair("worst", Integer.toString(r.worst)));
params.add(new BasicNameValuePair("percent", Float.toString(r.percent)));
params.add(new BasicNameValuePair("fail", Boolean.toString(r.fail)));
params.add(new BasicNameValuePair("mod", r.mod));
params.add(new BasicNameValuePair("combo", Integer.toString(r.combo)));
params.add(new BasicNameValuePair("gameScore", Integer.toString(r.score)));
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} }
for (int y=-1;y>-10;y--) {
Color[] col = new Color[WIDTH*HEIGHT]; //Execute and get the response.
for (int i=0;i<WIDTH;i++) { HttpResponse response = null;
for (int j=0;j<HEIGHT;j++) { try {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true); response = httpclient.execute(httppost);
} } catch (IOException e) {
} e.printStackTrace();
SongData ss = SongData.compareData(col); }
if (ss!=null) { HttpEntity entity = response.getEntity();
selectedSong = ss;
found=true; if (entity != null) {
break LOOP1; try (InputStream instream = entity.getContent()) {
Scanner s = new Scanner(instream).useDelimiter("\\A");
String result = s.hasNext() ? s.next() : "";
System.out.println(result);
instream.close();
} catch (UnsupportedOperationException | IOException e) {
e.printStackTrace();
} }
} }
} }
if (!found) { results.clear();
LOOP2:
for (int x=0;x>-10;x--) { try {
for (int y=0;y<10;y++) { JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/"+USERNAME);
Color[] col = new Color[WIDTH*HEIGHT]; JSONObject obj2 = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/bestplay/"+USERNAME+"/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
for (int i=0;i<WIDTH;i++) { p.lastRating = p.overallrating;
for (int j=0;j<HEIGHT;j++) { if (obj2.has("score")) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true); double newScore = obj2.getDouble("score");
} if (newScore>p.lastScore) {
} p.bestPlayTime=System.currentTimeMillis();
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP2;
}
}
for (int y=-1;y>-10;y--) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP2;
}
} }
p.lastScore = newScore;
} }
p.overallrating = (int)obj.getDouble("rating");
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
p.pullData(selectedSong.title, difficulty);
} catch (JSONException | IOException e) {
e.printStackTrace();
} }
recordingResults=false;
} }
if (!OnResultsScreen() && recordedResults) {
recordedResults=false;
}
}
}
}
MYROBOT.refreshScreen();
}
}catch(Exception e) {
e.printStackTrace();
}
}
private boolean OnResultsScreen() throws IOException {
//r.x-418, r.y-204
/*ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)),"png",new File("color1.png"));
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,196,40,40)),"png",new File("color2.png"));
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)),"png",new File("color3.png"));*/
Color c1 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)).getRGB(0, 0));
Color c2 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,196,40,40)).getRGB(0, 0));
Color c3 = new Color(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)).getRGB(0, 0));
//System.out.println(c1+"/"+c2+"/"+c3);
return c1.getRed()>=250 && c1.getGreen()>=250 && c1.getBlue()>=250 && c2.getRed()>=10 && c2.getRed()<=25 && c2.getGreen()>=200 && c2.getGreen()<=240 && c2.getBlue()>=180 && c2.getBlue()<=220 &&
c3.getRed()>=200 && c3.getRed()<=255 && c3.getGreen()>=200 && c3.getGreen()<=255 && c3.getBlue()>=140 && c3.getBlue()<=220;
}
}, private void GetCurrentDifficulty() {
0, Color c = new Color(MYROBOT.createScreenCapture(new Rectangle(320,274,10,10)).getRGB(0, 0));
50); //return c.getRed()==43 && c.getGreen()==88 && c.getBlue()==213;
if (c.getRed()>100 && c.getRed()<200 && c.getBlue()>200 && c.getBlue()<255 && c.getGreen()<50) {
difficulty="EXEX";
} else
if (c.getRed()>150 && c.getRed()<255 && c.getBlue()<50 && c.getGreen()<50) {
difficulty="EX";
} else
if (c.getRed()>175 && c.getRed()<225 && c.getBlue()<50 && c.getGreen()<175 && c.getGreen()>135) {
difficulty="H";
} else
if (c.getRed()>0 && c.getRed()<50 && c.getBlue()<50 && c.getGreen()<255 && c.getGreen()>190) {
difficulty="N";
} else
if (c.getRed()>0 && c.getRed()<50 && c.getBlue()>170 && c.getBlue()<230 && c.getGreen()<190 && c.getGreen()>150) {
difficulty="E";
}
}
private void GetCurrentSong() throws IOException {
BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(812-10,380-10,WIDTH+20,HEIGHT+20)));
boolean found=false;
LOOP1:
for (int x=0;x<10;x++) {
for (int y=0;y<10;y++) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP1;
}
}
for (int y=-1;y>-10;y--) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP1;
}
}
}
if (!found) {
LOOP2:
for (int x=0;x>-10;x--) {
for (int y=0;y<10;y++) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP2;
}
}
for (int y=-1;y>-10;y--) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP2;
}
}
}
}
} }
void go() throws FontFormatException, IOException { void go() throws FontFormatException, IOException {

Loading…
Cancel
Save