Skip to content

Commit

Permalink
Better calculation for challenge pages
Browse files Browse the repository at this point in the history
  • Loading branch information
BradBouquio committed Jan 29, 2021
1 parent c49e841 commit 6fbf93f
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -470,24 +470,35 @@ public void populateChallengeRank(Inventory menu, PlayerInfo pi, int page, boole

private List<Rank> getRanksForPage(int page, List<Rank> ranksOnPage) {
int rowsToSkip = (page - 1) * ROWS_OF_RANKS;
for (Iterator<Rank> it = ranksOnPage.iterator(); it.hasNext(); ) {
Rank rank = it.next();
int rowsInRank = getRows(rank);
if (rowsToSkip <= 0 || ((rowsToSkip - rowsInRank) < 0)) {
List<Rank> allRanks = new ArrayList<>(ranksOnPage);

int i = 1;
for (Iterator<Rank> it = ranksOnPage.iterator(); it.hasNext(); i++) {
it.next();
int rowsInRanks = calculateRows(allRanks.subList(0,i));
if (rowsToSkip <= 0 || ((rowsToSkip - rowsInRanks) < 0)) {
return ranksOnPage;
}
rowsToSkip -= rowsInRank;
it.remove();
}
return ranksOnPage;
}

private int calculateRows(List<Rank> ranksOnPage) {
int row = 0;
int totalRows = 0;
int previousRowsOnPage = 0;
int currentRows;

for (Rank rank : ranksOnPage) {
row += getRows(rank);
currentRows = getRows(rank);
totalRows += currentRows;

if(previousRowsOnPage < 5 && (currentRows + previousRowsOnPage) > 5){
totalRows = totalRows + (5 - previousRowsOnPage);
previousRowsOnPage = currentRows;
} else previousRowsOnPage = previousRowsOnPage + currentRows;
}
return row;
return totalRows;
}

private int getRows(Rank rank) {
Expand Down

0 comments on commit 6fbf93f

Please sign in to comment.