@ -162,7 +162,7 @@ public class MyRobot{
public static String USERNAME = "" ;
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 {
@ -266,315 +266,322 @@ public class MyRobot{
}
void BotMain ( ) {
lastmainlooptime = System . currentTimeMillis ( ) ;
while ( true ) {
try {
RunMainLoop ( ) ;
Thread . sleep ( 50 ) ;
} catch ( InterruptedException e ) {
e . printStackTrace ( ) ;
}
}
}
private void RunMainLoop ( ) {
try {
try {
JSONObject obj = FileUtils . readJsonFromUrl ( "http://45.33.13.215:4501/rating/" + USERNAME ) ;
p . lastRating = p . overallrating ;
p . overallrating = ( int ) obj . getDouble ( "rating" ) ;
if ( p . lastRating < p . overallrating ) { p . ratingTime = System . currentTimeMillis ( ) ; }
if ( obj . has ( "rating" ) ) {
p . overallrating = ( int ) obj . getDouble ( "rating" ) ;
if ( p . lastRating < p . overallrating ) { p . ratingTime = System . currentTimeMillis ( ) ; }
}
} catch ( JSONException e ) {
e . printStackTrace ( ) ;
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
Timer t = new Timer ( ) ;
t . scheduleAtFixedRate ( new TimerTask ( ) {
@Override
public void run ( ) {
try {
if ( CALIBRATION_MODE ) {
if ( MyRobot . calibrating ) {
MyRobot . calibrating = false ;
Overlay . OVERLAY . setVisible ( false ) ;
Thread . sleep ( 1000 ) ;
Calibrator c = new Calibrator ( ) ;
}
} else {
//ImageIO.write(MYROBOT.createScreenCapture(),"png",new File("testscreen.png"));
if ( checkSongSelect ( ) ) {
if ( ! overlayHidden ) {
overlayHidden = true ;
MyRobot . p . repaint ( ) ;
}
GetCurrentSong ( ) ;
GetCurrentDifficulty ( ) ;
recordedResults = false ;
if ( selectedSong ! = null & & difficulty ! = null ) {
if ( ! prevSongTitle . equalsIgnoreCase ( selectedSong . title ) | | ! prevDifficulty . equalsIgnoreCase ( difficulty ) ) {
System . out . println ( "On Song Select Screen: Current Song-" + selectedSong . title + " Diff:" + difficulty ) ;
p . pullData ( selectedSong . title , difficulty ) ;
prevSongTitle = selectedSong . title ;
prevDifficulty = difficulty ;
MyRobot . p . repaint ( ) ;
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 ) ;
}
}
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 ( ) ;
}
if ( CALIBRATION_MODE ) {
if ( MyRobot . calibrating ) {
MyRobot . calibrating = false ;
Overlay . OVERLAY . setVisible ( false ) ;
Thread . sleep ( 1000 ) ;
Calibrator c = new Calibrator ( ) ;
}
} else {
//ImageIO.write(MYROBOT.createScreenCapture(),"png",new File("testscreen.png"));
if ( checkSongSelect ( ) ) {
if ( ! overlayHidden ) {
overlayHidden = true ;
MyRobot . p . repaint ( ) ;
}
GetCurrentSong ( ) ;
GetCurrentDifficulty ( ) ;
recordedResults = false ;
if ( selectedSong ! = null & & difficulty ! = null ) {
if ( ! prevSongTitle . equalsIgnoreCase ( selectedSong . title ) | | ! prevDifficulty . equalsIgnoreCase ( difficulty ) ) {
System . out . println ( "On Song Select Screen: Current Song-" + selectedSong . title + " Diff:" + difficulty ) ;
MyRobot . p . refreshAllLabels ( ) ;
p . pullData ( selectedSong . title , difficulty ) ;
prevSongTitle = selectedSong . title ;
prevDifficulty = difficulty ;
MyRobot . p . repaint ( ) ;
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 ) ;
}
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 ;
}
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 ( ) ;
}
private void GetCurrentDifficulty ( ) {
Color c = new Color ( MYROBOT . createScreenCapture ( new Rectangle ( 320 , 274 , 10 , 10 ) ) . getRGB ( 0 , 0 ) ) ;
//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" ;
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 ( c . getRed ( ) > 0 & & c . getRed ( ) < 50 & & c . getBlue ( ) > 170 & & c . getBlue ( ) < 230 & & c . getGreen ( ) < 190 & & c . getGreen ( ) > 150 ) {
difficulty = "E" ;
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 ( ) ) ;
}
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 ;
}
} 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 ( ) ;
}
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 ;
//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 ( ) ;
}
}
}
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 ;
}
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 ( 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 ( ) {
Color c = new Color ( MYROBOT . createScreenCapture ( new Rectangle ( 320 , 274 , 10 , 10 ) ) . getRGB ( 0 , 0 ) ) ;
//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 ) ;
}
}
} ,
0 ,
50 ) ;
SongData ss = SongData . compareData ( col ) ;
if ( ss ! = null ) {
selectedSong = ss ;
found = true ;
break LOOP2 ;
}
}
}
}
}
void go ( ) throws FontFormatException , IOException {