@@ -318,25 +318,9 @@ synchronized public void updateCaps(boolean force, boolean dungeon) throws NoCon
318318 return ;
319319
320320 JsonArray rawCaps = new JsonArray ();
321- int last = 10 ;
322- for (int i =1 ; i <=last ; i ++) {
323- JsonObject raw = Json .parseObj (req .getCaptainsForSearch (i , 8 , false , true , dungeon ? SRC .Search .dungeons : SRC .Search .campaign , false , null ));
324- if (testUpdate (raw ))
325- raw = Json .parseObj (req .getCaptainsForSearch (i , 8 , false , true , dungeon ? SRC .Search .dungeons : SRC .Search .campaign , false , null ));
326-
327- JsonObject data = raw .getAsJsonObject ("data" );
328- last = data .get ("lastPage" ).getAsInt ();
329-
330- JsonArray loyalty = data .getAsJsonArray ("pveLoyalty" );
331- JsonArray captains = data .getAsJsonArray ("captains" );
332-
333- for (int j =0 ; j <loyalty .size (); j ++) {
334- captains .get (j ).getAsJsonObject ().addProperty (SRC .Raid .pveWins , loyalty .get (j ).getAsJsonObject ().getAsJsonPrimitive (SRC .Raid .pveWins ).getAsInt ());
335- captains .get (j ).getAsJsonObject ().addProperty (SRC .Raid .pveLoyaltyLevel , loyalty .get (j ).getAsJsonObject ().getAsJsonPrimitive (SRC .Raid .pveLoyaltyLevel ).getAsInt ());
336- }
337-
338- rawCaps .addAll (captains );
339- }
321+ SeedAndLastPage sap = new SeedAndLastPage ();
322+ for (int i =1 ; i <=sap .lastPage ; i ++)
323+ rawCaps .addAll (searchCap (i , sap , false , true , dungeon ? SRC .Search .dungeons : SRC .Search .campaign , false , null ));
340324
341325 Captain [] caps = new Captain [rawCaps .size ()];
342326
@@ -349,31 +333,50 @@ synchronized public void updateCaps(boolean force, boolean dungeon) throws NoCon
349333 uelis .afterUpdate ("caps::" +dungeon );
350334 }
351335
352- public synchronized void setCaps (Captain [] caps , boolean dungeon ) {
336+ synchronized public void setCaps (Captain [] caps , boolean dungeon ) {
353337 if (dungeon )
354338 dunCaps = caps ;
355339 else
356340 this .caps = caps ;
357341 }
358342
359- public JsonArray searchCap (int page , int resultsPerPage , boolean fav , boolean live , String mode , boolean searchForCaptain , String name ) throws NoConnectionException , NotAuthorizedException {
360- JsonObject rawd = Json .parseObj (req .getCaptainsForSearch (page , resultsPerPage , fav , live , mode , searchForCaptain , name ));
361- if (testUpdate (rawd ))
362- rawd = Json .parseObj (req .getCaptainsForSearch (page , resultsPerPage , fav , live , mode , searchForCaptain , name ));
343+ private static class SeedAndLastPage {
344+ public String seed = "0" ;
345+ public int lastPage = 10 ;
346+ public SeedAndLastPage () {}
347+ public SeedAndLastPage (String seed ) {
348+ this .seed = seed ;
349+ }
350+ }
351+
352+ private JsonArray searchCap (int page , SeedAndLastPage sap , boolean fav , boolean live , String mode , boolean searchForCaptain , String name ) throws NoConnectionException , NotAuthorizedException {
353+ JsonObject raw = Json .parseObj (req .getCaptainsForSearch (page , sap .seed , fav , live , mode , searchForCaptain , name ));
354+ if (testUpdate (raw ))
355+ raw = Json .parseObj (req .getCaptainsForSearch (page , sap .seed , fav , live , mode , searchForCaptain , name ));
363356
364- JsonObject raw = rawd .getAsJsonObject ("data" );
357+ JsonObject data = raw .getAsJsonObject ("data" );
365358
366- JsonArray loyalty = raw . getAsJsonArray ( "pveLoyalty" );
367- JsonArray captains = raw . getAsJsonArray ( "captains" );
359+ sap . seed = data . get ( "seed" ). getAsString ( );
360+ sap . lastPage = data . get ( "lastPage" ). getAsInt ( );
368361
369- for (int i =0 ; i <loyalty .size (); i ++) {
370- captains .get (i ).getAsJsonObject ().addProperty (SRC .Raid .pveWins , loyalty .get (i ).getAsJsonObject ().getAsJsonPrimitive (SRC .Raid .pveWins ).getAsInt ());
371- captains .get (i ).getAsJsonObject ().addProperty (SRC .Raid .pveLoyaltyLevel , loyalty .get (i ).getAsJsonObject ().getAsJsonPrimitive (SRC .Raid .pveLoyaltyLevel ).getAsInt ());
362+ JsonArray loyalty = data .getAsJsonArray ("pveLoyalty" );
363+ JsonArray captains = data .getAsJsonArray ("captains" );
364+
365+ for (int j =0 ; j <loyalty .size (); j ++) {
366+ JsonElement cap = captains .get (j );
367+ if (!cap .isJsonObject ())
368+ continue ;
369+ cap .getAsJsonObject ().addProperty (SRC .Raid .pveWins , loyalty .get (j ).getAsJsonObject ().getAsJsonPrimitive (SRC .Raid .pveWins ).getAsInt ());
370+ cap .getAsJsonObject ().addProperty (SRC .Raid .pveLoyaltyLevel , loyalty .get (j ).getAsJsonObject ().getAsJsonPrimitive (SRC .Raid .pveLoyaltyLevel ).getAsInt ());
372371 }
373372
374373 return captains ;
375374 }
376375
376+ public JsonArray searchCap (int page , String seed , boolean fav , boolean live , String mode , boolean searchForCaptain , String name ) throws NoConnectionException , NotAuthorizedException {
377+ return searchCap (page , new SeedAndLastPage (seed ), fav , live , mode , searchForCaptain , name );
378+ }
379+
377380 public Captain [] getCaps (boolean dungeon ) throws NoConnectionException , NotAuthorizedException {
378381 updateCaps (false , dungeon );
379382 return dungeon
0 commit comments